昇腾社区首页
中文
注册

Profiling性能数据采集

用户可以在图加载和图执行过程中,采集Profiling性能数据,用于性能分析,本节给出详细的采集方法。

功能介绍

采集Profiling性能数据有两种方式,如下表所示。

表1 Profiling性能数据采集方式

序号

采集方式

方式一

通过GEInitialize传入option参数:
  • ge.exec.profilingMode
  • ge.exec.profilingOptions

方式二

如果需要采集迭代轨迹数据,还需要通过GEInitialize传入option参数ge.exec.profilingOptions。传入字段包括training_trace/bp_point/fp_point。

支持的型号

Atlas 推理系列产品

Atlas 训练系列产品

Atlas A2训练系列产品/Atlas 800I A2推理产品

采集前配置

进行Profiling采集前,需要从完整样例参考中获取构建Graph并直接编译运行Graph样例后,进行如下操作:

  1. 在源码文件“main.cpp”开头添加“#include "ge/ge_prof.h"”代码。
  2. 在编译脚本“Makefile”内的“LIBS”行下添加“-lmsprofiler”字段或在“CMakeLists.txt”内的“target_link_libraries”行下添加“msprofiler”字段。
表2 头文件列表

定义接口的头文件

用途

对应的库文件

ge/ge_prof.h

用于定义Profiling配置的接口。

libmsprofiler.so

说明:

ge头文件在“CANN软件安装后文件存储路径/include/”目录下,ge库文件在“CANN软件安装后文件存储路径/lib64/”目录下。

通过方式二采集性能数据

该特性为全局特性,不是session级特性,使能后在所有session均配置生效。

建议的接口调用顺序为:

调用示例为:
 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
  // 构造Graph,该步骤省略
  // ......

  // 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";       //该路径需要提前创建
  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();