Pre Merge pull request !1467 from zhengyuanhua/master

pull/1467/MERGE
zhengyuanhua 4 years ago committed by Gitee
commit 1b9a15dde4

@ -108,6 +108,7 @@ set(TRAIN_SRC_LIST
"common/helper/model_cache_helper.cc"
"common/profiling/profiling_manager.cc"
"common/dump/dump_manager.cc"
"common/dump/dump_exception.cc"
"common/dump/dump_properties.cc"
"common/dump/opdebug_register.cc"
"common/dump/dump_op.cc"
@ -437,6 +438,7 @@ set(INFER_SRC_LIST
"common/formats/formats.cc"
"common/profiling/profiling_manager.cc"
"common/dump/dump_properties.cc"
"common/dump/dump_exception.cc"
"common/dump/dump_manager.cc"
"common/dump/dump_op.cc"
"common/dump/opdebug_register.cc"

@ -0,0 +1,234 @@
/**
* Copyright 2019-2021 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 "common/dump/dump_exception.h"
#include "common/ge/datatype_util.h"
#include "common/debug/memory_dumper.h"
#include "framework/common/debug/log.h"
#include "graph/manager/util/debug.h"
#include "graph/utils/tensor_utils.h"
#include "graph/load/model_manager/model_utils.h"
#include "proto/dump_task.pb.h"
namespace {
static uint64_t GetNowTime() {
uint64_t ret = 0;
mmTimeval tv;
if (mmGetTimeOfDay(&tv, nullptr) == 0) {
ret = tv.tv_sec * 1000000ULL + tv.tv_usec;
}
return ret;
}
static void ReplaceStringElem(std::string &str) {
for_each(str.begin(), str.end(), [](char &ch) {
if ((ch == ' ') || (ch == '.') || (ch == '/') || (ch == '\\')) {
ch = '_';
}
});
}
} // namespace
namespace ge {
ExceptionDumper::~ExceptionDumper() {}
void ExceptionDumper::SaveDumpOpInfo(const OpDescPtr &op, uint32_t task_id, uint32_t stream_id,
vector<void *> &input_addrs, vector<void *> &output_addrs) {
OpDescInfo op_desc_info;
SaveOpDescInfo(op, task_id, stream_id, op_desc_info);
op_desc_info.input_addrs = input_addrs;
op_desc_info.output_addrs = output_addrs;
op_desc_info_.emplace_back(op_desc_info);
}
void ExceptionDumper::SaveDumpOpInfo(const RuntimeParam &model_param, const OpDescPtr &op,
uint32_t task_id, uint32_t stream_id) {
OpDescInfo op_desc_info;
SaveOpDescInfo(op, task_id, stream_id, op_desc_info);
op_desc_info.input_addrs = ModelUtils::GetInputDataAddrs(model_param, op);
op_desc_info.output_addrs = ModelUtils::GetOutputDataAddrs(model_param, op);
op_desc_info_.emplace_back(op_desc_info);
}
void ExceptionDumper::SaveOpDescInfo(const OpDescPtr &op, uint32_t task_id, uint32_t stream_id,
OpDescInfo &op_desc_info) {
if (op == nullptr) {
GELOGW("[Save][OpExceptionInfo] op desc ptr is null.");
return;
}
GELOGD("[Save][OpExceptionInfo] Start to save dump op [%s] info of task_id: %u, stream_id: %u",
op->GetName().c_str(), task_id, stream_id);
op_desc_info.op_name = op->GetName();
op_desc_info.op_type = op->GetType();
op_desc_info.task_id = task_id;
op_desc_info.stream_id = stream_id;
for (size_t i = 0; i < op->GetAllInputsSize(); ++i) {
GeTensorDescPtr input_tensor_desc = op->MutableInputDesc(i);
if (input_tensor_desc == nullptr) {
continue;
}
op_desc_info.input_format.emplace_back(input_tensor_desc->GetFormat());
op_desc_info.input_shape.emplace_back(input_tensor_desc->GetShape().GetDims());
op_desc_info.input_data_type.emplace_back(input_tensor_desc->GetDataType());
int64_t input_size = 0;
if (TensorUtils::GetTensorSizeInBytes(*input_tensor_desc, input_size) != SUCCESS) {
GELOGW("[Save][OpExceptionInfo] Op [%s] get input size failed.", op->GetName().c_str());
return;
}
GELOGD("[Save][OpExceptionInfo] Save dump op info, the input size is %ld", input_size);
op_desc_info.input_size.emplace_back(input_size);
}
for (size_t j = 0; j < op->GetOutputsSize(); ++j) {
GeTensorDescPtr output_tensor_desc = op->MutableOutputDesc(j);
if (output_tensor_desc == nullptr) {
continue;
}
op_desc_info.output_format.emplace_back(output_tensor_desc->GetFormat());
op_desc_info.output_shape.emplace_back(output_tensor_desc->GetShape().GetDims());
op_desc_info.output_data_type.emplace_back(output_tensor_desc->GetDataType());
int64_t output_size = 0;
if (TensorUtils::GetTensorSizeInBytes(*output_tensor_desc, output_size) != SUCCESS) {
GELOGW("[Save][OpExceptionInfo] Op [%s] get output size failed.", op->GetName().c_str());
return;
}
GELOGD("[Save][OpExceptionInfo] Save dump op info, the output size is %ld.", output_size);
op_desc_info.output_size.emplace_back(output_size);
}
}
Status ExceptionDumper::DumpExceptionInfo(const std::vector<rtExceptionInfo> &exception_infos) const {
GELOGI("[Dump][Exception] Start to dump exception info.");
for (const rtExceptionInfo &iter : exception_infos) {
OpDescInfo op_desc_info;
if (GetOpDescInfo(iter.streamid, iter.taskid, op_desc_info)) {
toolkit::dumpdata::DumpData dump_data;
dump_data.set_version("2.0");
dump_data.set_dump_time(GetNowTime());
dump_data.set_op_name(op_desc_info.op_name);
for (size_t i = 0; i < op_desc_info.input_format.size(); ++i) {
toolkit::dumpdata::OpInput input;
input.set_data_type(toolkit::dumpdata::OutputDataType(
DataTypeUtil::GetIrDataType(op_desc_info.input_data_type[i])));
input.set_format(toolkit::dumpdata::OutputFormat(op_desc_info.input_format[i]));
for (auto dim : op_desc_info.input_shape[i]) {
input.mutable_shape()->add_dim(dim);
}
input.set_size(op_desc_info.input_size[i]);
GELOGI("[Dump][Exception] The input size int exception is %ld.", op_desc_info.input_size[i]);
dump_data.mutable_input()->Add(std::move(input));
}
for (size_t j = 0; j < op_desc_info.output_format.size(); ++j) {
toolkit::dumpdata::OpOutput output;
output.set_data_type(toolkit::dumpdata::OutputDataType(
DataTypeUtil::GetIrDataType(op_desc_info.output_data_type[j])));
output.set_format(toolkit::dumpdata::OutputFormat(op_desc_info.output_format[j]));
for (auto dim : op_desc_info.output_shape[j]) {
output.mutable_shape()->add_dim(dim);
}
output.set_size(op_desc_info.output_size[j]);
GELOGI("[Dump][Exception] The output size int exception is %ld.", op_desc_info.output_size[j]);
dump_data.mutable_output()->Add(std::move(output));
}
uint64_t now_time = GetNowTime();
std::string op_name = op_desc_info.op_name;
std::string op_type = op_desc_info.op_type;
ReplaceStringElem(op_name);
ReplaceStringElem(op_type);
string dump_file_path =
"./" + op_type + "." + op_name + "." + std::to_string(op_desc_info.task_id) + "." + std::to_string(now_time);
GELOGI("[Dump][Exception] The exception dump file path is %s.", dump_file_path.c_str());
uint64_t proto_size = dump_data.ByteSizeLong();
std::unique_ptr<char[]> proto_msg(new (std::nothrow) char[proto_size]);
bool ret = dump_data.SerializeToArray(proto_msg.get(), proto_size);
if (!ret || proto_size == 0) {
GELOGE(PARAM_INVALID, "[Dump][Exception] Dump data proto serialize failed.");
return PARAM_INVALID;
}
GE_CHK_STATUS_RET(MemoryDumper::DumpToFile(dump_file_path.c_str(), &proto_size, sizeof(uint64_t)),
"Failed to dump proto size");
GE_CHK_STATUS_RET(MemoryDumper::DumpToFile(dump_file_path.c_str(), proto_msg.get(), proto_size),
"Failed to dump proto msg");
if (DumpExceptionInput(op_desc_info, dump_file_path) != SUCCESS) {
GELOGE(PARAM_INVALID, "[Dump][Exception] Dump op [%s] exception input failed.", op_desc_info.op_name.c_str());
return PARAM_INVALID;
}
if (DumpExceptionOutput(op_desc_info, dump_file_path) != SUCCESS) {
GELOGE(PARAM_INVALID, "[Dump][Exception] Dump op [%s] exception output failed.", op_desc_info.op_name.c_str());
return PARAM_INVALID;
}
GELOGI("[Dump][Exception] Dump op [%s] exception info SUCCESS.", op_desc_info.op_name.c_str());
} else {
GELOGI("[Dump][Exception] Can't find op desc info ,task id:%u,stream id:%u", iter.taskid, iter.streamid);
return SUCCESS;
}
}
return SUCCESS;
}
bool ExceptionDumper::GetOpDescInfo(uint32_t stream_id, uint32_t task_id, OpDescInfo &op_desc_info) const {
GELOGI("[Get][OpDescInfo] There are %zu op need to dump.", op_desc_info_.size());
for (size_t index = 0; index < op_desc_info_.size(); ++index) {
OpDescInfo dump_op_info = op_desc_info_.at(index);
if (dump_op_info.task_id == task_id && dump_op_info.stream_id == stream_id) {
GELOGI("[Get][OpDescInfo] Find exception op [%s] of task_id: %u, stream_id: %u.",
dump_op_info.op_name.c_str(), task_id, stream_id);
op_desc_info = dump_op_info;
return true;
}
}
return false;
}
Status ExceptionDumper::DumpExceptionInput(const OpDescInfo &op_desc_info, const string &dump_file) const {
GELOGI("[Dump][ExceptionInput] Start to dump exception input");
for (size_t i = 0; i < op_desc_info.input_addrs.size(); i++) {
if (Debug::DumpDevMem(dump_file.data(), op_desc_info.input_addrs.at(i), op_desc_info.input_size.at(i)) != SUCCESS) {
GELOGE(PARAM_INVALID, "[Dump][ExceptionInput] Dump the %zu input data of op [%s] failed",
i, op_desc_info.op_name.c_str());
return PARAM_INVALID;
}
}
return SUCCESS;
}
Status ExceptionDumper::DumpExceptionOutput(const OpDescInfo &op_desc_info, const string &dump_file) const {
GELOGI("[Dump][ExceptionOutput] Start to dump exception output");
for (size_t i = 0; i < op_desc_info.output_addrs.size(); i++) {
if (Debug::DumpDevMem(dump_file.data(), op_desc_info.output_addrs.at(i), op_desc_info.output_size.at(i)) !=
SUCCESS) {
GELOGE(PARAM_INVALID, "[Dump][ExceptionInput] Dump the %zu input data of op [%s] failed",
i, op_desc_info.op_name.c_str());
return PARAM_INVALID;
}
}
return SUCCESS;
}
OpDescInfo *ExceptionDumper::MutableOpDescInfo(uint32_t task_id, uint32_t stream_id) {
for (OpDescInfo &op_desc_info : op_desc_info_) {
if (op_desc_info.task_id == task_id && op_desc_info.stream_id == stream_id) {
return &op_desc_info;
}
}
return nullptr;
}
} // namespace ge

@ -0,0 +1,48 @@
/**
* Copyright 2019-2021 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_COMMON_DUMP_DUMP_EXCEPTION_H_
#define GE_COMMON_DUMP_DUMP_EXCEPTION_H_
#include <vector>
#include "graph/op_desc.h"
#include "framework/common/ge_types.h"
#include "graph/load/model_manager/task_info/task_info.h"
namespace ge {
class ExceptionDumper {
public:
ExceptionDumper() = default;
~ExceptionDumper();
void SaveDumpOpInfo(const OpDescPtr &op, uint32_t task_id, uint32_t stream_id,
std::vector<void *> &input_addrs, std::vector<void *> &output_addrs);
void SaveDumpOpInfo(const RuntimeParam &model_param, const OpDescPtr &op, uint32_t task_id, uint32_t stream_id);
Status DumpExceptionInfo(const std::vector<rtExceptionInfo> &exception_infos) const;
bool GetOpDescInfo(uint32_t stream_id, uint32_t task_id, OpDescInfo &op_desc_info) const;
OpDescInfo *MutableOpDescInfo(uint32_t task_id, uint32_t stream_id);
private:
void SaveOpDescInfo(const OpDescPtr &op, uint32_t task_id, uint32_t stream_id, OpDescInfo &op_desc_info);
Status DumpExceptionInput(const OpDescInfo &op_desc_info, const std::string &dump_file) const;
Status DumpExceptionOutput(const OpDescInfo &op_desc_info, const std::string &dump_file) const;
std::vector<OpDescInfo> op_desc_info_;
};
} // namespace ge
#endif // GE_COMMON_DUMP_DUMP_OP_H_

@ -16,6 +16,7 @@ set(SRC_LIST
"../common/ge/plugin_manager.cc"
"../common/ge/op_tiling_manager.cc"
"../common/dump/dump_properties.cc"
"../common/dump/dump_exception.cc"
"../common/dump/dump_manager.cc"
"../common/dump/dump_op.cc"
"../common/dump/opdebug_register.cc"

@ -72,24 +72,6 @@ static bool ParseNameIndex(const std::string &node_name_index, std::string &node
static bool IsTensorDescWithSkipDumpAddrType(bool has_mem_type_attr, vector<int64_t> v_memory_type, size_t i) {
return has_mem_type_attr && (v_memory_type[i] == RT_MEMORY_L1);
}
static uint64_t GetNowTime() {
uint64_t ret = 0;
mmTimeval tv;
if (mmGetTimeOfDay(&tv, nullptr) == 0) {
ret = tv.tv_sec * 1000000ULL + tv.tv_usec;
}
return ret;
}
static void ReplaceStringElem(std::string &str) {
for_each(str.begin(), str.end(), [](char &ch) {
if ((ch == ' ') || (ch == '.') || (ch == '/') || (ch == '\\')) {
ch = '_';
}
});
}
} // namespace
static int32_t GetIrDataType(ge::DataType data_type) {
@ -194,66 +176,6 @@ void DataDumper::SaveOpDebugId(uint32_t task_id, uint32_t stream_id, void *op_de
is_op_debug_ = is_op_debug;
}
void DataDumper::SaveDumpOpInfo(const RuntimeParam &model_param, const OpDescPtr &op, uint32_t task_id,
uint32_t stream_id) {
GELOGD("Start SaveDumpOpInfo of task_id: %u, stream_id: %u", task_id, stream_id);
OpDescInfo op_desc_info;
op_desc_info.op_name = op->GetName();
op_desc_info.op_type = op->GetType();
op_desc_info.task_id = task_id;
op_desc_info.stream_id = stream_id;
for (size_t i = 0; i < op->GetAllInputsSize(); ++i) {
GeTensorDescPtr input_tensor_desc = op->MutableInputDesc(i);
if (input_tensor_desc == nullptr) {
continue;
}
op_desc_info.input_format.emplace_back(input_tensor_desc->GetFormat());
op_desc_info.input_shape.emplace_back(input_tensor_desc->GetShape().GetDims());
op_desc_info.input_data_type.emplace_back(input_tensor_desc->GetDataType());
int64_t input_size = 0;
if (TensorUtils::GetTensorSizeInBytes(*input_tensor_desc, input_size) != SUCCESS) {
GELOGW("Get input size failed");
return;
}
GELOGD("Save dump op info, the input size is %ld", input_size);
op_desc_info.input_size.emplace_back(input_size);
}
for (size_t j = 0; j < op->GetOutputsSize(); ++j) {
GeTensorDescPtr output_tensor_desc = op->MutableOutputDesc(j);
if (output_tensor_desc == nullptr) {
continue;
}
op_desc_info.output_format.emplace_back(output_tensor_desc->GetFormat());
op_desc_info.output_shape.emplace_back(output_tensor_desc->GetShape().GetDims());
op_desc_info.output_data_type.emplace_back(output_tensor_desc->GetDataType());
int64_t output_size = 0;
if (TensorUtils::GetTensorSizeInBytes(*output_tensor_desc, output_size) != SUCCESS) {
GELOGW("Get input size failed");
return;
}
GELOGD("Save dump op info, the output size is %ld", output_size);
op_desc_info.output_size.emplace_back(output_size);
}
op_desc_info.input_addrs = ModelUtils::GetInputDataAddrs(model_param, op);
op_desc_info.output_addrs = ModelUtils::GetOutputDataAddrs(model_param, op);
op_desc_info_.emplace_back(op_desc_info);
}
bool DataDumper::GetOpDescInfo(uint32_t stream_id, uint32_t task_id, OpDescInfo &op_desc_info) const {
GELOGI("There are %zu op need to dump.", op_desc_info_.size());
for (size_t index = 0; index < op_desc_info_.size(); ++index) {
OpDescInfo dump_op_info = op_desc_info_.at(index);
if (dump_op_info.task_id == task_id && dump_op_info.stream_id == stream_id) {
GELOGI("find exception op of task_id: %u, stream_id: %u.", task_id, stream_id);
op_desc_info = dump_op_info;
return true;
}
}
return false;
}
void DataDumper::SaveDumpTask(uint32_t task_id, uint32_t stream_id, const std::shared_ptr<OpDesc> &op_desc,
uintptr_t args) {
if (op_desc == nullptr) {
@ -906,98 +828,4 @@ void DataDumper::PrintCheckLog(string &dump_list_key) {
}
}
}
Status DataDumper::DumpExceptionInput(const OpDescInfo &op_desc_info, const string &dump_file) {
GELOGI("Start to dump exception input");
for (size_t i = 0; i < op_desc_info.input_addrs.size(); i++) {
if (Debug::DumpDevMem(dump_file.data(), op_desc_info.input_addrs.at(i), op_desc_info.input_size.at(i)) != SUCCESS) {
GELOGE(PARAM_INVALID, "Dump the %zu input data failed", i);
return PARAM_INVALID;
}
}
return SUCCESS;
}
Status DataDumper::DumpExceptionOutput(const OpDescInfo &op_desc_info, const string &dump_file) {
GELOGI("Start to dump exception output");
for (size_t i = 0; i < op_desc_info.output_addrs.size(); i++) {
if (Debug::DumpDevMem(dump_file.data(), op_desc_info.output_addrs.at(i), op_desc_info.output_size.at(i)) !=
SUCCESS) {
GELOGE(PARAM_INVALID, "Dump the %zu input data failed", i);
return PARAM_INVALID;
}
}
return SUCCESS;
}
Status DataDumper::DumpExceptionInfo(const std::vector<rtExceptionInfo> exception_infos) {
GELOGI("Start to dump exception info");
for (const rtExceptionInfo &iter : exception_infos) {
OpDescInfo op_desc_info;
if (GetOpDescInfo(iter.streamid, iter.taskid, op_desc_info)) {
toolkit::dumpdata::DumpData dump_data;
dump_data.set_version("2.0");
dump_data.set_dump_time(GetNowTime());
dump_data.set_op_name(op_desc_info.op_name);
for (size_t i = 0; i < op_desc_info.input_format.size(); ++i) {
toolkit::dumpdata::OpInput input;
input.set_data_type(toolkit::dumpdata::OutputDataType(GetIrDataType(op_desc_info.input_data_type[i])));
input.set_format(toolkit::dumpdata::OutputFormat(op_desc_info.input_format[i]));
for (auto dim : op_desc_info.input_shape[i]) {
input.mutable_shape()->add_dim(dim);
}
input.set_size(op_desc_info.input_size[i]);
GELOGI("The input size int exception is %ld", op_desc_info.input_size[i]);
dump_data.mutable_input()->Add(std::move(input));
}
for (size_t j = 0; j < op_desc_info.output_format.size(); ++j) {
toolkit::dumpdata::OpOutput output;
output.set_data_type(toolkit::dumpdata::OutputDataType(GetIrDataType(op_desc_info.output_data_type[j])));
output.set_format(toolkit::dumpdata::OutputFormat(op_desc_info.output_format[j]));
for (auto dim : op_desc_info.output_shape[j]) {
output.mutable_shape()->add_dim(dim);
}
output.set_size(op_desc_info.output_size[j]);
GELOGI("The output size int exception is %ld", op_desc_info.output_size[j]);
dump_data.mutable_output()->Add(std::move(output));
}
uint64_t now_time = GetNowTime();
std::string op_name = op_desc_info.op_name;
std::string op_type = op_desc_info.op_type;
ReplaceStringElem(op_name);
ReplaceStringElem(op_type);
string dump_file_path =
"./" + op_type + "." + op_name + "." + std::to_string(op_desc_info.task_id) + "." + std::to_string(now_time);
GELOGI("The exception dump file path is %s", dump_file_path.c_str());
uint64_t proto_size = dump_data.ByteSizeLong();
std::unique_ptr<char[]> proto_msg(new (std::nothrow) char[proto_size]);
bool ret = dump_data.SerializeToArray(proto_msg.get(), proto_size);
if (!ret || proto_size == 0) {
REPORT_INNER_ERROR("E19999", "Serialize proto to string fail when DataDumper %s", __FUNCTION__);
GELOGE(PARAM_INVALID, "Dump data proto serialize failed");
return PARAM_INVALID;
}
GE_CHK_STATUS_RET(MemoryDumper::DumpToFile(dump_file_path.c_str(), &proto_size, sizeof(uint64_t)),
"Failed to dump proto size");
GE_CHK_STATUS_RET(MemoryDumper::DumpToFile(dump_file_path.c_str(), proto_msg.get(), proto_size),
"Failed to dump proto msg");
if (DumpExceptionInput(op_desc_info, dump_file_path) != SUCCESS) {
GELOGE(PARAM_INVALID, "Dump exception input failed");
return PARAM_INVALID;
}
if (DumpExceptionOutput(op_desc_info, dump_file_path) != SUCCESS) {
GELOGE(PARAM_INVALID, "Dump exception output failed");
return PARAM_INVALID;
}
GELOGI("Dump exception info SUCCESS");
} else {
GELOGE(PARAM_INVALID, "Get op desc info failed,task id:%u,stream id:%u", iter.taskid, iter.streamid);
return PARAM_INVALID;
}
}
return SUCCESS;
}
} // namespace ge

@ -70,8 +70,6 @@ class DataDumper {
void SaveDumpInput(const std::shared_ptr<Node> &node);
void SaveDumpOpInfo(const RuntimeParam &model_param, const OpDescPtr &op, uint32_t task_id, uint32_t stream_id);
// args is device memory stored first output addr
void SaveDumpTask(uint32_t task_id, uint32_t stream_id, const std::shared_ptr<OpDesc> &op_desc, uintptr_t args);
void SaveEndGraphId(uint32_t task_id, uint32_t stream_id);
@ -87,14 +85,8 @@ class DataDumper {
void SetDumpProperties(const DumpProperties &dump_properties) { dump_properties_ = dump_properties; }
const DumpProperties &GetDumpProperties() const { return dump_properties_; }
bool GetOpDescInfo(uint32_t stream_id, uint32_t task_id, OpDescInfo &op_desc_info) const;
const std::vector<OpDescInfo> &GetAllOpDescInfo() const { return op_desc_info_; }
// Dump exception info
Status DumpExceptionInput(const OpDescInfo &op_desc_info, const string &dump_file);
Status DumpExceptionOutput(const OpDescInfo &op_desc_info, const string &dump_file);
Status DumpExceptionInfo(const std::vector<rtExceptionInfo> exception_infos);
private:
void ReleaseDevMem(void **ptr) noexcept;

@ -2656,9 +2656,9 @@ Status DavinciModel::ReturnResult(uint32_t data_id, const bool rslt_flg, const b
GE_CHECK_NOTNULL(model_manager);
auto exception_infos = model_manager->GetExceptionInfos();
if (exception_infos.size() > 0) {
GE_CHK_STATUS_RET(data_dumper_.DumpExceptionInfo(exception_infos), "Dump exception info failed");
GE_CHK_STATUS_RET(DumpExceptionInfo(exception_infos), "[Dump][Exception] Dump exception info failed.");
} else {
GELOGI("Exception info is null");
GELOGI("[Dump][Exception] Exception info is null");
}
GE_CHK_STATUS(listener_->OnComputeDone(model_id_, data_id, INTERNAL_ERROR, outputs), "OnComputeDone failed.");
return INTERNAL_ERROR;
@ -4340,4 +4340,36 @@ Status DavinciModel::InitL1DataDumperArgs() {
return SUCCESS;
}
void DavinciModel::UpdateOpIOAddrs(uint32_t task_id, uint32_t stream_id, const std::vector<void *> &io_addrs) {
if (fixed_mem_base_ == reinterpret_cast<uintptr_t>(mem_base_)) {
GELOGD("[Update][OpIOAddrs] No need to update op input output addr.");
return;
}
OpDescInfo *op_desc_info = exception_dumper_.MutableOpDescInfo(task_id, stream_id);
if (op_desc_info == nullptr) {
GELOGW("[Update][OpIOAddrs] Find op desc failed, task_id: %u, stream_id: %u.", task_id, stream_id);
return;
}
size_t input_size = op_desc_info->input_addrs.size();
size_t output_size = op_desc_info->output_addrs.size();
if (input_size + output_size != io_addrs.size()) {
GELOGW("[Update][OpIOAddrs] Op[%s] input size[%zu] and output size[%zu] is not equal to io addr size[%zu]",
op_desc_info->op_name.c_str(), input_size, output_size, io_addrs.size());
return;
}
vector<void *> input_addrs;
vector<void *> output_addrs;
for (size_t i = 0; i < io_addrs.size(); i++) {
if (i < input_size) {
input_addrs.emplace_back(GetRunAddress(io_addrs[i]));
} else {
output_addrs.emplace_back(GetRunAddress(io_addrs[i]));
}
}
op_desc_info->input_addrs = input_addrs;
op_desc_info->output_addrs = output_addrs;
GELOGD("[Update][OpIOAddrs] Op [%s] update input output addr success.", op_desc_info->op_name.c_str());
}
} // namespace ge

@ -29,6 +29,7 @@
#include "common/helper/om_file_helper.h"
#include "common/opskernel/ge_task_info.h"
#include "common/properties_manager.h"
#include "common/dump/dump_exception.h"
#include "common/dump/opdebug_register.h"
#include "common/types.h"
#include "framework/common/util.h"
@ -471,13 +472,17 @@ class DavinciModel {
Status ReportProfilingData();
void SaveDumpOpInfo(const RuntimeParam &model_param, const OpDescPtr &op, uint32_t task_id, uint32_t stream_id) {
data_dumper_.SaveDumpOpInfo(model_param, op, task_id, stream_id);
exception_dumper_.SaveDumpOpInfo(model_param, op, task_id, stream_id);
}
void SaveDumpTask(uint32_t task_id, uint32_t stream_id, const shared_ptr<OpDesc> &op_desc, uintptr_t args) {
data_dumper_.SaveDumpTask(task_id, stream_id, op_desc, args);
}
Status DumpExceptionInfo(const std::vector<rtExceptionInfo> &exception_infos) const {
return exception_dumper_.DumpExceptionInfo(exception_infos);
}
void SetKnownShapeGlobalStep(void *global_step) {
known_shape_global_step_ = global_step;
}
@ -557,8 +562,9 @@ class DavinciModel {
const DumpProperties &GetDumpProperties() const { return data_dumper_.GetDumpProperties(); }
bool GetOpDescInfo(uint32_t stream_id, uint32_t task_id, OpDescInfo &op_desc_info) const {
return data_dumper_.GetOpDescInfo(stream_id, task_id, op_desc_info);
return exception_dumper_.GetOpDescInfo(stream_id, task_id, op_desc_info);
}
void UpdateOpIOAddrs(uint32_t task_id, uint32_t stream_id, const std::vector<void *> &io_addrs);
private:
// memory address of weights
@ -1001,6 +1007,7 @@ class DavinciModel {
int64_t maxDumpOpNum_;
// for data dump
DataDumper data_dumper_;
ExceptionDumper exception_dumper_;
OpdebugRegister opdebug_register_;
uint64_t iterator_count_;
bool is_l1_fusion_enable_;

@ -1579,9 +1579,21 @@ Status ModelManager::GetOpDescInfo(uint32_t device_id, uint32_t stream_id, uint3
for (const auto &model : model_map_) {
auto davinci_model = model.second;
if (davinci_model->GetDeviceId() == device_id) {
GELOGI("Start to GetOpDescInfo of device_id: %u.", device_id);
GELOGI("[Get][OpDescInfo] Start to GetOpDescInfo of device_id: %u in davinci model.", device_id);
if (davinci_model->GetOpDescInfo(stream_id, task_id, op_desc_info)) {
GELOGI("Find specific node of stream_id: %u, task_id: %u.", stream_id, task_id);
GELOGI("[Get][OpDescInfo] Find specific node of stream_id: %u, task_id: %u in davinci model.",
stream_id, task_id);
return SUCCESS;
}
}
}
for (const auto &model : hybrid_model_map_) {
auto hybrid_model = model.second;
if (hybrid_model->GetDeviceId() == device_id) {
GELOGI("[Get][OpDescInfo] Start to GetOpDescInfo of device_id: %u in hybrid model.", device_id);
if (hybrid_model->GetOpDescInfo(stream_id, task_id, op_desc_info)) {
GELOGI("[Get][OpDescInfo] Find specific node of stream_id: %u, task_id: %u in hybrid model.",
stream_id, task_id);
return SUCCESS;
}
}

@ -359,6 +359,7 @@ void KernelExTaskInfo::SetIoAddrs(const OpDescPtr &op_desc) {
Status KernelExTaskInfo::UpdateArgs() {
GELOGI("KernelExTaskInfo::UpdateArgs in.");
davinci_model_->SetTotalIOAddrs(io_addrs_);
davinci_model_->UpdateOpIOAddrs(task_id_, stream_id_, io_addrs_);
GELOGI("KernelExTaskInfo::UpdateArgs success.");
return SUCCESS;
}

@ -523,6 +523,7 @@ Status KernelTaskInfo::UpdateArgs() {
return CopyNoncontinuousArgs(io_addr_offset_);
}
davinci_model_->SetTotalIOAddrs(io_addrs_);
davinci_model_->UpdateOpIOAddrs(task_id_, stream_id_, io_addrs_);
} else if (kernel_type_ == ccKernelType::AI_CPU || kernel_type_ == ccKernelType::CUST_AI_CPU) {
return CopyNoncontinuousArgs(sizeof(aicpu::AicpuParamHead));
}

@ -63,5 +63,27 @@ Status GraphExecutionContext::Synchronize(rtStream_t rt_stream) {
REPORT_CALL_ERROR("E19999", "invoke rtStreamSynchronize failed, ret = %d", rt_ret);
return RT_FAILED;
}
Status GraphExecutionContext::DumpExceptionInfo(const std::vector<rtExceptionInfo> &exception_infos) {
if (exception_infos.empty()) {
GELOGI("[Dump][ExceptionInfo] Exception info is null.");
return SUCCESS;
}
GELOGI("[Dump][ExceptionInfo] Start to search dynamic op info and to dump.");
if (exception_dumper.DumpExceptionInfo(exception_infos) != SUCCESS) {
GELOGE(FAILED, "[Dump][Exception] Dump dynamic op exception info failed.");
return FAILED;
}
GELOGI("[Dump][ExceptionInfo] Start to search static op info and to dump.");
for (const auto &iter : davinci_model) {
if (iter != nullptr) {
if (iter->DumpExceptionInfo(exception_infos) != SUCCESS) {
GELOGE(FAILED, "[Dump][ExceptionInfo] Dump static op exception info failed.");
return FAILED;
}
}
}
return SUCCESS;
}
} // namespace hybrid
} // namespace ge

@ -23,6 +23,7 @@
#include "common/properties_manager.h"
#include "framework/common/debug/ge_log.h"
#include "graph/ge_local_context.h"
#include "graph/load/model_manager/davinci_model.h"
#include "hybrid/common/npu_memory_allocator.h"
#include "hybrid/common/tensor_value.h"
#include "hybrid/executor/hybrid_profiler.h"
@ -54,6 +55,7 @@ struct GraphExecutionContext {
void SetErrorCode(Status error_code);
Status GetStatus() const;
Status Synchronize(rtStream_t rt_stream);
Status DumpExceptionInfo(const std::vector<rtExceptionInfo> &exception_infos);
uint64_t session_id = 0;
uint64_t context_id = 0;
@ -68,6 +70,8 @@ struct GraphExecutionContext {
DumpProperties dump_properties;
bool trace_enabled = false;
bool dump_enabled = false;
ExceptionDumper exception_dumper;
std::vector<std::shared_ptr<ge::DavinciModel>> davinci_model;
std::atomic_bool is_eos_;
long profiling_level = 0;
long iteration = 0;

@ -55,6 +55,8 @@ class HybridModelAsyncExecutor {
Status EnqueueData(const std::shared_ptr<InputDataWrapper> &data);
const GraphExecutionContext * GeContext() { return executor_->GetContext(); }
private:
Status InitInputDesc();

@ -18,6 +18,7 @@
#include "graph/ge_context.h"
#include "graph/runtime_inference_context.h"
#include "graph/utils/tensor_utils.h"
#include "graph/load/model_manager/model_manager.h"
#include "common/dump/dump_manager.h"
#include "common/profiling/profiling_manager.h"
@ -95,13 +96,23 @@ Status HybridModelExecutor::ExecuteGraphInternal(SubgraphExecutor &executor,
HYBRID_CHK_STATUS_RET(executor.ExecuteAsync(args.inputs, args.input_desc, args.outputs),
"Failed to execute partitioned call.");
RECORD_MODEL_EXECUTION_EVENT(&context_, "[ExecuteAsync] End");
if (!model_->IsSingleOp() && prof_mgr.ProfilingModelLoadOn()) {
GE_CHK_STATUS_RET_NOLOG(prof_mgr.ProfileStepInfo(index_id, model_id, 1, stream_, device_id));
}
if (!model_->IsSingleOp()) {
Status ret = executor.Synchronize();
if (ret != ge::SUCCESS) {
auto model_manager = ModelManager::GetInstance();
GE_CHECK_NOTNULL(model_manager);
auto exception_infos = model_manager->GetExceptionInfos();
if (!exception_infos.empty()) {
HYBRID_CHK_STATUS_RET(context_.DumpExceptionInfo(exception_infos),
"[Execute][GraphInternal] Dump exception info failed.");
}
GELOGE(ret, "[Execute][GraphInternal] Synchronize failed.");
}
HYBRID_CHK_STATUS_RET(executor.Synchronize(), "Failed to sync root graph.");
RECORD_MODEL_EXECUTION_EVENT(&context_, "[Synchronize] End");
}

@ -4,6 +4,7 @@
#include "common/dump/dump_manager.h"
#include "graph/ge_context.h"
#include "graph/runtime_inference_context.h"
#include "graph/load/model_manager/model_manager.h"
namespace ge {
namespace hybrid {
@ -266,6 +267,13 @@ Status HybridModelPipelineExecutor::Execute(HybridModelExecutor::ExecuteArgs &ar
ret = stage_executors_[i]->Synchronize();
if (ret != SUCCESS) {
auto model_manager = ModelManager::GetInstance();
GE_CHECK_NOTNULL(model_manager);
auto exception_infos = model_manager->GetExceptionInfos();
if (!exception_infos.empty()) {
HYBRID_CHK_STATUS_RET(context_.DumpExceptionInfo(exception_infos),
"[Execute][GraphInternal] Dump exception info failed.");
}
GELOGE(ret, "[Invoke][Synchronize] failed for [Executor: %zu].", i);
REPORT_CALL_ERROR("E19999", "[Executor: %zu] failed to Synchronize result.", i);
has_error = true;

@ -69,6 +69,7 @@ class NodeDoneCallback {
private:
Status PrepareConstInputs(const NodeItem &node_item);
Status DumpDynamicNode();
Status SaveDumpOpInfo();
Status ProfilingReport();
Status GetTaskDescInfo(const NodePtr node, const HybridModel *model,
std::vector<TaskDescInfo> &task_desc_info);
@ -266,6 +267,41 @@ Status NodeDoneCallback::DumpDynamicNode() {
return SUCCESS;
}
Status NodeDoneCallback::SaveDumpOpInfo() {
GE_CHECK_NOTNULL(graph_context_);
GE_CHECK_NOTNULL(graph_context_->model);
auto node = context_->GetNodeItem().node;
if (node == nullptr) {
GELOGE(PARAM_INVALID, "[Save][DumpOpInfo] Get node is nullptr.");
return PARAM_INVALID;
}
auto op_desc = node->GetOpDesc();
GE_CHECK_NOTNULL(op_desc);
vector<void *> input_addrs;
vector<void *> output_addrs;
for (int i = 0; i < context_->NumInputs(); i++) {
auto tensor_value = context_->GetInput(i);
GE_CHK_BOOL_RET_STATUS(tensor_value != nullptr, PARAM_INVALID, "[Save][DumpOpInfo] Tensor value is nullptr.");
void *input_addr = const_cast<void *>(tensor_value->GetData());
input_addrs.emplace_back(input_addr);
}
for (int j = 0; j < context_->NumOutputs(); j++) {
auto tensor_value = context_->GetOutput(j);
GE_CHK_BOOL_RET_STATUS(tensor_value != nullptr, PARAM_INVALID, "[Save][DumpOpInfo] Tensor value is nullptr.");
void *output_addr = const_cast<void *>(tensor_value->GetData());
output_addrs.emplace_back(output_addr);
}
uint32_t stream_id = context_->GetStreamId();
uint32_t task_id = context_->GetTaskId();
auto exception_dumper = graph_context_->exception_dumper;
exception_dumper.SaveDumpOpInfo(op_desc, task_id, stream_id, input_addrs, output_addrs);
return SUCCESS;
}
Status NodeDoneCallback::OnNodeDone() {
auto &node_item = context_->GetNodeItem();
GELOGI("[%s] Start callback process.", node_item.NodeName().c_str());
@ -278,6 +314,8 @@ Status NodeDoneCallback::OnNodeDone() {
GE_CHK_STATUS_RET(DumpDynamicNode(), "[Call][DumpDynamicNode] Failed.");
}
GE_CHK_STATUS_RET(SaveDumpOpInfo(), "Failed to dump op info.");
if (ProfilingManager::Instance().ProfilingModelExecuteOn()) {
GE_CHK_STATUS_RET(ProfilingReport(), "[Report][Profiling] of node[%s] failed.", node_item.NodeName().c_str());
}

@ -80,6 +80,12 @@ class HybridDavinciModel::Impl {
model_.SetOmName(model_name);
}
uint32_t GetDeviceId() {
return model_.GetDeviceId();
}
const GraphExecutionContext * GeContext() { return executor_.GeContext(); }
uint64_t GetSessionId() {
return model_.GetSessionId();
}
@ -186,6 +192,11 @@ void HybridDavinciModel::SetOmName(const string &om_name) {
}
}
uint32_t HybridDavinciModel::GetDeviceId() const {
GE_CHECK_NOTNULL(impl_);
return impl_->GetDeviceId();
}
Status HybridDavinciModel::GetDynamicBatchInfo(std::vector<std::vector<int64_t>> &batch_info, int32_t &dynamic_type) {
GE_CHECK_NOTNULL(impl_);
return impl_->GetDynamicBatchInfo(batch_info, dynamic_type);
@ -221,5 +232,22 @@ uint64_t HybridDavinciModel::GetSessionId() {
GE_CHECK_NOTNULL(impl_);
return impl_->GetSessionId();
}
bool HybridDavinciModel::GetOpDescInfo(uint32_t stream_id, uint32_t task_id, OpDescInfo &op_desc_info) const {
if (impl_ == nullptr) {
return false;
}
auto context = impl_->GeContext();
GE_CHECK_NOTNULL(context);
bool ret = context->exception_dumper.GetOpDescInfo(stream_id, task_id, op_desc_info);
if (!ret) {
for (const auto &iter : context->davinci_model) {
if (iter->GetOpDescInfo(stream_id, task_id, op_desc_info)) {
return true;
}
}
}
return false;
}
} // namespace hybrid
} // namespace ge

@ -59,6 +59,8 @@ class HybridDavinciModel {
void SetOmName(const string &om_name);
uint32_t GetDeviceId() const;
uint64_t GetSessionId();
Status GetDynamicBatchInfo(std::vector<std::vector<int64_t>> &batch_info, int32_t &dynamic_type);
@ -74,6 +76,8 @@ class HybridDavinciModel {
void SetModelDescVersion(bool is_new_model_desc);
bool GetOpDescInfo(uint32_t stream_id, uint32_t task_id, OpDescInfo &op_desc_info) const;
private:
HybridDavinciModel() = default;
class Impl;

@ -64,6 +64,10 @@ void HybridDavinciModel::SetDeviceId(uint32_t device_id) {
void HybridDavinciModel::SetOmName(const string &om_name) {
}
uint32_t HybridDavinciModel::GetDeviceId() const {
return 0;
}
uint64_t HybridDavinciModel::GetSessionId() {
return 0;
}
@ -87,5 +91,9 @@ Status HybridDavinciModel::GetInputOutputDescInfo(vector<InputOutputDescInfo> &i
void HybridDavinciModel::SetModelDescVersion(bool is_new_model_desc) {
}
bool HybridDavinciModel::GetOpDescInfo(uint32_t stream_id, uint32_t task_id, OpDescInfo &op_desc_info) const {
return true;
}
} // namespace hybrid
} // namespace ge

@ -20,6 +20,7 @@
#include <vector>
#include <queue>
#include <memory>
#include "common/dump/dump_exception.h"
#include "framework/common/ge_inner_error_codes.h"
#include "graph/load/model_manager/data_inputer.h"
#include "graph/load/model_manager/task_info/task_info.h"
@ -131,7 +132,6 @@ class HybridModel {
void SetInputDimsAndShapeRangesInfo(const vector<int64_t> &model_input_dims,
std::vector<std::pair<int64_t, int64_t>> &shape_ranges,
InputOutputDescInfo &input);
private:
friend class HybridModelBuilder;
friend class HybridModelAsyncExecutor;

@ -208,6 +208,8 @@ Status AiCoreNodeTask::ExecuteAsync(TaskContext &context, std::function<void()>
REPORT_CALL_ERROR("E19999", "rtGetTaskIdAndStreamID failed, ret: 0x%X.", rt_ret);
return RT_ERROR_TO_GE_STATUS(rt_ret);
}
context.SetTaskId(task_id);
context.SetStreamId(stream_id);
GELOGD("Aicore node[%s] task_id: %u, stream_id: %u.", context.GetNodeName(), task_id, stream_id);
(void)context.SaveProfilingTaskDescInfo(task_id, stream_id, kTaskTypeAicore, (*it)->GetBlockDim());
RECORD_EXECUTION_EVENT(context.GetExecutionContext(), context.GetNodeName(), "[AiCoreNodeLaunchKernel] End");

@ -208,6 +208,8 @@ Status AicpuNodeTaskBase::ExecuteAsync(TaskContext &context, std::function<void(
REPORT_CALL_ERROR("E19999", "rtGetTaskIdAndStreamID failed, ret: 0x%X.", rt_ret);
return RT_ERROR_TO_GE_STATUS(rt_ret);
}
context.SetTaskId(task_id);
context.SetStreamId(stream_id);
GELOGD("Aicpu node[%s] task_id: %u, stream_id: %u.", context.GetNodeName(), task_id, stream_id);
(void)context.SaveProfilingTaskDescInfo(task_id, stream_id, kTaskTypeAicpu, 0);
auto callback = [=, &context]() {

@ -30,7 +30,7 @@ namespace ge {
namespace hybrid {
REGISTER_NODE_EXECUTOR_BUILDER(NodeExecutorManager::ExecutorType::COMPILED_SUBGRAPH, KnownNodeExecutor);
Status KnownNodeTask:: ExecuteAsync(TaskContext &context, std::function<void()> done_callback) {
Status KnownNodeTask::ExecuteAsync(TaskContext &context, std::function<void()> done_callback) {
RECORD_EXECUTION_EVENT(context.GetExecutionContext(), context.GetNodeName(), "[KnownNodeTaskExecuteAsync] Start");
GELOGD("[%s] KnownNodeTask::ExecuteAsync in.", context.GetNodeName());
if (davinci_model_->GetTaskList().empty()) {
@ -114,6 +114,13 @@ Status KnownNodeTask::Init(TaskContext &context) {
GE_CHK_STATUS_RET(ModelManager::GetInstance()->DestroyAicpuKernel(davinci_model_->GetSessionId(),
davinci_model_->Id(), davinci_model_->SubModelId()),
"KnownNodeTask::Init destroy aicpu kernel failed.");
auto execution_context = const_cast<GraphExecutionContext *>(context.GetExecutionContext());
GE_CHECK_NOTNULL(execution_context);
auto &davinci_model = execution_context->davinci_model;
if (std::find(davinci_model.begin(), davinci_model.end(), davinci_model_) == davinci_model.end()) {
davinci_model.emplace_back(davinci_model_);
}
GELOGI("[%s] KnownNodeExecutor::Init success.", context.GetNodeName());
return SUCCESS;
}

@ -166,6 +166,7 @@ set(COMMON_SRC_FILES
"${GE_CODE_DIR}/ge/common/dump/dump_properties.cc"
"${GE_CODE_DIR}/ge/common/helper/model_helper.cc"
"${GE_CODE_DIR}/ge/common/dump/dump_manager.cc"
"${GE_CODE_DIR}/ge/common/dump/dump_exception.cc"
"${GE_CODE_DIR}/ge/common/dump/opdebug_register.cc"
"${GE_CODE_DIR}/ge/common/dump/dump_op.cc"
"${GE_CODE_DIR}/ge/common/helper/om_file_helper.cc"
@ -755,6 +756,7 @@ set(MULTI_PARTS_TEST_FILES
"common/datatype_transfer_unittest.cc"
"common/dump_manager_unittest.cc"
"common/dump_op_unittest.cc"
"common/dump_exception_unittest.cc"
"common/opdebug_register_unittest.cc"
"common/format_transfer_unittest.cc"
"common/format_transfer_transpose_unittest.cc"

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

Loading…
Cancel
Save