Skip to content

Commit a2c5dea

Browse files
committed
Add EXPORT_RAW_BLOB option and -raw_blob flag for compile_tool
1 parent 4d25dd6 commit a2c5dea

File tree

7 files changed

+62
-18
lines changed

7 files changed

+62
-18
lines changed

src/plugins/intel_npu/src/al/include/intel_npu/config/options.hpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1291,6 +1291,26 @@ struct DISABLE_VERSION_CHECK final : OptionBase<DISABLE_VERSION_CHECK, bool> {
12911291
}
12921292
};
12931293

1294+
struct EXPORT_RAW_BLOB final : OptionBase<EXPORT_RAW_BLOB, bool> {
1295+
static std::string_view key() {
1296+
return ov::intel_npu::export_raw_blob.name();
1297+
}
1298+
1299+
static bool defaultValue() {
1300+
return false;
1301+
}
1302+
1303+
#ifdef NPU_PLUGIN_DEVELOPER_BUILD
1304+
static std::string_view envVar() {
1305+
return "OV_NPU_EXPORT_RAW_BLOB";
1306+
}
1307+
#endif
1308+
1309+
static OptionMode mode() {
1310+
return OptionMode::RunTime;
1311+
}
1312+
};
1313+
12941314
struct BATCH_COMPILER_MODE_SETTINGS final : OptionBase<BATCH_COMPILER_MODE_SETTINGS, std::string> {
12951315
static std::string_view key() {
12961316
return ov::intel_npu::batch_compiler_mode_settings.name();

src/plugins/intel_npu/src/al/include/intel_npu/npu_private_properties.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,5 +493,12 @@ static constexpr ov::Property<std::string> backend_compilation_params{"NPU_BACKE
493493
*/
494494
static constexpr ov::Property<bool> disable_version_check{"NPU_DISABLE_VERSION_CHECK"};
495495

496+
/**
497+
* @brief [Only for NPU Plugin]
498+
* Type: boolean, default is false.
499+
* This option allows to skip writing plugin metadata to compiled model when exporting it
500+
*/
501+
static constexpr ov::Property<bool> export_raw_blob{"NPU_EXPORT_RAW_BLOB"};
502+
496503
} // namespace intel_npu
497504
} // namespace ov

src/plugins/intel_npu/src/common/src/filtered_config.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ bool FilteredConfig::isAvailable(std::string key) const {
4949
if (it != _enabled.end() && hasOpt(key)) {
5050
return it->second;
5151
}
52-
// if doesnt exist = not available
52+
// if doesn't exist = not available
5353
return false;
5454
}
5555

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

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -91,25 +91,27 @@ void CompiledModel::export_model(std::ostream& stream) const {
9191

9292
auto [blobSizesBeforeVersioning, initBlobSizes] = _graph->export_blob(stream);
9393

94-
std::optional<std::vector<ov::Layout>> inputLayouts = std::vector<ov::Layout>();
95-
std::optional<std::vector<ov::Layout>> outputLayouts = std::vector<ov::Layout>();
94+
if (!_config.get<EXPORT_RAW_BLOB>()) {
95+
std::optional<std::vector<ov::Layout>> inputLayouts = std::vector<ov::Layout>();
96+
std::optional<std::vector<ov::Layout>> outputLayouts = std::vector<ov::Layout>();
9697

97-
for (const ov::Output<const ov::Node>& nodeOutput : inputs()) {
98-
inputLayouts->push_back(
99-
std::dynamic_pointer_cast<const ov::op::v0::Parameter>(nodeOutput.get_node_shared_ptr())->get_layout());
100-
}
101-
for (const ov::Output<const ov::Node>& nodeOutput : outputs()) {
102-
outputLayouts->push_back(
103-
std::dynamic_pointer_cast<const ov::op::v0::Result>(nodeOutput.get_node_shared_ptr())->get_layout());
104-
}
98+
for (const ov::Output<const ov::Node>& nodeOutput : inputs()) {
99+
inputLayouts->push_back(
100+
std::dynamic_pointer_cast<const ov::op::v0::Parameter>(nodeOutput.get_node_shared_ptr())->get_layout());
101+
}
102+
for (const ov::Output<const ov::Node>& nodeOutput : outputs()) {
103+
outputLayouts->push_back(
104+
std::dynamic_pointer_cast<const ov::op::v0::Result>(nodeOutput.get_node_shared_ptr())->get_layout());
105+
}
105106

106-
Metadata<CURRENT_METADATA_VERSION>(blobSizesBeforeVersioning,
107-
CURRENT_OPENVINO_VERSION,
108-
initBlobSizes,
109-
_batchSize,
110-
inputLayouts,
111-
outputLayouts)
112-
.write(stream);
107+
Metadata<CURRENT_METADATA_VERSION>(blobSizesBeforeVersioning,
108+
CURRENT_OPENVINO_VERSION,
109+
std::move(initBlobSizes),
110+
_batchSize,
111+
std::move(inputLayouts),
112+
std::move(outputLayouts))
113+
.write(stream);
114+
}
113115
}
114116

115117
std::shared_ptr<const ov::Model> CompiledModel::get_runtime_model() const {

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,7 @@ void Plugin::init_options() {
315315
REGISTER_OPTION(STEPPING);
316316
REGISTER_OPTION(MAX_TILES);
317317
REGISTER_OPTION(DISABLE_VERSION_CHECK);
318+
REGISTER_OPTION(EXPORT_RAW_BLOB);
318319
REGISTER_OPTION(BATCH_COMPILER_MODE_SETTINGS);
319320
REGISTER_OPTION(TURBO);
320321
REGISTER_OPTION(WEIGHTLESS_BLOB);

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,7 @@ void Properties::registerPluginProperties() {
379379
TRY_REGISTER_SIMPLE_PROPERTY(ov::intel_npu::qdq_optimization, QDQ_OPTIMIZATION);
380380
TRY_REGISTER_SIMPLE_PROPERTY(ov::intel_npu::qdq_optimization_aggressive, QDQ_OPTIMIZATION_AGGRESSIVE);
381381
TRY_REGISTER_SIMPLE_PROPERTY(ov::intel_npu::disable_version_check, DISABLE_VERSION_CHECK);
382+
TRY_REGISTER_SIMPLE_PROPERTY(ov::intel_npu::export_raw_blob, EXPORT_RAW_BLOB);
382383
TRY_REGISTER_SIMPLE_PROPERTY(ov::intel_npu::batch_compiler_mode_settings, BATCH_COMPILER_MODE_SETTINGS);
383384
TRY_REGISTER_SIMPLE_PROPERTY(ov::hint::enable_cpu_pinning, ENABLE_CPU_PINNING);
384385
TRY_REGISTER_SIMPLE_PROPERTY(ov::workload_type, WORKLOAD_TYPE);
@@ -618,6 +619,7 @@ void Properties::registerCompiledModelProperties() {
618619
TRY_REGISTER_COMPILEDMODEL_PROPERTY_IFSET(ov::intel_npu::qdq_optimization, QDQ_OPTIMIZATION);
619620
TRY_REGISTER_COMPILEDMODEL_PROPERTY_IFSET(ov::intel_npu::qdq_optimization_aggressive, QDQ_OPTIMIZATION_AGGRESSIVE);
620621
TRY_REGISTER_COMPILEDMODEL_PROPERTY_IFSET(ov::intel_npu::disable_version_check, DISABLE_VERSION_CHECK);
622+
TRY_REGISTER_COMPILEDMODEL_PROPERTY_IFSET(ov::intel_npu::export_raw_blob, EXPORT_RAW_BLOB);
621623
TRY_REGISTER_COMPILEDMODEL_PROPERTY_IFSET(ov::intel_npu::batch_compiler_mode_settings,
622624
BATCH_COMPILER_MODE_SETTINGS);
623625
TRY_REGISTER_COMPILEDMODEL_PROPERTY_IFSET(ov::intel_npu::run_inferences_sequentially, RUN_INFERENCES_SEQUENTIALLY);

src/plugins/intel_npu/tools/compile_tool/main.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ static constexpr char targetDeviceMessage[] =
3333

3434
static constexpr char output_message[] = "Optional. Path to the output file. Default value: \"<model_xml_file>.blob\".";
3535

36+
static constexpr char raw_blob_message[] =
37+
"Optional. Specifies if the output blob should NOT contain NPU plugin metadata placed at the beginning of it.";
38+
3639
static constexpr char log_level_message[] = "Optional. Log level for OpenVINO library.";
3740

3841
static constexpr char config_message[] = "Optional. Path to the configuration file.";
@@ -85,6 +88,7 @@ DEFINE_bool(h, false, help_message);
8588
DEFINE_string(m, "", model_message);
8689
DEFINE_string(d, "", targetDeviceMessage);
8790
DEFINE_string(o, "", output_message);
91+
DEFINE_bool(raw_blob, false, raw_blob_message);
8892
DEFINE_string(log_level, "", log_level_message);
8993
DEFINE_string(c, "", config_message);
9094
DEFINE_bool(pc, false, perf_count_message);
@@ -320,6 +324,7 @@ static void showUsage() {
320324
std::cout << " -m <value> " << model_message << std::endl;
321325
std::cout << " -d <value> " << targetDeviceMessage << std::endl;
322326
std::cout << " -o <value> " << output_message << std::endl;
327+
std::cout << " -raw_blob " << raw_blob_message << std::endl;
323328
std::cout << " -c <value> " << config_message << std::endl;
324329
std::cout << " -ip <value> " << inputs_precision_message << std::endl;
325330
std::cout << " -op <value> " << outputs_precision_message << std::endl;
@@ -484,6 +489,13 @@ int main(int argc, char* argv[]) {
484489
if (FLAGS_pc) {
485490
configs["PERF_COUNT"] = "YES";
486491
}
492+
if (FLAGS_raw_blob) {
493+
if (FLAGS_d == "NPU") {
494+
configs["NPU_EXPORT_RAW_BLOB"] = "YES";
495+
} else {
496+
std::cout << "Ignoring -raw_blob flag used with other device than NPU." << std::endl;
497+
}
498+
}
487499

488500
std::cout << "Compiling model" << std::endl;
489501
auto compiledModel = core.compile_model(model, FLAGS_d, {configs.begin(), configs.end()});

0 commit comments

Comments
 (0)