!6240 Fix review_bot and codedex problems

Merge pull request !6240 from DeshiChen/0910_review_bot
pull/6240/MERGE
mindspore-ci-bot 5 years ago committed by Gitee
commit 014ea619a8

@ -199,6 +199,5 @@ void SetAkgKernelAttrs(const AnfNodePtr &anf_node) {
it->second(anf_node);
}
}
} // namespace kernel
} // namespace mindspore

@ -20,9 +20,7 @@
namespace mindspore {
namespace kernel {
void SetAkgKernelAttrs(const AnfNodePtr &anf_node);
} // namespace kernel
} // namespace mindspore
#endif // MINDSPORE_CCSRC_BACKEND_KERNEL_COMPILER_AKG_AKG_KERNEL_ATTRS_PROCESS_H

@ -37,11 +37,10 @@ class AkgKernelJsonDecoder {
AnfNodePtrList *res_graphs);
private:
ScalarPtr DecodeScalar(const nlohmann::json &scalar_json);
ValueNodePtr DecodeValueNode(const nlohmann::json &value_json, const FuncGraphPtr &func_graph);
ParameterPtr DecodeParameter(const nlohmann::json &parameter_json, const FuncGraphPtr &func_graph);
CNodePtr DecodeCNode(const nlohmann::json &cnode_json, const FuncGraphPtr &func_graph, const std::string &processor);
std::map<std::string, AnfNodePtr> nodes_map_{};
AnfNodePtr DecodeOutput(const std::vector<nlohmann::json> &output_descs, const FuncGraphPtr &func_graph);
std::map<std::string, AnfNodePtr> nodes_map_;
};
} // namespace kernel
} // namespace mindspore

@ -94,6 +94,14 @@ class AkgKernelJsonGenerator {
nlohmann::json *const attrs_json);
bool GetIOSize(const nlohmann::json &node_json, std::vector<size_t> *const input_size,
std::vector<size_t> *const output_size);
bool GenSingleJsons(const std::vector<AnfNodePtr> &anf_nodes, std::map<AnfNodePtr, nlohmann::json> *node_json_map);
void UpdateTensorName(const std::vector<AnfNodePtr> &anf_nodes, std::map<AnfNodePtr, nlohmann::json> *node_json_map);
nlohmann::json CreateInputsJson(const std::vector<AnfNodePtr> &anf_nodes, const std::vector<AnfNodePtr> &input_list,
const std::map<AnfNodePtr, nlohmann::json> &node_json_map);
nlohmann::json CreateOutputsJson(const std::vector<AnfNodePtr> &anf_nodes, const std::vector<AnfNodePtr> &input_list,
const std::vector<AnfNodePtr> &output_list, const nlohmann::json &inputs_json,
const std::map<AnfNodePtr, nlohmann::json> &node_json_map);
int GetOpCntInc();
size_t GetInputTensorIdxInc(const AnfNodePtr &anf_node, size_t input_idx);
size_t GetOutputTensorIdxInc();

