mskpp.get_kernel_from_binary

Function

Generates an instance that can call the user kernel function.

Function Prototype

def get_kernel_from_binary(kernel_binary_file: str, kernel_type: str = None, tiling_key: int = None) -> CompiledKernel

Parameters

Parameter

Input/Output

Description

kernel_binary_file

Input

Path of the operator kernel.o. You can run the find. -name '*.o' command in the project directory to search for the path.

Data type: str.

This parameter is required.

kernel_type

Input

Operator type. The value can be vec, cube, or mix.

If this parameter is not set, the msKPP may fail to obtain the data. Therefore, you are advised to manually assign a value.

Data type: str.

This parameter is optional.

tiling_key

Input

tiling_key used when the user kernel function is called. If this parameter is not set, the msKPP uses the latest mskpp.tiling_func calling result.

Data type: int.

This parameter is optional.

Return Value

Executable kernel object.

Table 1 Kernel input parameters

Parameter

Input/Output

Description

device_id

Input

Sets the NPU device ID, that is, the ID of Ascend AI Processor that runs ST cases.

Data type: int.

If this option is not specified, the default value 0 is used.

timeout

Input

In the CAModel simulation scenario, a long timeout period needs to be set by default. The value -1 indicates that the timeout period is not limited.

Data type: int.

The unit is ms. The default value is 300000.

repeat

Input

Number of repeated running times. The default value is 1.

Data type: int.

stream

Input

Reserved.

kernel_name

Input

Reserved.

The kernel object type is CompiledKernel. The kernel can be called in the following mode: kernel[blockdim](arg1, arg2, ..., timeout=-1, device_id=0, repeat=1). During actual calling, ensure that the input parameters of the CompiledKernel function are the same as those when the kernel is called.

Example

  • Example 1:
    def run_kernel(input_a, input_b, input_bias, output, workspace, tiling_data):
        kernel_binary_file = "MatmulLeakyreluCustom.o"   # The .o file name varies depending on the hardware and operating system.
        kernel = mskpp.get_kernel_from_binary(kernel_binary_file)
        return kernel(input_a, input_b, input_bias, output, workspace, tiling_data)
  • Example 2:
    def run_kernel(input_a, input_b, input_bias, output, workspace, tiling_data, tiling_key, blockdim):
        kernel_binary_file = "MatmulLeakyreluCustom.o"   # The .o file name varies depending on the hardware and operating system.
        kernel = mskpp.get_kernel_from_binary(kernel_binary_file, kernel_type='mix', tiling_key=tiling_key)
        return kernel[blockdim](input_a, input_b, input_bias, output, workspace, tiling_data, device_id=1, timeout=-1) # During simulation running, you need to manually set the timeout to -1.