From: @zhao_zhixuan Reviewed-by: @xchu42,@ji_chen Signed-off-by: @ji_chentags/v1.3.0
@@ -693,6 +693,22 @@ namespace { | |||
} | |||
} | |||
bool GeGenerator::CheckNoAicore(const ComputeGraphPtr &graph) { | |||
for (const auto &node : graph->GetDirectNode()) { | |||
if (node == nullptr) { | |||
continue; | |||
} | |||
auto op_desc = node->GetOpDesc(); | |||
if (op_desc == nullptr) { | |||
continue; | |||
} | |||
if (op_desc->GetOpEngineName() == kAIcoreEngine) { | |||
return false; | |||
} | |||
} | |||
return true; | |||
} | |||
Status GeGenerator::CheckForSingleOp(OpDescPtr &op_desc, const vector<GeTensor> &inputs, | |||
const vector<GeTensor> &outputs) { | |||
GE_CHECK_NOTNULL_EXEC(op_desc, return PARAM_INVALID); | |||
@@ -773,7 +789,7 @@ Status GeGenerator::BuildSingleOp(OpDescPtr &op_desc, const vector<GeTensor> &in | |||
bool all_shape = false; | |||
(void)AttrUtils::GetBool(op_desc, kAicpuAllshape, all_shape); | |||
if (all_shape) { | |||
if (all_shape && CheckNoAicore(root_graph)) { | |||
GELOGD("Get aicpu all_shape kernel!"); | |||
vector<GeTensor> inputs_dynamic; | |||
vector<GeTensor> outputs_dynamic; | |||
@@ -44,19 +44,46 @@ namespace ge { | |||
namespace { | |||
const size_t kDataOutputNum = 1; | |||
bool NeedHybridModel(GeModelPtr &ge_model) { | |||
Status IfInferDepend(GeModelPtr &ge_model, bool &flag) { | |||
auto comp_graph = GraphUtils::GetComputeGraph(ge_model->GetGraph()); | |||
GE_CHECK_NOTNULL(comp_graph); | |||
for (const auto &node : comp_graph->GetAllNodes()) { | |||
auto op_desc = node->GetOpDesc(); | |||
GE_CHECK_NOTNULL(op_desc); | |||
const auto &depends = op_desc->GetOpInferDepends(); | |||
if (!depends.empty()) { | |||
flag = true; | |||
return SUCCESS; | |||
} | |||
} | |||
return SUCCESS; | |||
} | |||
Status NeedHybridModel(GeModelPtr &ge_model, bool &flag) { | |||
bool infer_depend_flag = false; | |||
GE_CHK_STATUS_RET(IfInferDepend(ge_model, infer_depend_flag), "[Check][InferDepend] failed."); | |||
auto tasks = ge_model->GetModelTaskDefPtr()->task(); | |||
int32_t kernel_task_num = 0; | |||
for (int i = 0; i < tasks.size(); ++i) { | |||
auto task_type = static_cast<rtModelTaskType_t>(tasks[i].type()); | |||
if (task_type == RT_MODEL_TASK_KERNEL || task_type == RT_MODEL_TASK_ALL_KERNEL) { | |||
kernel_task_num++; | |||
if (kernel_task_num > 1) { | |||
return true; | |||
const auto &context = task_type == RT_MODEL_TASK_KERNEL ? tasks[i].kernel().context() : | |||
tasks[i].kernel_with_handle().context(); | |||
auto kernel_type = static_cast<ccKernelType>(context.kernel_type()); | |||
if (kernel_type == ccKernelType::TE) { | |||
if (infer_depend_flag) { | |||
flag = true; | |||
return SUCCESS; | |||
} | |||
kernel_task_num++; | |||
if (kernel_task_num > 1) { | |||
flag = true; | |||
return SUCCESS; | |||
} | |||
} | |||
} | |||
} | |||
return false; | |||
return SUCCESS; | |||
} | |||
} // namespace | |||
@@ -503,7 +530,9 @@ Status SingleOpModel::BuildDynamicOp(StreamResource &resource, DynamicSingleOp & | |||
auto ge_model = model_helper_.GetGeModel(); | |||
GE_CHECK_NOTNULL(ge_model); | |||
if (NeedHybridModel(ge_model)) { | |||
bool need_hybrid_model = false; | |||
GE_CHK_STATUS_RET(NeedHybridModel(ge_model, need_hybrid_model), "[Check][NeedHybridModel] failed."); | |||
if (need_hybrid_model) { | |||
GELOGD("Build single op HybridModel."); | |||
GE_CHK_STATUS_RET_NOLOG(hybrid::NodeExecutorManager::GetInstance().EnsureInitialized()); | |||
auto root_model = model_helper_.GetGeRootModel(); | |||
@@ -98,6 +98,7 @@ class GE_FUNC_VISIBILITY GeGenerator { | |||
Status BuildSingleOp(OpDescPtr &op_desc, const vector<GeTensor> &inputs, const vector<GeTensor> &outputs, | |||
const string &model_file_name, OpEngineType engine_type, ModelBufferData &model_buff, | |||
bool is_offline = true); | |||
bool CheckNoAicore(const ComputeGraphPtr &graph); | |||
Status CheckForSingleOp(OpDescPtr &op_desc, const vector<GeTensor> &inputs, const vector<GeTensor> &outputs); | |||
using GeRootModelPtr = std::shared_ptr<ge::GeRootModel>; | |||
@@ -88,6 +88,13 @@ TEST_F(UtestGeGenerator, test_build_single_op_online) { | |||
EXPECT_EQ(generator.BuildSingleOpModel(op_desc, inputs, outputs, ENGINE_AIVECTOR, model_buffer), FAILED); | |||
} | |||
TEST_F(UtestGeGenerator, test_check_aicore) { | |||
GeGenerator generator; | |||
generator.Initialize({}); | |||
auto graph = MakeGraph(); | |||
EXPECT_EQ(generator.CheckNoAicore(graph), true); | |||
} | |||
TEST_F(UtestGeGenerator, test_graph_manager) { | |||
GraphManager graph_manager; | |||
GraphPartitioner graph_partitioner; | |||
@@ -17,7 +17,6 @@ | |||
#include <gtest/gtest.h> | |||
#include <vector> | |||
//#include "cce/taskdown_common.hpp" | |||
#include "graph/load/model_manager/model_utils.h" | |||
#include "graph/utils/graph_utils.h" | |||
#include "runtime/rt.h" | |||
@@ -196,4 +195,31 @@ TEST_F(UtestSingleOpModel, test_op_task_get_profiler_args) { | |||
ASSERT_EQ(model_id, 1); | |||
} | |||
TEST_F(UtestSingleOpModel, test_build_dynamic_op) { | |||
string model_data_str = "123456789"; | |||
SingleOpModel model("model", model_data_str.c_str(), model_data_str.size()); | |||
model.netoutput_op_ = make_shared<OpDesc>("NetOutput", "NetOutput"); | |||
model.model_helper_.model_ = ge::MakeShared<ge::GeModel>(); | |||
// make graph | |||
auto compute_graph = make_shared<ComputeGraph>("graph"); | |||
auto data_op = make_shared<OpDesc>("Data", DATA); | |||
auto data_node = compute_graph->AddNode(data_op); | |||
auto graph = GraphUtils::CreateGraphFromComputeGraph(compute_graph); | |||
model.model_helper_.model_->SetGraph(graph); | |||
// set task_def | |||
auto model_task_def = make_shared<domi::ModelTaskDef>(); | |||
domi::TaskDef *task_def = model_task_def->add_task(); | |||
task_def->set_type(RT_MODEL_TASK_KERNEL); | |||
domi::KernelDef *kernel_def = task_def->mutable_kernel(); | |||
domi::KernelContext *context = kernel_def->mutable_context(); | |||
context->set_kernel_type(2); // ccKernelType::TE | |||
model.model_helper_.model_->SetModelTaskDef(model_task_def); | |||
std::mutex stream_mu_; | |||
DynamicSingleOp dynamic_single_op(0, &stream_mu_, nullptr); | |||
StreamResource res((uintptr_t)1); | |||
model.BuildDynamicOp(res, dynamic_single_op); | |||
} | |||