!1133 update graphengine_0222

From: @shenwei41
Reviewed-by: @lilongfei15,@ljl0711
Signed-off-by: @ljl0711
pull/1133/MERGE
mindspore-ci-bot 4 years ago committed by Gitee
commit b9050a8c51

@ -189,7 +189,6 @@ set(TRAIN_SRC_LIST
"graph/passes/atomic_addr_clean_pass.cc"
"graph/passes/mark_same_addr_pass.cc"
"graph/passes/mark_graph_unknown_status_pass.cc"
"graph/passes/dynamic_single_op_reset_shape_pass.cc"
"graph/passes/mark_agnostic_pass.cc"
"graph/partition/dynamic_shape_partition.cc"
"graph/partition/stage_partition.cc"
@ -351,6 +350,7 @@ set(TRAIN_SRC_LIST
"hybrid/executor/node_done_manager.cc"
"hybrid/executor/hybrid_profiler.cc"
"hybrid/executor/hybrid_model_executor.cc"
"hybrid/executor/hybrid_model_pipeline_executor.cc"
"hybrid/executor/hybrid_model_async_executor.cc"
"hybrid/executor/hybrid_execution_context.cc"
"hybrid/executor/subgraph_context.cc"
@ -388,6 +388,9 @@ set(TRAIN_SRC_LIST
"client/ge_api.cc"
"analyzer/analyzer.cc"
"ir_build/ge_ir_build.cc"
"ir_build/attr_options/utils.cc"
"ir_build/attr_options/keep_dtype_option.cc"
"ir_build/attr_options/weight_compress_option.cc"
"ir_build/atc_ir_common.cc"
"graph/build/memory/memory_assigner.cc"
"graph/build/memory/graph_mem_assigner.cc"
@ -495,7 +498,6 @@ set(INFER_SRC_LIST
"graph/passes/atomic_addr_clean_pass.cc"
"graph/passes/mark_same_addr_pass.cc"
"graph/passes/mark_graph_unknown_status_pass.cc"
"graph/passes/dynamic_single_op_reset_shape_pass.cc"
"graph/passes/mark_agnostic_pass.cc"
"graph/common/omg_util.cc"
"graph/common/bcast.cc"
@ -641,6 +643,9 @@ set(INFER_SRC_LIST
"graph/load/model_manager/task_info/super_kernel/super_kernel.cc"
"hybrid/hybrid_davinci_model_stub.cc"
"ir_build/ge_ir_build.cc"
"ir_build/attr_options/utils.cc"
"ir_build/attr_options/keep_dtype_option.cc"
"ir_build/attr_options/weight_compress_option.cc"
"ir_build/atc_ir_common.cc"
"graph/preprocess/insert_op/ge_aipp_op.cc"
"graph/preprocess/insert_op/util_insert_aipp_op.cc"

@ -512,8 +512,8 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY Status ModelHelper::LoadModel(c
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY Status ModelHelper::LoadRootModel(const ge::ModelData &model_data) {
if (model_data.model_data == nullptr || model_data.model_len == 0) {
GELOGE(GE_EXEC_MODEL_DATA_SIZE_INVALID, "Model_data is nullptr, or model_data_size is 0");
return GE_EXEC_MODEL_DATA_SIZE_INVALID;
GELOGE(ACL_ERROR_GE_EXEC_MODEL_DATA_SIZE_INVALID, "Model_data is nullptr, or model_data_size is 0");
return ACL_ERROR_GE_EXEC_MODEL_DATA_SIZE_INVALID;
}
if (is_assign_model_) {

@ -207,9 +207,9 @@ Status OmFileLoadHelper::LoadModelPartitionTable(uint8_t *model_data, uint32_t m
"ModelFileHeader length :%zu, ModelPartitionTable length :%zu",
index, partition_table->num, sizeof(ModelFileHeader), partition_table_size);
if (model_data_size <= cur_offset) {
GELOGE(GE_EXEC_MODEL_DATA_SIZE_INVALID, "invalid model data, partition_table->num:%u, model data size %u",
GELOGE(ACL_ERROR_GE_EXEC_MODEL_DATA_SIZE_INVALID, "invalid model data, partition_table->num:%u, model data size %u",
partition_table->num, model_data_size);
return GE_EXEC_MODEL_DATA_SIZE_INVALID;
return ACL_ERROR_GE_EXEC_MODEL_DATA_SIZE_INVALID;
}
for (uint32_t i = 0; i < partition_table->num; i++) {
@ -231,9 +231,10 @@ Status OmFileLoadHelper::LoadModelPartitionTable(uint8_t *model_data, uint32_t m
}
if (partition.size > model_data_size || cur_offset > model_data_size - partition.size) {
GELOGE(GE_EXEC_MODEL_DATA_SIZE_INVALID, "The partition size %u is greater than the model data size %u.",
GELOGE(ACL_ERROR_GE_EXEC_MODEL_DATA_SIZE_INVALID,
"The partition size %u is greater than the model data size %u.",
partition.size + cur_offset, model_data_size);
return GE_EXEC_MODEL_DATA_SIZE_INVALID;
return ACL_ERROR_GE_EXEC_MODEL_DATA_SIZE_INVALID;
}
cur_offset += partition.size;
GELOGD("Partition, type:%d, size:%u, model_index:%u", static_cast<int>(partition.type), partition.size, index);

@ -81,6 +81,7 @@ set(SRC_LIST
"../hybrid/executor/node_done_manager.cc"
"../hybrid/executor/hybrid_profiler.cc"
"../hybrid/executor/hybrid_model_executor.cc"
"../hybrid/executor/hybrid_model_pipeline_executor.cc"
"../hybrid/executor/hybrid_model_async_executor.cc"
"../hybrid/executor/hybrid_execution_context.cc"
"../hybrid/executor/subgraph_context.cc"

@ -175,14 +175,14 @@ bool IsDynamicImageSizeMatchModel(uint64_t image_height, uint64_t image_width,
bool IsDynmaicDimsSizeMatchModel(const vector<uint64_t> cur_dynamic_dims,
const vector<vector<int64_t>> &batch_info) {
if (batch_info.empty()) {
GELOGE(ge::FAILED, "Dynamic batch info is empty.");
GELOGE(ACL_ERROR_GE_PARAM_INVALID, "Dynamic batch info is empty.");
return false;
}
bool find_match = false;
for (auto resolution : batch_info) {
if (cur_dynamic_dims.size() != resolution.size()) {
GELOGE(ge::FAILED, "Cur dynamic dims param num is %zu, current resolution size is %zu.",
GELOGE(ACL_ERROR_GE_PARAM_INVALID, "Cur dynamic dims param num is %zu, current resolution size is %zu.",
cur_dynamic_dims.size(), resolution.size());
return false;
}
@ -199,7 +199,7 @@ bool IsDynmaicDimsSizeMatchModel(const vector<uint64_t> cur_dynamic_dims,
}
}
if (!find_match) {
GELOGE(ge::FAILED, "choose dynamic dims can not match the gear of model.");
GELOGE(ACL_ERROR_GE_PARAM_INVALID, "choose dynamic dims can not match the gear of model.");
}
return find_match;
}

@ -70,6 +70,9 @@ GRAPH_MANAGER_LOCAL_SRC_FILES := \
BUILER_SRC_FILES := \
ir_build/ge_ir_build.cc \
ir_build/attr_options/utils.cc \
ir_build/attr_options/keep_dtype_option.cc \
ir_build/attr_options/weight_compress_option.cc \
ir_build/atc_ir_common.cc \
ANALYZER_SRC_FILES:= \
@ -111,7 +114,6 @@ OMG_HOST_SRC_FILES := \
graph/passes/atomic_addr_clean_pass.cc \
graph/passes/mark_same_addr_pass.cc \
graph/passes/mark_graph_unknown_status_pass.cc \
graph/passes/dynamic_single_op_reset_shape_pass.cc \
graph/passes/mark_agnostic_pass.cc \
graph/common/omg_util.cc \
graph/common/bcast.cc \

@ -114,7 +114,6 @@ LIBGE_LOCAL_SRC_FILES := \
graph/passes/atomic_addr_clean_pass.cc \
graph/passes/mark_same_addr_pass.cc \
graph/passes/mark_graph_unknown_status_pass.cc \
graph/passes/dynamic_single_op_reset_shape_pass.cc \
graph/passes/mark_agnostic_pass.cc \
graph/partition/dynamic_shape_partition.cc \
graph/partition/stage_partition.cc \
@ -312,6 +311,9 @@ LIBGE_LOCAL_SRC_FILES := \
executor/ge_executor.cc \
analyzer/analyzer.cc \
ir_build/ge_ir_build.cc \
ir_build/attr_options/utils.cc \
ir_build/attr_options/keep_dtype_option.cc \
ir_build/attr_options/weight_compress_option.cc \
ir_build/atc_ir_common.cc \
LIBCLIENT_LOCAL_SRC_FILES := \

@ -48,7 +48,7 @@ const char *const kVectorEngine = "VectorEngine";
const char *const kAIcoreEngine = "AIcoreEngine";
const char *const kFileNameSuffix = "online";
const char *const kAicpuAllshape = "_AllShape";
const size_t kDynamicDimSize = 1;
constexpr char const *kAttrSupportDynamicShape = "support_dynamicshape";
const int64_t kDynamicDimValue = -2;
std::map<ge::OpEngineType, std::string> engine_type_map{
@ -251,30 +251,6 @@ static void GetOpsProtoPath(string &opsproto_path) {
opsproto_path = (path_base + "ops/op_proto/custom/" + ":") + (path_base + "ops/op_proto/built-in/");
}
static Status CheckShapeReset(const OpDescPtr &op_desc, bool &change_shape_flag) {
GE_CHECK_NOTNULL_EXEC(op_desc, return PARAM_INVALID);
change_shape_flag = false;
for (size_t i = 0; i < op_desc->GetAllInputsDesc().size(); i++) {
auto input_desc = op_desc->MutableInputDesc(static_cast<uint32_t>(i));
GE_CHECK_NOTNULL(input_desc);
// pass scalar input desc
auto dims = input_desc->GetShape().GetDims();
if (dims.size() == kDynamicDimSize && dims[0] == kDynamicDimValue) {
change_shape_flag = true;
}
}
for (size_t i = 0; i < op_desc->GetAllOutputsDesc().size(); i++) {
auto output_desc = op_desc->MutableOutputDesc(static_cast<uint32_t>(i));
GE_CHECK_NOTNULL(output_desc);
// pass scalar output desc
auto dims = output_desc->GetShape().GetDims();
if (dims.size() == kDynamicDimSize && dims[0] == kDynamicDimValue) {
change_shape_flag = true;
}
}
return SUCCESS;
}
static Status ResetTensorVecShape(const vector<GeTensor> &inputs, vector<GeTensor> &inputs_dynamic) {
for (auto input : inputs) {
auto input_desc = input.GetTensorDesc();
@ -289,7 +265,7 @@ static Status ResetTensorVecShape(const vector<GeTensor> &inputs, vector<GeTenso
bool is_const = false;
(void)AttrUtils::GetBool(input_desc, CONST_ATTR_NAME_INPUT, is_const);
if (!is_const && shape_ori.GetDims().size() > 0) {
if (!is_const) {
int64_t storage_format = FORMAT_NCHW;
if (ge::AttrUtils::GetInt(desc, ge::ATTR_NAME_STORAGE_FORMAT, storage_format) &&
!ge::AttrUtils::SetListInt(desc, ge::ATTR_NAME_STORAGE_SHAPE, dynamic_shape_dims)) {
@ -645,6 +621,32 @@ namespace {
}
return is_need;
}
Status CheckDynamicSupport(GeModelPtr &ge_model, const ComputeGraphPtr &graph) {
bool support_dynamic = true;
bool is_dynamic = false;
for (const auto &node : graph->GetDirectNode()) {
GE_CHECK_NOTNULL(node);
if (node->GetType() == DATA || node->GetType() == CONSTANT || node->GetType() == CONSTANTOP ||
node->GetType() == NETOUTPUT) {
continue;
}
auto op_desc = node->GetOpDesc();
GE_CHECK_NOTNULL(op_desc);
if (AttrUtils::HasAttr(op_desc, kAttrSupportDynamicShape)) {
is_dynamic = true;
(void) AttrUtils::GetBool(op_desc, kAttrSupportDynamicShape, support_dynamic);
if (!support_dynamic) {
GELOGW("Node[%s] doesn't support dynamic shape.", node->GetName().c_str());
break;
}
}
}
if (is_dynamic) {
(void) AttrUtils::SetBool(ge_model, kAttrSupportDynamicShape, support_dynamic);
}
return SUCCESS;
}
}
Status GeGenerator::CheckForSingleOp(OpDescPtr &op_desc, const vector<GeTensor> &inputs,
@ -719,14 +721,14 @@ Status GeGenerator::BuildSingleOp(OpDescPtr &op_desc, const vector<GeTensor> &in
GELOGE(PARAM_INVALID, "GetSubgraphInstanceNameToModel is empty.");
return PARAM_INVALID;
}
const ComputeGraphPtr root_graph = ge_root_model->GetRootGraph();
GeModelPtr &ge_model = name_to_ge_model.begin()->second;
GE_CHK_STATUS_RET_NOLOG(CheckDynamicSupport(ge_model, root_graph));
GELOGD("The opType in op_desc_tmp is [%s]", op_desc_tmp->GetType().c_str());
bool all_shape = false;
bool dynamic_flag = false;
(void)AttrUtils::GetBool(op_desc, kAicpuAllshape, all_shape);
CheckShapeReset(op_desc, dynamic_flag);
if (dynamic_flag || all_shape) {
if (all_shape) {
GELOGD("Get aicpu all_shape kernel!");
vector<GeTensor> inputs_dynamic;
vector<GeTensor> outputs_dynamic;

File diff suppressed because it is too large Load Diff

@ -125,6 +125,14 @@ class GraphMemoryAssigner {
ge::Status ReAssignAtomicMemory(bool is_loop_graph);
ge::Status GetAllRef(const NodePtr &node, std::map<int32_t, int32_t> &out2ins);
bool AssignContinuousInputMemoryWithAtomicProcessDirectly(const NodePtr &input_continuous_node,
std::map<NodePtr, uint32_t> &node_2_continuous_type);
ge::Status AssignContinuousInputMemoryWithAtomicProcess(const NodePtr &input_continuous_node,
uint32_t continuous_type);
ge::Status FilterAtomicNodesForMemoryAssign(map<string, map<NodePtr, vector<NodePtr>>> &normal_atomic_nodes_map,
map<string, vector<NodePtr>> &connecting_output_atomic_nodes);

@ -35,7 +35,7 @@ using std::vector;
namespace {
const int64_t kTaskNumPerNormalNode = 3;
const int64_t kTaskNumPerHcclNode = 200;
const int64_t kTaskNumPerHcclNode = 245;
const char *const kTrueStr = "true";
const char *const kFalseStr = "false";

@ -728,6 +728,7 @@ Status DavinciModel::Init(void *dev_ptr, size_t mem_size, void *weight_ptr, size
GE_CHK_RT_RET(rtSetCtxINFMode((fp_ceiling_mode != "0")));
}
SetProfileTime(MODEL_LOAD_END);
// collect profiling for ge
GE_CHK_STATUS_RET(InitModelProfile(), "Init model profile failed");
auto &profiling_manager = ProfilingManager::Instance();
@ -2279,8 +2280,12 @@ Status DavinciModel::SinkModelProfile() {
}
// stream id info
uint32_t streamId = profile.fusion_info.stream_id;
reporter_data.data = (unsigned char *)&streamId;
uint32_t stream_id = 0;
auto iter = profiler_report_op_info_.find(fusion_op_name);
if (iter != profiler_report_op_info_.end()) {
stream_id = iter->second.second;
}
reporter_data.data = (unsigned char *)&stream_id;
reporter_data.dataLen = sizeof(int32_t);
GE_CHK_BOOL_EXEC(prof_mgr.CallMsprofReport(reporter_data) == 0, return FAILED,
"Reporter data fail, model id:%u.", this->Id());
@ -3278,8 +3283,8 @@ bool DavinciModel::CheckInputAndModelSize(const int64_t &input_size, const int64
}
// The input and model input size can not be exactly equal because user input is not definite.
if ((input_size + kDataMemAlignSizeCompare) < op_size) {
GELOGE(FAILED, "Input size [%ld] can not be smaller than op size [%ld] after 64-byte alignment", input_size,
op_size);
GELOGE(ACL_ERROR_GE_PARAM_INVALID,
"Input size [%ld] can not be smaller than op size [%ld] after 64-byte alignment", input_size, op_size);
return false;
}
return true;
@ -3329,27 +3334,28 @@ Status DavinciModel::UpdateIoTaskArgs(const std::map<uint32_t, ZeroCopyOffset> &
string input_or_output = "input";
is_input ? input_or_output = "input" : input_or_output = "output";
if (blobs.size() != data_info.size()) {
GELOGE(FAILED, "Verify %s data num failed: model requires %zu, but user actually feeds %zu",
GELOGE(ACL_ERROR_GE_PARAM_INVALID, "Verify %s data num failed: model requires %zu, but user actually feeds %zu",
input_or_output.c_str(), data_info.size(), blobs.size());
return FAILED;
return ACL_ERROR_GE_PARAM_INVALID;
}
for (const auto &data : data_info) {
if (data.first >= blobs.size()) { // check data index.
GELOGE(FAILED, "Verify %s data num failed: can not find No.%u data, because user only feeds %zu",
GELOGE(ACL_ERROR_GE_PARAM_INVALID, "Verify %s data num failed: can not find No.%u data, because user only feeds %zu",
input_or_output.c_str(), data.first, blobs.size());
return FAILED;
return ACL_ERROR_GE_PARAM_INVALID;
}
const DataBuffer &buffer = blobs[data.first]; // index of data.
if (buffer.data == nullptr) {
GELOGE(FAILED, "data_buf.data is nullptr, index=%u", data.first);
return FAILED;
GELOGE(ACL_ERROR_GE_PARAM_INVALID, "data_buf.data is nullptr, index=%u", data.first);
return ACL_ERROR_GE_PARAM_INVALID;
}
if (!CheckInputAndModelSize(buffer.length, data.second.GetDataSize(), is_dynamic)) {
GELOGE(FAILED, "Check input size and model size failed, op[%s]", data.second.GetOpName().c_str());
return FAILED;
GELOGE(ACL_ERROR_GE_PARAM_INVALID,
"Check input size and model size failed, op[%s]", data.second.GetOpName().c_str());
return ACL_ERROR_GE_PARAM_INVALID;
}
void *basic_addr = data.second.GetBasicAddr();
@ -3357,9 +3363,10 @@ Status DavinciModel::UpdateIoTaskArgs(const std::map<uint32_t, ZeroCopyOffset> &
if (copy_only_addrs_.count(basic_addr) > 0) {
if (is_input) {
GELOGI("[IMAS] Find addr %p need direct copy from user malloc input %p", basic_addr, buffer.data);
if (rtMemcpy(basic_addr, data_size, buffer.data, buffer.length, RT_MEMCPY_DEVICE_TO_DEVICE) != RT_ERROR_NONE) {
GELOGE(FAILED, "Non-zero copy data node copy failed");
return FAILED;
rtError_t rt_ret = rtMemcpy(basic_addr, data_size, buffer.data, buffer.length, RT_MEMCPY_DEVICE_TO_DEVICE);
if (rt_ret != RT_ERROR_NONE) {
GELOGE(rt_ret, "Non-zero copy data node copy failed");
return RT_ERROR_TO_GE_STATUS(rt_ret);
}
}
GELOGI("No need to exeucte zero copy task because this addr %p need direct copy.", basic_addr);
@ -3380,7 +3387,7 @@ Status DavinciModel::UpdateIoTaskArgs(const std::map<uint32_t, ZeroCopyOffset> &
}
uintptr_t addr_val = reinterpret_cast<uintptr_t>(addr);
if (task.UpdateTaskParam(addr_val, buffer_addr) != SUCCESS) {
return FAILED;
return ACL_ERROR_GE_PARAM_INVALID;
}
}
}

@ -55,16 +55,18 @@ const char *const kDeleteCustOp = "deleteCustOp";
const int kTimeSpecNano = 1000000000;
const int kTimeSpecMiro = 1000000;
const int kOpNameMaxSize = 100;
#pragma pack(push, 1)
struct CustAicpuSoBuf {
uint64_t kernelSoBuf;
uint32_t kernelSoBufLen;
uint64_t kernelSoName;
uint32_t kernelSoNameLen;
} __attribute__((packed));
};
struct BatchLoadOpFromBufArgs {
uint32_t soNum;
uint64_t args;
} __attribute__((packed));
};
#pragma pack(pop)
} // namespace
DumpProperties ModelManager::dump_properties_;
@ -328,7 +330,8 @@ Status ModelManager::LoadModelOnline(uint32_t &model_id, const shared_ptr<ge::Ge
GELOGE(FAILED, "davinci_model is nullptr");
return FAILED;
}
davinci_model->SetProfileTime(MODEL_LOAD_START, (timespec.tv_sec * kTimeSpecNano +
timespec.tv_nsec)); // 1000 ^ 3 converts second to nanosecond
davinci_model->SetId(model_id);
davinci_model->SetDeviceId(GetContext().DeviceId());
@ -355,10 +358,6 @@ Status ModelManager::LoadModelOnline(uint32_t &model_id, const shared_ptr<ge::Ge
InsertModel(model_id, davinci_model);
GELOGI("Parse model %u success.", model_id);
davinci_model->SetProfileTime(MODEL_LOAD_START, (timespec.tv_sec * kTimeSpecNano +
timespec.tv_nsec)); // 1000 ^ 3 converts second to nanosecond
davinci_model->SetProfileTime(MODEL_LOAD_END);
} while (0);
GE_CHK_RT(rtDeviceReset(static_cast<int32_t>(GetContext().DeviceId())));
@ -1085,6 +1084,8 @@ Status ModelManager::LoadModelOffline(uint32_t &model_id, const ModelData &model
GELOGE(ACL_ERROR_GE_MEMORY_ALLOCATION, "Make shared failed since other exception raise");
return ACL_ERROR_GE_MEMORY_ALLOCATION;
}
davinci_model->SetProfileTime(MODEL_LOAD_START, (timespec.tv_sec * kTimeSpecNano +
timespec.tv_nsec)); // 1000 ^ 3 converts second to nanosecond
ret = davinci_model->Assign(ge_model);
if (ret != SUCCESS) {
GELOGW("assign model failed.");
@ -1122,10 +1123,6 @@ Status ModelManager::LoadModelOffline(uint32_t &model_id, const ModelData &model
GELOGI("Parse model %u success.", model_id);
davinci_model->SetProfileTime(MODEL_LOAD_START, (timespec.tv_sec * kTimeSpecNano +
timespec.tv_nsec)); // 1000 ^ 3 converts second to nanosecond
davinci_model->SetProfileTime(MODEL_LOAD_END);
GE_IF_BOOL_EXEC(ret == SUCCESS, device_count++);
return SUCCESS;
} while (0);

@ -29,6 +29,10 @@
#include "hybrid/node_executor/aicpu/aicpu_ext_info.h"
#include "framework/common/debug/log.h"
namespace {
const char *const kAicpuAllshape = "_AllShape";
} // namespace
namespace ge {
Status KernelExTaskInfo::InitTaskExtInfo(const std::string &ext_info, const OpDescPtr &op_desc) {
if (ext_info.empty()) {
@ -50,6 +54,25 @@ Status KernelExTaskInfo::InitTaskExtInfo(const std::string &ext_info, const OpDe
GE_CHK_STATUS_RET(ext_handle->UpdateExecuteMode(true), "UpdateExecuteMode failed.");
GELOGD("Update aicpu_task ext_info bit_map execute mode to 1.");
bool all_shape = false;
(void)AttrUtils::GetBool(op_desc, kAicpuAllshape, all_shape);
if (all_shape) {
GELOGD("Aicpu all_shape kernel need to update io shape.");
for (uint32_t i = 0; i < num_inputs; i++) {
auto input_desc = op_desc->MutableInputDesc(i);
GE_CHECK_NOTNULL(input_desc);
GE_CHK_STATUS_RET(ext_handle->UpdateInputShapeAndType(i, *input_desc),
"Input[%u] update input shape failed.", i);
}
if (unknown_type != DEPEND_COMPUTE) {
for (uint32_t j = 0; j < num_outputs; j++) {
auto output_desc = op_desc->MutableOutputDesc(j);
GE_CHECK_NOTNULL(output_desc);
GE_CHK_STATUS_RET(ext_handle->UpdateOutputShapeAndType(j, *output_desc),
"Output[%u] update output shape failed.", j);
}
}
}
auto rt_ret = rtMalloc(&ext_info_addr_, ext_handle->GetExtInfoLen(), RT_MEMORY_HBM);
GE_IF_BOOL_EXEC(rt_ret != RT_ERROR_NONE,
GELOGE(RT_FAILED, "rtMalloc ext_info error: 0x%X, size=%zu", rt_ret, ext_info.size());

@ -43,6 +43,7 @@ constexpr int64_t kInvalidGroupKey = -1;
constexpr uint32_t kSKTSingleSize = 1;
const char *kIsLastNode = "is_last_node";
const char *kIsFirstNode = "is_first_node";
const char *const kAicpuAllshape = "_AllShape";
const int64_t kCloseSkt = 100;
const uint32_t kAddrLen = sizeof(void *);
const int kBaseInt = 10;
@ -985,6 +986,23 @@ Status KernelTaskInfo::InitAicpuTaskExtInfo(const std::string &ext_info) {
GE_CHK_STATUS_RET(ext_handle->UpdateExecuteMode(true), "UpdateExecuteMode failed.");
GELOGD("Update aicpu_task ext_info bit_map execute mode to 1.");
bool all_shape = false;
(void)AttrUtils::GetBool(op_desc_, kAicpuAllshape, all_shape);
if (all_shape) {
GELOGD("Aicpu all_shape kernel need to update io shape.");
for (uint32_t i = 0; i < num_inputs; i++) {
auto input_desc = op_desc_->MutableInputDesc(i);
GE_CHECK_NOTNULL(input_desc);
GE_CHK_STATUS_RET(ext_handle->UpdateInputShapeAndType(i, *input_desc),
"Input[%u] update input shape failed.", i);
}
for (uint32_t j = 0; j < num_outputs; j++) {
auto output_desc = op_desc_->MutableOutputDesc(j);
GE_CHECK_NOTNULL(output_desc);
GE_CHK_STATUS_RET(ext_handle->UpdateOutputShapeAndType(j, *output_desc),
"Output[%u] update output shape failed.", j);
}
}
auto rt_ret = rtMalloc(&aicpu_ext_info_addr_, ext_handle->GetExtInfoLen(), RT_MEMORY_HBM);
if (rt_ret != RT_ERROR_NONE) {
GELOGE(RT_FAILED, "rtMalloc ext_info error: 0x%X, size=%zu", rt_ret, ext_info.size());

@ -59,7 +59,6 @@
#include "graph/passes/iterator_op_pass.h"
#include "graph/passes/link_gen_mask_nodes_pass.h"
#include "graph/passes/mark_graph_unknown_status_pass.h"
#include "graph/passes/dynamic_single_op_reset_shape_pass.h"
#include "graph/passes/merge_pass.h"
#include "graph/passes/merge_input_memcpy_pass.h"
#include "graph/passes/merge_to_stream_merge_pass.h"
@ -643,22 +642,11 @@ Status GraphManager::ReplaceSubgraphWithOriGraph(const ComputeGraphPtr &compute_
Status GraphManager::SetSubgraph(uint64_t session_id, ComputeGraphPtr compute_graph, GraphPartitioner &partitioner) {
GE_CHECK_NOTNULL(compute_graph);
PassManager pass_for_dynamic_shape_reset_optimize;
GE_CHK_STATUS_RET(pass_for_dynamic_shape_reset_optimize.AddPass(
"SetSubgraph::AfterSetSubgraph::DynamicSingleOpResetShapePass", new (std::nothrow) DynamicSingleOpResetShapePass))
GE_TIMESTAMP_START(pass_for_dynamic_shape_reset_optimize);
Status ret = pass_for_dynamic_shape_reset_optimize.Run(compute_graph);
GE_TIMESTAMP_END(pass_for_dynamic_shape_reset_optimize, "SetSubgraph::AfterSetSubgraph");
if (ret != SUCCESS && ret != NOT_CHANGED) {
GELOGE(ret, "Run passes when optimize subgraph failed");
return ret;
}
auto sub_graph_map = partitioner.GetSubGraphMap();
GELOGD("Directly optimize subgraph with build mode:%s, and step:%s.",
options_.build_mode.c_str(),
options_.build_step.c_str());
ret = OptimizeSubGraphWithMultiThreads(compute_graph, sub_graph_map, session_id);
Status ret = OptimizeSubGraphWithMultiThreads(compute_graph, sub_graph_map, session_id);
if (ret != SUCCESS) {
GELOGE(ret, "Multiply optimize subgraph failed");
return ret;
@ -3032,6 +3020,7 @@ Status GraphManager::OptimizeSubgraph(const GraphNodePtr &graph_node, ComputeGra
return FAILED;
}
GE_TIMESTAMP_EVENT_END(GraphPartitionDynamicShape, "OptimizeSubgraph::GraphPartitionDynamicShape");
GE_DUMP(compute_graph, "AfterDynamicShapePartition");
GE_TIMESTAMP_START(GraphPartition);
GraphPartitioner &partitioner = GetCompilerStages(graph_node->GetGraphId()).partitioner;
ret = partitioner.Partition(compute_graph, GraphPartitioner::kPartitioning);

@ -84,15 +84,14 @@ Status HcomOmeUtil::GetHcomCount(const ge::ConstOpDescPtr &op_desc, HcclDataType
int32_t size = 0;
GE_CHK_STATUS_RET(HcomOmeUtil::GetHcclTypeSize(data_type, size), "GetHcomCount: GetHcclTypeSize fail!");
if (op_desc->GetType() == HCOMRECEIVE) {
vector<int64_t> shape_dims;
bool ret = ge::AttrUtils::GetListInt(op_desc, HCOM_ATTR_SHAPE, shape_dims);
if (ret == false) {
GELOGE(PARAM_INVALID, "op:HcomReceive, op desc no attr: shape.");
return PARAM_INVALID;
for (size_t i = 0; i < op_desc->GetOutputsSize(); ++i) {
int64_t output_size = 0;
GE_CHECK_NOTNULL(op_desc->GetOutputDescPtr(i));
GE_CHK_STATUS_RET(ge::TensorUtils::GetSize(*op_desc->GetOutputDescPtr(i), output_size),
"Get size from TensorDesc failed, op: %s, output index: %zu.", op_desc->GetName().c_str(), i);
output_size = (output_size + align_size - 1) / align_size * align_size;
total_size += output_size;
}
ge::GeShape shape = ge::GeShape(shape_dims);
int64_t input_size = shape.GetShapeSize() * size;
total_size = (input_size + align_size - 1) / align_size * align_size;
} else {
for (size_t i = 0; i < op_desc->GetInputsSize(); i++) {
int64_t input_size = 0;

@ -742,6 +742,12 @@ Status GraphOptimize::HandleMemoryRWConflict(ComputeGraphPtr &compute_graph) {
if (node->GetType() == NETOUTPUT && AttrUtils::HasAttr(node->GetOpDesc(), ATTR_NAME_PARENT_NODE_INDEX)) {
continue;
}
bool identity_reserved = false;
AttrUtils::GetBool(node->GetOpDesc(), ATTR_NAME_CANNOT_BE_DELETED, identity_reserved);
if (identity_reserved) {
GELOGD("Identity [%s] need to be reserved", node->GetName().c_str());
continue;
}
if (node->GetType() == IDENTITY || node->GetType() == READVARIABLEOP) {
// split identity
ret = SplitIdentity(node);

@ -607,6 +607,9 @@ Status ge::GraphPartitioner::AddPartitionsToGraphNode(vector<ge::SubGraphInfoPtr
return FAILED;
}
auto &engine_name = graph_info_.partitions_.at(sub_graph);
(void)AttrUtils::SetStr(sub_graph, ATTR_NAME_PARENT_GRAPH_NAME, compute_graph->GetName());
GELOGD("set attr success. subgraph(%s) with parent graph(%s)", sub_graph->GetName().c_str(),
compute_graph->GetName().c_str());
GE_DUMP(sub_graph, sub_graph->GetName() + "_" + mode_2_str_[graph_info_.mode_]);
if (!session_graph_id.empty()) {
GE_IF_BOOL_EXEC(!AttrUtils::SetStr(sub_graph, ATTR_NAME_SESSION_GRAPH_ID, session_graph_id),
@ -614,9 +617,6 @@ Status ge::GraphPartitioner::AddPartitionsToGraphNode(vector<ge::SubGraphInfoPtr
}
// flush parent node of subgraph
sub_graph->SetParentNode(compute_graph->GetParentNode());
(void)AttrUtils::SetStr(*sub_graph, ATTR_NAME_PARENT_GRAPH_NAME, compute_graph->GetName());
GELOGD("set attr success. subgraph(%s) with parent graph(%s)", sub_graph->GetName().c_str(),
compute_graph->GetName().c_str());
auto sgi = MakeShared<SubGraphInfo>();
if (sgi == nullptr) {
GELOGE(GE_GRAPH_PARAM_NULLPTR, "[GraphPartitioner]: MakeShared sub graph info failed.");
@ -805,8 +805,19 @@ Status ge::GraphPartitioner::SplitSubGraphs(ge::ComputeGraphPtr compute_graph) {
GELOGD("In anchor index is %d", AnchorUtils::GetIdx(in_anchor));
for (auto &peer_out_anchor : in_anchor->GetPeerAnchors()) {
GELOGD("Peer out anchor index is %d", AnchorUtils::GetIdx(peer_out_anchor));
// All nodes have a copy in corresponding_node_in_partitions_, so function at can not be execption
auto parent_node = graph_info_.corresponding_node_in_partitions_.at(peer_out_anchor->GetOwnerNode());
// Normally, all nodes have a copy in corresponding_node_in_partitions_, so function at can not be exception
auto iter = graph_info_.corresponding_node_in_partitions_.find(peer_out_anchor->GetOwnerNode());
if (iter == graph_info_.corresponding_node_in_partitions_.end()) {
GELOGE(GRAPH_FAILED,
"[SpiltSubGraphs]: node[%s]id[%ld]'s parent_node[%s]id[%ld]"
"should make corresponding in advance",
node->GetOpDesc()->GetName().c_str(), node->GetOpDesc()->GetId(),
peer_out_anchor->GetOwnerNode()->GetOpDesc()->GetName().c_str(),
peer_out_anchor->GetOwnerNode()->GetOpDesc()->GetId());
return GRAPH_FAILED;
}
auto parent_node = iter->second;
GE_CHECK_NOTNULL(parent_node);
GELOGD("Parent node name is %s", parent_node->GetName().c_str());
// add edge
auto src_anchor = parent_node->GetOutAnchor(AnchorUtils::GetIdx(peer_out_anchor));

@ -52,6 +52,7 @@ Status StagePartitioner::Partition() {
return SUCCESS;
}
GE_DUMP(root_graph_, "BeforeStagePartition");
if (SplitStageLevel() != SUCCESS) {
GELOGE(FAILED, "Split graph-stage for graph %s failed.", root_graph_->GetName().c_str());
return FAILED;
@ -74,6 +75,7 @@ Status StagePartitioner::Partition() {
"maybe stage_level was not set correctly.", root_graph_->GetName().c_str());
return FAILED;
}
GE_DUMP(root_graph_, "AfterStagePartition");
return SUCCESS;
}

@ -26,9 +26,9 @@ namespace {
namespace ge {
Status CondPass::Run(NodePtr &node) {
ComputeGraphPtr graph = nullptr;
OutDataAnchorPtr cond_out_anchor = nullptr;
OutDataAnchorPtr peer_out_anchor = nullptr;
InDataAnchorPtr cond_in_anchor = nullptr;
Status ret = GetCondInfo(node, graph, cond_out_anchor, cond_in_anchor);
Status ret = GetCondInfo(node, graph, peer_out_anchor, cond_in_anchor);
if (ret == NOT_CHANGED) {
return SUCCESS;
} else if (ret != SUCCESS) {
@ -48,18 +48,18 @@ Status CondPass::Run(NodePtr &node) {
if (cond_tensor.MutableShape().GetDim(0) == UNKNOWN_DIM_NUM) {
GELOGI("Output tensor rank of Cond is unknown.");
if (cond_tensor.GetDataType() == DT_STRING) {
GE_CHK_STATUS_RET(HandleStringCond(graph, cond_out_anchor, cond_in_anchor), "HandleStringCond for %s failed.",
GE_CHK_STATUS_RET(HandleStringCond(graph, peer_out_anchor, cond_in_anchor), "HandleStringCond for %s failed.",
op_desc->GetName().c_str())
}
return SUCCESS;
}
if (!cond_tensor.GetShape().IsScalar()) {
GE_CHK_STATUS_RET(HandleNonScalarCond(graph, cond_out_anchor, cond_in_anchor), "HandleNonScalarCond for %s failed.",
GE_CHK_STATUS_RET(HandleNonScalarCond(graph, peer_out_anchor, cond_in_anchor), "HandleNonScalarCond for %s failed.",
op_desc->GetName().c_str())
} else {
switch (cond_tensor.GetDataType()) {
case DT_STRING:
GE_CHK_STATUS_RET(HandleStringCond(graph, cond_out_anchor, cond_in_anchor), "HandleStringCond for %s failed.",
GE_CHK_STATUS_RET(HandleStringCond(graph, peer_out_anchor, cond_in_anchor), "HandleStringCond for %s failed.",
op_desc->GetName().c_str())
break;
case DT_BOOL:
@ -69,7 +69,7 @@ Status CondPass::Run(NodePtr &node) {
case DT_INT16:
case DT_INT8:
case DT_INT64:
GE_CHK_STATUS_RET(HandleScalarCond(graph, cond_out_anchor, cond_in_anchor, cond_tensor.GetDataType()),
GE_CHK_STATUS_RET(HandleScalarCond(graph, peer_out_anchor, cond_in_anchor, cond_tensor.GetDataType()),
"HandleScalarCond for %s failed.", op_desc->GetName().c_str())
break;
case DT_INT32:
@ -96,21 +96,21 @@ Status CondPass::Run(NodePtr &node) {
/// @brief Get cond info for if / while
/// @param [in] node: If / While op
/// @param [out] graph: owner_graph of if node / while_cond subgraph
/// @param [out] cond_out_anchor: peer_cond_anchor
/// @param [out] peer_out_anchor: peer_cond_anchor
/// @param [out] cond_in_anchor: cond_input
/// @return Status
///
Status CondPass::GetCondInfo(const NodePtr &node, ComputeGraphPtr &graph, OutDataAnchorPtr &cond_out_anchor,
Status CondPass::GetCondInfo(const NodePtr &node, ComputeGraphPtr &graph, OutDataAnchorPtr &peer_out_anchor,
InDataAnchorPtr &cond_in_anchor) {
GE_CHECK_NOTNULL(node);
std::string type = node->GetType();
if (kIfOpTypes.count(type) != 0) {
if (GetCondInfoForIf(node, graph, cond_out_anchor, cond_in_anchor) != SUCCESS) {
if (GetCondInfoForIf(node, graph, peer_out_anchor, cond_in_anchor) != SUCCESS) {
GELOGE(FAILED, "Get cond_info for if node failed.");
return FAILED;
}
} else if (kWhileOpTypes.count(type) != 0) {
if (GetCondInfoForWhile(node, graph, cond_out_anchor, cond_in_anchor) != SUCCESS) {
if (GetCondInfoForWhile(node, graph, peer_out_anchor, cond_in_anchor) != SUCCESS) {
GELOGE(FAILED, "Get cond_info for while node failed.");
return FAILED;
}
@ -126,19 +126,19 @@ Status CondPass::GetCondInfo(const NodePtr &node, ComputeGraphPtr &graph, OutDat
/// @brief Get cond info for if node
/// @param [in] node: If op
/// @param [out] graph: owner_graph of if node
/// @param [out] cond_out_anchor: peer_cond_anchor
/// @param [out] peer_out_anchor: peer_cond_anchor
/// @param [out] cond_in_anchor: cond_input of if
/// @return Status
///
Status CondPass::GetCondInfoForIf(const NodePtr &node, ComputeGraphPtr &graph, OutDataAnchorPtr &cond_out_anchor,
Status CondPass::GetCondInfoForIf(const NodePtr &node, ComputeGraphPtr &graph, OutDataAnchorPtr &peer_out_anchor,
InDataAnchorPtr &cond_in_anchor) {
GE_CHECK_NOTNULL(node);
graph = node->GetOwnerComputeGraph();
GE_CHECK_NOTNULL(graph);
cond_in_anchor = node->GetInDataAnchor(IF_COND_INPUT);
GE_CHECK_NOTNULL(cond_in_anchor);
cond_out_anchor = cond_in_anchor->GetPeerOutAnchor();
GE_CHECK_NOTNULL(cond_out_anchor);
peer_out_anchor = cond_in_anchor->GetPeerOutAnchor();
GE_CHECK_NOTNULL(peer_out_anchor);
return SUCCESS;
}
@ -146,11 +146,11 @@ Status CondPass::GetCondInfoForIf(const NodePtr &node, ComputeGraphPtr &graph, O
/// @brief Get cond info for while node
/// @param [in] node: While op
/// @param [out] graph: while_cond subgraph
/// @param [out] cond_out_anchor: peer_cond_anchor
/// @param [out] peer_out_anchor: peer_cond_anchor
/// @param [out] cond_in_anchor: input of NetOutput in cond_graph
/// @return Status
///
Status CondPass::GetCondInfoForWhile(const NodePtr &node, ComputeGraphPtr &graph, OutDataAnchorPtr &cond_out_anchor,
Status CondPass::GetCondInfoForWhile(const NodePtr &node, ComputeGraphPtr &graph, OutDataAnchorPtr &peer_out_anchor,
InDataAnchorPtr &cond_in_anchor) {
GE_CHECK_NOTNULL(node);
OpDescPtr op_desc = node->GetOpDesc();
@ -177,8 +177,8 @@ Status CondPass::GetCondInfoForWhile(const NodePtr &node, ComputeGraphPtr &graph
cond_in_anchor = net_output_node->GetInDataAnchor(0);
GE_CHECK_NOTNULL(cond_in_anchor);
cond_out_anchor = cond_in_anchor->GetPeerOutAnchor();
GE_CHECK_NOTNULL(cond_out_anchor);
peer_out_anchor = cond_in_anchor->GetPeerOutAnchor();
GE_CHECK_NOTNULL(peer_out_anchor);
return SUCCESS;
}
@ -186,56 +186,56 @@ Status CondPass::GetCondInfoForWhile(const NodePtr &node, ComputeGraphPtr &graph
///
/// @brief Process Cond Op with non-scalar cond_input: cond->Size->If / NetOutput(while)
/// @param [in] graph
/// @param [in] out_anchor: peer_cond_anchor
/// @param [in] in_anchor: cond_input
/// @param [in] peer_out_anchor: peer_cond_anchor
/// @param [in] cond_in_anchor: cond_input
/// @return Status
///
Status CondPass::HandleNonScalarCond(const ComputeGraphPtr &graph, const OutDataAnchorPtr &out_anchor,
const InDataAnchorPtr &in_anchor) {
Status CondPass::HandleNonScalarCond(const ComputeGraphPtr &graph, const OutDataAnchorPtr &peer_out_anchor,
const InDataAnchorPtr &cond_in_anchor) {
GELOGI("Handle cond with non-scalar cond-input.");
return InsertNode(graph, out_anchor, in_anchor, SIZE);
return InsertNode(graph, peer_out_anchor, cond_in_anchor, SIZE);
}
///
/// @brief Process Cond Op with scalar-string cond_input: cond->StringLength(int32)->If / NetOutput(while)
/// @param [in] graph
/// @param [in] out_anchor: peer_cond_anchor
/// @param [in] in_anchor: cond_input
/// @param [in] peer_out_anchor: peer_cond_anchor
/// @param [in] cond_in_anchor: cond_input
/// @return Status
///
Status CondPass::HandleStringCond(const ComputeGraphPtr &graph, const OutDataAnchorPtr &out_anchor,
const InDataAnchorPtr &in_anchor) {
Status CondPass::HandleStringCond(const ComputeGraphPtr &graph, const OutDataAnchorPtr &peer_out_anchor,
const InDataAnchorPtr &cond_in_anchor) {
GELOGI("Handle cond with scalar-string cond-input.");
return InsertNode(graph, out_anchor, in_anchor, kStringLength);
return InsertNode(graph, peer_out_anchor, cond_in_anchor, kStringLength);
}
///
/// @brief Process Cond Op with scalar cond_input: cond->Cast(2int32)->If / NetOutput(while)
/// @param [in] graph
/// @param [in] out_anchor: peer_cond_anchor
/// @param [in] in_anchor: cond_input
/// @param [in] peer_out_anchor: peer_cond_anchor
/// @param [in] cond_in_anchor: cond_input
/// @param [in] src_type
/// @return Status
///
Status CondPass::HandleScalarCond(const ComputeGraphPtr &graph, const OutDataAnchorPtr &out_anchor,
const InDataAnchorPtr &in_anchor, DataType src_type) {
GE_CHECK_NOTNULL(in_anchor);
GE_CHECK_NOTNULL(out_anchor);
GE_CHECK_NOTNULL(out_anchor->GetOwnerNode()->GetOpDesc());
Status CondPass::HandleScalarCond(const ComputeGraphPtr &graph, const OutDataAnchorPtr &peer_out_anchor,
const InDataAnchorPtr &cond_in_anchor, DataType src_type) {
GE_CHECK_NOTNULL(cond_in_anchor);
GE_CHECK_NOTNULL(peer_out_anchor);
GE_CHECK_NOTNULL(peer_out_anchor->GetOwnerNode()->GetOpDesc());
GELOGI("Handle cond with scalar cond-input.");
GeTensorDesc tensor = out_anchor->GetOwnerNode()->GetOpDesc()->GetOutputDesc(out_anchor->GetIdx());
std::string cast_name = in_anchor->GetOwnerNode()->GetName() + "_Cast";
GeTensorDesc tensor = peer_out_anchor->GetOwnerNode()->GetOpDesc()->GetOutputDesc(peer_out_anchor->GetIdx());
std::string cast_name = cond_in_anchor->GetOwnerNode()->GetName() + "_Cast";
NodePtr cast_node = AddCastNode(graph, cast_name, tensor, src_type, DT_INT32);
if (cast_node == nullptr) {
GELOGE(FAILED, "Add Cast node failed, name:%s.", cast_name.c_str());
return FAILED;
}
if (GraphUtils::InsertNodeAfter(out_anchor, { in_anchor }, cast_node) != GRAPH_SUCCESS) {
if (GraphUtils::InsertNodeAfter(peer_out_anchor, { cond_in_anchor }, cast_node) != GRAPH_SUCCESS) {
GELOGE(FAILED, "Insert Cast node %s between %s->%s failed.",
cast_node->GetName().c_str(), out_anchor->GetOwnerNode()->GetName().c_str(),
in_anchor->GetOwnerNode()->GetName().c_str());
cast_node->GetName().c_str(), peer_out_anchor->GetOwnerNode()->GetName().c_str(),
cond_in_anchor->GetOwnerNode()->GetName().c_str());
return FAILED;
}
@ -245,27 +245,27 @@ Status CondPass::HandleScalarCond(const ComputeGraphPtr &graph, const OutDataAnc
///
/// @brief Insert node
/// @param [in] graph
/// @param [in] out_anchor
/// @param [in] in_anchor
/// @param [in] peer_out_anchor
/// @param [in] in_data_anchor
/// @param [in] type
/// @return Status
///
Status CondPass::InsertNode(const ComputeGraphPtr &graph, const OutDataAnchorPtr &out_anchor,
const InDataAnchorPtr &in_anchor, const std::string &type) {
GE_CHECK_NOTNULL(out_anchor);
GE_CHECK_NOTNULL(in_anchor);
Status CondPass::InsertNode(const ComputeGraphPtr &graph, const OutDataAnchorPtr &peer_out_anchor,
const InDataAnchorPtr &in_data_anchor, const std::string &type) {
GE_CHECK_NOTNULL(peer_out_anchor);
GE_CHECK_NOTNULL(in_data_anchor);
GELOGD("Begin to insert %s node.", type.c_str());
GE_CHECK_NOTNULL(out_anchor->GetOwnerNode()->GetOpDesc());
GE_CHECK_NOTNULL(in_anchor->GetOwnerNode()->GetOpDesc());
GeTensorDesc in_tensor = out_anchor->GetOwnerNode()->GetOpDesc()->GetOutputDesc(out_anchor->GetIdx());
GeTensorDesc out_tensor = in_anchor->GetOwnerNode()->GetOpDesc()->GetInputDesc(out_anchor->GetIdx());
GE_CHECK_NOTNULL(peer_out_anchor->GetOwnerNode()->GetOpDesc());
GE_CHECK_NOTNULL(in_data_anchor->GetOwnerNode()->GetOpDesc());
GeTensorDesc in_tensor = peer_out_anchor->GetOwnerNode()->GetOpDesc()->GetOutputDesc(peer_out_anchor->GetIdx());
GeTensorDesc out_tensor = in_data_anchor->GetOwnerNode()->GetOpDesc()->GetInputDesc(in_data_anchor->GetIdx());
out_tensor.SetDataType(DT_INT32);
out_tensor.SetOriginDataType(DT_INT32);
out_tensor.SetShape(in_tensor.GetShape());
out_tensor.SetOriginShape(in_tensor.GetOriginShape());
OpDescBuilder op_desc_builder(in_anchor->GetOwnerNode()->GetName() + "_" + type, type);
OpDescBuilder op_desc_builder(in_data_anchor->GetOwnerNode()->GetName() + "_" + type, type);
OpDescPtr op_desc = op_desc_builder.AddInput("x", in_tensor).AddOutput("y", out_tensor).Build();
if (op_desc == nullptr) {
GELOGE(FAILED, "Create op_desc failed.");
@ -278,10 +278,10 @@ Status CondPass::InsertNode(const ComputeGraphPtr &graph, const OutDataAnchorPtr
}
AddRePassNode(new_node);
if (GraphUtils::InsertNodeAfter(out_anchor, { in_anchor }, new_node) != GRAPH_SUCCESS) {
if (GraphUtils::InsertNodeAfter(peer_out_anchor, { in_data_anchor }, new_node) != GRAPH_SUCCESS) {
GELOGE(FAILED, "Insert %s node %s between %s->%s failed.", type.c_str(),
new_node->GetName().c_str(), out_anchor->GetOwnerNode()->GetName().c_str(),
in_anchor->GetOwnerNode()->GetName().c_str());
new_node->GetName().c_str(), peer_out_anchor->GetOwnerNode()->GetName().c_str(),
in_data_anchor->GetOwnerNode()->GetName().c_str());
return FAILED;
}

@ -28,76 +28,76 @@ class CondPass : public BaseNodePass {
/// @brief Get cond info for if / while
/// @param [in] node: If / While op
/// @param [out] graph: owner_graph of if node / while_cond subgraph
/// @param [out] cond_out_anchor: peer_cond_anchor
/// @param [out] peer_out_anchor: peer_cond_anchor
/// @param [out] cond_in_anchor: cond_input
/// @return Status
///
static Status GetCondInfo(const NodePtr &node, ComputeGraphPtr &graph, OutDataAnchorPtr &cond_out_anchor,
InDataAnchorPtr &cond_in_anchor);
static Status GetCondInfo(const NodePtr &node, ComputeGraphPtr &graph, OutDataAnchorPtr &peer_out_anchor,
InDataAnchorPtr &cond_in_anchor);
///
/// @brief Get cond info for if node
/// @param [in] node: If op
/// @param [out] graph: owner_graph of if node
/// @param [out] cond_out_anchor: peer_cond_anchor
/// @param [out] peer_out_anchor: peer_cond_anchor
/// @param [out] cond_in_anchor: cond_input of if
/// @return Status
///
static Status GetCondInfoForIf(const NodePtr &node, ComputeGraphPtr &graph, OutDataAnchorPtr &cond_out_anchor,
InDataAnchorPtr &cond_in_anchor);
static Status GetCondInfoForIf(const NodePtr &node, ComputeGraphPtr &graph, OutDataAnchorPtr &peer_out_anchor,
InDataAnchorPtr &cond_in_anchor);
///
/// @brief Get cond info for while node
/// @param [in] node: While op
/// @param [out] graph: while_cond subgraph
/// @param [out] cond_out_anchor: peer_cond_anchor
/// @param [out] peer_out_anchor: peer_cond_anchor
/// @param [out] cond_in_anchor: input of NetOutput in cond_graph
/// @return Status
///
static Status GetCondInfoForWhile(const NodePtr &node, ComputeGraphPtr &graph, OutDataAnchorPtr &cond_out_anchor,
InDataAnchorPtr &cond_in_anchor);
static Status GetCondInfoForWhile(const NodePtr &node, ComputeGraphPtr &graph, OutDataAnchorPtr &peer_out_anchor,
InDataAnchorPtr &cond_in_anchor);
///
/// @brief Process Cond Op with non-scalar cond_input
/// @param [in] graph
/// @param [in] out_anchor: peer_cond_anchor
/// @param [in] in_anchor: cond_input
/// @param [in] peer_out_anchor: peer_cond_anchor
/// @param [in] cond_in_anchor: cond_input
/// @return Status
///
Status HandleNonScalarCond(const ComputeGraphPtr &graph, const OutDataAnchorPtr &out_anchor,
const InDataAnchorPtr &in_anchor);
Status HandleNonScalarCond(const ComputeGraphPtr &graph, const OutDataAnchorPtr &peer_out_anchor,
const InDataAnchorPtr &cond_in_anchor);
///
/// @brief Process Cond Op with scalar-string cond_input
/// @param [in] graph
/// @param [in] out_anchor: peer_cond_anchor
/// @param [in] in_anchor: cond_input
/// @param [in] peer_out_anchor: peer_cond_anchor
/// @param [in] cond_in_anchor: cond_input
/// @return Status
///
Status HandleStringCond(const ComputeGraphPtr &graph, const OutDataAnchorPtr &out_anchor,
const InDataAnchorPtr &in_anchor);
Status HandleStringCond(const ComputeGraphPtr &graph, const OutDataAnchorPtr &peer_out_anchor,
const InDataAnchorPtr &cond_in_anchor);
///
/// @brief Process Cond Op with scalar cond_input
/// @param [in] graph
/// @param [in] out_anchor: peer_cond_anchor
/// @param [in] in_anchor: cond_input
/// @param [in] peer_out_anchor: peer_cond_anchor
/// @param [in] cond_in_anchor: cond_input
/// @param [in] src_type
/// @return Status
///
Status HandleScalarCond(const ComputeGraphPtr &graph, const OutDataAnchorPtr &out_anchor,
const InDataAnchorPtr &in_anchor, DataType src_type);
Status HandleScalarCond(const ComputeGraphPtr &graph, const OutDataAnchorPtr &peer_out_anchor,
const InDataAnchorPtr &cond_in_anchor, DataType src_type);
///
/// @brief Insert node
/// @param [in] graph
/// @param [in] out_anchor
/// @param [in] in_anchor
/// @param [in] peer_out_anchor
/// @param [in] in_data_anchor
/// @param [in] type
/// @return Status
///
Status InsertNode(const ComputeGraphPtr &graph, const OutDataAnchorPtr &out_anchor,
const InDataAnchorPtr &in_anchor, const std::string &type);
Status InsertNode(const ComputeGraphPtr &graph, const OutDataAnchorPtr &peer_out_anchor,
const InDataAnchorPtr &in_data_anchor, const std::string &type);
///
/// @brief Add cast node

@ -1,155 +0,0 @@
/**
* Copyright 2020 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "graph/passes/dynamic_single_op_reset_shape_pass.h"
#include "common/ge_inner_error_codes.h"
#include "graph/utils/node_utils.h"
#include "graph/utils/graph_utils.h"
#include "graph/utils/tensor_utils.h"
#include "graph/utils/op_desc_utils.h"
#include "graph/utils/type_utils.h"
#include "graph/debug/ge_attr_define.h"
namespace ge {
namespace {
const int64_t kDynamicShapeDim = -2;
const char *const kEngineNameAiCpu = "DNN_VM_AICPU_ASCEND";
const char *const kEngineNameAiCpuTf = "DNN_VM_AICPU";
} // namespace
Status DynamicSingleOpResetShapePass::Run(ComputeGraphPtr graph) {
GE_CHECK_NOTNULL(graph);
std::shared_ptr<GELib> instance = ge::GELib::GetInstance();
if (instance == nullptr || !instance->InitFlag()) {
GELOGE(ge::GE_CLI_GE_NOT_INITIALIZED, "Run CompileNodesPass failed.");
return ge::GE_CLI_GE_NOT_INITIALIZED;
}
// pass if graph has not aicpu node.
bool is_not_aicpu = false;
if (CheckAllAicpuNodes(graph, is_not_aicpu) != SUCCESS) {
GELOGE(ge::GE_CLI_GE_NOT_INITIALIZED, "Check if graph has not aicpu node failed.");
return ge::GE_CLI_GE_NOT_INITIALIZED;
}
if (is_not_aicpu) {
GELOGI("The graph [%s] has not aicpu node, whose aicpu nodes would not be reset dynamic shape",
graph->GetName().c_str());
return SUCCESS;
}
for (const auto &node : graph->GetDirectNode()) {
GE_CHECK_NOTNULL(node->GetOpDesc());
// pass input and output node
if (node->GetType() == DATA || node->GetType() == CONSTANT || node->GetType() == CONSTANTOP ||
node->GetType() == NETOUTPUT) {
continue;
}
// pass node without attr: ATTR_SINGLE_OP_SCENE
bool single_aicpu_unknown = false;
if (!AttrUtils::GetBool(node->GetOpDesc(), ATTR_SINGLE_OP_SCENE, single_aicpu_unknown) ||
!single_aicpu_unknown) {
continue;
}
// reset aicpu shape to unknown shape
auto op_desc = node->GetOpDesc();
if (ResetOpShape(op_desc) != SUCCESS) {
GELOGE(ge::GE_CLI_GE_NOT_INITIALIZED, "Reset node[%s] dynamic shapr failed.", node->GetName().c_str());
return ge::GE_CLI_GE_NOT_INITIALIZED;
}
GELOGD("Reset dynamic aicpu node [%s] shape success!", node->GetName().c_str());
}
GELOGD("Reset dynamic aicpu nodes shape of graph [%s] success!", graph->GetName().c_str());
return SUCCESS;
}
Status DynamicSingleOpResetShapePass::CheckAllAicpuNodes(const ComputeGraphPtr &graph, bool &is_not_aicpu) {
is_not_aicpu = false;
for (const auto &node : graph->GetDirectNode()) {
GE_CHECK_NOTNULL(node->GetOpDesc());
// pass input and output node
if (node->GetType() == DATA || node->GetType() == CONSTANT || node->GetType() == CONSTANTOP ||
node->GetType() == NETOUTPUT) {
continue;
}
// find if there are aicpu nodes.
auto op_desc = node->GetOpDesc();
string engine_name = op_desc->GetOpEngineName();
if (engine_name.empty()) {
GELOGE(GRAPH_FAILED, "Get engine failed of node[%s].", node->GetName().c_str());
return GRAPH_FAILED;
}
if (engine_name != kEngineNameAiCpu && engine_name != kEngineNameAiCpuTf) {
is_not_aicpu = true;
return SUCCESS;
}
}
return SUCCESS;
}
bool DynamicSingleOpResetShapePass::CheckIfConstInput(const GeTensorDescPtr &input_tensor_desc) {
bool is_const = false;
(void)AttrUtils::GetBool(input_tensor_desc, CONST_ATTR_NAME_INPUT, is_const);
return is_const;
}
Status DynamicSingleOpResetShapePass::ResetOpShape(OpDescPtr &op_desc) {
GE_CHECK_NOTNULL(op_desc);
std::vector<int64_t> dynamic_shape_dims = {kDynamicShapeDim};
GeShape dynamic_shape(dynamic_shape_dims);
(void)ResetInputTensorShape(op_desc, dynamic_shape);
(void)ResetOutputTensorShape(op_desc, dynamic_shape);
return SUCCESS;
}
Status DynamicSingleOpResetShapePass::ResetInputTensorShape(OpDescPtr &op_desc,
const GeShape &dynamic_shape) {
GE_CHECK_NOTNULL(op_desc);
for (size_t i = 0; i < op_desc->GetAllInputsDesc().size(); i++) {
auto input_desc = op_desc->MutableInputDesc(static_cast<uint32_t>(i));
GE_CHECK_NOTNULL(input_desc);
// pass scalar input desc
auto dims_ori = input_desc->GetShape().GetDims();
if (dims_ori.size() == 0) {
continue;
}
// pass const input
if (CheckIfConstInput(input_desc)) {
continue;
}
input_desc->SetShape(dynamic_shape);
}
return SUCCESS;
}
Status DynamicSingleOpResetShapePass::ResetOutputTensorShape(OpDescPtr &op_desc, const GeShape &dynamic_shape) {
GE_CHECK_NOTNULL(op_desc);
for (size_t i = 0; i < op_desc->GetAllOutputsDesc().size(); i++) {
auto output_desc = op_desc->MutableOutputDesc(static_cast<uint32_t>(i));
GE_CHECK_NOTNULL(output_desc);
// pass scalar input desc
auto output_dims_ori = output_desc->GetShape().GetDims();
if (output_dims_ori.size() == 0) {
continue;
}
output_desc->SetShape(dynamic_shape);
}
return SUCCESS;
}
} // namespace ge

@ -1,36 +0,0 @@
/**
* Copyright 2020 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef GE_GRAPH_PASSES_DYNAMIC_SINGLE_OP_RESET_SHAPE_PASS_H_
#define GE_GRAPH_PASSES_DYNAMIC_SINGLE_OP_RESET_SHAPE_PASS_H_
#include "graph/graph.h"
#include "inc/graph_pass.h"
#include "init/gelib.h"
namespace ge {
class DynamicSingleOpResetShapePass : public GraphPass {
public:
Status Run(ComputeGraphPtr graph) override;
private:
Status ResetOpShape(OpDescPtr &op_desc);
Status ResetInputTensorShape(OpDescPtr &op_desc, const GeShape &dynamic_shape);
Status ResetOutputTensorShape(OpDescPtr &op_desc, const GeShape &dynamic_shape);
Status CheckAllAicpuNodes(const ComputeGraphPtr &graph, bool &is_not_aicpu);
bool CheckIfConstInput(const GeTensorDescPtr &input_tensor_desc);
};
} // namespace ge
#endif // GE_GRAPH_PASSES_DYNAMIC_SINGLE_OP_RESET_SHAPE_PASS_H_

@ -17,6 +17,7 @@
#include "graph/utils/node_utils.h"
#include "graph/utils/tensor_utils.h"
#include "graph/debug/ge_attr_define.h"
namespace ge {
const size_t kTwoInputNodesSize = 2;
@ -32,53 +33,110 @@ Status MarkAgnosticPass::Run(ComputeGraphPtr graph) {
GELOGD("Op: %s, Index:0,has no input", node->GetName().c_str());
continue;
}
AttrUtils::SetInt(op_tensor, "_format_continuous", 1);
AttrUtils::SetInt(node->GetOpDesc(), "_format_agnostic", 1);
AttrUtils::SetListInt(node->GetOpDesc(), "_format_agnostic_except_input", std::vector<int64_t>({1}));
AttrUtils::SetInt(op_tensor, ATTR_NAME_FORMAT_CONTINUOUS, 1);
AttrUtils::SetInt(node->GetOpDesc(), ATTR_NAME_FORMAT_AGNOSTIC, 1);
AttrUtils::SetListInt(node->GetOpDesc(), ATTR_NAME_FORMAT_AGNOSTIC_EXCEPT_INPUT, std::vector<int64_t>({1}));
continue;
}
if (node_type == IDENTITY) {
GELOGD("Mark format agnostic for identity node %s", node->GetName().c_str());
AttrUtils::SetInt(node->GetOpDesc(), "_format_agnostic", 1);
AttrUtils::SetInt(node->GetOpDesc(), ATTR_NAME_FORMAT_AGNOSTIC, 1);
continue;
}
if (node_type == REFMERGE || node_type == REFSWITCH) {
GELOGD("Mark format agnostic for regmerge and refswitch node %s", node->GetName().c_str());
AttrUtils::SetInt(node->GetOpDesc(), "_format_agnostic", 1);
AttrUtils::SetListInt(node->GetOpDesc(), "_format_agnostic_except_input", std::vector<int64_t>({1}));
AttrUtils::SetInt(node->GetOpDesc(), ATTR_NAME_FORMAT_AGNOSTIC, 1);
AttrUtils::SetListInt(node->GetOpDesc(), ATTR_NAME_FORMAT_AGNOSTIC_EXCEPT_INPUT, std::vector<int64_t>({1}));
continue;
}
if (node_type == MERGE) {
GELOGD("Mark format agnostic and continuous for merge node %s", node->GetName().c_str());
const auto &input_nodes = node->GetInAllNodes();
/// Enter-----------+
/// +-> Merge
/// NextIteration---+
if (input_nodes.size() == kTwoInputNodesSize) {
if (input_nodes.at(0)->GetType() == ENTER && input_nodes.at(1)->GetType() == NEXTITERATION) {
continue;
}
}
const OpDescPtr op_desc = node->GetOpDesc();
const GeTensorDescPtr op_tensor = op_desc->MutableOutputDesc(0);
if (op_tensor == nullptr) {
GELOGD("Op: %s, Index:0,has no output", node->GetName().c_str());
continue;
}
AttrUtils::SetInt(op_tensor, "_format_continuous", 1);
// Merge----------->NetOutput only set format_cofntinuous attr
const auto &output_nodes = node->GetOutAllNodes();
if (output_nodes.size() > 0) {
// Always set continuous attr for merge output 0
GE_CHK_STATUS_RET(SetContinuousAttr(node, {0}));
// Merge-->NetOutput only set merge output 0's continuous attr
const auto &output_nodes = node->GetOutDataNodes();
if (!output_nodes.empty()) {
if (output_nodes.at(0)->GetType() == NETOUTPUT) {
continue;
}
}
AttrUtils::SetInt(node->GetOpDesc(), "_format_agnostic", 1);
AttrUtils::SetListInt(node->GetOpDesc(), "_format_agnostic_except_output", std::vector<int64_t>({1}));
// Set format agnostic attr for merge in and out tensordesc
AttrUtils::SetInt(node->GetOpDesc(), ATTR_NAME_FORMAT_AGNOSTIC, 1);
AttrUtils::SetListInt(node->GetOpDesc(), ATTR_NAME_FORMAT_AGNOSTIC_EXCEPT_OUTPUT, std::vector<int64_t>({1}));
// Set attr for enter and nextiteration
if (HandWhileLoop(node) != SUCCESS) {
GELOGE(FAILED, "Node: %s type merge handle while loop failed", node->GetName().c_str());
return FAILED;
}
continue;
}
}
return SUCCESS;
}
bool MarkAgnosticPass::IsWhileLoop(const NodePtr &merge_node, NodePtr &enter, NodePtr &next) {
auto node_type = NodeUtils::GetNodeType(*merge_node);
if (node_type != MERGE) {
GELOGW("Node %s type %s is not merge op.", merge_node->GetName().c_str(), node_type.c_str());
return false;
}
/// Enter-----------+
/// +-> Merge
/// NextIteration---+
auto input_nodes = merge_node->GetInDataNodes();
if (input_nodes.size() != kTwoInputNodesSize) {
GELOGD("Node %s type %s with [data input size[%zu]] is not enter-merge-nextiteration target.",
merge_node->GetName().c_str(), node_type.c_str(), input_nodes.size());
return false;
}
auto in_node0 = input_nodes.at(0);
auto in_node1 = input_nodes.at(1);
auto in_type0 = NodeUtils::GetNodeType(in_node0);
auto in_type1 = NodeUtils::GetNodeType(in_node1);
if ((in_type0 != ENTER || in_type1 != NEXTITERATION) && (in_type0 != NEXTITERATION || in_type1 != ENTER)) {
GELOGD("Node %s type %s with [data input0's type %s input1's type %s] is not enter-merge-nextiteration target.",
merge_node->GetName().c_str(), node_type.c_str(), in_type0.c_str(), in_type1.c_str());
return false;
}
enter = in_node0;
next = in_node1;
return true;
}
Status MarkAgnosticPass::HandWhileLoop(const NodePtr &node) {
NodePtr enter = nullptr;
NodePtr next = nullptr;
if (!IsWhileLoop(node, enter, next)) {
return SUCCESS;
}
GE_CHECK_NOTNULL(enter);
GE_CHECK_NOTNULL(next);
// Set continuous attr
GE_CHK_STATUS_RET(SetContinuousAttr(enter, {0}));
GE_CHK_STATUS_RET(SetContinuousAttr(next, {0}));
// Set format agnostic attr
(void)AttrUtils::SetInt(enter->GetOpDesc(), ATTR_NAME_FORMAT_AGNOSTIC, 1);
(void)AttrUtils::SetInt(next->GetOpDesc(), ATTR_NAME_FORMAT_AGNOSTIC, 1);
return SUCCESS;
}
Status MarkAgnosticPass::SetContinuousAttr(const NodePtr &node, const std::vector<uint32_t> &indexes) {
auto op_desc = node->GetOpDesc();
GE_CHECK_NOTNULL(op_desc);
// This flag is for fe performance optimization
(void)AttrUtils::SetBool(op_desc, ATTR_NAME_REFRESH_CONTINUOUS_FLAG, true);
for (auto index : indexes) {
auto out = op_desc->MutableOutputDesc(index);
GE_CHECK_NOTNULL(out);
// This attr is for out's dtype and format continuous with it's peer input
(void)AttrUtils::SetInt(out, ATTR_NAME_FORMAT_CONTINUOUS, 1);
}
return SUCCESS;
}
} // namespace ge

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save