Skip to content

Commit 44f7a0d

Browse files
Implementing the export path for the CiD branch
1 parent 9b688b6 commit 44f7a0d

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed

src/plugins/intel_npu/src/compiler_adapter/include/driver_graph.hpp

+4
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ class DriverGraph final : public IGraph {
2525

2626
void export_blob(std::ostream& stream) const override;
2727

28+
void custom_export(std::ostream& stream,
29+
const std::shared_ptr<IGraph> initGraph,
30+
const std::shared_ptr<ov::Model> initModel) const override;
31+
2832
std::vector<ov::ProfilingInfo> process_profiling_output(const std::vector<uint8_t>& profData,
2933
const Config& config) const override;
3034

src/plugins/intel_npu/src/compiler_adapter/src/driver_graph.cpp

+57
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
#include "intel_npu/config/common.hpp"
88
#include "intel_npu/config/runtime.hpp"
99
#include "intel_npu/utils/zero/zero_api.hpp"
10+
#include "openvino/pass/manager.hpp"
11+
#include "openvino/pass/serialize.hpp"
1012

1113
namespace intel_npu {
1214

@@ -63,6 +65,61 @@ void DriverGraph::export_blob(std::ostream& stream) const {
6365
_logger.info("Write blob to stream successfully.");
6466
}
6567

68+
void DriverGraph::custom_export(std::ostream& stream,
69+
const std::shared_ptr<IGraph> initGraph,
70+
const std::shared_ptr<ov::Model> initModel) const {
71+
const uint8_t* initBlobPtr = nullptr;
72+
const uint8_t* mainBlobPtr = nullptr;
73+
size_t initBlobSize = -1;
74+
size_t mainBlobSize = -1;
75+
std::vector<uint8_t> initBlob;
76+
std::vector<uint8_t> mainBlob;
77+
78+
if (_blobIsReleased) {
79+
OPENVINO_THROW("Model was imported (not compiled) by the plugin. Model export is forbidden in this case!");
80+
}
81+
82+
_zeGraphExt->getGraphBinary(initGraph->get_handle(), initBlob, initBlobPtr, initBlobSize);
83+
_zeGraphExt->getGraphBinary(_handle, mainBlob, mainBlobPtr, mainBlobSize);
84+
85+
std::stringstream xmlContent;
86+
std::stringstream binContent;
87+
88+
ov::pass::Manager manager("SaveModel");
89+
manager.register_pass<ov::pass::Serialize>(xmlContent, binContent);
90+
manager.run_passes(initModel);
91+
92+
xmlContent.seekg(0, std::ios::end);
93+
uint32_t xmlSize = xmlContent.tellp();
94+
xmlContent.seekg(0, std::ios::beg);
95+
binContent.seekg(0, std::ios::end);
96+
uint32_t binSize = binContent.tellp();
97+
binContent.seekg(0, std::ios::beg);
98+
99+
stream << xmlSize;
100+
stream << xmlContent.rdbuf();
101+
102+
stream << binSize;
103+
stream << binContent.rdbuf();
104+
105+
stream << mainBlobSize;
106+
stream.write(reinterpret_cast<const char*>(mainBlobPtr), mainBlobSize);
107+
108+
stream << initBlobSize;
109+
stream.write(reinterpret_cast<const char*>(initBlobPtr), initBlobSize);
110+
111+
if (!stream) {
112+
_logger.error("Write blob to stream failed. Blob is broken!");
113+
} else {
114+
if (_logger.level() >= ov::log::Level::INFO) {
115+
std::stringstream str;
116+
str << "Blob size: " << mainBlobSize + initBlobSize + 4 * sizeof(uint32_t) + xmlSize + binSize << std::endl;
117+
_logger.info(str.str().c_str());
118+
}
119+
_logger.info("Write blob to stream successfully.");
120+
}
121+
}
122+
66123
std::vector<ov::ProfilingInfo> DriverGraph::process_profiling_output(const std::vector<uint8_t>& profData,
67124
const Config& config) const {
68125
OPENVINO_THROW("Profiling post-processing is not supported.");

0 commit comments

Comments
 (0)