aclrtAllocatorSetFreeFuncToDesc
aclrtAllocatorSetObjToDesc
函数功能
使用用户提供的Allocator场景下,向Allocator描述信息中设置Allocator对象。
函数原型
aclErroraclrtAllocatorSetObjToDesc(aclrtAllocatorDesc allocatorDesc, aclrtAllocator allocator)
参数说明
| 参数名 | 输入/输出 | 说明 |
|---|---|---|
| allocatorDesc | 输入 | Allocator描述符指针。 需提前调用aclrtAllocatorCreateDesc接口设置Allocator描述信息。 |
| allocator | 输入 | 用户提供的Allocator对象指针。 |
返回值说明
返回0表示成功,返回其它值表示失败。
父主题: aclrtAllocatorDesc
aclrtAllocatorSetAllocFuncToDesc
函数功能
使用用户提供的Allocator场景下,设置"申请内存block"的回调函数。
函数原型
aclError aclrtAllocatorSetAllocFuncToDesc(aclrtAllocatorDesc allocatorDesc, aclrtAllocatorAllocFunc func)
参数说明
| 参数名 | 输入/输出 | 说明 |
|---|---|---|
| allocatorDesc | 输入 | Allocator描述符指针。 需提前调用aclrtAllocatorCreateDesc接口设置Allocator描述信息。 |
| func | 输入 | 申请内存block的回调函数。 回调函数定义如下: text<br>typedef void *(*aclrtAllocatorAllocFunc)(aclrtAllocator allocator, size_t size);<br>aclrtAllocator的定义如下: text<br>typedef void *aclrtAllocator;<br> |
返回值说明
返回0表示成功,返回其它值表示失败。
父主题: aclrtAllocatorDesc
aclrtAllocatorSetAllocAdviseFuncToDesc
函数功能
使用用户提供的Allocator场景下,设置"根据建议地址申请内存block"的回调函数,一般用于内存复用场景。
函数原型
aclError aclrtAllocatorSetAllocAdviseFuncToDesc(aclrtAllocatorDesc allocatorDesc, aclrtAllocatorAllocAdviseFunc func)
参数说明
| 参数名 | 输入/输出 | 说明 |
|---|---|---|
| allocatorDesc | 输入 | Allocator描述符指针。 需提前调用aclrtAllocatorCreateDesc接口设置Allocator描述信息。 |
| func | 输入 | 根据建议地址申请内存block的回调函数。 回调函数定义如下: text<br>typedef void *(*aclrtAllocatorAllocAdviseFunc)(aclrtAllocator allocator, size_t size, aclrtAllocatorAddr addr);<br>aclrtAllocator、aclrtAllocatorAddr的定义如下: text<br>typedef void *aclrtAllocator;<br>typedef void *aclrtAllocatorAddr;<br> |
返回值说明
返回0表示成功,返回其它值表示失败。
父主题: aclrtAllocatorDesc
aclrtAllocatorSetFreeFuncToDesc
函数功能
使用用户提供的Allocator场景下,设置"释放内存block"的回调函数。
函数原型
aclError aclrtAllocatorSetFreeFuncToDesc(aclrtAllocatorDesc allocatorDesc, aclrtAllocatorFreeFunc func)
参数说明
| 参数名 | 输入/输出 | 说明 |
|---|---|---|
| allocatorDesc | 输入 | Allocator描述符指针。 需提前调用aclrtAllocatorCreateDesc接口设置Allocator描述信息。 |
| func | 输入 | 释放内存block的回调函数。 回调函数定义如下: text<br>typedef void (*aclrtAllocatorFreeFunc)(aclrtAllocator allocator, aclrtAllocatorBlock block);<br> aclrtAllocator、aclrtAllocatorBlock的定义如下: text<br>typedef void *aclrtAllocator;<br>typedef void *aclrtAllocatorBlock;<br> |
返回值说明
返回0表示成功,返回其它值表示失败。
父主题: aclrtAllocatorDesc
aclrtAllocatorSetGetAddrFromBlockFuncToDesc
函数功能
使用用户提供的Allocator场景下,设置"根据申请来的block获取device内存地址"的回调函数。
函数原型
aclError aclrtAllocatorSetGetAddrFromBlockFuncToDesc**(aclrtAllocatorDesc allocatorDesc, aclrtAllocatorGetAddrFromBlockFunc func)**
参数说明
| 参数名 | 输入/输出 | 说明 |
|---|---|---|
| allocatorDesc | 输入 | Allocator描述符指针。 需提前调用aclrtAllocatorCreateDesc接口设置Allocator描述信息。 |
| func | 输入 | 根据申请来的block获取device内存地址的回调函数。 回调函数定义如下: text<br>typedef void *(*aclrtAllocatorGetAddrFromBlockFunc)(aclrtAllocatorBlock block);<br>aclrtAllocatorBlock的定义如下: text<br>typedef void *aclrtAllocatorBlock;<br> |
返回值说明
返回0表示成功,返回其它值表示失败。
父主题: aclrtAllocatorDesc
内存未释放
现象描述
测试用例长稳运行时,出现内存泄漏的现象,内存占用持续上升。如图1所示。
图1 内存占用持续上升

可能原因
分析上述日志信息,可能存在以下故障原因:
系统存在只申请内存不释放内存的问题,正常情况下,内存申请与释放必须成对出现。
处理步骤
针对分析的故障可能原因,可以参考下面步骤处理:
排查所有的内存申请和释放的地方,保证申请与释放一一对应。例如aclrtMalloc与aclrtFree,aclrtMallocHost与aclrtFreeHost、aclrtCreateStream与aclrtDestroyStream等。
父主题: FAQ
Event数量超过上限导致aclrtRecordEvent接口返回失败
现象描述
调用aclrtRecordEvent接口在Stream中记录一个Event时,日志中的报错如下,红框中是关键日志信息,提示Event ID申请失败:

可能原因
分析上述日志信息,可能存在以下故障原因:Event ID的数量超过上限。
处理步骤
多Stream之间同步等待的场景下,Event ID的资源时可以复用的,复用Event ID的流程是:在调用aclrtRecordEvent接口+aclrtStreamWaitEvent接口后,若指定的Event已完成,则需要及时调用aclrtResetEvent接口释放Event资源。
需要用户按照复用Event ID的流程优化代码逻辑。
父主题: FAQ
在线提单