文档
注册

Profiling AscendCL API for Extension(Profiling AscendCL API扩展接口)

为了获取用户和上层框架程序的性能数据,Profiling开启msproftx功能之前,需要在程序内调用msproftx相关接口(Profiling AscendCL API扩展接口)来对用户程序进行打点以输出对应的性能数据。调用接口如Profiling AscendCL API扩展接口所示,调用示例如Profiling AscendCL API扩展接口调用示例所示。

Profiling AscendCL API扩展接口

表1 Profiling AscendCL API扩展接口

接口

说明

aclprofCreateStamp

创建msproftx事件标记,用于描述瞬时事件。

aclprofSetStampTraceMessage

为msproftx事件标记携带描述信息,在Profiling解析结果中msprof_tx summary数据展示。

aclprofMark

msproftx标记瞬时事件。

aclprofPush

msproftx用于记录事件发生的时间跨度的开始时间。与aclprofPop成对使用,仅能在单线程内使用。

aclprofPop

msproftx用于记录事件发生的时间跨度的结束时间。与aclprofPush成对使用,仅能在单线程内使用。

aclprofRangeStart

msproftx用于记录事件发生的时间跨度的开始时间。与aclprofRangeStop成对使用,可跨线程使用。

aclprofRangeStop

msproftx用于记录事件发生的时间跨度的结束时间。与aclprofRangeStart成对使用,可跨线程使用。

aclprofDestroyStamp

释放msproftx事件标记。

Profiling AscendCL API扩展接口调用示例

Profiling msproftx接口,示例如下加粗部分代码。

示例一(aclprofMark示例):
 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
40
41
42
43
44
45
46
47
48
49
50
//1.AscendCL初始化

//2.申请运行管理资源,包括设置用于计算的Device、创建Context、创建Stream
stamp = aclprofCreateStamp();
aclprofSetStampTraceMessage(stamp, "aclrtCreateStream_mark", strlen("AscendCL_Init_Mark"));
aclprofMark(stamp);    //标记Create Stream事件
aclprofDestroyStamp(stamp);
ret = aclrtCreateStream(&stream_);

//3..Profiling初始化
//设置数据落盘路径
const char *aclProfPath = "...";
aclprofInit(aclProfPath, strlen(aclProfPath));

//4.进行Profiling配置
uint32_t deviceIdList[1] = {0};
//创建配置结构体
aclprofConfig *config = aclprofCreateConfig(deviceIdList, 1, ACL_AICORE_ARITHMETIC_UTILIZATION, 
    nullptr,ACL_PROF_ACL_API | ACL_PROF_TASK_TIME);
aclprofStart(config);

aclprofStepInfo *stepInfo = aclprofCreateStepInfo();
int ret = aclprofGetStepTimestamp(stepInfo, ACL_STEP_START, stream_);

//5.模型加载,加载成功后,返回标识模型的modelId
stamp = aclprofCreateStamp();
aclprofSetStampTraceMessage(stamp, "model_load_mark", strlen("model_load_mark"));
aclprofMark(stamp);      //标记模型加载事件
aclprofDestroyStamp(stamp);

//6.创建aclmdlDataset类型的数据,用于描述模型的输入数据input、输出数据output

//7.执行模型
ret = aclmdlExecute(modelId, input, output);

//8.处理模型推理结果

//9.释放描述模型输入/输出信息、内存等资源,卸载模型
int ret = aclprofGetStepTimestamp(stepInfo, ACL_STEP_END, stream_);
aclprofDestroyStepInfo(stepInfo);

//10.关闭Profiling配置, 释放配置资源, 释放Profiling组件资源
aclprofStop(config);
aclprofDestroyConfig(config);
aclprofFinalize();

//11.释放运行管理资源

//12. AscendCL去初始化
//......
示例二(aclprofPush/aclprofPop示例,适用于单线程):
 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
40
41
42
43
44
45
46
47
//1.AscendCL初始化

//2.申请运行管理资源,包括设置用于计算的Device、创建Context、创建Stream
ret = aclrtCreateStream(&stream_);

