跳到主要内容

函数:create_kernel

函数:register_compile_func

C函数原型aclError aclopRegisterCompileFunc(const char *opType, aclopCompileFunc func)
Python函数ret = acl.op.register_compile_func(op_type, func)
函数功能动态Shape场景下,注册算子选择器,用于在算子执行时,能针对不同shape,选择相应的Tiling策略。 如果某算子已注册算子选择器,则不允许重新注册,如果需要变更算子选择器,必须先调用acl.op.unregister_compile_func接口取消注册,然后再调用acl.op.register_compile_func接口重新注册。
输入说明op_type:str,算子类型。 func:python函数对象,算子选择器回调函数,函数定义: Python侧格式如下:
python<br>def call_back_func(num_inputs, input_desc, num_outputs, output_desc, op_attr, aclop_kernel_desc):<br>pass<br>
返回值说明ret:int,错误码。
- 返回0表示成功。
- 返回其它值表示失败。
约束说明

父主题: 算子编译

函数:unregister_compile_func

C函数原型aclError aclopUnregisterCompileFunc**(const char *opType)**
Python函数ret = acl.op.unregister_compile_func(op_type)
函数功能动态Shape场景下,取消注册算子选择器。
输入说明op_type:str,算子类型。
返回值说明ret:int,错误码。
- 返回0表示成功。
- 返回其它值表示失败。
约束说明

父主题: 算子编译

函数:create_kernel

C函数原型aclError aclopCreateKernel(const char *opType, const char *kernelId, const char *kernelName, void *binData, int binSize, aclopEngineType enginetype, aclDataDeallocator deallocator)
Python函数ret = acl.op.create_kernel(op_type, kernel_id, kernel_name, bin_data, bin_size, enginetype, deallocator)
函数功能动态Shape场景下,将算子注册到系统内部,运行算子时使用。
输入说明op_type:str,算子类型。 kernel_id:str,算子执行时要指定的Kernel ID。 kernel_name:str,算子Kernel名称,和算子二进制文件中的kernelName保持一致。 bin_data:int,算子Kernel文件的内存地址。 bin_size:int,算子Kernel文件的内存大小,单位为byte。 enginetype:int,表示算子执行引擎,该参数只有acl.op.update.params接口的compile_flag参数值为ACL_COMPILE_SYS时有效。
- 0:ACL_ENGINE_SYS,不关心具体执行引擎时填写。
- 1:ACL_ENGINE_AICORE,将算子编译成AI Core算子。
- 2:ACL_ENGINE_VECTOR,将算子编译成Vector Core算子。
**deallocator:**int,指定是否自动释放bin_data内存。
- 0:不自动释放,数据由调用者自行编写代码进行释放。
- 1:自动释放,内部会设置回调函数释放bin_data内存。
返回值说明ret:int,错误码。
- 返回0表示成功。
- 返回其它值表示失败。
约束说明

父主题: 算子编译

函数:set_kernel_args

C函数原型aclError aclopSetKernelArgs(aclopKernelDesc *kernelDesc, const char *kernelId, uint32_t blockDim, const void *args, uint32_t argSize)
Python函数ret = acl.op.set_kernel_args(kernel_desc, kernel_id, block_dim, args, arg_size)
函数功能动态Shape场景下,设置算子Tiling参数、执行并发数。
输入说明kernel_desc:int,Kernel描述缓存,aclopKernelDesc类型的指针地址。 kernel_id:str,算子执行时要指定的Kernel ID,与调用acl.op.create.kernel时传递的kernel_id一致。 **block_dim:**int,Kernel执行的并发数。 bin_data:int,算子Kernel文件的内存地址。 bin_size:int,算子Kernel文件的内存大小,单位为byte。 **args:**int,Tiling参数,需要通过numpy数组tobytes方法获取bytes对象,然后使用acl.utils.bytes_to_ptr()接口获取Tiling参数指针地址。 arg_size:int,Tiling参数内存大小,单位为Byte,为numpy.tobytes()转换得到bytes的对象长度,可用len函数获取。
返回值说明ret:int,错误码。
- 返回0表示成功。
- 返回其它值表示失败。
约束说明

父主题: 算子编译

函数:set_kernel_workspace_sizes

C函数原型aclError aclopSetKernelWorkspaceSizes(aclopKernelDesc *kernelDesc, int numWorkspaces, size_t *workspaceSizes)
Python函数ret = acl.op.set_kernel_workspace_sizes(kernel_desc, num_workspaces, workspace_sizes)
函数功能动态Shape场景下,设置算子Workspace参数。
输入说明kernel_desc:int,Kernel描述缓存,aclopKernelDesc类型的指针地址。 num_workspaces:int,Workspaces个数。 **workspace_sizes:**int,Workspaces大小的数组地址。
返回值说明ret:int,错误码。
- 返回0表示成功。
- 返回其它值表示失败。
约束说明为非必须接口,根据算子情况可选。

父主题: 算子编译

函数:update_params

C函数原型aclError aclopUpdateParams(const char *opType, int numInputs, const aclTensorDesc *const inputDesc[], int numOutputs, const aclTensorDesc *const outputDesc[], const aclopAttr *attr**)**
Python函数ret = acl.op.update_params(op_type, input_desc, output_desc, attr)
函数功能动态Shape场景下,设置算子Tiling参数、执行并发数。
输入说明op_type:str,算子类型名称。 input_desc:list,算子输入tensor的描述。 output_desc:list,算子输出tensor的描述。 attr:int,算子属性。
返回值说明ret:int,错误码。
- 返回0表示成功。
- 返回其它值表示失败。
约束说明

父主题: 算子编译

在线提单