After the operator kernel and host implementations are developed, build the operator project to generate a custom OPP runfile (*.run). The build workflow includes:
{
"version": 1,
"cmakeMinimumRequired": {
"major": 3,
"minor": 19,
"patch": 0
},
"configurePresets": [
{
"name": "default",
"displayName": "Default Config",
"description": "Default build using Unix Makefiles generator",
"generator": "Unix Makefiles",
"binaryDir": "${sourceDir}/build_out",
"cacheVariables": {
"CMAKE_BUILD_TYPE": {
"type": "STRING",
"value": "Release"
},
"ENABLE_SOURCE_PACKAGE": {
"type": "BOOL",
"value": "True"
},
"ENABLE_BINARY_PACKAGE": {
"type": "BOOL",
"value": "True"
},
"ASCEND_COMPUTE_UNIT": {
"type": "STRING",
"value": "ascendxxx"
},
"ENABLE_TEST": {
"type": "BOOL",
"value": "True"
},
"vendor_name": {
"type": "STRING",
"value": "customize"
},
"ASCEND_PYTHON_EXECUTABLE": {
"type": "STRING",
"value": "python3"
},
"CMAKE_INSTALL_PREFIX": {
"type": "PATH",
"value": "${sourceDir}/build_out"
},
"ENABLE_CROSS_COMPILE": {
"type": "BOOL",
"value": "False"
},
"CMAKE_CROSS_PLATFORM_COMPILER": {
"type": "PATH",
"value": "/usr/bin/aarch64-linux-gnu-g++"
},
"ASCEND_PACK_SHARED_LIBRARY": {
"type": "BOOL",
"value": "False"
}
}
}
]
}
|
Parameter |
Description |
Default Value |
|---|---|---|
|
CMAKE_BUILD_TYPE |
Compilation mode options:
|
Release |
|
ENABLE_SOURCE_PACKAGE |
Whether to enable source code compilation |
True: enabled. |
|
ENABLE_BINARY_PACKAGE |
Whether to enable binary compilation |
True: enabled. |
|
vendor_name |
Indicates the name of the vendor to which the custom operator belongs. You are advised to specify the vendor name to avoid conflicts with OPPs provided by other vendors. |
customize |
|
ASCEND_PACK_SHARED_LIBRARY |
Whether to enable dynamic library compilation |
False |
|
Environment Variable |
Configuration Description |
|---|---|
|
CMAKE_CXX_COMPILER_LAUNCHER |
Configures the C++ compiler (such as g++) and BiSheng Compiler launcher as ccache, enabling cache compilation, accelerating repeated compilation, and improving build efficiency. Before using this function, you need to install ccache. The following shows how to perform configuration in the corresponding CMakeLists.txt file: set(CMAKE_CXX_COMPILER_LAUNCHER <launcher_program>) <launcher_program> indicates the ccache installation path, for example, /usr/bin/ccache. set(CMAKE_CXX_COMPILER_LAUNCHER /usr/bin/ccache) |
./build.sh
After the project is built successfully, an OPP runfile named custom_opp_<target os>_<target architecture>.run is generated in the build_out directory.
To save build process logs, use the environment variable ASCENDC_BUILD_LOG_DIR to control the storage path. If no error occurs during compilation, the log file name is followed by _success. If an error occurs, the corresponding error information is displayed on the screen, indicating the path and name of the log file, and the log file name is followed by _error.
# To store build logs in /home/build_log/, do as follows and disable log storage by default. export ASCENDC_BUILD_LOG_DIR=/home/build_log/
After the operator code is implemented, if the current platform architecture is consistent with the operating environment, compile the operator package by referring to the previous section. To implement cross compilation of the operator package, perform the following steps:
|
Current Platform Architecture |
Operating Environment Platform Architecture |
Commands for Downloading Build Tools |
|---|---|---|
|
x86_64 |
aarch64 |
sudo apt-get install -y g++-aarch64-linux-gnu |
|
aarch64 |
x86_64 |
sudo apt-get install g++-x86-64-linux-gnu |
"ENABLE_CROSS_COMPILE": {
"type": "BOOL",
"value": "True"
}"CMAKE_CROSS_PLATFORM_COMPILER": {
"type": "PATH",
"value": "/usr/bin/aarch64-linux-gnu-g++"
}After the project is built successfully, an OPP runfile named custom_opp_<target os>_<target architecture>.run is generated in the build_out directory.
In an operator project, if you want to add some custom compilation options to the kernel code, you can customize the compilation options by referring to the following method:
Modify the CMakeLists.txt file in the op_kernel directory of the operator project and use add_ops_compile_options to add compilation options as follows:
add_ops_compile_options(OpType COMPUTE_UNIT soc_version1 soc_version2 ... OPTIONS option1 option2 ...)
The following table describes the parameters.
|
Parameter |
Optional/Required |
Description |
|---|---|---|
|
OpType: operator type. |
Required |
The first parameter must be set to the operator type. To make the setting take effect for all operators in the operator project, set this parameter to ALL. |
|
COMPUTE_UNIT |
Optional |
AI processor models on which compilation options take effect. Multiple AI processor models are separated by spaces. If this parameter is not set, the configuration takes effect for all AI processor models.
NOTE:
The COMPUTE_UNIT configuration procedure is as follows:
|
|
OPTIONS |
Required |
Custom compilation options. Multiple compilation options are separated by spaces.
|
add_ops_compile_options(AddCustom COMPUTE_UNIT Ascendxxxyy ... OPTIONS -DNEW_MACRO1=xx) add_ops_compile_options(AddCustom COMPUTE_UNIT Ascendxxxyy ... OPTIONS -DNEW_MACRO2=xx) add_ops_compile_options(AddCustom COMPUTE_UNIT Ascendxxxyy ... OPTIONS -DNEW_MACRO3=xx)
--tiling_key=1,2
--kernel-template-input="D_T_X=A1,A2;D_T_Y=B;D_T_Z=C" --kernel-template-input='D_T_X=A1,A2;D_T_Y=B;D_T_Z=C'
When configuring template parameter combinations, ensure that the template parameter names match those defined at the kernel entry and on the host. For the values of template parameter combinations, if there are custom types, replace them with their corresponding numeric values. If the data type is natively supported, the value must be the same as the input parameter at the kernel entry. The following is an example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
// Template parameter definition #define ADD_TPL_FP16 10 #define ADD_TPL_FP32 20 ASCENDC_TPL_ARGS_DECL(AddCustomTemplateNativeDtype, ASCENDC_TPL_DATATYPE_DECL(D_T_X, C_DT_FLOAT, C_DT_FLOAT16, ASCENDC_TPL_INPUT(0)), ASCENDC_TPL_DTYPE_DECL(D_T_Y, ADD_TPL_FP16, ADD_TPL_FP32), ASCENDC_TPL_DATATYPE_DECL(D_T_Z, C_DT_FLOAT, C_DT_FLOAT16, ASCENDC_TPL_OUTPUT(0)), ASCENDC_TPL_UINT_DECL(TILE_NUM, ASCENDC_TPL_8_BW, ASCENDC_TPL_UI_MIX, 2, 0, 2, 3, 5, 10, 12, 13, 9, 8), ASCENDC_TPL_BOOL_DECL(IS_SPLIT, 0, 1), ); ASCENDC_TPL_SEL( ASCENDC_TPL_ARGS_SEL( ASCENDC_TPL_DATATYPE_SEL(D_T_X, C_DT_FLOAT), ASCENDC_TPL_DTYPE_SEL(D_T_Y, ADD_TPL_FP32), ASCENDC_TPL_DATATYPE_SEL(D_T_Z, C_DT_FLOAT), ASCENDC_TPL_UINT_SEL(TILE_NUM, ASCENDC_TPL_UI_LIST, 1, 8), ASCENDC_TPL_BOOL_SEL(IS_SPLIT, 0, 1), ASCENDC_TPL_DETERMINISTIC_SEL(true), ASCENDC_TPL_KERNEL_TYPE_SEL(ASCENDC_TPL_AIV_ONLY), ), ASCENDC_TPL_ARGS_SEL( ASCENDC_TPL_DATATYPE_SEL(D_T_X, C_DT_FLOAT16), ASCENDC_TPL_DTYPE_SEL(D_T_Y, ADD_TPL_FP16), ASCENDC_TPL_DATATYPE_SEL(D_T_Z, C_DT_FLOAT16), ASCENDC_TPL_UINT_SEL(TILE_NUM, ASCENDC_TPL_UI_LIST, 1, 8), ASCENDC_TPL_BOOL_SEL(IS_SPLIT, 0, 1), ASCENDC_TPL_DETERMINISTIC_SEL(false), ASCENDC_TPL_KERNEL_TYPE_SEL(ASCENDC_TPL_AIV_ONLY), ), ); #endif // Kernel entry if constexpr (std::is_same_v<D_T_X, float> && std::is_same_v<D_T_Z, float>) { KernelAdd<D_T_X, float, D_T_Z> op; op.Init(x, y, z, tiling_data.totalLength, TILE_NUM); op.Process1(); } else if constexpr (std::is_same_v<D_T_X, half> && std::is_same_v<D_T_Z, half>){ KernelAdd<D_T_X, half, D_T_Z> op; op.Init(x, y, z, tiling_data.totalLength, TILE_NUM); |
The compilation option example is as follows:
--kernel-template-input="D_T_X=10;D_T_Y=half;D_T_Z=10" --kernel-template-input="D_T_X=10,20;D_T_Y=half,float;D_T_Z=10,20"