Skip to content

Commit f7f65f3

Browse files
committed
Export init and main separately
1 parent 9f8c1dd commit f7f65f3

File tree

3 files changed

+81
-53
lines changed

3 files changed

+81
-53
lines changed

src/plugins/intel_npu/src/plugin/include/compiled_model.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ class CompiledModel final : public ICompiledModel {
8080
std::map<std::string, std::tuple<bool, ov::PropertyMutability, std::function<ov::Any(const Config&)>>> _properties;
8181
std::vector<ov::PropertyName> _supportedProperties;
8282

83+
// mutable bool exportInitFlag = false;
8384
std::shared_ptr<IGraph> _graph;
8485
std::shared_ptr<IGraph> _initGraph;
8586
std::shared_ptr<ov::Model> _initModel;

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

+8-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,14 @@ void CompiledModel::export_model(std::ostream& stream) const {
128128
_graph->custom_export(stream, _initGraph, _initModel);
129129
return;
130130
}
131-
_graph->export_blob(stream);
131+
132+
// DEBUG EXPORT
133+
// if (!exportInitFlag) {
134+
// _graph->export_blob(stream);
135+
// exportInitFlag = true;
136+
// } else {
137+
// _initGraph->export_blob(stream);
138+
// }
132139
}
133140

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

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

+72-52
Original file line numberDiff line numberDiff line change
@@ -2,36 +2,34 @@
22
// SPDX-License-Identifier: Apache-2.0
33
//
44

5+
#include <gflags/gflags.h>
6+
57
#include <algorithm>
68
#include <chrono>
79
#include <cstdlib>
810
#include <fstream>
911
#include <iostream>
1012
#include <map>
13+
#include <openvino/core/partial_shape.hpp>
14+
#include <openvino/openvino.hpp>
1115
#include <string>
1216
#include <unordered_map>
1317
#include <vector>
1418

15-
#include <gflags/gflags.h>
16-
17-
#include <openvino/core/partial_shape.hpp>
18-
#include <openvino/openvino.hpp>
19-
2019
#include "tools_helpers.hpp"
2120

22-
2321
static constexpr char help_message[] = "Optional. Print the usage message.";
2422

2523
static constexpr char model_message[] = "Required. Path to the XML model.";
2624

2725
static constexpr char targetDeviceMessage[] =
28-
"Required. Specify a target device for which executable network will be compiled.\n"
29-
" Use \"-d HETERO:<comma-separated_devices_list>\" format to "
30-
"specify HETERO plugin.\n"
31-
" Use \"-d MULTI:<comma-separated_devices_list>\" format to "
32-
"specify MULTI plugin.\n"
33-
" The application looks for a suitable plugin for the specified "
34-
"device.";
26+
"Required. Specify a target device for which executable network will be compiled.\n"
27+
" Use \"-d HETERO:<comma-separated_devices_list>\" format to "
28+
"specify HETERO plugin.\n"
29+
" Use \"-d MULTI:<comma-separated_devices_list>\" format to "
30+
"specify MULTI plugin.\n"
31+
" The application looks for a suitable plugin for the specified "
32+
"device.";
3533

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

@@ -42,42 +40,42 @@ static constexpr char config_message[] = "Optional. Path to the configuration fi
4240
static constexpr char inputs_precision_message[] = "Optional. Specifies precision for all input layers of the network.";
4341

4442
static constexpr char outputs_precision_message[] =
45-
"Optional. Specifies precision for all output layers of the network.";
43+
"Optional. Specifies precision for all output layers of the network.";
4644

4745
static constexpr char iop_message[] =
48-
"Optional. Specifies precision for input and output layers by name.\n"
49-
" Example: -iop \"input:FP16, output:FP16\".\n"
50-
" Notice that quotes are required.\n"
51-
" Overwrites precision from ip and op options for specified "
52-
"layers.";
46+
"Optional. Specifies precision for input and output layers by name.\n"
47+
" Example: -iop \"input:FP16, output:FP16\".\n"
48+
" Notice that quotes are required.\n"
49+
" Overwrites precision from ip and op options for specified "
50+
"layers.";
5351

5452
static constexpr char inputs_layout_message[] = "Optional. Specifies layout for all input layers of the network.";
5553

5654
static constexpr char outputs_layout_message[] = "Optional. Specifies layout for all output layers of the network.";
5755

