Skip to content

Commit dbe1b41

Browse files
committed
Add EXPORT_RAW_BLOB option and -raw_blob flag for compile_tool
1 parent 5fb69ea commit dbe1b41

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
@@ -1313,6 +1313,26 @@ struct DISABLE_VERSION_CHECK final : OptionBase<DISABLE_VERSION_CHECK, bool> {
13131313
}
13141314
};
13151315

1316+
struct EXPORT_RAW_BLOB final : OptionBase<EXPORT_RAW_BLOB, bool> {
1317+
static std::string_view key() {
1318+
return ov::intel_npu::export_raw_blob.name();
1319+
}
1320+
1321+
static bool defaultValue() {
1322+
return false;
1323+
}
1324+
1325+
#ifdef NPU_PLUGIN_DEVELOPER_BUILD
1326+
static std::string_view envVar() {
1327+
return "OV_NPU_EXPORT_RAW_BLOB";
1328+
}
1329+
#endif
1330+
1331+
static OptionMode mode() {
1332+
return OptionMode::RunTime;
1333+
}
1334+
};
1335+
13161336
struct BATCH_COMPILER_MODE_SETTINGS final : OptionBase<BATCH_COMPILER_MODE_SETTINGS, std::string> {
13171337
static std::string_view key() {
13181338
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
@@ -444,5 +444,12 @@ static constexpr ov::Property<std::string> backend_compilation_params{"NPU_BACKE
444444
*/
445445
static constexpr ov::Property<bool> disable_version_check{"NPU_DISABLE_VERSION_CHECK"};
446446

447+
/**
448+
* @brief [Only for NPU Plugin]
449+
* Type: boolean, default is false.
450+
* This option allows to skip writing plugin metadata to compiled model when exporting it
451+
*/
452+
static constexpr ov::Property<bool> export_raw_blob{"NPU_EXPORT_RAW_BLOB"};
453+
447454
} // namespace intel_npu
448455
} // 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
@@ -86,25 +86,27 @@ void CompiledModel::export_model(std::ostream& stream) const {
8686

8787
auto [blobSizesBeforeVersioning, initBlobSizes] = _graph->export_blob(stream);
8888

89-
std::optional<std::vector<ov::Layout>> inputLayouts = std::vector<ov::Layout>();
90-
std::optional<std::vector<ov::Layout>> outputLayouts = std::vector<ov::Layout>();
89+
if (!_config.get<EXPORT_RAW_BLOB>()) {
90+
std::optional<std::vector<ov::Layout>> inputLayouts = std::vector<ov::Layout>();
91+
std::optional<std::vector<ov::Layout>> outputLayouts = std::vector<ov::Layout>();
9192

92-
for (const ov::Output<const ov::Node>& nodeOutput : inputs()) {
93-
inputLayouts->push_back(
94-
std::dynamic_pointer_cast<const ov::op::v0::Parameter>(nodeOutput.get_node_shared_ptr())->get_layout());
95-
}
96-
for (const ov::Output<const ov::Node>& nodeOutput : outputs()) {
97-
outputLayouts->push_back(
98-
std::dynamic_pointer_cast<const ov::op::v0::Result>(nodeOutput.get_node_shared_ptr())->get_layout());
99-
}
93+
for (const ov::Output<const ov::Node>& nodeOutput : inputs()) {
94+
inputLayouts->push_back(
95+
std::dynamic_pointer_cast<const ov::op::v0::Parameter>(nodeOutput.get_node_shared_ptr())->get_layout());
96+
}
97+
for (const ov::Output<const ov::Node>& nodeOutput : outputs()) {
98+
outputLayouts->push_back(
99+
std::dynamic_pointer_cast<const ov::op::v0::Result>(nodeOutput.get_node_shared_ptr())->get_layout());
100+
}
100101

101-
Metadata<CURRENT_METADATA_VERSION>(blobSizesBeforeVersioning,
102-
CURRENT_OPENVINO_VERSION,
103-
initBlobSizes,
104-
_batchSize,
105-
inputLayouts,
106-
outputLayouts)
107-
.write(stream);
102+
Metadata<CURRENT_METADATA_VERSION>(blobSizesBeforeVersioning,
103+
CURRENT_OPENVINO_VERSION,
104+
std::move(initBlobSizes),
105+
_batchSize,
106+
std::move(inputLayouts),
107+
std::move(outputLayouts))
108+
.write(stream);
109+
}
108110
}
109111

110112
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
@@ -316,6 +316,7 @@ void Plugin::init_options() {
316316
REGISTER_OPTION(STEPPING);
317317
REGISTER_OPTION(MAX_TILES);
318318
REGISTER_OPTION(DISABLE_VERSION_CHECK);
319+
REGISTER_OPTION(EXPORT_RAW_BLOB);
319320
REGISTER_OPTION(BATCH_COMPILER_MODE_SETTINGS);
320321
REGISTER_OPTION(TURBO);
321322
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
@@ -378,6 +378,7 @@ void Properties::registerPluginProperties() {
378378
TRY_REGISTER_SIMPLE_PROPERTY(ov::intel_npu::qdq_optimization, QDQ_OPTIMIZATION);
379379
TRY_REGISTER_SIMPLE_PROPERTY(ov::intel_npu::qdq_optimization_aggressive, QDQ_OPTIMIZATION_AGGRESSIVE);
380380
TRY_REGISTER_SIMPLE_PROPERTY(ov::intel_npu::disable_version_check, DISABLE_VERSION_CHECK);
381+
TRY_REGISTER_SIMPLE_PROPERTY(ov::intel_npu::export_raw_blob, EXPORT_RAW_BLOB);
381382
TRY_REGISTER_SIMPLE_PROPERTY(ov::intel_npu::batch_compiler_mode_settings, BATCH_COMPILER_MODE_SETTINGS);
382383
TRY_REGISTER_SIMPLE_PROPERTY(ov::hint::enable_cpu_pinning, ENABLE_CPU_PINNING);
383384
TRY_REGISTER_SIMPLE_PROPERTY(ov::workload_type, WORKLOAD_TYPE);
@@ -617,6 +618,7 @@ void Properties::registerCompiledModelProperties() {
617618
TRY_REGISTER_COMPILEDMODEL_PROPERTY_IFSET(ov::intel_npu::qdq_optimization, QDQ_OPTIMIZATION);
618619
TRY_REGISTER_COMPILEDMODEL_PROPERTY_IFSET(ov::intel_npu::qdq_optimization_aggressive, QDQ_OPTIMIZATION_AGGRESSIVE);
619620
TRY_REGISTER_COMPILEDMODEL_PROPERTY_IFSET(ov::intel_npu::disable_version_check, DISABLE_VERSION_CHECK);
621+
TRY_REGISTER_COMPILEDMODEL_PROPERTY_IFSET(ov::intel_npu::export_raw_blob, EXPORT_RAW_BLOB);
620622
TRY_REGISTER_COMPILEDMODEL_PROPERTY_IFSET(ov::intel_npu::batch_compiler_mode_settings,
621623
BATCH_COMPILER_MODE_SETTINGS);
622624
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)