Skip to content

Commit 6f21d77

Browse files
Filling some basic functions
1 parent e8120dd commit 6f21d77

File tree

6 files changed

+63
-15
lines changed

6 files changed

+63
-15
lines changed

src/plugins/intel_npu/src/plugin/include/blob_writer.hpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,23 @@ class BlobWriter {
1919
public:
2020
BlobWriter();
2121

22-
void register_section(const ISection& section);
22+
void register_section(const std::shared_ptr<ISection>& section);
2323

2424
void register_offset_in_table(const ISection::SectionID id, const uint64_t offset);
2525

2626
void write(std::ostream& stream, const std::shared_ptr<IGraph>& graph);
2727

2828
void append_compatibility_requirement(const CREToken requirement_token);
2929

30-
private:
31-
void register_cre();
30+
size_t offset = 0;
3231

32+
private:
3333
void write_persistent_format_region();
3434

35-
std::unordered_set<ISection::SectionID> registered_sections_ids;
36-
std::vector<ISection> registered_sections;
37-
std::unordered_map<ISection::SectionID, uint64_t> offsets_table;
38-
CRESection cre;
35+
std::unordered_set<ISection::SectionID> m_registered_sections_ids;
36+
std::vector<std::shared_ptr<ISection>> m_registered_sections;
37+
std::unordered_map<ISection::SectionID, uint64_t> m_offsets_table;
38+
std::shared_ptr<CRESection> m_cre;
3939
};
4040

4141
} // namespace intel_npu

src/plugins/intel_npu/src/plugin/include/cre.hpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ using CREToken = uint16_t;
1212

1313
class CRESection final : public ISection {
1414
public:
15-
static constexpr SectionID id = 100;
16-
1715
CRESection();
1816

1917
void write(std::ostream& stream, BlobWriter* writer) override;
@@ -23,7 +21,7 @@ class CRESection final : public ISection {
2321
void append_to_expression(const CREToken requirement_token);
2422

2523
private:
26-
std::vector<CREToken> expression;
24+
std::vector<CREToken> m_expression;
2725
};
2826

2927
} // namespace intel_npu

src/plugins/intel_npu/src/plugin/include/isection.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class ISection {
2727
SectionID get_section_id();
2828

2929
private:
30-
SectionID section_id;
30+
SectionID m_section_id;
3131
};
3232

3333
} // namespace intel_npu

src/plugins/intel_npu/src/plugin/src/blob_writer.cpp

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,23 @@
66

77
namespace intel_npu {
88

9-
BlobWriter::BlobWriter() {
10-
register_cre();
9+
BlobWriter::BlobWriter() : m_cre(std::make_shared<CRESection>()) {
10+
register_section(m_cre);
11+
}
12+
13+
void BlobWriter::register_section(const std::shared_ptr<ISection>& section) {
14+
m_registered_sections.push_back(section);
15+
OPENVINO_ASSERT(!m_registered_sections_ids.count(section->get_section_id()));
16+
m_registered_sections_ids.insert(section->get_section_id());
17+
}
18+
19+
void BlobWriter::append_compatibility_requirement(const CREToken requirement_token) {
20+
m_cre->append_to_expression(requirement_token);
21+
}
22+
23+
void BlobWriter::register_offset_in_table(const ISection::SectionID id, const uint64_t offset) {
24+
OPENVINO_ASSERT(!m_offsets_table.count(id));
25+
m_offsets_table[id] = offset;
1126
}
1227

1328
} // namespace intel_npu

src/plugins/intel_npu/src/plugin/src/cre.cpp

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,31 @@
44

55
#include "cre.hpp"
66

7-
namespace intel_npu {} // namespace intel_npu
7+
namespace {
8+
9+
constexpr intel_npu::ISection::SectionID CRE_SECTION_ID = 100;
10+
11+
constexpr intel_npu::CREToken AND = 50000;
12+
constexpr intel_npu::CREToken OR = 50001;
13+
constexpr intel_npu::CREToken OPEN = 50002;
14+
constexpr intel_npu::CREToken CLOSE = 50003;
15+
16+
const std::unordered_set<intel_npu::CREToken> RESERVED_TOKENS{AND, OR, OPEN, CLOSE};
17+
18+
} // namespace
19+
20+
namespace intel_npu {
21+
22+
CRESection::CRESection() : ISection(CRE_SECTION_ID), m_expression({AND}) {}
23+
24+
void CRESection::append_to_expression(const CREToken requirement_token) {
25+
OPENVINO_ASSERT(!RESERVED_TOKENS.count(requirement_token));
26+
m_expression.push_back(requirement_token);
27+
}
28+
29+
void CRESection::write(std::ostream& stream, BlobWriter* writer) {
30+
stream.write(reinterpret_cast<const char*>(m_expression.data()), m_expression.size());
31+
writer->offset += m_expression.size();
32+
}
33+
34+
} // namespace intel_npu

src/plugins/intel_npu/src/plugin/src/isection.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,12 @@
44

55
#include "isection.hpp"
66

7-
namespace intel_npu {} // namespace intel_npu
7+
namespace intel_npu {
8+
9+
ISection::ISection(const SectionID section_id) : m_section_id(section_id) {}
10+
11+
ISection::SectionID ISection::get_section_id() {
12+
return m_section_id;
13+
}
14+
15+
} // namespace intel_npu

0 commit comments

Comments
 (0)