@ -36,15 +36,23 @@
namespace mindspore {
namespace kernel {
namespace {
constexpr int32_t PROCESS_NUM = 16;
constexpr int32_t TIME_OUT = 300;
bool AkgAscendKernelBuilder::AkgOpParallelBuild(
const std::vector<std::pair<AkgKernelJsonGenerator, AnfNodePtr>> &build_args) {
void SetKernelMod(const KernelPackPtr &kernel_pack, const AkgKernelJsonGenerator &json_generator,
const AnfNodePtr &anf_node) {
auto kernel_mod_ptr = std::make_shared<AkgKernelMod>(kernel_pack);
kernel_mod_ptr->SetInputSizeList(json_generator.input_size_list());
kernel_mod_ptr->SetOutputSizeList(json_generator.output_size_list());
AnfAlgo::SetKernelMod(kernel_mod_ptr, anf_node.get());
}
} // namespace
std::vector<std::string> AkgAscendKernelBuilder::GetNotCachedKernelJsons(const std::vector<JsonNodePair> &build_args) {
// Remove cached nodes, gether unique nodes, and collect repeated nodes which need postprecess.
std::vector<std::string> jsons;
std::unordered_set<std::string> kernel_name_set;
std::vector<std::pair<AkgKernelJsonGenerator, AnfNodePtr>> repeat_nodes;
for (const auto &[json_generator, anf_node] : build_args) {
MS_EXCEPTION_IF_NULL(anf_node);
auto kernel_name = json_generator.kernel_name();
@ -53,15 +61,12 @@ bool AkgAscendKernelBuilder::AkgOpParallelBuild(
if (cached_kernel_pack != nullptr) {
MS_LOG(DEBUG) << "Use cached kernel, kernel_name[" << kernel_name << "], fullname_with_scope["
<< anf_node->fullname_with_scope() << "].";
auto kernel_mod_ptr = std::make_shared<AkgKernelMod>(cached_kernel_pack);
kernel_mod_ptr->SetInputSizeList(json_generator.input_size_list());
kernel_mod_ptr->SetOutputSizeList(json_generator.output_size_list());
AnfAlgo::SetKernelMod(kernel_mod_ptr, anf_node.get());
SetKernelMod(cached_kernel_pack, json_generator, anf_node);
continue;
}
if (kernel_name_set.count(kernel_name) != 0) {
repeat_nodes.push_back({json_generator, anf_node});
repeat_nodes_.push_back({json_generator, anf_node});
continue;
}
kernel_name_set.insert(kernel_name);
@ -69,7 +74,43 @@ bool AkgAscendKernelBuilder::AkgOpParallelBuild(
kernel::SaveJsonInfo(kernel_name, kernel_json);
jsons.push_back(kernel_json);
}
return jsons;
}
bool AkgAscendKernelBuilder::InsertToCache(const std::vector<JsonNodePair> &build_args) {
for (const auto &[json_generator, anf_node] : build_args) {
auto kernel_name = json_generator.kernel_name();
auto new_kernel_pack = tbe::TbeUtils::InsertCache(kernel_name, GetProcessorStr(anf_node));
if (new_kernel_pack == nullptr) {
MS_LOG(ERROR) << "Insert to cache failed, kernel_name[" << kernel_name << "], fullname_with_scope["
<< anf_node->fullname_with_scope() << "].";
return false;
}
SetKernelMod(new_kernel_pack, json_generator, anf_node);
MS_LOG(DEBUG) << "Akg compile " << kernel_name << " kernel and insert cache successfully!";
}
return true;
}
bool AkgAscendKernelBuilder::HandleRepeatNodes() {
for (const auto &[json_generator, anf_node] : repeat_nodes_) {
auto kernel_name = json_generator.kernel_name();
auto cached_kernel_pack = tbe::TbeUtils::SearchCache(kernel_name, GetProcessorStr(anf_node));
if (cached_kernel_pack == nullptr) {
MS_LOG(ERROR) << "Use cached kernel failed, kernel_name[" << kernel_name << "], fullname_with_scope["
<< anf_node->fullname_with_scope() << "].";
return false;
}
MS_LOG(INFO) << "Use just compiled kernel, kernel_name[" << kernel_name << "], fullname_with_scope["
<< anf_node->fullname_with_scope() << "].";
SetKernelMod(cached_kernel_pack, json_generator, anf_node);
}
return true;
}
bool AkgAscendKernelBuilder::AkgOpParallelBuild(const std::vector<JsonNodePair> &build_args) {
repeat_nodes_.clear();
auto jsons = GetNotCachedKernelJsons(build_args);
if (jsons.empty()) {
return true;
}
@ -89,56 +130,35 @@ bool AkgAscendKernelBuilder::AkgOpParallelBuild(
}
// All unique done here, cache them and set kernel.
for (const auto &[json_generator, anf_node] : build_args) {
auto kernel_name = json_generator.kernel_name();
auto new_kernel_pack = tbe::TbeUtils::InsertCache(kernel_name, GetProcessorStr(anf_node));
if (new_kernel_pack == nullptr) {
MS_LOG(ERROR) << "Insert to cache failed, kernel_name[" << kernel_name << "], fullname_with_scope["
<< anf_node->fullname_with_scope() << "].";
return false;
}
auto kernel_mod_ptr = std::make_shared<AkgKernelMod>(new_kernel_pack);
kernel_mod_ptr->SetInputSizeList(json_generator.input_size_list());
kernel_mod_ptr->SetOutputSizeList(json_generator.output_size_list());
AnfAlgo::SetKernelMod(kernel_mod_ptr, anf_node.get());
MS_LOG(DEBUG) << "Akg compile " << kernel_name << " kernel and insert cache successfully!";
if (!InsertToCache(build_args)) {
MS_LOG(ERROR) << "Insert cache failed.";
return false;
}
// Handle repeated nodes.
for (const auto &[json_generator, anf_node] : repeat_nodes) {
auto kernel_name = json_generator.kernel_name();
auto cached_kernel_pack = tbe::TbeUtils::SearchCache(kernel_name, GetProcessorStr(anf_node));
if (cached_kernel_pack == nullptr) return false;
MS_LOG(INFO) << "Use just compiled kernel, kernel_name[" << kernel_name << "], fullname_with_scope["
<< anf_node->fullname_with_scope() << "].";
auto kernel_mod_ptr = std::make_shared<AkgKernelMod>(cached_kernel_pack);
kernel_mod_ptr->SetInputSizeList(json_generator.input_size_list());
kernel_mod_ptr->SetOutputSizeList(json_generator.output_size_list());
AnfAlgo::SetKernelMod(kernel_mod_ptr, anf_node.get());
if (!HandleRepeatNodes()) {
MS_LOG(ERROR) << "Handle repeat nodes failed.";
return false;
}
return true;
}
bool AkgAscendKernelParallelBuild(const std::vector<AnfNodePtr> &anf_nodes) {
std::vector<std::pair<AkgKernelJsonGenerator, AnfNodePtr>> json_and_node;
std::vector<JsonNodePair> json_and_node;
for (const auto &anf_node : anf_nodes) {
MS_EXCEPTION_IF_NULL(anf_node);
AkgKernelJsonGenerator akg_kernel_json_generator;
KernelPackPtr kernel_pack = nullptr;
auto cnode = anf_node->cast<CNodePtr>();
MS_EXCEPTION_IF_NULL(cnode);
if (AnfAlgo::IsGraphKernel(cnode)) {
auto func_graph = AnfAlgo::GetCNodeFuncGraphPtr(cnode);
MS_EXCEPTION_IF_NULL(func_graph);
auto mng = func_graph->manager();
if (mng == nullptr) {
mng = Manage(func_graph, true);
func_graph->set_manager(mng);
}
MS_EXCEPTION_IF_NULL(func_graph);
std::vector<AnfNodePtr> node_list;
std::vector<AnfNodePtr> input_list;
std::vector<AnfNodePtr> output_list;
std::vector<AnfNodePtr> node_list, input_list, output_list;
MS_LOG(INFO) << "Akg start compile composite op[" << anf_node->fullname_with_scope() << "]";
GetValidKernelNodes(func_graph, &node_list, &input_list, &output_list);
if (!akg_kernel_json_generator.CollectFusedJson(node_list, input_list, output_list)) {
@ -146,7 +166,7 @@ bool AkgAscendKernelParallelBuild(const std::vector<AnfNodePtr> &anf_nodes) {
}
} else {
if (!akg_kernel_json_generator.CollectJson(anf_node)) {
MS_EXCEPTION(UnknownError) << "Akg build failed op[" << anf_node->fullname_with_scope() << "].";
MS_EXCEPTION(UnknownError) << "Akg build failed basic op[" << anf_node->fullname_with_scope() << "].";
}
}
json_and_node.push_back({akg_kernel_json_generator, anf_node});

@ -27,12 +27,20 @@
namespace mindspore {
namespace kernel {
using JsonNodePair = std::pair<AkgKernelJsonGenerator, AnfNodePtr>;
class AkgAscendKernelBuilder {
public:
AkgAscendKernelBuilder() = default;
~AkgAscendKernelBuilder() = default;
bool AkgOpParallelBuild(const std::vector<JsonNodePair> &build_args);
private:
std::vector<std::string> GetNotCachedKernelJsons(const std::vector<JsonNodePair> &build_args);
bool InsertToCache(const std::vector<JsonNodePair> &build_args);
bool HandleRepeatNodes();
bool AkgOpParallelBuild(const std::vector<std::pair<AkgKernelJsonGenerator, AnfNodePtr>> &build_args);
std::vector<JsonNodePair> repeat_nodes_;
};
bool AkgAscendKernelParallelBuild(const std::vector<AnfNodePtr> &anf_nodes);

@ -1,4 +1,3 @@
/**
* Copyright 2020 Huawei Technologies Co., Ltd
*
@ -32,7 +31,6 @@ class BasicOpsFusion : public Pass {
bool Run(const FuncGraphPtr &func_graph) override;
};
using FuseBasicPtr = std::shared_ptr<BasicOpsFusion>;
} // namespace opt
} // namespace mindspore
#endif // MINDSPORE_CCSRC_BACKEND_OPTIMIZER_GRAPH_KERNEL_BASIC_OPS_FUSION_H_

@ -128,7 +128,7 @@ FuncGraphPtr GraphKernelExpander::CreateExpandFuncGraph(const CNodePtr &node) {
MS_LOG(DEBUG) << "CallPyFn: [" << kGetGraphKernelOpExpander << "] with input json:\n" << node_desc_str;
auto ret = parse::python_adapter::CallPyFn(kGraphKernelModule, kGetGraphKernelOpExpander, node_desc_str);
// parse result.
if (ret.is(py::none())) {
if (py::isinstance<py::none>(ret)) {
MS_LOG(ERROR) << "CallPyFn: [" << kGetGraphKernelOpExpander << "] return invalid result, input json:\n"
<< node_desc_str;
return nullptr;

@ -211,9 +211,9 @@ AnfNodePtr DeleteAttrInInput(const FuncGraphPtr &func_graph, const CNodePtr &cno
return new_cnode;
}
AnfNodePtrList EliminateMakeTuple(const FuncGraphPtr *fg, FuncGraphManagerPtr *mng) {
AnfNodePtrList EliminateMakeTuple(const FuncGraphPtr &fg, const FuncGraphManagerPtr &mng) {
AnfNodePtrList outs;
auto out_node = (*fg)->output();
auto out_node = fg->output();
if (IsPrimitiveCNode(out_node, prim::kPrimMakeTuple)) {
std::vector<AnfNodePtr> output_args;
auto out_cnode = out_node->cast<CNodePtr>();
@ -228,8 +228,8 @@ AnfNodePtrList EliminateMakeTuple(const FuncGraphPtr *fg, FuncGraphManagerPtr *m
}
}
if (output_args.size() != out_cnode->inputs().size()) {
auto new_out = (*fg)->NewCNode(output_args);
(*mng)->Replace(out_node, new_out);
auto new_out = fg->NewCNode(output_args);
mng->Replace(out_node, new_out);
}
for (size_t i = 1; i < output_args.size(); ++i) {
@ -241,6 +241,27 @@ AnfNodePtrList EliminateMakeTuple(const FuncGraphPtr *fg, FuncGraphManagerPtr *m
outs.push_back(out_node);
return outs;
}
bool GenJson(const AnfNodePtrList &op_nodes, const AnfNodePtrList &inputs, const AnfNodePtrList &outputs,
const DumpOption &dump_option, nlohmann::json *op_desc,
std::map<std::string, AnfNodePtr> *address_node_map) {
kernel::AkgKernelJsonGenerator akg_kernel_json_generator(dump_option);
if (!akg_kernel_json_generator.CollectFusedJson(op_nodes, inputs, outputs)) {
MS_LOG(ERROR) << "Collect json desc failed.";
return false;
}
*op_desc = akg_kernel_json_generator.kernel_json();
if (address_node_map != nullptr) {
*address_node_map = akg_kernel_json_generator.address_node_map();
}
std::string fused_name;
std::for_each(op_nodes.begin(), op_nodes.end(), [&fused_name](const AnfNodePtr &node) {
(void)fused_name.append(AnfAlgo::GetCNodeName(node)).append("_");
});
MS_LOG(INFO) << "Collect fusion json: " << fused_name;
return true;
}
} // namespace
void SetNewKernelInfo(const AnfNodePtr &new_node, const FuncGraphPtr &fg, const AnfNodePtrList &inputs,
@ -457,7 +478,7 @@ void FuseNodesToSubGraph(const std::vector<AnfNodePtr> &fuse_nodes,
mng->Replace(n, out);
}
EliminateMakeTuple(&fg, &mng);
EliminateMakeTuple(fg, mng);
// set graphKernel attr
std::string fuse_op_name = "";
for (auto &fuse_node : fuse_nodes) {
@ -476,50 +497,26 @@ void FuseNodesToSubGraph(const std::vector<AnfNodePtr> &fuse_nodes,
fg->set_attr(FUNC_GRAPH_ATTR_GRAPH_KERNEL, MakeValue(fuse_op_name));
}
bool AnfToJsonDesc(const AnfNodePtrList &nodes, DumpOption dump_option, nlohmann::json *op_desc,
bool AnfToJsonDesc(const AnfNodePtrList &nodes, const DumpOption &dump_option, nlohmann::json *op_desc,
std::map<std::string, AnfNodePtr> *address_node_map) {
MS_EXCEPTION_IF_NULL(op_desc);
if (nodes.empty()) {
MS_LOG(ERROR) << "Input nodes is empty.";
return false;
}
bool has_graph_kernel =
std::any_of(nodes.begin(), nodes.end(), [](const AnfNodePtr &node) { return AnfAlgo::IsGraphKernel(node); });
bool has_graph_kernel = std::any_of(nodes.begin(), nodes.end(), AnfAlgo::IsGraphKernel);
bool is_single_graph_kernel = has_graph_kernel && nodes.size() == 1;
auto gen_json = [&dump_option, &op_desc, &address_node_map](const AnfNodePtrList &op_nodes,
const AnfNodePtrList &inputs,
const AnfNodePtrList &outputs) -> bool {
kernel::AkgKernelJsonGenerator akg_kernel_json_generator(dump_option);
if (!akg_kernel_json_generator.CollectFusedJson(op_nodes, inputs, outputs)) {
MS_LOG(ERROR) << "Collect json desc failed.";
return false;
}
*op_desc = akg_kernel_json_generator.kernel_json();
if (address_node_map != nullptr) {
*address_node_map = akg_kernel_json_generator.address_node_map();
}
std::string fused_name;
std::for_each(op_nodes.begin(), op_nodes.end(), [&fused_name](const AnfNodePtr &node) {
(void)fused_name.append(AnfAlgo::GetCNodeName(node)).append("_");
});
MS_LOG(INFO) << "Collect fusion json: " << fused_name;
return true;
};
FuncGraphPtr fg;
AnfNodePtrList op_nodes;
AnfNodePtrList inputs;
AnfNodePtrList outputs;
AnfNodePtrList op_nodes, inputs, outputs;
if (is_single_graph_kernel) {
fg = AnfAlgo::GetCNodeFuncGraphPtr(nodes[0]);
kernel::GetValidKernelNodes(fg, &op_nodes, &inputs, &outputs);
return gen_json(op_nodes, inputs, outputs);
return GenJson(op_nodes, inputs, outputs, dump_option, op_desc, address_node_map);
} else if (!has_graph_kernel) {
std::tie(fg, inputs, outputs) = compile::TransformSegmentToAnfGraph(nodes);
op_nodes = nodes;
return gen_json(op_nodes, inputs, outputs);
return GenJson(op_nodes, inputs, outputs, dump_option, op_desc, address_node_map);
}
std::tie(fg, inputs, outputs) = compile::TransformSegmentToAnfGraph(nodes);
@ -540,10 +537,10 @@ bool AnfToJsonDesc(const AnfNodePtrList &nodes, DumpOption dump_option, nlohmann
inputs.clear();
outputs.clear();
kernel::GetValidKernelNodes(fg, &op_nodes, &inputs, &outputs);
return gen_json(op_nodes, inputs, outputs);
return GenJson(op_nodes, inputs, outputs, dump_option, op_desc, address_node_map);
}
bool AnfToJsonDesc(const std::vector<AnfNodePtrList> &graphs, DumpOption dump_option, nlohmann::json *op_desc) {
bool AnfToJsonDesc(const std::vector<AnfNodePtrList> &graphs, const DumpOption &dump_option, nlohmann::json *op_desc) {
MS_EXCEPTION_IF_NULL(op_desc);
std::vector<nlohmann::json> graphs_desc;
for (auto const &graph_nodes : graphs) {

@ -46,9 +46,9 @@ void ReplaceNewFuseCNode(const FuncGraphPtr &kernel_graph, const AnfNodePtr &new
void FuseNodesToSubGraph(const std::vector<AnfNodePtr> &fuse_nodes,
const std::shared_ptr<session::KernelGraph> &kernel_graph, const std::string &postfix,
bool is_before_kernel_select);
bool AnfToJsonDesc(const AnfNodePtrList &nodes, DumpOption dump_option, nlohmann::json *op_desc,
bool AnfToJsonDesc(const AnfNodePtrList &nodes, const DumpOption &dump_option, nlohmann::json *op_desc,
std::map<std::string, AnfNodePtr> *address_node_map = nullptr);
bool AnfToJsonDesc(const std::vector<AnfNodePtrList> &graphs, DumpOption dump_option, nlohmann::json *op_desc);
bool AnfToJsonDesc(const std::vector<AnfNodePtrList> &graphs, const DumpOption &dump_option, nlohmann::json *op_desc);
FuncGraphPtr JsonDescToAnf(const std::string &json_desc, const std::vector<AnfNodePtr> &inputs);
bool JsonDescToAnf(const std::string &json_desc, const std::map<std::string, AnfNodePtr> &address_node_map,
std::vector<AnfNodePtrList> *res_graphs);

@ -57,8 +57,6 @@ inline void TraverseFuncGraph(const FuncGraphPtr &root, std::function<void(AnfNo
TraverseFuncGraphFromCNode(root->get_return(), callback);
}
class AreaGraph;
class Splitter;
class Area {
public:
explicit Area(const AnfNodePtrList &anf_arr) {
@ -73,6 +71,8 @@ class Area {
}
}
~Area() = default;
// Set the external inputs of spy as a Parameter.
void CreateParameters(const FuncGraphPtr &func_graph, std::unordered_map<ParameterPtr, AnfNodePtr> *param_node_map) {
std::unordered_map<AnfNodePtr, ParameterPtr> node_param_map;
@ -148,8 +148,8 @@ class Area {
}
}
friend AreaGraph;
friend Splitter;
const std::unordered_set<AnfNodePtr> &nodes() const { return nodes_; }
const std::vector<AnfNodePtr> &spy_cnodes() const { return spy_cnodes_; }
private:
// This is a CNode that does not belong to this area.
@ -170,9 +170,8 @@ class AreaGraph {
// Build an area graph to maintain the relation between areas.
// Input node_groups: A group list, each element is a AnfNode list representing the node set in this group.
static AreaGraphPtr BuildAreaGraph(const std::vector<AnfNodePtrList> &node_groups) {
AreaGraph *area_graph_ptr = new (std::nothrow) AreaGraph(node_groups);
if (!area_graph_ptr) return nullptr;
auto area_graph = AreaGraphPtr(area_graph_ptr);
auto area_graph = AreaGraphPtr(new AreaGraph(node_groups));
if (area_graph == nullptr) return nullptr;
if (!area_graph->TopoSort()) {
MS_LOG(WARNING) << "The groups have a cycle.";
return nullptr;
@ -184,12 +183,12 @@ class AreaGraph {
// The output `main_cnodes` is a topo-sorted cnode list in main graph, holding the new sub_func_graphs.
// The output `cnode_group_id` represents the indices of main_cnodes before topo-sorting.
void SplitGraph(const FuncGraphPtr &main_func_graph, std::vector<CNodePtr> *main_cnodes,
std::vector<size_t> *cnode_group_id, std::function<void(Area *)> expand_callback) {
std::vector<size_t> *cnode_group_id, std::function<void(const Area &)> expand_callback) {
main_cnodes->clear();
main_cnodes->resize(areas_.size(), nullptr);
for (auto &area : this->areas_) {
expand_callback(&area);
expand_callback(area);
}
for (auto index : topo_order_) {
@ -208,6 +207,8 @@ class AreaGraph {
return;
}
~AreaGraph() = default;
private:
explicit AreaGraph(const std::vector<AnfNodePtrList> &node_groups) : edge_prev_(node_groups.size()) {
for (size_t i = 0; i < node_groups.size(); ++i) {
@ -217,7 +218,7 @@ class AreaGraph {
}
}
for (auto &area : areas_) {
for (auto &spy : area.spy_cnodes_) {
for (auto &spy : area.spy_cnodes()) {
auto cnode = spy->cast<CNodePtr>();
MS_EXCEPTION_IF_NULL(cnode);
size_t v = node_area_map_[spy];
@ -333,8 +334,8 @@ class Splitter {
// The output new_subgraph_cnodes are topo sorted, use a list to store its order in split_plan.
std::vector<size_t> cnodes_group_id;
std::function<void(Area *)> expand_callback = std::bind(&Splitter::AreaExpand, this, std::placeholders::_1);
area_graph->SplitGraph(main_func_graph_, &new_subgraph_cnodes_, &cnodes_group_id, expand_callback);
area_graph->SplitGraph(main_func_graph_, &new_subgraph_cnodes_, &cnodes_group_id,
[this](const Area &area) { this->AreaExpand(area); });
RebuildGraph(cnodes_group_id);
@ -348,6 +349,8 @@ class Splitter {
return SplitterPtr(new Splitter(main_cnode, split_schemer));
}
~Splitter() = default;
private:
Splitter(const CNodePtr &main_cnode, SplitSchemerPtr split_schemer)
: main_func_graph_(main_cnode->func_graph()), old_subgraph_cnode_(main_cnode), split_schemer_(split_schemer) {}
@ -479,9 +482,9 @@ class Splitter {
}
// Copy all Parameter and ValueNode that the area used.
void AreaExpand(Area *area) {
void AreaExpand(const Area &area) {
std::unordered_map<AnfNodePtr, AnfNodePtr> old_valuenode_and_param_map;
for (auto sub_node : area->nodes_) {
for (auto sub_node : area.nodes()) {
auto sub_cnode = sub_node->cast<CNodePtr>();
if (sub_cnode == nullptr) continue;
for (size_t i = 1; i < sub_cnode->inputs().size(); ++i) {
@ -565,7 +568,7 @@ class CostModelSplitSchemer : public Splitter::SplitSchemer {
auto json_desc_str = json_desc.dump();
MS_LOG(DEBUG) << "CallPyFn: [" << kGraphKernelSplitFunc << "] with input json:\n" << json_desc_str;
auto ret = parse::python_adapter::CallPyFn(kGraphKernelModule, kGraphKernelSplitFunc, json_desc_str);
if (ret.is(py::none())) {
if (py::isinstance<py::none>(ret)) {
MS_LOG(ERROR) << "CallPyFn: [" << kGraphKernelSplitFunc << "] return invalid result. input json:\n"
<< json_desc_str;
return false;

@ -463,13 +463,15 @@ std::string AddGlobalId(const std::string &filename) {
static size_t g_id = 0;
std::ostringstream s;
auto i = filename.rfind('/');
if (i == string::npos) {
if (i >= filename.size()) {
s << std::setfill('0') << std::setw(4) << g_id << "_";
s << filename;
} else {
s << filename.substr(0, i + 1);
s << std::setfill('0') << std::setw(4) << g_id << "_";
s << filename.substr(i + 1);
if (i + 1 < filename.size()) {
s << filename.substr(i + 1);
}
}
++g_id;
return s.str();

@ -236,12 +236,7 @@ void UpdateKernelFormatInfo(const CNodePtr &kernel_node, const std::vector<TypeI
}
void SetGraphKernelInfo(const CNodePtr &kernel_node, const FuncGraphPtr &func_graph) {
MS_EXCEPTION_IF_NULL(kernel_node);
MS_EXCEPTION_IF_NULL(func_graph);
std::vector<AnfNodePtr> node_list;
std::vector<AnfNodePtr> input_list;
std::vector<AnfNodePtr> output_list;
std::vector<AnfNodePtr> node_list, input_list, output_list;
kernel::GetValidKernelNodes(func_graph, &node_list, &input_list, &output_list);
std::vector<std::string> graph_input_format;
@ -295,6 +290,22 @@ void SetGraphKernelInfo(const CNodePtr &kernel_node, const FuncGraphPtr &func_gr
AnfAlgo::SetSelectKernelBuildInfo(graph_selected_info, kernel_node.get());
SetTensorDeviceInfo(*graph_selected_info, kernel_node);
}
void PrintUnsupportedTypeException(const CNodePtr &kernel_node, const std::vector<TypeId> &inputs_type,
const std::vector<TypeId> &outputs_type) {
auto kernel_name = AnfAlgo::GetCNodeName(kernel_node);
std::string build_type = "in [";
std::for_each(std::begin(inputs_type), std::end(inputs_type),
[&build_type](auto i) { build_type += mindspore::kernel::TypeId2String(i) + " "; });
build_type += "] out [";
std::for_each(std::begin(outputs_type), std::end(outputs_type),
[&build_type](auto i) { build_type += mindspore::kernel::TypeId2String(i) + " "; });
build_type += "]";
auto supported_type_lists = SupportedTypeList(kernel_node);
MS_EXCEPTION(TypeError) << "Select GPU kernel op[" << kernel_name
<< "] fail! Incompatible data type!\nThe supported data types are " << supported_type_lists
<< ", but get " << build_type;
}
} // namespace
void FormatTransformChecker::CheckSupportFormatTransform(const std::shared_ptr<session::KernelGraph> &kernel_graph) {
@ -329,7 +340,7 @@ void FormatTransformChecker::CheckSupportFormatTransform(const std::shared_ptr<s
void SetKernelInfo(const CNodePtr &kernel_node, KernelType kernel_type) {
if (AnfAlgo::IsGraphKernel(kernel_node)) {
auto func_graph = GetValueNode<FuncGraphPtr>(kernel_node->input(kAnfPrimitiveIndex));
auto func_graph = AnfAlgo::GetCNodeFuncGraphPtr(kernel_node);
MS_EXCEPTION_IF_NULL(func_graph);
SetGraphKernelInfo(kernel_node, func_graph);
return;
@ -351,8 +362,7 @@ void SetKernelInfo(const CNodePtr &kernel_node, KernelType kernel_type) {
if (IsNeedProcessFormatInfo(kernel_node, inputs_type)) {
UpdateKernelFormatInfo(kernel_node, inputs_type, &inputs_format, &outputs_format, &origin_data_format);
}
std::shared_ptr<KernelBuildInfo::KernelBuildInfoBuilder> builder =
std::make_shared<KernelBuildInfo::KernelBuildInfoBuilder>();
auto builder = std::make_shared<KernelBuildInfo::KernelBuildInfoBuilder>();
builder->SetOriginDataFormat(origin_data_format);
builder->SetInputsFormat(inputs_format);
builder->SetInputsDeviceType(inputs_type);
@ -360,35 +370,23 @@ void SetKernelInfo(const CNodePtr &kernel_node, KernelType kernel_type) {
builder->SetOutputsDeviceType(outputs_type);
bool result = false;
KernelType res_kernel_type = UNKNOWN_KERNEL_TYPE;
if (kernel_type == UNKNOWN_KERNEL_TYPE) {
result =
kernel::GpuKernelFactory::GetInstance().SearchRegistered(AnfAlgo::GetCNodeName(kernel_node), builder->Build());
if (!result) {
result = SelectAkgKernel(kernel_node, builder->Build());
res_kernel_type = AKG_KERNEL;
kernel_type = AKG_KERNEL;
}
} else if (kernel_type == AKG_KERNEL) {
result = SelectAkgKernel(kernel_node, builder->Build());
res_kernel_type = AKG_KERNEL;
}
if (!result) {
auto kernel_name = AnfAlgo::GetCNodeName(kernel_node);
std::string build_type = "in [";
std::for_each(std::begin(inputs_type), std::end(inputs_type),
[&build_type](auto i) { build_type += mindspore::kernel::TypeId2String(i) + " "; });
build_type += "] out [";
std::for_each(std::begin(outputs_type), std::end(outputs_type),
[&build_type](auto i) { build_type += mindspore::kernel::TypeId2String(i) + " "; });
build_type += "]";
auto supported_type_lists = SupportedTypeList(kernel_node);
MS_EXCEPTION(TypeError) << "Select GPU kernel op[" << kernel_name
<< "] fail! Incompatible data type!\nThe supported data types are " << supported_type_lists
<< ", but get " << build_type;
}
builder->SetKernelType(res_kernel_type);
PrintUnsupportedTypeException(kernel_node, inputs_type, outputs_type);
return;
}
builder->SetKernelType(kernel_type);
builder->SetProcessor(kernel::Processor::CUDA);
AnfAlgo::SetSelectKernelBuildInfo(builder->Build(), kernel_node.get());
SetTensorDeviceInfo(*(builder->Build()), kernel_node);

Loading…
Cancel
Save