Skip to content

Commit 3d14fbf

Browse files
Compilable and exportable
1 parent 545f540 commit 3d14fbf

File tree

9 files changed

+44
-32
lines changed

9 files changed

+44
-32
lines changed

src/plugins/intel_npu/src/common/include/intel_npu/common/blob_reader.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class BlobReader {
2828
void copy_data_from_source(char* destination, const size_t size);
2929

3030
template <class T>
31-
void interpret_data_from_source(T& destination);
31+
void interpret_data_from_source(T*& destination);
3232

3333
ov::Tensor get_roi_tensor(const size_t size);
3434

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ class BlobWriter {
3434
private:
3535
std::unordered_set<SectionID> m_registered_sections_ids;
3636
std::queue<std::shared_ptr<ISection>> m_registered_sections;
37-
std::shared_ptr<std::unordered_map<SectionID, uint64_t>> m_offsets_table;
3837
std::shared_ptr<CRESection> m_cre;
38+
std::shared_ptr<std::unordered_map<SectionID, uint64_t>> m_offsets_table;
3939

4040
/**
4141
* @brief TODO

src/plugins/intel_npu/src/common/src/blob_reader.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ void BlobReader::copy_data_from_source(char* destination, const size_t size) {
4141
}
4242

4343
template <class T>
44-
void BlobReader::interpret_data_from_source(T& destination) {
45-
destination = reinterpret_cast<T>(m_source.get().data<const char>());
46-
m_cursor += sizeof(&T);
44+
void BlobReader::interpret_data_from_source(T*& destination) {
45+
destination = reinterpret_cast<T*>(m_source.get().data<const char>());
46+
m_cursor += sizeof(T);
4747
}
4848

4949
ov::Tensor BlobReader::get_roi_tensor(const size_t size) {

src/plugins/intel_npu/src/common/src/blob_writer.cpp

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,23 @@ BlobWriter::BlobWriter()
2222
m_offsets_table(std::make_shared<std::unordered_map<SectionID, uint64_t>>()),
2323
m_logger("BlobWriter", Logger::global().level()) {
2424
register_section(m_cre);
25+
append_compatibility_requirement(CRE::PredefinedCapabilityToken::CRE_EVALUATION);
2526
}
2627

27-
BlobWriter::BlobWriter(const std::shared_ptr<BlobReader>& blob_reader) {
28-
// TODO after reader is done, while constructing the compiledModel
28+
BlobWriter::BlobWriter(const std::shared_ptr<BlobReader>& blob_reader)
29+
: m_cre(std::dynamic_pointer_cast<CRESection>(blob_reader->retrieve_section(PredefinedSectionID::CRE))),
30+
m_offsets_table(blob_reader->m_offsets_table),
31+
m_logger("BlobWriter", Logger::global().level()) {
32+
// TODO review the class const qualifiers
33+
// TODO handle offsets table section properly, multiple exports
34+
std::unordered_map<SectionID, std::shared_ptr<ISection>> m_parsed_sections;
35+
for (const auto& [section_id, section] : m_parsed_sections) {
36+
// The offsets table section is added by the write() method after writing all registered sections (jic the
37+
// registered sections will alter the table). Therefore, this section should be omitted here.
38+
if (section_id != PredefinedSectionID::OFFSETS_TABLE) {
39+
register_section(section);
40+
}
41+
}
2942
}
3043

3144
void BlobWriter::register_section(const std::shared_ptr<ISection>& section) {
@@ -82,15 +95,14 @@ void BlobWriter::write(std::ostream& stream) {
8295
std::optional<uint64_t> length = section->get_length();
8396

8497
if (length.has_value()) {
85-
auto position_before_write = stream.tellp();
8698
stream.write(reinterpret_cast<const char*>(&length.value()), sizeof(length.value()));
99+
auto position_before_write = stream.tellp();
87100
section->write(stream, this);
88101

89-
std::cout << typeid(*section.get()).name() << std::endl;
90-
OPENVINO_ASSERT(length.value() == stream.tellp() - position_before_write,
102+
OPENVINO_ASSERT(length.value() == static_cast<uint64_t>(stream.tellp() - position_before_write),
91103
"Mismatch between the length provided by the section class and the size written in the "
92-
"blob. Section type: ",
93-
typeid(*section.get()).name());
104+
"blob. Section ID: ",
105+
section_id); // TODO name via macro maybe
94106
} else {
95107
// Use the cursor to deduce the length
96108
uint64_t length = 0; // placeholder

src/plugins/intel_npu/src/common/src/cre.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ inline bool or_function(bool a, bool b) {
2525

2626
namespace intel_npu {
2727

28-
CRE::CRE() : m_expression({CRE::AND}) {}
28+
CRE::CRE() : m_expression({CRE::AND}) {} // TODO can lead to expression with 0 or 1 operands, fix that
2929

3030
void CRE::write(std::ostream& stream) {
31-
stream.write(reinterpret_cast<const char*>(m_expression.data()), m_expression.size());
31+
stream.write(reinterpret_cast<const char*>(m_expression.data()), m_expression.size() * sizeof(Token));
3232
}
3333

3434
void CRE::append_to_expression(const CRE::Token requirement_token) {
@@ -135,7 +135,7 @@ void CRESection::write(std::ostream& stream, BlobWriter* writer) {
135135
}
136136

137137
std::optional<uint64_t> CRESection::get_length() const {
138-
return m_cre.get_expression_length();
138+
return m_cre.get_expression_length() * sizeof(CRE::Token);
139139
}
140140

141141
bool CRESection::check_compatibility(const std::unordered_set<CRE::Token>& plugin_capabilities) {

src/plugins/intel_npu/src/common/src/offsets_table.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ OffsetsTableSection::OffsetsTableSection(const std::shared_ptr<std::unordered_ma
1515

1616
void OffsetsTableSection::write(std::ostream& stream, BlobWriter* writer) {
1717
for (const auto& [key, value] : *m_offsets_table) {
18-
stream.write(reinterpret_cast<const char*>(key), sizeof(key));
19-
stream.write(reinterpret_cast<const char*>(value), sizeof(value));
18+
stream.write(reinterpret_cast<const char*>(&key), sizeof(key));
19+
stream.write(reinterpret_cast<const char*>(&value), sizeof(value));
2020
}
2121
}
2222

src/plugins/intel_npu/src/compiler_adapter/src/compiler_schedules_sections.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ std::shared_ptr<ISection> ELFInitSchedulesSection::read(BlobReader* blob_reader,
101101

102102
std::vector<ov::Tensor> init_schedules;
103103
for (const auto& init_size : init_sizes) {
104-
init_schedules.push_back(blob_reader->get_roi_tensor(section_length));
104+
init_schedules.push_back(blob_reader->get_roi_tensor(init_size));
105105
}
106106

107107
return std::make_shared<ELFInitSchedulesSection>(init_schedules);

src/plugins/intel_npu/src/plugin/src/io_layouts_section.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,11 @@ std::shared_ptr<ISection> IOLayoutsSection::read(BlobReader* blob_reader, const
9292
try {
9393
layouts.push_back(ov::Layout(std::move(layoutString)));
9494
} catch (const ov::Exception&) {
95-
_logger.warning("Error encountered while constructing an ov::Layout object. %s index: %d. Value "
96-
"read from blob: %s. A default value will be used instead.",
97-
logger_addition,
98-
layout_index,
99-
layoutString.c_str());
95+
logger.warning("Error encountered while constructing an ov::Layout object. %s index: %d. Value "
96+
"read from blob: %s. A default value will be used instead.",
97+
logger_addition,
98+
layout_index,
99+
layoutString.c_str());
100100
layouts.push_back(ov::Layout());
101101
}
102102
}

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#include "batch_size_section.hpp"
1010
#include "compiled_model.hpp"
1111
#include "compiler_adapter_factory.hpp"
12-
#include "compiler_schedules_section.hpp"
12+
#include "compiler_schedules_sections.hpp"
1313
#include "driver_compiler_adapter.hpp"
1414
#include "intel_npu/common/blob_reader.hpp"
1515
#include "intel_npu/common/blob_writer.hpp"
@@ -1155,18 +1155,18 @@ std::shared_ptr<ov::ICompiledModel> Plugin::parse(const ov::Tensor& tensorBig, c
11551155
}
11561156

11571157
auto graph = compiler->parse(
1158-
mainScheduleSection->get_main_schedule(),
1158+
mainScheduleSection->get_schedule(),
11591159
localConfig,
1160-
weightsSeparationEnabled ? std::make_optional(initSchedulesSection->get_init_schedules()) : std::nullopt,
1160+
weightsSeparationEnabled ? std::make_optional(initSchedulesSection->get_schedules()) : std::nullopt,
11611161
weightsSeparationEnabled ? std::make_optional(originalModel) : std::nullopt);
11621162

11631163
graph->update_network_name("net" + std::to_string(_compiledModelLoadCounter++));
1164-
const std::shared_ptr<ov::Model> modelDummy =
1165-
create_dummy_model(graph->get_metadata().inputs,
1166-
graph->get_metadata().outputs,
1167-
batchSize,
1168-
ioLayoutsSection != nullptr ? ioLayoutsSection->get_input_layouts() : std::nullopt,
1169-
ioLayoutsSection != nullptr ? ioLayoutsSection->get_output_layouts() : std::nullopt);
1164+
const std::shared_ptr<ov::Model> modelDummy = create_dummy_model(
1165+
graph->get_metadata().inputs,
1166+
graph->get_metadata().outputs,
1167+
batchSize,
1168+
ioLayoutsSection != nullptr ? std::make_optional<>(ioLayoutsSection->get_input_layouts()) : std::nullopt,
1169+
ioLayoutsSection != nullptr ? std::make_optional<>(ioLayoutsSection->get_output_layouts()) : std::nullopt);
11701170

11711171
if (batchSize.has_value()) {
11721172
if (batchSize.value() > 0) {

0 commit comments

Comments
 (0)