Dynamic and static operator library build is a process of generating dynamic and static libraries from operator implementation code and related files. Compared with custom operator package build, dynamic and static library build significantly simplifies the integration and deployment process. The process involves compiling and linking the operator implementation on the kernel, tiling implementation on the host, adaptation file for integration into a graph, and automatically generated single-operator call implementation code into dynamic and static libraries.
The following header files are automatically generated:
The dynamic and static operator library build supports the following models:
The procedure for building the dynamic and static operator libraries is as follows:
"ASCEND_PACK_SHARED_LIBRARY": {
"type": "BOOL",
"value": "True"
}
./build.sh
After the build is successful, the following files are generated in the ${CMAKE_INSTALL_PREFIX}/op_api directory:
The directory structure is as follows:
├── op_api
│ ├── include
│ ├── aclnn_optype1.h // aclnn header file for single-operator call
│ └── aclnn_optype2.h
│ └── aclnn_optypexxx.h
│ └── op_proto.h // Header file for operator prototype definition
│ ├── lib
│ ├── cmake
│ └── ${vendor_name}
│ ├──${vendor_name}-config.cmake // Installation file, which defines the configuration options and variables in the project
│ └──${vendor_name}-targets.cmake // Installation file, which defines the build targets ${vendor_name}::static and ${vendor_name}::shared for static and dynamic libraries, respectively. This makes it easier to use the static and dynamic libraries and automatically handle library dependencies.
│ ├── libcust_opapi.so // Dynamic operator library
│ └── lib${vendor_name}.a // Static operator library
In the single-operator call scenario, you can integrate and use the dynamic and static libraries generated in Operator Library Build as follows:
find_package(${vendor_name} REQUIRED # ${vendor_name} is the name of the generated operator package.
PATHS ${CUST_PKG_PATH} # ${CUST_PKG_PATH} is the path for storing the generated operator package.
NO_DEFAULT_PATH
)
target_link_libraries(op_runner PRIVATE
...
${vendor_name}::shared # The related target dependencies are automatically included.
...
)
find_package(${vendor_name} REQUIRED # ${vendor_name} is the name of the generated operator package.
PATHS ${CUST_PKG_PATH} # ${CUST_PKG_PATH} is the path for storing the generated operator package.
NO_DEFAULT_PATH
)
target_link_libraries(op_runner PRIVATE
...
${vendor_name}::static # The related target dependencies are automatically included.
...
)
find_package(${vendor_name1} REQUIRED # ${vendor_name1} is the name of the generated operator package.
PATHS ${CUST_PKG_PATH_1} # ${CUST_PKG_PATH_1} is the path for storing the generated operator package.
NO_DEFAULT_PATH
)
find_package(${vendor_name2} REQUIRED # ${vendor_name2} is the name of the generated operator package.
PATHS ${CUST_PKG_PATH_2} # ${CUST_PKG_PATH_2} is the path for storing the generated operator package.
NO_DEFAULT_PATH
)
target_link_libraries(op_runner PRIVATE
...
${vendor_name1}::static # The related static library target dependencies are automatically included.
${vendor_name2}::shared # The related dynamic library target dependencies are automatically included.
...
)
set_target_properties(cust_opapi PROPERTIES
OUTPUT_NAME ${vendor_name}
)
After build, modify the ${vendor_name}-targets.cmake file in the op_api directory and change libcust_opapi.so to lib${vendor_name}.so. Ensure the consistency of the dynamic library names.
export ASCEND_CUSTOM_OPP_PATH=${CMAKE_INSTALL_PREFIX}/op_api/lib/:${ASCEND_CUSTOM_OPP_PATH}
If the dynamic library build and operator package build functions are used at the same time, the dynamic library generated by the former has a higher priority.
In the following example, path1 and path3 are the directories generated during operator package build, and path2 and path4 are the directories for storing the dynamic library build artifacts. The build artifact priorities are 2 > 4 > 1 > 3.
ASCEND_CUSTOM_OPP_PATH=<path1>/vendor_name1:<path2>/op_api/lib/:<path3>/vendor_name3:<path4>/op_api/lib/