Using Ascend Graph APIs for Data Profiling

Ascend Graph APIs are used to collect profile data during graph construction.

The --task-trace option will be discarded in later versions. Use --task-time instead.

Applicability

Atlas inference product

Atlas training product

Atlas A2 training product/Atlas A2 inference product

Atlas A3 training product/Atlas A3 inference product

Atlas 350 Accelerator Card

Enabling Modes

Table 1 Profile data collection modes

Method

API

Pass options through the GEInitialize API.

  • ge.exec.profilingMode
  • ge.exec.profilingOptions

You can pass ge.exec.profilingOptions through the GEInitialize API to profile iteration trace data. The passed fields include training_trace, bp_point, and fp_point.

This method saves profile data to the path set in the output parameter of ge.exec.profilingOptions.

aclgrph APIs

  • aclgrphProfInit
  • aclgrphProfFinalize
  • aclgrphProfCreateConfig
  • aclgrphProfDestroyConfig
  • aclgrphProfStart
  • aclgrphProfStop

This method saves profile data to the path set in the profiler_path parameter of aclgrphProfInit.

For details about the APIs, see Graph Development.

Raw Performance Data Profiling (Passing Options Through the GEInitialize API)

The following is an example of using GEInitialize to pass required option arguments:

// 0. System init
std::map<AscendString, AscendString> config = {{"ge.exec.deviceId", "0"},
                        {"ge.graphRunMode", "1"},
                        {"ge.exec.precision_mode", "allow_fp32_to_fp16"},
                        {"ge.exec.profilingMode", "1"},
                        {"ge.exec.profilingOptions",  R"({"output":"/tmp/profiling","training_trace":"on","fp_point":"","bp_point":""})"}};
    Status ret = ge::GEInitialize(config);
    if (ret != SUCCESS) {
        return FAILED;
    }

Raw Performance Data Profiling (aclgrph APIs)

This following is an example of calling APIs to collect profile data:

  // Construct a graph. The details are omitted here.
  // ......

  // init ge
  std::map<std::string, std::string> ge_options = {{"ge.socVersion", "Ascendxxx"}, {"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::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;
  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_r, outputs_r);

  ge::aclgrphProfStop(pro_config);

  ge::aclgrphProfDestroyConfig(pro_config);

  ge::aclgrphProfFinalize();

  delete session;
  ge::GEFinalize();

Profiling Description

After the Ascend Graph API method is configured for data collection, parse the raw data and export the parsing results as visualized timeline and summary files. For details, see Using the msprof Command to Parse, Query, and Export the Profile Data.