Project Build
Create the build and release directories in the udf_workspace/01_udf_add directory.
After the build is complete, the built .so file is generated in workspace/udf_add/release.
- Create the build directory.
mkdir -p build
- Create the release directory.
mkdir -p release
- Go to the build directory.
cd build
- Configure environment variables. The following uses the default path after Toolkit installation as a non-root user as an example. Run the following command based on the actual path of set_env.sh:
source ${HOME}/Ascend/cann/set_env.shThe preceding environment variables take effect only in the current window. You can add the preceding commands to the environment variable configuration file (for example, the .bashrc file) as required.
- Build the project.
- In a non-cross compilation scenario (the architectures of the development environment and operating environment are the same), the following is an example: Compile the .so file of the x86_64 type, set target lib to libadd.so, and use g++ as the compiler.
cmake .. -DTOOLCHAIN=g++ -DRELEASE_DIR=../release -DRESOURCE_TYPE=X86 -DUDF_TARGET_LIB=add && make
- -DTOOLCHAIN: name of the compiler. For example, g++.
- -DRELEASE_DIR: path for storing the target file after compilation.
- -DRESOURCE_TYPE: type of the compiled resource (x86, AArch, or Ascend).
- x86: Set this value to x86 if the target .so file needs to be deployed on the host with the x86 architecture.
- AArch: Set this value to AArch if the target .so file needs to be deployed on the host of the AArch type.
- Ascend: Set this value to Ascend if the target .so file needs to be deployed on the device.
- -DUDF_TARGET_LIB: name of the target .so file after compilation. For example, if add is set, libadd.so is generated.
- In the cross compilation scenario (the development environment is x86_64 and the operating environment is AArch64), compile .so files of the Ascend type and set target lib to libadd.so. The compiler is ${INSTALL_DIR}/toolkit/toolchain/hcc/bin/aarch64-target-linux-gnu-g++. Replace ${INSTALL_DIR} with the CANN component directory. For example, if the installation is performed by the root user, the default file storage path is /usr/local/Ascend/cann.For example:
cmake .. -DTOOLCHAIN=${INSTALL_DIR}/toolkit/toolchain/hcc/bin/aarch64-target-linux-gnu-g++ -DRELEASE_DIR=../release -DRESOURCE_TYPE=Ascend -DUDF_TARGET_LIB=add && make
- In a non-cross compilation scenario (the architectures of the development environment and operating environment are the same), the following is an example: Compile the .so file of the x86_64 type, set target lib to libadd.so, and use g++ as the compiler.
Parent topic: UDF Development