5856
static constexpr char iol_message[] =
59-
"Optional. Specifies layout for input and output layers by name.\n"
60-
" Example: -iol \"input:NCHW, output:NHWC\".\n"
61-
" Notice that quotes are required.\n"
62-
" Overwrites layout from il and ol options for specified layers.";
57+
"Optional. Specifies layout for input and output layers by name.\n"
58+
" Example: -iol \"input:NCHW, output:NHWC\".\n"
59+
" Notice that quotes are required.\n"
60+
" Overwrites layout from il and ol options for specified layers.";
6361

6462
static constexpr char inputs_model_layout_message[] =
65-
"Optional. Specifies model layout for all input layers of the network.";
63+
"Optional. Specifies model layout for all input layers of the network.";
6664

6765
static constexpr char outputs_model_layout_message[] =
68-
"Optional. Specifies model layout for all output layers of the network.";
66+
"Optional. Specifies model layout for all output layers of the network.";
6967

7068
static constexpr char ioml_message[] =
71-
"Optional. Specifies model layout for input and output tensors by name.\n"
72-
" Example: -ionl \"input:NCHW, output:NHWC\".\n"
73-
" Notice that quotes are required.\n"
74-
" Overwrites layout from il and ol options for specified layers.";
69+
"Optional. Specifies model layout for input and output tensors by name.\n"
70+
" Example: -ionl \"input:NCHW, output:NHWC\".\n"
71+
" Notice that quotes are required.\n"
72+
" Overwrites layout from il and ol options for specified layers.";
7573

7674
static const char shape_message[] =
77-
" Set shape for model input. For example, \"input1[1,3,224,224],input2[1,4]\" or \"[1,3,224,224]\""
78-
" in case of one input size. This parameter affect model input shape and can be dynamic."
79-
" For dynamic dimensions use symbol `?` or '-1'. Ex. [?,3,?,?]."
80-
" For bounded dimensions specify range 'min..max'. Ex. [1..10,3,?,?].";
75+
" Set shape for model input. For example, \"input1[1,3,224,224],input2[1,4]\" or \"[1,3,224,224]\""
76+
" in case of one input size. This parameter affect model input shape and can be dynamic."
77+
" For dynamic dimensions use symbol `?` or '-1'. Ex. [?,3,?,?]."
78+
" For bounded dimensions specify range 'min..max'. Ex. [1..10,3,?,?].";
8179

8280
static const char override_model_batch_size[] = "Enforce a model to be compiled for batch size";
8381

