Skip to content

Commit f8c482f

Browse files
committed
Add method compileWS_v3
1 parent 3dc4c6b commit f8c482f

File tree

2 files changed

+71
-6
lines changed

2 files changed

+71
-6
lines changed

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

+19-4
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,30 @@ class ICompiler : public std::enable_shared_from_this<ICompiler> {
6262
const Config& config) const = 0;
6363

6464
/**
65-
* @brief TODO
65+
* @brief Sequantial compilation of Init(s) and Main
6666
*
67-
* @param model
68-
* @param config
69-
* @return NetworkDescription
67+
* "Stateful compiler" approach
7068
*/
7169
virtual std::shared_ptr<NetworkDescription> compileWS_v2(const std::shared_ptr<ov::Model>& model,
7270
const Config& config) = 0;
7371

72+
/**
73+
* @brief Sequantial compilation of Init(s) and Main
74+
*
75+
* "Stateless compiler" approach
76+
* We want to get multiple Inits in the case of a large number of weights.
77+
* This allows us to build pipeline:
78+
* Allocate W1 -> Init1
79+
* Allocate W2 -> Init2
80+
* Allocate W3 -> Init2
81+
*
82+
* This is why there is an additional parameter callNumber:
83+
* Compiler should somehow understand wich Init(or Main) to return
84+
* Plugin does not know total numbers og Init schedules
85+
*/
86+
virtual std::shared_ptr<NetworkDescription> compileWS_v3(const std::shared_ptr<ov::Model>& model,
87+
const Config& config, size_t callNumber) const = 0;
88+
7489
/**
7590
* @brief Returns information about supported layers of the network passed
7691
* @param model The model to be queried

src/plugins/intel_npu/src/compiler_adapter/src/plugin_compiler_adapter.cpp

+52-2
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,17 @@ std::vector<std::shared_ptr<IGraph>> PluginCompilerAdapter::compileWS(const std:
115115

116116
_logger.debug("compile start");
117117

118+
const auto starts_with = [](const std::string& str, const std::string& prefix) {
119+
return str.substr(0, prefix.size()) == prefix;
120+
};
121+
const auto isInit = [&](std::string name) {
122+
return starts_with(name, "init");
123+
};
124+
125+
const auto isMain = [&](std::string name) {
126+
return starts_with(name, "main");
127+
};
128+
118129
switch (config.get<SEPARATE_WEIGHTS_VERSION>()) {
119130
case 1: {
120131
const std::vector<std::shared_ptr<NetworkDescription>> initMainNetworkDescriptions =
@@ -124,8 +135,47 @@ std::vector<std::shared_ptr<IGraph>> PluginCompilerAdapter::compileWS(const std:
124135
mainNetworkDescription = initMainNetworkDescriptions[1];
125136
} break;
126137
case 2: {
127-
initNetworkDescription = _compiler->compileWS_v2(model, config);
128-
mainNetworkDescription = _compiler->compileWS_v2(model, config);
138+
// initNetworkDescription = _compiler->compileWS_v2(model, config);
139+
// mainNetworkDescription = _compiler->compileWS_v2(model, config);
140+
141+
std::vector<std::shared_ptr<NetworkDescription>> initDscrs;
142+
while(auto networkDescription = _compiler->compileWS_v2(model, config)) {
143+
if(isInit(networkDescription->metadata.name)) {
144+
initDscrs.push_back(networkDescription);
145+
continue;
146+
}
147+
if(!isMain(networkDescription->metadata.name)) {
148+
throw std::runtime_error("Unexpected network name: " + networkDescription->metadata.name);
149+
}
150+
151+
mainNetworkDescription = std::move(networkDescription);
152+
break;
153+
}
154+
155+
// FIXME
156+
initNetworkDescription = std::move(initDscrs[0]);
157+
} break;
158+
case 3: {
159+
//initNetworkDescription = _compiler->compileWS_v3(model, config, 0);
160+
//mainNetworkDescription = _compiler->compileWS_v3(model, config, 1);
161+
162+
std::vector<std::shared_ptr<NetworkDescription>> initDscrs;
163+
size_t i = 0;
164+
while(auto networkDescription = _compiler->compileWS_v3(model, config, i++)) {
165+
if(isInit(networkDescription->metadata.name)) {
166+
initDscrs.push_back(networkDescription);
167+
continue;
168+
}
169+
if(!isMain(networkDescription->metadata.name)) {
170+
throw std::runtime_error("Unexpected network name: " + networkDescription->metadata.name);
171+
}
172+
173+
mainNetworkDescription = std::move(networkDescription);
174+
break;
175+
}
176+
177+
// FIXME
178+
initNetworkDescription = std::move(initDscrs[0]);
129179
} break;
130180
default:
131181
OPENVINO_THROW("Invalid \"SEPARATE_WEIGHTS_VERSION\" value found within the \"compileWS\" call");

0 commit comments

Comments
 (0)