//3..Profiling初始化
//设置数据落盘路径
const char *aclProfPath = "...";
aclprofInit(aclProfPath, strlen(aclProfPath));

//4.进行Profiling配置
uint32_t deviceIdList[1] = {0};
//创建配置结构体
aclprofConfig *config = aclprofCreateConfig(deviceIdList, 1, ACL_AICORE_ARITHMETIC_UTILIZATION, 
    nullptr,ACL_PROF_ACL_API | ACL_PROF_TASK_TIME);
aclprofStart(config);

aclprofStepInfo *stepInfo = aclprofCreateStepInfo();
int ret = aclprofGetStepTimestamp(stepInfo, ACL_STEP_START, stream_);

//5.模型加载,加载成功后,返回标识模型的modelId

//6.创建aclmdlDataset类型的数据,用于描述模型的输入数据input、输出数据output

//7.执行模型(模型仅在单线程执行)
stamp = aclprofCreateStamp();
aclprofSetStampTraceMessage(stamp, "aclmdlExecute_duration", strlen("aclmdlExecute_duration"));
aclprofPush(stamp);
ret = aclmdlExecute(modelId, input, output);
aclprofPop(stamp);
aclprofDestroyStamp(stamp);

//8.处理模型推理结果

//9.释放描述模型输入/输出信息、内存等资源,卸载模型
int ret = aclprofGetStepTimestamp(stepInfo, ACL_STEP_END, stream_);
aclprofDestroyStepInfo(stepInfo);

//10.关闭Profiling配置, 释放配置资源, 释放Profiling组件资源
aclprofStop(config);
aclprofDestroyConfig(config);
aclprofFinalize();

//11.释放运行管理资源

//12. AscendCL去初始化
//......
示例三(aclprofRangeStart/aclprofRangeStop示例,适用于单线程或跨线程):
 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
40
41
42
43
44
45
46
47
//1.AscendCL初始化

//2.申请运行管理资源,包括设置用于计算的Device、创建Context、创建Stream
ret = aclrtCreateStream(&stream_);

//3..Profiling初始化
//设置数据落盘路径
const char *aclProfPath = "...";
aclprofInit(aclProfPath, strlen(aclProfPath));

//4.进行Profiling配置
uint32_t deviceIdList[1] = {0};
//创建配置结构体
aclprofConfig *config = aclprofCreateConfig(deviceIdList, 1, ACL_AICORE_ARITHMETIC_UTILIZATION, 
    nullptr,ACL_PROF_ACL_API | ACL_PROF_TASK_TIME);
aclprofStart(config);

aclprofStepInfo *stepInfo = aclprofCreateStepInfo();
int ret = aclprofGetStepTimestamp(stepInfo, ACL_STEP_START, stream_);

//5.模型加载,加载成功后,返回标识模型的modelId

//6.创建aclmdlDataset类型的数据,用于描述模型的输入数据input、输出数据output

//7.执行模型(模型在跨线程执行)
stamp = aclprofCreateStamp();
aclprofSetStampTraceMessage(stamp, "aclmdlExecute_duration", strlen("aclmdlExecute_duration"));
aclprofRangeStart(stamp, &rangeId);
ret = aclmdlExecute(modelId, input, output);
aclprofRangeStop(rangeId);
aclprofDestroyStamp(stamp);

//8.处理模型推理结果

//9.释放描述模型输入/输出信息、内存等资源,卸载模型
int ret = aclprofGetStepTimestamp(stepInfo, ACL_STEP_END, stream_);
aclprofDestroyStepInfo(stepInfo);

//10.关闭Profiling配置, 释放配置资源, 释放Profiling组件资源
aclprofStop(config);
aclprofDestroyConfig(config);
aclprofFinalize();

//11.释放运行管理资源

//12. AscendCL去初始化
//......

Profiling AscendCL API扩展接口在main函数内调用。

搜索结果
找到“0”个结果

当前产品无相关内容

未找到相关内容,请尝试其他搜索词