Skip to content

Commit

Permalink
Add subgraph identificator for operation name, so one operation in tw…
Browse files Browse the repository at this point in the history
…o subgraphs can be distincted as two different operations
  • Loading branch information
AsyaPronina committed Sep 30, 2024
1 parent 36b6e3c commit 63b7088
Showing 1 changed file with 25 additions and 11 deletions.
36 changes: 25 additions & 11 deletions src/plugins/intel_npu/src/plugin/npuw/partitioning/partitioning.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,8 @@ class Partitioner {

// Map every function call instance' Parameter and result
// back to its prototype Parameter and Result
std::unordered_map<PPtr, PPtr> param_call_to_proto;
std::unordered_map<RPtr, RPtr> result_call_to_proto;
std::unordered_map<std::string, PPtr> param_call_to_proto;
std::unordered_map<std::string, RPtr> result_call_to_proto;
};
std::map<std::string, FunctionPipeline> all_functions;

Expand All @@ -202,7 +202,8 @@ class Partitioner {
void createFunction(FunctionPipeline& func_ggg);

template <typename T, typename M>
void rearrange_to_function_protocol(const std::vector<T>& protocol, std::vector<T>& call, const M& call_to_proto) {
void rearrange_to_function_protocol(const std::vector<T>& protocol, std::vector<T>& call, const M& call_to_proto,
const std::shared_ptr<ov::Model>& model) {
LOG_DEBUG("Rearranging...");
LOG_BLOCK();
LOG_DEBUG("Protocol: " << protocol.size());
Expand All @@ -214,7 +215,7 @@ class Partitioner {
LOG_DEBUG("Call: " << call.size());
for (auto&& c : call) {
LOG_BLOCK();
auto p_c = call_to_proto.at(c);
auto p_c = call_to_proto.at(model->get_friendly_name() + "_" + c->get_friendly_name());
to_proto.push_back(p_c);
LOG_DEBUG(c << " (which is " << p_c << ")");
}
Expand Down Expand Up @@ -388,7 +389,7 @@ void Partitioner::identifySubgraphs() {
std::make_shared<ov::op::v0::Parameter>(output.get_element_type(), output.get_partial_shape());
result = std::static_pointer_cast<ov::Node>(new_param);
}
input_mapping[orig_node] = result;
input_mapping[orig_node] = result;;
return result;
};
for (auto&& input_layer_name : group.input_layers) {
Expand Down Expand Up @@ -923,6 +924,7 @@ void Partitioner::propagateScalars(const std::string& func_name) {
// Instead it should only take shared scalars into account!
dup_scalars[{func_name, this_layer_name}]++;
}

return res;
};
propagate(func_name, match_fcn, scalar_bank);
Expand Down Expand Up @@ -1347,7 +1349,7 @@ void Partitioner::matchParameters(const std::string& func_name) {
LOG_DEBUG("Find orig parameter for " << node);
auto& orig_param = proto_parameters.at(pkey);
auto this_param = std::dynamic_pointer_cast<PPtr::element_type>(node);
func.param_call_to_proto[this_param] = orig_param;
func.param_call_to_proto[call.get()->get_friendly_name() + "_" + this_param->get_friendly_name()] = orig_param;
}
}
}
Expand Down Expand Up @@ -1392,7 +1394,7 @@ void Partitioner::matchResults(const std::string& func_name) {
RKey rkey = {layer_to_prototype.at(port.get_node()->get_friendly_name()), port.get_index()};
auto& orig_result = proto_results.at(rkey);
auto this_result = std::dynamic_pointer_cast<RPtr::element_type>(node);
func.result_call_to_proto[this_result] = orig_result;
func.result_call_to_proto[call->get_friendly_name() + "_" + this_result->get_friendly_name()] = orig_result;
}
}
}
Expand Down Expand Up @@ -1516,8 +1518,10 @@ void Partitioner::matchRepeatedSubgraphs(const std::string& func_name) {
funcall._gflops = this_sg._gflops; // duplicated code again!
funcall._ops = this_sg._ops; // duplicated code again!
funcall._avoid_list = this_sg._avoid_list; // duplicated code again!
rearrange_to_function_protocol(body_params, funcall._parameters, func_ggg.param_call_to_proto);
rearrange_to_function_protocol(body_results, funcall._results, func_ggg.result_call_to_proto);
auto param_call_to_proto = func_ggg.param_call_to_proto;

rearrange_to_function_protocol(body_params, funcall._parameters, func_ggg.param_call_to_proto, *mod_iter);
rearrange_to_function_protocol(body_results, funcall._results, func_ggg.result_call_to_proto, *mod_iter);

auto func_iter = P.functions.find(func_name);
NPUW_ASSERT(func_iter != P.functions.end());
Expand Down Expand Up @@ -1786,9 +1790,13 @@ void Partitioner::finalizeLinks() {
} else {
// A function call: find in the prototype subgraph
auto& params = P.functions.at(sg_desc._funcall)._model->get_parameters();
std::cout << "SUBGRAPH PARAM: " << model->get_friendly_name() + "_" +
sg_desc._funcall + "__" + std::to_string(subgr_idx_to - 1) + "_" + ptr->get_friendly_name() << std::endl;
auto& proto = func_pipeline_type == FunctionPipelineType::CWAI
? ptr // no protos in the CWAI case..
: all_functions.at(sg_desc._funcall).param_call_to_proto.at(ptr);
: all_functions.at(sg_desc._funcall).param_call_to_proto.
at(model->get_friendly_name() + "_" +
sg_desc._funcall + "__" + std::to_string(subgr_idx_to - 1) + "_" + ptr->get_friendly_name());
auto param_iter = std::find(params.begin(), params.end(), proto);
NPUW_ASSERT(param_iter != params.end());
return std::distance(params.begin(), param_iter);
Expand All @@ -1807,9 +1815,13 @@ void Partitioner::finalizeLinks() {
} else {
// A function call: find in the prototype subgraph
auto& results = P.functions.at(sg_desc._funcall)._model->get_results();
std::cout << "SUBGRAPH RESULT: " << model->get_friendly_name() + "_" +
sg_desc._funcall + "__" + std::to_string(subgr_idx_from - 1) + "_" + ptr->get_friendly_name() << std::endl;
auto& proto = func_pipeline_type == FunctionPipelineType::CWAI
? ptr // no protos in the CWAI case...
: all_functions.at(sg_desc._funcall).result_call_to_proto.at(ptr);
: all_functions.at(sg_desc._funcall).result_call_to_proto
.at(model->get_friendly_name() + "_" +
sg_desc._funcall + "__" + std::to_string(subgr_idx_from - 1) + "_" + ptr->get_friendly_name());
auto result_iter = std::find(results.begin(), results.end(), proto);
NPUW_ASSERT(result_iter != results.end());
return std::distance(results.begin(), result_iter);
Expand All @@ -1827,6 +1839,8 @@ void Partitioner::finalizeLinks() {
std::size_t subgraph_idx_to;
PPtr subgraph_param_to;
std::tie(subgraph_idx_to, subgraph_param_to) = ptr_link.first;
LOG_DEBUG("Record link " << subgraph_idx_to << " : "<<
subgraph_param_to);
auto param_idx = get_idx_param(subgraph_idx_to, subgraph_param_to);

std::size_t subgraph_idx_from;
Expand Down

0 comments on commit 63b7088

Please sign in to comment.