In the operator JSON configuration file with fixed input/output order, outputs are arranged after inputs, that is, regular input/output arrangement. Therefore, the parameters of the kernel entrypoint function are arranged accordingly.
Remarks
Regular input/output arrangement (all output parameters are arranged after input parameters): For example, the parameter arrangement of the kernel entrypoint function is as follows:
extern "C" __global__ __aicore__ void add_custom(GM_ADDR input1, GM_ADDR input2, GM_ADDR output)
Developers of a standard custom operator project usually configure the operator JSON file in this way.
The following uses the AddCustom operator as an example to describe the JSON configuration. For details about the parameters, see Table 1.
{
"op_type": "AddCustom",
"data_script": "./add_golden.py",
"gen_data": true,
"inputs": [
{
"name": "x",
"dtype": "int32",
"format": "ND",
"ignore": false,
"shape": [32],
"param_type": "required",
"data_file": "x.bin"
},
{
"name": "y",
"dtype": "int32",
"format": "ND",
"ignore": false,
"shape": [32],
"param_type": "required",
"data_file": "y.bin"
}
],
"outputs": [
{
"name": "z",
"dtype": "int32",
"format": "ND",
"ignore": false,
"shape": [32],
"param_type": "required",
"data_file": "golden_z.bin"
}
],
"attrs": [
{
"name": "mask",
"dtype": "list_int",
"value": [0,0]
},
{
"name": "repeatTimes",
"dtype": "int",
"value": 1
},
// ...
]
} Table 1 Operator JSON parameters with fixed input/output order
| Parameter | Configuration Item | Data Type | Parameter Description | Value Description | Mandatory |
|---|---|---|---|---|---|
| op_type | N/A | string | Operator name. | Strictly matches the operator to be tuned. | Yes |
| data_script | N/A | 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 | N/A | 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 |
inputs / outputs | name | string | Name of the input/output parameter of the kernel function. | Set this parameter as required. If generated using the binary operator template file, the name should not be changed. | Yes |
inputs / outputs | 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 |
inputs / outputs | format | string | Input/Output storage format. | ND and NZ are supported. | Yes |
inputs / outputs | 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 |
inputs / outputs | ignore | bool | Whether to ignore the input/output. | - true: The input/output can be ignored, and the global memory is not allocated. - false: The input/output cannot be ignored. The default value is false. | No |
inputs / outputs | param_type | string | Whether the input/output is required. | - required - optional Note: When param_type is set to optional: - If ignore is set to false, the input is considered not exist. - If ignore is set to true, the input is considered to exist. - Intermediate dangling inputs are not supported. For example, if there are three inputs x, y, and z, ignore cannot be set to false, true, and false respectively. | Yes |
inputs / outputs | data_file | string | - For inputs, this parameter indicates the .bin file of input data. - For outputs, this parameter indicates 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 |
inputs / outputs | data_value | Determined by dtype. | Input scalar value. | Set this parameter based on site requirements. NOTE - This parameter can be set only for the input node. - 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 |
inputs / outputs | value_depend | string | Whether the input is of the Const type. | This parameter is optional. If this parameter is not set, the input is not of the Const type. - true: The input is of the Const type. - false: The input is not of the Const type. | No |
| attrs | name | string | Attribute name of an operator, which is the unique identifier for an operator. | In some scenarios, attrs is missing, so it needs to be set as required. | Yes |
| attrs | dtype | string | Data type. | In some scenarios, attrs is missing, so it needs to be set as required. | Yes |
| attrs | value | Variable | Attribute value. | In some scenarios, attrs is missing, so it needs to be set as required. | Yes |
Scenario 1: Scalar input is supported.
For Scalar input, delete data_file from the inputs option in the JSON file, set shape to null, and set data_value to a specified scalar value.
{
"op_type": "xxxx",
"data_script": "",
"gen_data": false,
"inputs": [{
"name": "tileNumIn",
"dtype": "uint32",
"param_type": "required",
"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,
"inputs":
[{
"name": "key0",
"dtype": "float16",
"format": "ND",
"ignore": false,
"shape": [1,5,8192,128],
"param_type": "required",
"data_file": "/home/data/input/k_0.bin"
},{
"name": "key1",
"dtype": "float16",
"format": "ND",
"ignore": false,
"shape": [1,5,8192,128],
"param_type": "required",
"data_file": "/home/data/input/k_1.bin"
}]
} Scenario 3: In-place operator input is supported.
Currently, this method is not supported.
If an operator is an in-place operator, the input and output addresses are the same. When configuring the operator in JSON format, ensure that outputs and inputs have the same configuration items except data_file. A configuration example is as follows:
{
"op_type": "AddCustom",
"data_script": "./add_golden.py",
"gen_data": true,
"inputs": [
{
"name": "x",
"dtype": "int32",
"format": "ND",
"ignore": false,
"shape": [32],
"param_type": "required",
"data_file": "x.bin"
},
{
"name": "y",
"dtype": "int32",
"format": "ND",
"ignore": false,
"shape": [32],
"param_type": "required",
"data_file": "y.bin"
}
],
"outputs": [
{
"name": "x",
"dtype": "int32",
"format": "ND",
"ignore": false,
"shape": [32],
"param_type": "required",
"data_file": "golden_x.bin"
}
],
"attrs": [
{
"name": "mask",
"dtype": "list_int",
"value": [0,0]
},
{
"name": "repeatTimes",
"dtype": "int",
"value": 1
}
]
}