compile

Function

Compiles the kernel delivery code and returns an executable kernel object.

Function Prototype

kernel = compile(build_script, gen_file)

Parameters

Parameter

Input/Output

Description

build_script

Input

Script for compiling the kernel in the template library.

Data type: str.

This parameter is required.

gen_file

Input

Path of the kernel delivery code file generated by the code_gen API. Generally, the return value of the code_gen API is used.

Data type: str.

This parameter is required.

output_bin_path

Input

Path of the executable file generated after compilation.

Data type: str.

This parameter is optional. The default value is _gen_module.so.

use_cache

Input

After this parameter is enabled, no compilation is performed but the file specified by output_bin_path is loaded.

Data type: bool.

This parameter is optional. The default value is False.

Return Value

Kernel object that can be run. The type is CompiledKernel. The kernel can be called in the following mode: kernel[blockdim](arg1, arg2, ..., timeout=-1, device_id=0, repeat=1), where arg1, arg2, ... are input parameters of the kernel.

Example

kernel = compile(build_script, gen_file)
kernel[blockdim](arg1, arg2, ..., device_id=0)
Table 1 Optional input parameters of CompiledKernel

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.