Build from Source
1. Environment Preparation
Complete the basic environment setup before compiling from source. See Quick Install for detailed instructions.
2. Environment Verification
Verify the environment after installing the CANN packages.
# Check CANN Toolkit version (default installation path). <arch> represents CPU architecture (aarch64 or x86_64). For WebIDE scenarios, replace /usr/local with /home/developer.
cat /usr/local/Ascend/cann/<arch>-linux/ascend_toolkit_install.info
# Check CANN ops version (default installation path). <opsname> represents the ops subpackage name to query. For WebIDE scenarios, replace /usr/local with /home/developer.
cat /usr/local/Ascend/cann/<arch>-linux/ascend_ops_install.info
3. Environment Variable Configuration
Select the appropriate command based on your scenario:
# Default installation path (root user example). For non-root users, replace /usr/local with ${HOME}.
source /usr/local/Ascend/cann/set_env.sh
# Custom installation path
source ${install_path}/cann/set_env.sh
4. Source Code Compilation
4.1 Download Source Code
If your compilation environment can access the network, open-source third-party software downloads automatically during compilation. Use the following command to download the source code:
git clone https://gitcode.com/cann/graph-autofusion.git
If your compilation environment cannot access the network, download the source code and open-source software packages in a networked environment. Upload them manually to your compilation environment:
-
In a networked environment, visit the project homepage. Use the
Download ziporClonebutton to download the source code. -
Download the
makeselfandcann-cmakethird-party open-source software.Open-Source Software Version Download Link makeself 2.5.0 makeself-release-2.5.0-patch1.tar.gz cann-cmake master-002 cmake-master-002.tar.gz -
Upload the source code and third-party open-source software to the offline compilation environment. Extract the source code.
# Extract source code unzip graph-autofusion.zip -
Create an open_source directory at the same level as the source code. Place the third-party open-source software packages in the open_source directory and extract them.
# Create open_source directory mkdir open_source # Move third-party open-source software packages to open_source directory mv makeself-release-2.5.0-patch1.tar.gz open_source/ mv cmake-master-002.tar.gz open_source/ # Extract third-party open-source software packages and rename (cann-cmake package remains unchanged) cd open_source tar -zxvf makeself-release-2.5.0-patch1.tar.gz && mv makeself-release-2.5.0 makeself -
The file directory structure after completion:
├── graph-autofusion # Extracted source repository │ ├── cmake │ └── ... ├── open_source # Third-party open-source software │ └── makeself │ ├── COPYING │ ├── Makefile │ ├── README.md │ └── ... │ └── cmake-master-002.tar.gz
4.2 Install Dependencies
4.2.1 Install Dependencies
The following lists dependencies used for source code compilation. Pay attention to version requirements:
Note
If you use the mirror method for project experience, all dependencies are included in init_env.sh. You can skip this dependency installation step.
-
Python3 >= 3.8.0 (Python virtual environment recommended)
Note
- Python announced 3.8.x EOL. CANN will stop support for this version in 10.0.0. Please upgrade to >= 3.9.x.
-
Create and activate a virtual environment:
python3 -m venv venv source venv/bin/activate -
Install dependencies:
cd graph-autofusion pip3 install -r super_kernel/requirements-dev.txt
-
patch
# Ubuntu/Debian installation example. For other operating systems, install manually. sudo apt-get install patch -
CMake >= 3.16.0 (version 3.20.0 recommended)
# Ubuntu/Debian installation example. For other operating systems, install manually. sudo apt-get install cmake
4.2.2 Check Compilation Environment
After environment preparation, execute the environment check script. Confirm whether the current environment meets compilation requirements.
bash scripts/check_env.sh
Check result descriptions:
| Status | Meaning | Recommendation |
|---|---|---|
| [PASS] | Check passed | No action required |
| [WARNING] | Non-critical dependency missing or version deviation | Fix recommended, does not affect core compilation |
| [ERROR] | Critical dependency missing or version incompatible | Must fix, otherwise compilation cannot proceed |
Note
All check items and version constraints in the environment check script come strictly from docs/build.md and super_kernel/requirements-dev.txt. If documentation and dependencies update, synchronize changes to the script.
4.3 Compilation
Navigate to the source repository root directory. Execute the following command to compile:
bash build.sh --pkg
View more compilation parameters through bash build.sh -h. After successful execution, cann-graph-autofusion_${cann_version}_linux-${arch}.run generates in the build_out directory.
- --pkg indicates building a run package.
- ${cann_version} indicates the cann version number.
- ${arch} indicates CPU architecture, for example, aarch64 or x86_64.
During compilation, CMake automatically downloads third-party source packages (abseil-cpp, boost, json, protobuf, symengine, googletest, mockcpp, and so on) required by autofuse and superkernel AOT UT from external networks (for example, https://gitcode.com/cann-src-third-party/ and Huawei Cloud OBS) through ExternalProject_Add. If your compilation environment cannot directly access external networks (for example, enterprise intranet or Docker container default bridge network), select the appropriate solution:
Solution 1: Configure Network Proxy (Recommended)
If the environment has an HTTP proxy that can access external networks, set the http_proxy / https_proxy environment variables before compilation. build.sh automatically passes these proxy variables to CMake subprocesses:
# Set proxy (modify according to actual proxy address)
export http_proxy=http://user:password@proxy-server:port
export https_proxy=http://user:password@proxy-server:port
# Execute compilation
bash build.sh --pkg
Note
build.shautomatically detects and inheritshttp_proxyandhttps_proxyenvironment variables in the current shell. No additional configuration required.- If you use git proxy (configured through
git config --global http.proxy), confirm that the shell environment also sets corresponding environment variables. Verify throughecho $http_proxy.
Solution 2: Manually Pre-download Third-Party Packages In environments without any external network access, pre-download third-party source packages on a networked machine. Copy them to the specified directory in the compilation environment for offline compilation.
-
Download the following third-party packages on a networked machine:
-
Copy the downloaded packages to the corresponding subdirectories under
output/third_party/in the compilation environment (create if not exist):# Create directory structure under source root mkdir -p output/third_party/{abseil-cpp,json,boost,protoc,symengine,gtest,mockcpp} # Place downloaded packages in corresponding directories (filenames must match the table below) # abseil-cpp-20230802.1.tar.gz → output/third_party/abseil-cpp/ # json-3.11.3.tar.gz → output/third_party/json/ # boost_1_87_0.tar.gz → output/third_party/boost/ # protobuf-25.1.tar.gz → output/third_party/protoc/ # symengine-0.12.0.tar.gz → output/third_party/symengine/ # googletest-1.14.0.tar.gz → output/third_party/gtest/ # mockcpp-2.7.tar.gz → output/third_party/mockcpp/ # mockcpp-2.7-h5.patch → output/third_party/ # preferred path # mockcpp-2.7-h5.patch → output/third_party/pkg/ # fallback pathExample placement for the mockcpp package and patch file:
# Preferred placement mkdir -p output/third_party/mockcpp cp mockcpp-2.7.tar.gz output/third_party/mockcpp/ cp mockcpp-2.7-h5.patch output/third_party/ # Alternative fallback placement mkdir -p output/third_party/mockcpp output/third_party/pkg cp mockcpp-2.7.tar.gz output/third_party/mockcpp/ cp mockcpp-2.7-h5.patch output/third_party/pkg/To manually verify that the mockcpp patch can be applied before compilation, run the following git commands in a temporary directory. This is not required for normal builds because CMake performs this step automatically.
# Run from the source root. This example uses the preferred patch path. GRAPH_AUTOFUSION_HOME=$(pwd) rm -rf /tmp/mockcpp_patch_check mkdir -p /tmp/mockcpp_patch_check tar -zxf output/third_party/mockcpp/mockcpp-2.7.tar.gz -C /tmp/mockcpp_patch_check --strip-components=1 cd /tmp/mockcpp_patch_check git init git apply --check ${GRAPH_AUTOFUSION_HOME}/output/third_party/mockcpp-2.7-h5.patch # To apply the patch manually, continue with: git apply ${GRAPH_AUTOFUSION_HOME}/output/third_party/mockcpp-2.7-h5.patchIf the patch is placed in the fallback path, replace the patch path above with
${GRAPH_AUTOFUSION_HOME}/output/third_party/pkg/mockcpp-2.7-h5.patch.Note
mockcpp-2.7-h5.patchis required to build mockcpp. Whenadd_cann_third_party(mockcpp)is used, CMake automatically applies this patch withgit init && git apply ${PATCH_FILE}after extractingmockcpp-2.7.tar.gz. No manual patch step is required.- For offline compilation, prepare both
mockcpp-2.7.tar.gzandmockcpp-2.7-h5.patch. If the patch file is missing, CMake attempts to download it from the network, which causes offline builds to fail. - The preferred mockcpp patch lookup path is
output/third_party/mockcpp-2.7-h5.patch. If that path does not exist, CMake usesoutput/third_party/pkg/mockcpp-2.7-h5.patch. - The patch is applied automatically during the CMake ExternalProject patch stage. Do not pre-extract and modify the
output/third_party/mockcppsource directory manually, because later builds may clean or overwrite it.
-
During compilation, specify the local path through
--cann_3rd_lib_pathto skip the download step:bash build.sh --pkg --cann_3rd_lib_path=$(pwd)/output/third_party
Note
- If you do not specify
--cann_3rd_lib_path, the default search path is./output/third_party. Therefore, you can omit this parameter when packages exist in the default path. - CMake build scripts prioritize checking whether corresponding tarballs already exist in the local path. If they exist, the download skips.
4.4 Installation and Uninstallation
Important
You must install the compiled .run package before running UT/ST tests. Otherwise, LD_LIBRARY_PATH will load older versions of dynamic libraries from the CANN installation path, causing runtime errors such as undefined symbol.
Installation
After local verification completes, execute the following command to install the compiled package. Ensure the installation user has execute permission for the package.
# Specify installation path if needed: --install-path=${install_path}
./build_out/cann-graph-autofusion_${cann_version}_linux-${arch}.run --full --quiet --pylocal
Note
- The installation path (default or specified) must match the path where you installed the cann-toolkit package.
- --full indicates full installation mode.
- --install-path specifies the installation path. If not specified, the default installation path is
/usr/local/Ascend(root user) or${HOME}/Ascend(non-root user). - --quiet indicates silent installation. It skips human-computer interaction.
- --pylocal determines whether to install .whl files inside the package along the run package installation path.
- If you select this parameter, .whl installs in the
${ascend_install_path}/cann/python/site-packagespath. - If you do not select this parameter, .whl installs in the local python path, for example,
/usr/local/python3.7.5/lib/python3.7/site-packages.
- If you select this parameter, .whl installs in the
- --autofuse indicates whether to install autofuse component-related compilation artifacts. Current package installation does not install autofuse by default. Add this option to install autofuse.
- For more installation options, use the --help option to view.
Uninstallation
If you want to uninstall the installed package, execute the following command:
# Add --install-path=${install_path} if installed to a specified path
./build_out/cann-graph-autofusion_${cann_version}_linux-${arch}.run --uninstall
4.5 Test Verification
After installation, you can perform developer testing. Ensure you have completed Environment Preparation and installed the compiled .run package before executing operations in this section.
-
UT Verification
bash build.sh -u --cann_3rd_lib_path=$(pwd)/output/third_partyAfter execution, check the UT test execution status through the output log. Successful test case execution prints
passedwithout anyfailedprint. Confirm all test cases pass. -
ST Verification
bash build.sh -s --cann_3rd_lib_path=$(pwd)/output/third_partyAfter execution, check the ST test execution status through the output log. Successful test case execution prints
passedwithout anyfailedprint. Confirm all test cases pass. -
Coverage Verification
bash build.sh -u -c --cann_3rd_lib_path=$(pwd)/output/third_party # UT coverage bash build.sh -s -c --cann_3rd_lib_path=$(pwd)/output/third_party # ST coverage bash build.sh -c --cann_3rd_lib_path=$(pwd)/output/third_party # UT coverage + ST coverageAfter execution, check the coverage status through the output log. Confirm all test cases pass.
After installation, refer to Sample Execution to try running samples.