(Optional) Compiling Source Code
If the version of the binary deliverable in the .run installation package is inconsistent with your environment version, you need to compile the source code. The user environment configuration file is gcc/glibc/kernel/kernel.
- Compilation of the driver source code, which supports automatic compilation and DKMS hosting. For details, see Installation from Source Code.
- Compilation of the driver and user-mode program source code, which is stored in the .run installation package as a .tar package. You can perform decompression and compilation as required. For details, see Source Package.
Source Package
If the kernel version of the host differs greatly from the required version, use the source package for compilation. The source package compilation method applies only to versions earlier than NPU 20.0.0.
You can check the NPU version from the driver package name. For example, if the driver package name is A300-3000-NPU_Driver-20.0.0-ARM64-Ubuntu18.04.run, the NPU version is 20.0.0.
Obtaining and Decompressing the Installation Package
Prerequisites
All operations of source code compilation are performed as user root.
Procedure
- Obtain the .run package. For details, see Obtaining Software Packages.
- Install the .run installation package to the default directory or a specified directory. The default directory /usr/local/HiAI/ is used as an example. For details about how to install the .run installation package, see Installing the Driver.Figure 9-5 shows the directory structure of the decompressed package.
- install.sh: After the source code compilation is complete, run this script to copy the compiled file to the installation directory of the .run installation package.
- readme.txt: compilation description document.
- source.tar.gz: source code package.
Compiling Source Code
Source code compilation is optional. If the version of the binary deliverable in the .run installation package is incompatible with your environment, you need to recompile it. Otherwise, you do not need to recompile it. The user environment configuration file is gcc/glibc/kernel/kernel.
Prerequisites
- The software to be installed before source code compilation is as follows, but is not limited to the following software. You can install the software as prompted.
- Ubuntu (Due to PDF document format restrictions, if a command line is wrapped, copy the command to Word or Notepad, replace the line wrap point with a space to merge the lines into one, and copy it back to the server for execution.)
apt-get install gcc linux-headers-$(uname -r) g++ texinfo flex bison autoconf automake libtool libsysfs-dev
- CentOS (Due to PDF document format restrictions, if a command line is wrapped, copy the command to Word or Notepad, replace the line wrap point with a space to merge the lines into one, and copy it back to the server for execution.)
yum install gcc linux-headers-$(uname -r) g++ texinfo flex bison autoconf automake libtool libsysfs
- Ubuntu (Due to PDF document format restrictions, if a command line is wrapped, copy the command to Word or Notepad, replace the line wrap point with a space to merge the lines into one, and copy it back to the server for execution.)
- Permission processing
After the .run package is installed, security hardening is performed for security purposes. If a message is displayed indicating that you do not have the permission to perform some operations, perform the following operations to perform security dehardening. After the operations are complete, perform security hardening again.
Switch to the root user and run the following command:
Dehardening command:
chattr -i -R installation path of the .run package
Hardening command:
chattr +i -R installation path of the .run package
For example, if the .run package uses the default installation path, the dehardening command is chattr -i -R /usr/local/HiAI/.
Procedure
To compile source code, you need to decompress the source code package, compile the source code, and specify the compilation tool chain and kernel source code directory. The procedure is as follows:
- Run the cd /usr/local/HiAI/source command to go to the directory of the source code package.
- Run the tar zxvf source.tar.gz command to decompress the source code package source.tar.gz.
- Run the cd source command to go to the source code directory.
- This step applies only to the Ubuntu OS.
Run the following command to configure the user email address and user name:
git config --global user.email "you@example.com" git config --global user.name "Your Name"
- Run the source code compilation command make ARCH=? KERNEL_DIR=? O=?.
Parameters are described as follows:
- ARCH: compilation platform, Arm64 by default.
- KERNEL_DIR: kernel root directory, which needs to be specified for the compilation driver ko. This directory must contain the .config file and include directory.
- O: output directory of compilation results. The value can be an absolute directory or a relative directory. The default value is the out folder in the current directory.
Example:
- Compilation command on the Ubuntu x86 OS: (The following is a command. Due to the restriction of the PDF file format, the command that exceeds one line will be automatically wrapped. Therefore, you need to manually combine the following command into one line and then copy the line to the server for execution.)
make ARCH=x86 HOST_OS=Ubuntu KERNEL_DIR=/usr/src/linux-headers-`uname -r`
- Compilation command on the CentOS x86 OS:
make ARCH=x86 HOST_OS=CentOS KERNEL_DIR=/usr/src/kernels/`uname -r`
- Compilation command on the CentOS Arm OS: (The following is a command. Due to the restriction of the PDF file format, the command that exceeds one line will be automatically wrapped. Therefore, you need to manually combine the following command into one line and then copy the line to the server for execution.)
make ARCH=arm64 HOST_OS=CentOS KERNEL_DIR=/usr/src/kernels/`uname -r` CROSS_COMPILE=/usr/bin/
In the preceding command, /usr/bin/ is the local GCC path in the Arm environment.
- CROSS_COMPILE: indicates the cross compilation GCC. This parameter needs to be specified during cross compilation and compilation in the Arm environment.
- HOST_OS: indicates the OS on which the compiled image runs. Currently, CentOS and Ubuntu (default) are supported.
- uname -r: indicates that the current kernel version is used for source code compilation. Before running the compilation command, run make clean to clear the files generated by the last make command.
- If the page shown in Figure 9-6 is displayed, the compilation is successful.
Compiling and Installing the Source Code
Prerequisites
You have decompressed and compiled the installation package. For details, see Compiling Source Code.
Procedure
- Run the install.sh script in the source directory to install the compilation file to the .run installation package directory.
Installation command: ./install.sh compile_out_dir
compile_out_dir is the output directory of source code compilation results.- If the O parameter is set during the compilation, the value of compile_out_dir must consistent with the value of the O parameter.
- If the default directory is used, the value is /out/release_imags.
If the following information is displayed, the Installation is successful:
compiler files install success
- Run the reboot command to restart the host OS.