Compare commits

...

6 Commits
master ... r0.5

@ -1,3 +1,22 @@
# Release 0.5.0-beta
## Major Features and Improvements
- Optimize Allreduce trailing parallelism, rebuild the calculation graph dependencies, adjust the calculation order, and maximize the efficiency of calculation and gradient aggregation communication in parallel, especially in large data volume gradient aggregation and low bandwidth/large cluster scenarios You can get a bigger income.
- Advance constant folding, variable fusion, conversion operator related optimization pass to the end of the graph preparation.
- Modify memory allocation algorithm, optimize GE memory allocation, and reduce memory usage in training multi-PCS scenarios.
- Support IR composition, model compilation, inference execution in the same process.
## Bugfixes
- Fix the bug that the graphic attribute "output_name_idx_" is not serialized to the GEIR model file, resulting in the failure of the Fast-RCNN network offline inference model generation。
- Introduce timestamp in the dump data storage directory, to ensure that the dump file generated is in a different directory each time it is executed.
- Reinforce the ParserJsonFile interface to fix the program coredump bug caused by the injection of abnormal json files.
- Fix the bug that Stream binding failure scenario and sream resource leakage.
## Thanks to our Contributors
Thanks goes to these wonderful people:
wangcongweiyangyanghaorangxutianchunshibeiji
Contributions of any kind are welcome!
# Release 0.3.0-alpha
## Major Features and Improvements

@ -1,7 +1,7 @@
graphengine_add_pkg(securec
VER 1.1.10
URL https://gitee.com/openeuler/bounds_checking_function/repository/archive/v1.1.10.tar.gz
MD5 0782dd2351fde6920d31a599b23d8c91
URL https://gitee.com/openeuler/libboundscheck/repository/archive/v1.1.10.tar.gz
MD5 193f0ca5246c1dd84920db34d2d8249f
LIBS c_sec
PATCHES ${GE_SOURCE_DIR}/third_party/patch/securec/securec.patch001
CMAKE_OPTION " "

@ -204,9 +204,6 @@ const std::string SAVE_ORIGINAL_MODEL = "ge.saveOriginalModel";
// Save original model file name
const std::string ORIGINAL_MODEL_FILE = "ge.originalModelFile";
// FE enable quant optimize
const std::string QUANT_OPTIMIZE = "ge.quantOptimize";
const char *const OPTION_GE_MAX_DUMP_FILE_NUM = "ge.maxDumpFileNum";
const char *const OPTION_GE_MAX_DUMP_FILE_SIZE = "ge.maxDumpFileSize";
const char *const OPTION_GE_MAX_DUMP_OP_NUM = "ge.maxDumpOpNum";
@ -274,7 +271,6 @@ static const char *const ENABLE_SINGLE_STREAM = ge::ENABLE_SINGLE_STREAM;
static const char *const AICORE_NUM = ge::AICORE_NUM.c_str();
static const char *const FUSION_SWITCH_FILE = ge::FUSION_SWITCH_FILE.c_str();
static const char *const ENABLE_SMALL_CHANNEL = ge::ENABLE_SMALL_CHANNEL.c_str();
static const char *const QUANT_OPTIMIZE = ge::QUANT_OPTIMIZE.c_str();
static const char *const OP_SELECT_IMPL_MODE = ge::OP_SELECT_IMPL_MODE.c_str();
static const char *const OUTPUT_TYPE = ge::OUTPUT_DATATYPE.c_str();
static const char *const BUFFER_OPTIMIZE = ge::BUFFER_OPTIMIZE.c_str();
@ -304,7 +300,6 @@ const std::set<std::string> global_options = {CORE_TYPE,
AICORE_NUM,
FUSION_SWITCH_FILE,
ENABLE_SMALL_CHANNEL,
QUANT_OPTIMIZE,
OP_SELECT_IMPL_MODE,
OPTYPELIST_FOR_IMPLMODE};
} // namespace ir_option

