Operator Project Build
Overview
After the operator deliverable development is complete, you need to build the operator project to generate a custom OPP runfile (.run). The build workflow includes:
- Build the AI CPU operator code implementation files (.h and .cc) into libcust_aicpu_kernels.so.
- Build the AI CPU operator information library definition file (.ini) into cust_aicpu_kernel.json.
- Build the operator prototype definition files (.h and .cc) into libcust_op_proto.so.
- Build the operator plugin implementation file (.cc) into libcust_tf_parsers.so.
- Windows OSs do not support local build.
- The AI CPU operator project of an earlier version is incompatible with the latest version of the Ascend-CANN-Toolkit. You need to modify the CMakeLists.txt file and rebuild the operator project. The solution is as follows:
- 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.
- Modify the CMakeLists.txt file in the /cpukernel directory of the operator project.
Build Procedure
- (Optional) Modify the cpukernel/CMakeLists.txt file in the project directory.
- include_directories: Add the directories of the header files to be included.
Example:
include_directories( directoryPath1 directoryPath2 )
- link_directories: Add the directories of the library files to be linked with.
Example:
link_directories( directoryPath3 directoryPath4 )
- link_libraries: Add library files for operator implementation.
Example:
link_libraries( libName1 libName2)
- include_directories: Add the directories of the header files to be included.
- Perform build configuration.
On the MindStudio project page, select the operator project and choose on 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 1 Build configurations dialog box
Table 1 Parameter description Parameter
Description
Name
Custom configuration name. The default value is Release.
Build type
Configuration type, which is optional. The default value is Release.
Toolchain
Toolchain configurator, which preconfigures a custom toolchain with the same architecture as the installed CANN package and supports local and remote 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.If the remote toolchain is used, a deployment is added by default. You need to configure environment variables.
Enter ASCEND_OPP_PATH, ASCEND_TENSOR_COMPILER_INCLUDE, and ASCEND_AICPU_PATH in the Environment Variables text box.ASCEND_OPP_PATH=Ascend-CANN-Toolkit installation directory/ascend-toolkit/latest/opp; ASCEND_TENSOR_COMPILER_INCLUDE=Ascend-CANN-Toolkit installation directory/ascend-toolkit/latest/include; ASCEND_AICPU_PATH=Ascend-CANN-Toolkit installation directory/ascend-toolkit/latest
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.
AICPU_KERNEL_TARGET=cust_aicpu_kernels_3.3.0
During local 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.
If an error is reported during GCC-based compilation on an AI CPU operator project, refer to What Do I Do When an Error Is Reported during GCC-based Compilation on an AI CPU Operator Project? to rectify the fault.
- View the build result in the lower part of MindStudio. The custom OPP runfile 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.