Operator Project Build
Overview
After the operator deliverable development is complete, you need to build the operator project to generate a custom operator installation package custom_opp_Linux_Arch.run. The build workflow includes:
- Build the operator information library definition file (.ini) into an operator information library (.json).
- Build the AI CPU operator code implementation files (.h and .cc) into a dynamic library file libcust_aicpu_kernels.so.
- Build the operator plugin implementation files (.h and .cc) into an operator plugin libcust_{tf|caffe|onnx}_parsers.so.
- Build the operator prototype definition files (.h and .cc) into an operator prototype library libcust_op_proto.so.

- Modify the CMakeLists.txt file in the /cpukernel directory of the operator project.
... set(AICPU_SOC_VERSION $ENV{AICPU_SOC_VERSION}) message(STATUS "AICPU_SOC_VERSION=${AICPU_SOC_VERSION}") # Add the following code. if(EXISTS "${ASCEND_AICPU_PATH}/opp/built-in/op_impl/aicpu/aicpu_kernel/lib/${AICPU_SOC_VERSION}/libascend_protobuf.a") target_link_options(${AICPU_KERNEL_TARGET} PRIVATE -s -Wl,-Bsymbolic -Wl,--exclude-libs=libascend_protobuf.a ) target_link_libraries(${AICPU_KERNEL_TARGET} PRIVATE -Wl,--whole-archive ${ASCEND_AICPU_PATH}/opp/built-in/op_impl/aicpu/aicpu_kernel/lib/${AICPU_SOC_VERSION}/libascend_protobuf.a -Wl,--no-whole-archive ) endif() if(EXISTS "${ASCEND_AICPU_PATH}/opp/built-in/op_impl/aicpu/aicpu_kernel/lib/${AICPU_SOC_VERSION}/libcpu_kernels_context.a") ... - Rebuild the operator project by referring to this section.
Build Procedure
- (Optional) Configure the path of the third-party library referenced by the AI CPU operator by modifying the cpukernel/CMakeLists.txt file in the operator project directory.
- include_directories: Add the directories of the header files to be included.
The following is an example:
include_directories( directoryPath1 directoryPath2 )
- link_directories: Add the directories of the library files to be linked with.
The following is an example:
link_directories( directoryPath3 directoryPath4 )
- link_libraries: Add library files for operator implementation.
The following is an example:
link_libraries( libName1 libName2)
- include_directories: Add the directories of the header files to be included.
- On the MindStudio IDE project page, select the operator project and choose from the top menu bar.
- Go to the Build Configuration dialog box. Click
to add configurations. By default, the Release(default) build type is added. For details, see Table 1.Figure 2 Build configurations dialog box
Table 1 Description of build configuration parameters Parameter
Description
Name
Custom configuration name. Defaults to Release.
Build type
Configuration type, which is optional. Defaults to Release.
Toolchain
Toolchain configurator, which preconfigures a custom toolchain with the same architecture as the installed CANN package and supports local build.
You can click Manage toolchains... to customize the toolchain. For details, see Toolchains.
CMake options
CMake option. The default value is -DCMAKE_BUILD_TYPE=Release.
Build directory
Relative path of the build directory, which is relative to the project directory.
Build options
Build acceleration option.
Environment variables
Environment variable configuration, which can be set before project build.
You can manually configure the environment variables or click
to configure them in the dialog box displayed.Environment from path
Enter a path or click
on the right to select the environment variable configuration file. The configuration file is filled in with one or more lines of <variable name>=<variable value>, for example:APATH=/usr/local/xxx X_PATH=/xxx/xxx
You are advised to configure the AICPU_KERNEL_TARGET environment variable and add the software version number as a suffix to the name of the dynamic library file to avoid library file naming conflicts due to AI CPU upgrade.
If this environment variable is not set, the default value cust_aicpu_kernels is used.
During build, add the environment variable to the OS.export ASCEND_AICPU_PATH=Ascend-CANN-Toolkit installation directory/ascend-toolkit/latest export AICPU_KERNEL_TARGET=cust_aicpu_kernels_3.3.0 (recommended) - Click
or choose to start the build. - View the build result in the lower part of MindStudio. The custom operator installation package custom_opp_Linux_Arch.run is generated in the cmake-build directory of the operator project.
The value of Arch is obtained based on the CANN package and toolchain information.