@@ -152,14 +150,14 @@ ov::element::Type getType(std::string value, const supported_type_t& supported_p
152150
}
153151
ov::element::Type getType(const std::string& value) {
154152
static const supported_type_t supported_types = {
155-
{"FP32", ov::element::f32}, {"f32", ov::element::f32}, {"FP16", ov::element::f16},
156-
{"f16", ov::element::f16}, {"BF16", ov::element::bf16}, {"bf16", ov::element::bf16},
157-
{"U64", ov::element::u64}, {"u64", ov::element::u64}, {"I64", ov::element::i64},
158-
{"i64", ov::element::i64}, {"U32", ov::element::u32}, {"u32", ov::element::u32},
159-
{"I32", ov::element::i32}, {"i32", ov::element::i32}, {"U16", ov::element::u16},
160-
{"u16", ov::element::u16}, {"I16", ov::element::i16}, {"i16", ov::element::i16},
161-
{"U8", ov::element::u8}, {"u8", ov::element::u8}, {"I8", ov::element::i8},
162-
{"i8", ov::element::i8}, {"BOOL", ov::element::boolean}, {"boolean", ov::element::boolean},
153+
{"FP32", ov::element::f32}, {"f32", ov::element::f32}, {"FP16", ov::element::f16},
154+
{"f16", ov::element::f16}, {"BF16", ov::element::bf16}, {"bf16", ov::element::bf16},
155+
{"U64", ov::element::u64}, {"u64", ov::element::u64}, {"I64", ov::element::i64},
156+
{"i64", ov::element::i64}, {"U32", ov::element::u32}, {"u32", ov::element::u32},
157+
{"I32", ov::element::i32}, {"i32", ov::element::i32}, {"U16", ov::element::u16},
158+
{"u16", ov::element::u16}, {"I16", ov::element::i16}, {"i16", ov::element::i16},
159+
{"U8", ov::element::u8}, {"u8", ov::element::u8}, {"I8", ov::element::i8},
160+
{"i8", ov::element::i8}, {"BOOL", ov::element::boolean}, {"boolean", ov::element::boolean},
163161
};
164162

165163
return getType(value, supported_types);
@@ -169,9 +167,15 @@ bool isFP32(const ov::element::Type& type) {
169167
return type == ov::element::f32;
170168
}
171169

172-
void configurePrePostProcessing(std::shared_ptr<ov::Model>& model, const std::string& ip, const std::string& op,
173-
const std::string& iop, const std::string& il, const std::string& ol,
174-
const std::string& iol, const std::string& iml, const std::string& oml,
170+
void configurePrePostProcessing(std::shared_ptr<ov::Model>& model,
171+
const std::string& ip,
172+
const std::string& op,
173+
const std::string& iop,
174+
const std::string& il,
175+
const std::string& ol,
176+
const std::string& iol,
177+
const std::string& iml,
178+
const std::string& oml,
175179
const std::string& ioml) {
176180
auto preprocessor = ov::preprocess::PrePostProcessor(model);
177181
const auto inputs = model->inputs();
@@ -367,17 +371,19 @@ static std::map<std::string, std::string> parseConfigFile(char comment = '#') {
367371
continue;
368372
}
369373
size_t spacePos = option.find_first_of(" \t\n\r");
370-
OPENVINO_ASSERT(spacePos != std::string::npos, "Failed to find a space separator in "
371-
"provided plugin config option: " +
372-
option);
374+
OPENVINO_ASSERT(spacePos != std::string::npos,
375+
"Failed to find a space separator in "
376+
"provided plugin config option: " +
377+
option);
373378

374379
std::string key = option.substr(0, spacePos);
375380

376381
std::string value{};
377382
size_t valueStart = option.find_first_not_of(" \t\n\r", spacePos);
378-
OPENVINO_ASSERT(valueStart != std::string::npos, "An invalid config parameter value detected, "
379-
"it mustn't be empty: " +
380-
option);
383+
OPENVINO_ASSERT(valueStart != std::string::npos,
384+
"An invalid config parameter value detected, "
385+
"it mustn't be empty: " +
386+
option);
381387
size_t valueEnd = option.find_last_not_of(" \t\n\r");
382388
value = option.substr(valueStart, valueEnd - valueStart + 1);
383389

@@ -403,7 +409,6 @@ std::string getFileNameFromPath(const std::string& path,
403409

404410
using TimeDiff = std::chrono::milliseconds;
405411

406-
407412
int main(int argc, char* argv[]) {
408413
try {
409414
TimeDiff loadNetworkTimeElapsed{0};
@@ -444,6 +449,7 @@ int main(int argc, char* argv[]) {
444449
if (FLAGS_shape.empty()) {
445450
setModelBatch(model, FLAGS_override_model_batch_size);
446451
}
452+
447453
std::cout << "Printing Input and Output Info from model" << std::endl;
448454
printInputAndOutputsInfoShort(*model);
449455
auto timeBeforeLoadNetwork = std::chrono::steady_clock::now();
@@ -453,7 +459,7 @@ int main(int argc, char* argv[]) {
453459
std::cout << "Compiling model" << std::endl;
454460
auto compiledModel = core.compile_model(model, FLAGS_d, {configs.begin(), configs.end()});
455461
loadNetworkTimeElapsed =
456-
std::chrono::duration_cast<TimeDiff>(std::chrono::steady_clock::now() - timeBeforeLoadNetwork);
462+
std::chrono::duration_cast<TimeDiff>(std::chrono::steady_clock::now() - timeBeforeLoadNetwork);
457463
std::string outputName = FLAGS_o;
458464
if (outputName.empty()) {
459465
outputName = getFileNameFromPath(fileNameNoExt(FLAGS_m)) + ".blob";
@@ -467,6 +473,20 @@ int main(int argc, char* argv[]) {
467473
std::cout << "Writing into file - " << outputName << std::endl;
468474
compiledModel.export_model(outputFile);
469475
}
476+
477+
// DEBUG EXPORT
478+
// {
479+
// std::string outputInitName = outputName.substr(0, outputName.size()-5) + "_init.blob";
480+
// std::ofstream outputInitFile{outputInitName, std::ios::out | std::ios::binary};
481+
// if (!outputInitFile.is_open()) {
482+
// std::cout << "Outputting file " << outputInitName << " can't be opened for writing" << std::endl;
483+
// return EXIT_FAILURE;
484+
// } else {
485+
// std::cout << "Writing into file - " << outputInitName << std::endl;
486+
// compiledModel.export_model(outputInitFile);
487+
// }
488+
// }
489+
470490
std::cout << "Done. LoadNetwork time elapsed: " << loadNetworkTimeElapsed.count() << " ms" << std::endl;
471491
} catch (const std::exception& error) {
472492
std::cerr << error.what() << std::endl;

0 commit comments

Comments
 (0)