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.

Table 1 Profile data collection modes

No.

Collection Mode

Mode 1

Pass the options arguments to the GEInitialize call:
  • ge.exec.profilingMode
  • ge.exec.profilingOptions

Mode 2

To enable iteration tracing, pass the ge.exec.profilingOptions arguments to the GEInitialize call. The required fields include training_trace, bp_point, and fp_point.

Applicability

Atlas Training Series Product

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:

  1. Add #include "ge/ge_prof.h" at the beginning of the source code file main.cpp.
  2. 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.
Table 2 Header files

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.

A call example is as follows.
 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();