Profile Data Collection
You can collect profile data for performance analysis during graph loading and running. This section describes how to collect profile data.
Overview
Profile data can be collected in two modes, as described in the following table.
Applicability
Configuration Before Profiling
Before profiling, obtain the sample by referring to the description in Sample Reference, build and run the graph sample, and then perform the following operations:
- Add #include "ge/ge_prof.h" at the beginning of the source code file main.cpp.
- Add the -lmsprofiler field under the LIBS line in the Makefile build script. Alternatively, add the msprofiler field under the target_link_libraries line in the CMakeLists.txt file.
|
Header File |
Function |
Matching Library File |
|---|---|---|
|
ge/ge_prof.h |
Defines the Profiling configuration APIs. |
libmsprofiler.so
NOTE:
The GE header files are stored in the {CANN software installation directory}/include/ directory, and the GE library files are stored in the {CANN software installation directory}/lib64/ directory. |
Collecting Profile Data Using Mode 2
This feature is a global feature rather than a session-level feature. The configuration takes effect on all sessions.
Call the APIs in the following sequence.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
// Construct a graph. The details are omitted here. // ...... // init ge std::map<std::string, std::string> ge_options = {{"ge.socVersion", "xxx"}, {"ge.graphRunMode", "1"}}; ge::GEInitialize(ge_options); std::string profilerResultPath = "/home/test/prof"; // Create the path in advance. uint32_t length = strlen("/home/test/prof"); ret = ge::aclgrphProfInit(profilerResultPath.c_str(), length); std::map<string, string> options = {{"a", "b"}, {"c", "d"}}; uint32_t graphId = 0; ge::Graph graph; ge::Session *session = new Session(options); ret = session->AddGraph(graphId, graph); uint32_t deviceid_list[1] = {0}; uint32_t device_nums = 1; uint64_t data_type_config = ProfDataTypeConfig::kProfTaskTime | ProfDataTypeConfig::kProfAiCoreMetrics | ProfDataTypeConfig::kProfAicpu | ProfDataTypeConfig::kProfTrainingTrace | ProfDataTypeConfig::kProfHccl | ProfDataTypeConfig:: kProfL2cache; std::vector<ge::Tensor> inputs; std::vector<ge::Tensor> outputs; ProfAicoreEvents *aicore_events = NULL; ProfilingAicoreMetrics aicore_metrics = ProfilingAicoreMetrics::kAicoreArithmeticUtilization; ge::aclgrphProfConfig *pro_config = ge::aclgrphProfCreateConfig(deviceid_list, device_nums, aicore_metrics, aicore_events, data_type_config); ge::aclgrphProfStart(pro_config); session->RunGraph(graphId, inputs, outputs); ge::aclgrphProfStop(pro_config); ge::aclgrphProfDestroyConfig(pro_config); ge::aclgrphProfFinalize(); delete session; ge::GEFinalize(); |