@ -43,6 +43,7 @@
#define DYNAMIC_INPUT_TD_NUM(name) ("__dynamic_input_" + name + "_cnt")
namespace ge {
class Operator;
class OperatorImpl;
class NamedAttrs;
class Graph;
@ -50,6 +51,7 @@ class AttrValue;
using SubgraphBuilder = std::function<Graph()>;
using OperatorImplPtr = std::shared_ptr<OperatorImpl>;
using OperatorPtr = std::shared_ptr<Operator>;
class OpIO;
using OutHandler = std::shared_ptr<OpIO>;

@ -67,6 +67,7 @@ using google::protobuf::Message;
class OpRegistrationDataImpl;
using ParseParamFunc = std::function<domi::Status(const google::protobuf::Message *, ge::Operator &)>;
using ParseParamByOpFunc = std::function<domi::Status(const ge::Operator &, ge::Operator &)>;
using FusionParseParamFunc =
std::function<domi::Status(const std::vector<const google::protobuf::Message *>, ge::Operator &)>;
using ParseSubgraphFunc = std::function<Status(const std::string &subgraph_name, const ge::Graph &graph)>;
@ -85,6 +86,8 @@ class FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY OpRegistrationData {
OpRegistrationData &ParseParamsFn(const ParseParamFunc &parseParamFn);
OpRegistrationData &ParseParamsByOperatorFn(const ParseParamByOpFunc &parse_param_by_op_fn);
OpRegistrationData &FusionParseParamsFn(const FusionParseParamFunc &fusionParseParamFn);
OpRegistrationData &ParseSubgraphPostFn(const ParseSubgraphFunc &subgraph_post_fn);
@ -100,6 +103,7 @@ class FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY OpRegistrationData {
std::set<std::string> GetOriginOpTypeSet() const;
domi::FrameworkType GetFrameworkType() const;
ParseParamFunc GetParseParamFn() const;
ParseParamByOpFunc GetParseParamByOperatorFn() const;
FusionParseParamFunc GetFusionParseParamFn() const;
ParseSubgraphFunc GetParseSubgraphPostFn() const;

@ -183,6 +183,7 @@ struct ModelData {
uint32_t model_len = 0; // Model binary data length
int32_t priority = 0; // Model priority
std::string key; // Key path for encrypt model, Empty for unencrypt
std::string om_name; // om file name, used for data dump
};
// The definition of Model information

@ -46,6 +46,8 @@ class ModelHelper {
static Status TransModelToGeModel(const ModelPtr& model, GeModelPtr& ge_model);
static Status TransGeModelToModel(const GeModelPtr& geModelPtr, ModelPtr& modelPtr);
Status GetBaseNameFromFileName(const std::string& file_name, std::string& base_name);
Status GetModelNameFromMergedGraphName(const std::string& graph_name, std::string& model_name);
private:
bool is_assign_model_ = false;

@ -62,7 +62,7 @@ class GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY GeExecutor {
// Get input and output descriptor
ge::Status GetModelDescInfo(uint32_t model_id, std::vector<ge::TensorDesc> &input_desc,
std::vector<ge::TensorDesc> &output_desc);
std::vector<ge::TensorDesc> &output_desc, bool new_model_desc = false);
///
/// @ingroup ge

@ -98,7 +98,9 @@ Status DumpInfershapeJson(const ge::Graph &graph, const char *json_file);
Status SetOutputNodeInfo(ge::Graph &graph, const std::string &output_type, const std::string &output_format);
Status GetOutputLeaf(ge::NodePtr node, std::vector<std::pair<ge::NodePtr, int32_t>> &output_nodes_info,
Status GetOutputLeaf(ge::NodePtr node, std::vector<std::pair<ge::NodePtr, int32_t>> &output_nodes_info);
void GetOutputNodesNameAndIndex(std::vector<std::pair<ge::NodePtr, int32_t>> &output_nodes_info,
std::vector<std::string> &output_nodes_name);
void UpdateOmgCtxWithParserCtx();

@ -94,6 +94,8 @@ struct OmgContext {
std::vector<std::pair<std::string, int32_t>> user_out_nodes;
// net out nodes (where user_out_nodes or leaf nodes)
std::vector<std::string> net_out_nodes;
// net out nodes top names(only caffe has top)
std::vector<std::string> out_top_names;
// path for the aicpu custom operator so_file
std::vector<std::string> aicpu_op_run_paths;
// ddk version

@ -139,6 +139,8 @@ GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string NEW_AIPP
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_NAME_AIPP_INPUTS;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_NAME_AIPP_OUTPUTS;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_NAME_INPUT_DIMS;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_NAME_SESSION_GRAPH_ID;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_NAME_PARENT_GRAPH_NAME;
@ -181,6 +183,8 @@ GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_NAM
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_NAME_STREAM_CYCLE_EVENT_FLAG;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_NAME_DYNAMIC_OUTPUT_DIMS;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_NAME_INPUT_ORIGIN_SIZE;
// to be deleted
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_TO_BE_DELETED;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string PERMUTE_RESHAPE_FUSION;

@ -31,6 +31,7 @@ class ShapeRefiner {
static graphStatus InferShapeAndType(const NodePtr &node, bool before_subgraph);
static graphStatus InferShapeAndType(const NodePtr &node);
static graphStatus InferShapeAndType(const ConstNodePtr &node, Operator &op);
static void ClearContextMap();
private:
static void PrintInOutTensorShape(const ge::NodePtr &node, const std::string &phase);

@ -121,6 +121,8 @@ const std::string NEW_AIPP_CONV_OP = "new_conv_op_for_aipp";
const std::string ATTR_NAME_AIPP_INPUTS = "_aipp_inputs";
const std::string ATTR_NAME_AIPP_OUTPUTS = "_aipp_outputs";
const std::string ATTR_NAME_INPUT_DIMS = "input_dims";
const std::string ATTR_NAME_SESSION_GRAPH_ID = "_session_graph_id";
const std::string ATTR_NAME_PARENT_GRAPH_NAME = "_parent_graph_name";
@ -154,6 +156,7 @@ const std::string ATTR_NAME_RTSWITCH_RECV_EVENT_ID = "rtswitch_event_id";
const std::string ATTR_NAME_AUTOMIC_ADD_START = "automic_add_addr_start";
const std::string ATTR_NAME_AUTOMIC_ADD_MEM_SIZE = "automic_add_mem_size";
const std::string ATTR_NAME_DYNAMIC_OUTPUT_DIMS = "_dynamic_output_dims";
const std::string ATTR_NAME_INPUT_ORIGIN_SIZE = "input_origin_size";
// To be deleted
const std::string ATTR_TO_BE_DELETED = "to_be_deleted";

@ -1,5 +1,5 @@
LOCAL_PATH := $(call my-dir)
include $(LOCAL_PATH)/stub/Makefile
COMMON_LOCAL_SRC_FILES := \
./proto/om.proto \
./proto/ge_ir.proto \
@ -85,6 +85,29 @@ LOCAL_PROPRIETARY_MODULE := true
include $(BUILD_HOST_SHARED_LIBRARY)
#compiler for host
include $(CLEAR_VARS)
LOCAL_MODULE := stub/libgraph
LOCAL_CFLAGS += -DFMK_SUPPORT_DUMP -O2
LOCAL_CPPFLAGS += -fexceptions
LOCAL_C_INCLUDES := $(COMMON_LOCAL_C_INCLUDES)
LOCAL_SRC_FILES := \
../../out/atc/lib64/stub/graph.cc \
../../out/atc/lib64/stub/operator.cc \
../../out/atc/lib64/stub/tensor.cc \
../../out/atc/lib64/stub/operator_factory.cc \
LOCAL_SHARED_LIBRARIES :=
LOCAL_LDFLAGS := -lrt -ldl
LOCAL_MULTILIB := 64
LOCAL_PROPRIETARY_MODULE := true
include $(BUILD_HOST_SHARED_LIBRARY)
#compiler for device
include $(CLEAR_VARS)
@ -111,6 +134,32 @@ LOCAL_PROPRIETARY_MODULE := true
include $(BUILD_SHARED_LIBRARY)
#compiler for device
include $(CLEAR_VARS)
LOCAL_MODULE := stub/libgraph
LOCAL_CFLAGS += -O2
LOCAL_C_INCLUDES := $(COMMON_LOCAL_C_INCLUDES)
LOCAL_SRC_FILES := \
../../out/atc/lib64/stub/graph.cc \
../../out/atc/lib64/stub/operator.cc \
../../out/atc/lib64/stub/tensor.cc \
../../out/atc/lib64/stub/operator_factory.cc \
LOCAL_SHARED_LIBRARIES :=
LOCAL_LDFLAGS := -lrt -ldl
ifeq ($(device_os),android)
LOCAL_LDFLAGS := -ldl
endif
LOCAL_MULTILIB := 64
LOCAL_PROPRIETARY_MODULE := true
include $(BUILD_SHARED_LIBRARY)
# compile for ut/st
include $(CLEAR_VARS)

@ -759,6 +759,7 @@ graphStatus Node::Verify() const {
GELOGW("Verify UpdateOutputName failed");
}
}
node_op.BreakConnect();
}
if (op_->CommonVerify() == GRAPH_SUCCESS) {

@ -818,7 +818,9 @@ graphStatus OpDesc::InferShapeAndType() {
}
}
Operator op_proxy = ge::OpDescUtils::CreateOperatorFromOpDesc(shared_from_this());
return (graphStatus)infer_func_(op_proxy);
graphStatus ret = (graphStatus)infer_func_(op_proxy);
op_proxy.BreakConnect();
return ret;
}
graphStatus OpDesc::DefaultInferFormat() {
@ -863,12 +865,14 @@ graphStatus OpDesc::DefaultInferFormat() {
}
graphStatus OpDesc::OpVerify() {
Operator op_proxy = ge::OpDescUtils::CreateOperatorFromOpDesc(shared_from_this());
if (verifier_func_ == nullptr) {
verifier_func_ = OperatorFactoryImpl::GetVerifyFunc(GetType());
}
if (verifier_func_ != nullptr) {
return (graphStatus)verifier_func_(op_proxy);
Operator op_proxy = ge::OpDescUtils::CreateOperatorFromOpDesc(shared_from_this());
graphStatus ret = (graphStatus)verifier_func_(op_proxy);
op_proxy.BreakConnect();
return ret;
}
return GRAPH_SUCCESS;
}

@ -21,7 +21,7 @@
#include <mutex>
#include <queue>
#include <set>
#include "array_ops.h"
#include "./array_ops.h"
#include "debug/ge_log.h"
#include "debug/ge_op_types.h"
#include "debug/ge_util.h"
@ -931,7 +931,7 @@ OperatorImplPtr Operator::GetOperatorImplPtr() const { return operator_impl_; }
void Operator::BreakConnect() const {
if (operator_impl_ == nullptr) {
GELOGE(GRAPH_FAILED, "operator impl is nullptr.");
GELOGW("operator impl is nullptr.");
return;
}
operator_impl_->ClearInputLinks();
@ -1318,6 +1318,8 @@ class GraphBuilderImpl {
string type = src_op_impl->op_desc_->GetType();
auto node_op = ge::OperatorFactory::CreateOperator("node_op", type);
auto tensor_desc = ge::OpDescUtils::GetOpDescFromOperator(node_op);
node_op.BreakConnect();
GE_CHK_BOOL_EXEC(tensor_desc != nullptr, continue, "tensor_desc is null.");
if ((tensor_desc->GetInputsSize() == 0 && tensor_desc->GetOutputsSize() > 0) || type == DATA ||
type == VARIABLE || type == INITDATA || type == GETNEXT) {
@ -1542,6 +1544,7 @@ void GraphUtils::BreakConnect(const std::map<OperatorImplPtr, NodePtr> &all_node
}
op_impl->ClearOutputLinks();
op_impl->ClearInputLinks();
OperatorKeeper::GetInstance().CheckOutOperator(op_impl);
}
}
} // namespace ge

@ -235,6 +235,7 @@ graphStatus ShapeRefiner::InferShapeAndType(const ConstNodePtr &node, Operator &
GELOGD("get op from OperatorFactory success. opType: %s", op_type.c_str());
auto temp_op_desc = ge::OpDescUtils::GetOpDescFromOperator(node_op);
node_op.BreakConnect();
if (temp_op_desc == nullptr) {
GELOGE(GRAPH_FAILED, "temp op desc is null");
return GRAPH_FAILED;
@ -328,6 +329,9 @@ InferenceContextPtr CreateInferenceContext(const std::unordered_map<NodePtr, Inf
namespace {
std::unordered_map<NodePtr, InferenceContextPtr> context_map;
}
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY void ShapeRefiner::ClearContextMap() { context_map.clear(); }
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY graphStatus ShapeRefiner::InferShapeAndType(const NodePtr &node) {
return InferShapeAndType(node, true);
}

@ -0,0 +1,6 @@
inc_path := $(shell pwd)/inc/external/
out_path := $(shell pwd)/out/atc/lib64/stub/
stub_path := $(shell pwd)/common/graph/stub/
mkdir_stub := $(shell mkdir -p $(out_path))
graph_local_stub := $(shell $(HI_PYTHON) $(stub_path)/gen_stubapi.py $(inc_path) $(out_path))

File diff suppressed because it is too large Load Diff

@ -187,14 +187,11 @@ void TBEPluginManager::LoadCustomOpLib() {
std::vector<OpRegistrationData> registration_datas = domi::OpRegistry::Instance()->registrationDatas;
GELOGI("The size of registration_datas is: %zu", registration_datas.size());
for (OpRegistrationData reg_data : registration_datas) {
bool ret = CheckRegisterStatus(reg_data);
if (ret) {
GELOGD("Begin to register optype: %s, imply_type: %u", reg_data.GetOmOptype().c_str(),
static_cast<uint32_t>(reg_data.GetImplyType()));
domi::OpRegistry::Instance()->Register(reg_data);
}
}
}
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY void TBEPluginManager::LoadPluginSo() {
vector<string> file_list;
@ -230,31 +227,6 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY void TBEPluginManager::LoadPlug
}
}
bool TBEPluginManager::CheckRegisterStatus(const OpRegistrationData &reg_data) {
bool ret = true;
static char *parser_priority = std::getenv("PARSER_PRIORITY");
static bool keep_cce = parser_priority != nullptr && string(parser_priority) == "cce";
auto ori_optype_set = reg_data.GetOriginOpTypeSet();
for (const auto &op_type : ori_optype_set) {
domi::ImplyType imply_type = domi::OpRegistry::Instance()->GetImplyTypeByOriOpType(op_type);
GELOGD("Enter into reg_data loop. op_type = %s , om_optype_ = %s", op_type.c_str(), reg_data.GetOmOptype().c_str());
if (imply_type != domi::ImplyType::BUILDIN) {
if ((keep_cce && reg_data.GetImplyType() != domi::ImplyType::CCE) ||
(!keep_cce && reg_data.GetImplyType() != domi::ImplyType::TVM)) {
GELOGD("op_type[%s] does not need to be changed, om_optype:%s.", op_type.c_str(),
reg_data.GetOmOptype().c_str());
ret = false;
} else {
GELOGI("op_type[%s] will be changed to om_optype:%s.", op_type.c_str(), reg_data.GetOmOptype().c_str());
}
} else {
GELOGD("First register in ge initialize, original type: %s, om_optype: %s, imply type: %d.", op_type.c_str(),
reg_data.GetOmOptype().c_str(), static_cast<int>(reg_data.GetImplyType()));
}
}
return ret;
}
Status TBEPluginManager::CheckCustomAiCpuOpLib() {
std::vector<std::string> vec_op_type;

@ -63,7 +63,6 @@ class TBEPluginManager {
static void GetCustomOpPath(std::string &customop_path);
void LoadCustomOpLib();
static Status CheckCustomAiCpuOpLib();
static bool CheckRegisterStatus(const OpRegistrationData &reg_data);
SoHandlesVec handles_vec_;
static std::map<string, string> options_;

@ -184,7 +184,8 @@ ModelHelper::SaveOriginalGraphToOmModel(const ge::Graph &graph, const std::strin
// Model
ModelPtr model_ptr = ge::MakeShared<ge::Model>();
GE_CHECK_NOTNULL_EXEC(model_ptr, return MEMALLOC_FAILED);
model_ptr->SetName(compute_graph->GetName());
std::string original_model_name = compute_graph->GetName() + "_original";
model_ptr->SetName(original_model_name);
model_ptr->SetGraph(graph);
model_ptr->SetVersion(static_cast<uint32_t>(OM_PROTO_VERSION));
string framework_version;
@ -504,4 +505,36 @@ Status ModelHelper::ReleaseLocalModelData() noexcept {
}
return result;
}
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY Status ModelHelper::GetBaseNameFromFileName(const string &file_name,
string &base_name) {
GELOGD("Get base_name from file, file_name:%s", file_name.c_str());
GE_CHK_BOOL_EXEC_WARN(!file_name.empty(), return FAILED, "File path may not valid, check params --output");
size_t start_position = 0;
// using output as base_name (ignore ".om")
size_t filename_suffixes = 3;
if (file_name.find_last_of('/') != string::npos) {
start_position = file_name.find_last_of('/') + 1;
}
size_t end_position = file_name.length() - filename_suffixes;
base_name = file_name.substr(start_position, end_position - start_position);
GE_CHK_BOOL_EXEC_WARN(!base_name.empty(), return FAILED, "Get base_name failed, check params --output");
return SUCCESS;
}
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY Status
ModelHelper::GetModelNameFromMergedGraphName(const string &graph_name, string &model_name) {
GELOGD("Get model_name from graph_name, graph_name:%s", graph_name.c_str());
// this can only be used after merged graph(graph name will be append with "_x", x is index);
GE_CHK_BOOL_EXEC_WARN(!graph_name.empty(), return FAILED, "File path may not valid, check params --output");
size_t start_position = 0;
size_t end_position = graph_name.length();
// using graph as model_name (ignore "_x", x is the index of graph)
if (graph_name.find_last_of('_') != string::npos) {
end_position = graph_name.find_last_of('_');
}
model_name = graph_name.substr(start_position, end_position);
GE_CHK_BOOL_EXEC_WARN(!model_name.empty(), return FAILED, "Get model_name failed, check params --output");
return SUCCESS;
}
} // namespace ge

@ -15,7 +15,7 @@
*/
#include "common/model_parser/base.h"
#include "common/helper/model_helper.h"
#include <securec.h>
#include <sys/sysinfo.h>
#include <fstream>
@ -61,7 +61,8 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY Status ModelParserBase::LoadFro
// read data as a block:
(void)fs.read(data, len);
ModelHelper model_helper;
model_helper.GetBaseNameFromFileName(model_path, model_data.om_name);
// Set the model data parameter
model_data.model_data = data;
model_data.model_len = len;

@ -16,15 +16,12 @@
#include "common/profiling/profiling_manager.h"
#include <nlohmann/json.hpp>
#include "framework/common/debug/ge_log.h"
#include "framework/common/debug/log.h"
#include "framework/common/string_util.h"
#include "graph/ge_context.h"
#include "runtime/base.h"
using Json = nlohmann::json;
namespace {
const char *const kJobID = "jobID";
const char *const kDeviceID = "deviceID";
@ -35,6 +32,7 @@ const char *const kEvents = "events";
const char *const kAiCoreEvents = "ai_core_events";
const char *const kName = "name";
const char *const kTraceID = "traceId";
const char *const kProfDir = "resultPath";
const size_t kReportMaxLen = 2048;
} // namespace
@ -100,6 +98,10 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY ge::Status ProfilingManager::In
Json start_prof_conf = Json::parse(config);
Json &prof_conf = start_prof_conf[kStartCfg][0];
job_id_ = prof_conf[kJobID];
auto iter = prof_conf.find(kProfDir);
if (iter != prof_conf.end()) {
prof_dir_ = prof_conf[kProfDir];
}
Json &device_id = prof_conf[kDeviceID];
if (device_id.size() != 0) {
vector<int32_t>().swap(device_id_);
@ -126,23 +128,36 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY ge::Status ProfilingManager::In
}
}
GELOGI("Profiling json config from acl:%s", config.c_str());
Json &features = prof_conf[kFeatures];
if (ParseFeaturesFromAclCfg(features) != SUCCESS) {
GELOGE(FAILED, "Parse feature from acl cfg failed.");
return FAILED;
}
is_profiling_ = true;
} catch (...) {
GELOGE(FAILED, "Json conf is not invalid !");
return ge::PARAM_INVALID;
}
#endif
return ge::SUCCESS;
}
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY ge::Status ProfilingManager::ParseFeaturesFromAclCfg(
const Json &features) {
#ifdef DAVINCI_SUPPORT_PROFILING
try {
for (size_t i = 0; i < features.size(); ++i) {
Json &feature = features[i];
const Json &feature = features[i];
if ((feature.find(kName) == feature.end()) || feature[kName].is_null()) {
continue;
}
const std::string &name = feature[kName];
if (name == "op_trace") {
GELOGI("Op trace config from acl");
Json &conf = feature[kConf];
Json &events = conf[0][kEvents];
const Json &conf = feature[kConf];
const Json &events = conf[0][kEvents];
const std::string &ai_core_events = events[0][kAiCoreEvents];
GELOGI("Op trace config from acl ai_core_events:%s", ai_core_events.c_str());
is_op_trace_ = true;
// op trace get conf
ProfMgrConf prof_mgr_conf;
int result = ProfMgrGetConf(ai_core_events, &prof_mgr_conf);
if (result != 0) {
@ -154,10 +169,16 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY ge::Status ProfilingManager::In
GELOGI("Op trace profiling iter num %d,", op_trace_iter_num_);
} else if (name == "task_trace") {
is_op_trace_ = false;
if (feature.find(kConf) != feature.end()) {
const Json &conf = feature[kConf];
std::stringstream task_trace_conf;
task_trace_conf << conf;
task_trace_conf_ = task_trace_conf.str();
}
GELOGI("Task trace config from acl");
} else if (name == "system_trace") {
is_op_trace_ = false;
Json &conf = feature[kConf];
const Json &conf = feature[kConf];
std::stringstream system_trace_conf;
system_trace_conf << conf;
system_trace_conf_ = system_trace_conf.str();
@ -165,10 +186,8 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY ge::Status ProfilingManager::In
}
profiling_opts_.push_back(name);
}
is_profiling_ = true;
} catch (...) {
GELOGE(FAILED, "Json conf is not invalid !");
GELOGE(ge::PARAM_INVALID, "Json conf feature is not invalid !");
return ge::PARAM_INVALID;
}
#endif
@ -235,6 +254,10 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY ge::Status ProfilingManager::St
p_device[kDeviceID] = std::to_string(device_id);
p_device[kJobID] = job_id_;
p_device[kTraceID] = std::to_string(GetContext().TraceId());
if (!prof_dir_.empty()) {
p_device[kProfDir] = prof_dir_;
GELOGI("Prof dir: %s.", prof_dir_.c_str());
}
Json features;
if (is_op_trace_) {
@ -258,6 +281,10 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY ge::Status ProfilingManager::St
Json f;
if (profiling_opts_[i] == "system_trace") {
f[kConf] = nlohmann::json::parse(system_trace_conf_);
} else if (profiling_opts_[i] == "task_trace") {
if (!task_trace_conf_.empty()) {
f[kConf] = nlohmann::json::parse(task_trace_conf_);
}
}
f[kName] = profiling_opts_[i];
features[i] = f;
@ -292,6 +319,7 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY ge::Status ProfilingManager::St
GELOGW("ProfMgrStartUp failed.");
return FAILED;
}
GELOGD("StartProfiling, prof_handle: %p", prof_handle);
prof_handle_vec_.push_back(prof_handle);
}
#endif
@ -314,8 +342,7 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY void ProfilingManager::StopProf
for (size_t i = 0; i < prof_handle_vec_.size(); ++i) {
int result = ProfMgrStop(prof_handle_vec_[i]);
if (result != 0) {
GELOGW("ProfMgr stop return fail:%d.", result);
return;
GELOGW("ProfMgr stop return fail:%d, handle:%p", result, prof_handle_vec_[i]);
}
}
vector<void *>().swap(prof_handle_vec_);

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

Loading…
Cancel
Save