跳到主要内容

aclrtAllocatorSetAllocAdviseFuncToDesc

aclrtAllocatorDestroyDesc​

函数功能​

销毁通过aclrtAllocatorCreateDesc接口创建的aclrtAllocatorDesc类型的数据。同步接口。

原型​

aclErroraclrtAllocatorDestroyDesc(aclrtAllocatorDesc allocatorDesc)

参数说明​

参数名输入/输出说明
allocatorDesc输入待销毁的aclrtAllocatorDesc类型的数据。

返回值说明​

返回0表示成功,返回其它值表示失败。

父主题: aclrtAllocatorDesc

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

在线提单