|
7 | 7 | #include "intel_npu/config/common.hpp"
|
8 | 8 | #include "intel_npu/config/runtime.hpp"
|
9 | 9 | #include "intel_npu/utils/zero/zero_api.hpp"
|
| 10 | +#include "openvino/pass/manager.hpp" |
| 11 | +#include "openvino/pass/serialize.hpp" |
10 | 12 |
|
11 | 13 | namespace intel_npu {
|
12 | 14 |
|
@@ -63,6 +65,61 @@ void DriverGraph::export_blob(std::ostream& stream) const {
|
63 | 65 | _logger.info("Write blob to stream successfully.");
|
64 | 66 | }
|
65 | 67 |
|
| 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 | + |
66 | 123 | std::vector<ov::ProfilingInfo> DriverGraph::process_profiling_output(const std::vector<uint8_t>& profData,
|
67 | 124 | const Config& config) const {
|
68 | 125 | OPENVINO_THROW("Profiling post-processing is not supported.");
|
|
0 commit comments