To support interleaved configuration of input and output parameters, normalized params configuration is provided. All input and output parameters are placed in the params option. The parameters in the operator JSON configuration file can be arranged in two modes: regular and interleaved. Ensure that the parameter order is the same as that of the kernel entrypoint function.
The debugging tool does not support this configuration.
Regular input/output arrangement (all output parameters are arranged after input parameters): For example, the parameters of the kernel entrypoint function are arranged as follows: extern "C" __global__ __aicore__ void add_custom(GM_ADDR input1, GM_ADDR input2, GM_ADDR input3, GM_ADDR output).
Interleaved input/output arrangement (input and output parameters are interleaved): For example, the parameters of the kernel entrypoint function are arranged as follows: extern "C" __global__ __aicore__ void add_custom(GM_ADDR input1, GM_ADDR input2, GM_ADDR output, GM_ADDR input3). The output parameter is arranged before input3.
This method is recommended for the kernel launch project.
The following uses the AddCustom operator as an example to describe the JSON configuration. For details about the parameters, see Table 1.
{
"op_type": "add_custom",
"data_script": "",
"gen_data": false,
"params": [{
"name": "x",
"dtype": "float16",
"param_type": "input",
"shape": [1,16384],
"data_file": "x.bin"
},
{
"name": "z",
"dtype": "float16",
"param_type": "output",
"shape": [1,16384],
"data_file": "golden_z.bin"
},
{
"name": "y",
"dtype": "float16",
"param_type": "input",
"shape": [1,16384],
"data_file": "y.bin"
},
],
"kernel_info": {
"kernel_source": "add_custom.cpp",
"kernel_name": "add_custom",
"kernel_includes": []
}
} Table 1 Operator JSON parameters with normalized params
| Parameter | Configuration Item | Data Type | Parameter Description | Value Description | Mandatory |
|---|---|---|---|---|---|
| op_type | - | string | Operator name. | Strictly matches the operator to be tuned. | Yes |
| data_script | - | string | Data generation script (Python), which is used to generate input and golden data. | Set this parameter as required, such as "/home/flash_attention_golden.py". Note: If no data generation script exists, set this parameter to empty or null. | No |
| gen_data | - | bool | Whether to generate the input and golden data based on data_script. | - true: Use the script to generate data. - false (default): Do not use the script to generate data. | Yes |
| params | name | string | Name of the input/output parameter of the kernel function. | Set this parameter as needed. | Yes |
| params | dtype | string | Input/Output data type. | Currently, bool, int, int8, int16, int32, int64, uint8, uint16, uint32, uint64, float16, float32, float64, and bfloat16 are supported. Note: Only one data type can be specified for dtype in the operator JSON configuration. | Yes |
| params | param_type | string | Whether a node is an input or output node. | - input: input node. - output: output node. | Yes |
| params | shape | list | Input/Output shape. | Set the actual shape of the operator, for example, [24,20,144,8]. Note: If the input is a scalar, set shape to null. | Yes |
| params | data_file | string | - When param_type is set to input, this parameter specifies the .bin file of input data. - When param_type is set to output, this parameter specifies the .bin file of golden data. | Set the path of the .bin file as required. The path must be an absolute path, for example, "/home/data.bin". NOTE - If data_file is set to empty or null, the accuracy of the output result is not compared. - If the input is a scalar, data_file is deleted and only data_value needs to be configured. | No |
| params | data_value | Determined by dtype. | Input scalar value. | Set this parameter based on site requirements. NOTE - This parameter can be set only when param_type is set to input. - data_value and data_file are mutually exclusive. If data_value is configured, data_file must be deleted and shape must be null, indicating that the node is scalar input. | No |
kernel_info Note: These parameters need to be set only for the kernel launch project. | kernel_source | string | Absolute path of the kernel entry source file. The format is Absolute path+File name. | Set this parameter based on the developed kernel function information. | Yes |
| kernel_info | kernel_name | string | Name of the kernel entrypoint function. | Set this parameter based on the developed kernel function information. | Yes |
| kernel_info | kernel_includes | list | Path of the header files on which the kernel file depends. | Set [] or multiple paths in it. | Yes |
Scenario 1: Scalar input is supported.
For Scalar input, delete data_file from the params option in the JSON file, set param_type to input, shape to null, and data_value to the specified scalar value.
{
"op_type": "xxxx",
"data_script": "",
"gen_data": false,
"params": [{
"name": "input_1",
"dtype": "float16",
"param_type": "input",
"shape": null,
"data_value": 8
}
]
} Scenario 2: TensorList input is supported.
For TensorList input, use square brackets ([]) to represent this parameter. Each item in the list indicates a tensor. The following is an example:
{
"op_type": "xxxx",
"data_script": "",
"gen_data": false,
"params": [
[{
"name": "input_1",
"dtype": "float16",
"param_type": "input",
"shape": [1,16384],
"data_file": "input_1.bin"
},
{
"name": "input_2",
"dtype": "float16",
"param_type": "input",
"shape": [1,16384],
"data_file": "input_2.bin"
}],
{
"name": "output",
"dtype": "float16",
"param_type": "output",
"shape": [1,16384],
"data_file": "golden.bin"
},
],
"kernel_info": {
"kernel_source": "add_custom.cpp",
"kernel_name": "add_custom",
"kernel_includes": []
}
} Scenario 3: In-place operator input is supported.
If an operator is an in-place operator, the input and output have the same addresses. When configuring the operator in JSON format, ensure that they have the same configuration items except param_type and data_file. A configuration example is as follows:
{
"op_type": "add_custom",
"data_script": "",
"gen_data": false,
"params": [{
"name": "x",
"dtype": "float16",
"param_type": "input",
"shape": [1,16384],
"data_file": "x.bin"
},
{
"name": "x",
"dtype": "float16",
"param_type": "output",
"shape": [1,16384],
"data_file": "golden_x.bin"
},
{
"name": "y",
"dtype": "float16",
"param_type": "input",
"shape": [1,16384],
"data_file": "y.bin"
},
],
"kernel_info": {
"kernel_source": "add_custom.cpp",
"kernel_name": "add_custom",
"kernel_includes": []
}
}