Quick Start
This section provides example commands for quickly installing the CANN software. For details, see the CANN Software Installation Guide.
You are advised to use the online installation (Conda) method. It allows you to directly install the software package of the latest or specified version without installing the dependencies in advance.
Preparing for Installation
- Before installing the CANN, ensure that the NPU driver and firmware have been installed. Run the query command to query the driver information. If the driver information is returned and no exception occurs, you can continue to install the CANN. If the NPU driver and firmware are not installed, install them by referring to "Installing the NPU Driver and Firmware".
1npu-smi info - Except for the online installation (Conda) method, ensure that the Python environment and pip3 are available when using other installation methods. Currently, the CANN supports Python 3.7.x to 3.13.x.
- Online installation (Conda): The installation directory of the Conda virtual environment and all its upper-level directories must have the 755 permission.
- Offline installation: Click here to download the CANN package and upload it to any path in the installation environment.
To upgrade an earlier version to CANN 8.5.0, you must use parameters or uninstall all earlier versions and then install CANN 8.5.0. Otherwise, the installation may fail.
Installing CANN
Product Type |
OS |
Installation Method |
Installation Command |
||
|---|---|---|---|---|---|
Atlas A3 series |
openEuler |
Online installation (Conda) |
|
||
Online installation (Yum) |
|
||||
Offline installation |
|
||||
Ubuntu |
Online installation (Conda) |
|
|||
Offline installation |
|
||||
Debian |
Online installation (Conda) |
|
|||
Offline installation |
|
||||
Kylin |
Online installation (Conda) |
|
|||
Online installation (Yum) |
|
||||
Offline installation |
|
||||
CentOS |
Online installation (Conda) |
|
|||
Online installation (Yum) |
|
||||
Offline installation |
|
||||
BCLinux |
Online installation (Conda) |
|
|||
Online installation (Yum) |
|
||||
Offline installation |
|
||||
UOSV20 |
Online installation (Conda) |
|
|||
Online installation (Yum) |
|
||||
Offline installation |
|
||||
AntOS |
Online installation (Conda) |
|
|||
Online installation (Yum) |
|
||||
Offline installation |
|
||||
AliOS |
Online installation (Conda) |
|
|||
Online installation (Yum) |
|
||||
Offline installation |
|
||||
CTyunOS |
Online installation (Conda) |
|
|||
Online installation (Yum) |
|
||||
Offline installation |
|
||||
CULinux |
Online installation (Conda) |
|
|||
Online installation (Yum) |
|
||||
Offline installation |
|
||||
Tlinux |
Online installation (Conda) |
|
|||
Online installation (Yum) |
|
||||
Offline installation |
|
||||
MTOS |
Online installation (Conda) |
|
|||
Online installation (Yum) |
|
||||
Offline installation |
|
||||
vesselOS |
Online installation (Conda) |
|
|||
Online installation (Yum) |
|
||||
Offline installation |
|
||||
veLinux |
Online installation (Conda) |
|
|||
Offline installation |
|
||||
Atlas A2 series |
openEuler |
Online installation (Conda) |
|
||
Online installation (Yum) |
|
||||
Offline installation |
|
||||
Ubuntu |
Online installation (Conda) |
|
|||
Offline installation |
|
||||
Debian |
Online installation (Conda) |
|
|||
Offline installation |
|
||||
Kylin |
Online installation (Conda) |
|
|||
Online installation (Yum) |
|
||||
Offline installation |
|
||||
CentOS |
Online installation (Conda) |
|
|||
Online installation (Yum) |
|
||||
Offline installation |
|
||||
BCLinux |
Online installation (Conda) |
|
|||
Online installation (Yum) |
|
||||
Offline installation |
|
||||
UOSV20 |
Online installation (Conda) |
|
|||
Online installation (Yum) |
|
||||
Offline installation |
|
||||
AntOS |
Online installation (Conda) |
|
|||
Online installation (Yum) |
|
||||
Offline installation |
|
||||
AliOS |
Online installation (Conda) |
|
|||
Online installation (Yum) |
|
||||
Offline installation |
|
||||
CTyunOS |
Online installation (Conda) |
|
|||
Online installation (Yum) |
|
||||
Offline installation |
|
||||
CULinux |
Online installation (Conda) |
|
|||
Online installation (Yum) |
|
||||
Offline installation |
|
||||
Tlinux |
Online installation (Conda) |
|
|||
Online installation (Yum) |
|
||||
Offline installation |
|
||||
MTOS |
Online installation (Conda) |
|
|||
Online installation (Yum) |
|
||||
Offline installation |
|
||||
vesselOS |
Online installation (Conda) |
|
|||
Online installation (Yum) |
|
||||
Offline installation |
|
||||
veLinux |
Online installation (Conda) |
|
|||
Offline installation |
|
||||
Atlas training series |
openEuler |
Online installation (Conda) |
|
||
Online installation (Yum) |
|
||||
Offline installation |
|
||||
Ubuntu |
Online installation (Conda) |
|
|||
Offline installation |
|
||||
Debian |
Online installation (Conda) |
|
|||
Offline installation |
|
||||
Kylin |
Online installation (Conda) |
|
|||
Online installation (Yum) |
|
||||
Offline installation |
|
||||
CentOS |
Online installation (Conda) |
|
|||
Online installation (Yum) |
|
||||
Offline installation |
|
||||
BCLinux |
Online installation (Conda) |
|
|||
Online installation (Yum) |
|
||||
Offline installation |
|
||||
UOSV20 |
Online installation (Conda) |
|
|||
Online installation (Yum) |
|
||||
Offline installation |
|
||||
AntOS |
Online installation (Conda) |
|
|||
Online installation (Yum) |
|
||||
Offline installation |
|
||||
AliOS |
Online installation (Conda) |
|
|||
Online installation (Yum) |
|
||||
Offline installation |
|
||||
CTyunOS |
Online installation (Conda) |
|
|||
Online installation (Yum) |
|
||||
Offline installation |
|
||||
CULinux |
Online installation (Conda) |
|
|||
Online installation (Yum) |
|
||||
Offline installation |
|
||||
Tlinux |
Online installation (Conda) |
|
|||
Online installation (Yum) |
|
||||
Offline installation |
|
||||
MTOS |
Online installation (Conda) |
|
|||
Online installation (Yum) |
|
||||
Offline installation |
|
||||
vesselOS |
Online installation (Conda) |
|
|||
Online installation (Yum) |
|
||||
Offline installation |
|
||||
veLinux |
Online installation (Conda) |
|
|||
Offline installation |
|
||||
Atlas inference series |
openEuler |
Online installation (Conda) |
|
||
Online installation (Yum) |
|
||||
Offline installation |
|
||||
Ubuntu |
Online installation (Conda) |
|
|||
Offline installation |
|
||||
Debian |
Online installation (Conda) |
|
|||
Offline installation |
|
||||
Kylin |
Online installation (Conda) |
|
|||
Online installation (Yum) |
|
||||
Offline installation |
|
||||
CentOS |
Online installation (Conda) |
|
|||
Online installation (Yum) |
|
||||
Offline installation |
|
||||
BCLinux |
Online installation (Conda) |
|
|||
Online installation (Yum) |
|
||||
Offline installation |
|
||||
UOSV20 |
Online installation (Conda) |
|
|||
Online installation (Yum) |
|
||||
Offline installation |
|
||||
AntOS |
Online installation (Conda) |
|
|||
Online installation (Yum) |
|
||||
Offline installation |
|
||||
AliOS |
Online installation (Conda) |
|
|||
Online installation (Yum) |
|
||||
Offline installation |
|
||||
CTyunOS |
Online installation (Conda) |
|
|||
Online installation (Yum) |
|
||||
Offline installation |
|
||||
CULinux |
Online installation (Conda) |
|
|||
Online installation (Yum) |
|
||||
Offline installation |
|
||||
Tlinux |
Online installation (Conda) |
|
|||
Online installation (Yum) |
|
||||
Offline installation |
|
||||
MTOS |
Online installation (Conda) |
|
|||
Online installation (Yum) |
|
||||
Offline installation |
|
||||
vesselOS |
Online installation (Conda) |
|
|||
Online installation (Yum) |
|
||||
Offline installation |
|
||||
veLinux |
Online installation (Conda) |
|
|||
Offline installation |
|
||||
Atlas 200I/500 A2 inference series |
openEuler |
Online installation (Conda) |
|
||
Online installation (Yum) |
|
||||
Offline installation |
|
||||
Ubuntu |
Online installation (Conda) |
|
|||
Offline installation |
|
||||
Debian |
Online installation (Conda) |
|
|||
Offline installation |
|
||||
Kylin |
Online installation (Conda) |
|
|||
Online installation (Yum) |
|
||||
Offline installation |
|
||||
CentOS |
Online installation (Conda) |
|
|||
Online installation (Yum) |
|
||||
Offline installation |
|
||||
BCLinux |
Online installation (Conda) |
|
|||
Online installation (Yum) |
|
||||
Offline installation |
|
||||
UOSV20 |
Online installation (Conda) |
|
|||
Online installation (Yum) |
|
||||
Offline installation |
|
||||
AntOS |
Online installation (Conda) |
|
|||
Online installation (Yum) |
|
||||
Offline installation |
|
||||
AliOS |
Online installation (Conda) |
|
|||
Online installation (Yum) |
|
||||
Offline installation |
|
||||
CTyunOS |
Online installation (Conda) |
|
|||
Online installation (Yum) |
|
||||
Offline installation |
|
||||
CULinux |
Online installation (Conda) |
|
|||
Online installation (Yum) |
|
||||
Offline installation |
|
||||
Tlinux |
Online installation (Conda) |
|
|||
Online installation (Yum) |
|
||||
Offline installation |
|
||||
MTOS |
Online installation (Conda) |
|
|||
Online installation (Yum) |
|
||||
Offline installation |
|
||||
vesselOS |
Online installation (Conda) |
|
|||
Online installation (Yum) |
|
||||
Offline installation |
|
||||
veLinux |
Online installation (Conda) |
|
|||
Offline installation |
|
Sample Running
This sample uses the Abs operator as an example to demonstrate the operator call logic, process, and build script. Modify the API call script (*.cpp) and build script (CMakeLists) as needed. Note that the sample is compiled using CMake. Ensure that CMake 3.14 or later has been installed in the environment.
- Run the following command to configure environment variables:
source ${install_path}/set_env.sh${install_path} indicates the installation directory of the CANN software, for example, /usr/local/Ascend/cann.
- Create the sample code file test_abs.cpp in any directory (for example, /home) and write the following content to the file:
#include <iostream> #include <vector> #include "acl/acl.h" #include "aclnnop/aclnn_abs.h" #define CHECK_RET(cond, return_expr) \ do { \ if (!(cond)) { \ return_expr; \ } \ } while (0) #define LOG_PRINT(message, ...) \ do { \ printf(message, ##__VA_ARGS__); \ } while (0) int64_t GetShapeSize(const std::vector<int64_t>& shape) { int64_t shapeSize = 1; for (auto i : shape) { shapeSize *= i; } return shapeSize; } void PrintOutResult(std::vector<int64_t> &shape, void** deviceAddr) { auto size = GetShapeSize(shape); std::vector<float> resultData(size, 0); auto ret = aclrtMemcpy(resultData.data(), resultData.size() * sizeof(resultData[0]), *deviceAddr, size * sizeof(resultData[0]), ACL_MEMCPY_DEVICE_TO_HOST); CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("copy result from device to host failed. ERROR: %d\n", ret); return); for (int64_t i = 0; i < size; i++) { LOG_PRINT("mean result[%ld] is: %f\n", i, resultData[i]); } } int Init(int32_t deviceId, aclrtStream* stream) { // The initialization code is written in a fixed format. auto ret = aclInit(nullptr); CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclInit failed. ERROR: %d\n", ret); return ret); ret = aclrtSetDevice(deviceId); CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclrtSetDevice failed. ERROR: %d\n", ret); return ret); ret = aclrtCreateStream(stream); CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclrtCreateStream failed. ERROR: %d\n", ret); return ret); return 0; } template <typename T> int CreateAclTensor(const std::vector<T>& hostData, const std::vector<int64_t>& shape, void** deviceAddr, aclDataType dataType, aclTensor** tensor) { auto size = GetShapeSize(shape) * sizeof(T); // Call aclrtMalloc to allocate device memory. auto ret = aclrtMalloc(deviceAddr, size, ACL_MEM_MALLOC_HUGE_FIRST); CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclrtMalloc failed. ERROR: %d\n", ret); return ret); // Call aclrtMemcpy to copy the data from the host to the device. ret = aclrtMemcpy(*deviceAddr, size, hostData.data(), size, ACL_MEMCPY_HOST_TO_DEVICE); CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclrtMemcpy failed. ERROR: %d\n", ret); return ret); // Calculate the strides of consecutive tensors. std::vector<int64_t> strides(shape.size(), 1); for (int64_t i = shape.size() - 2; i >= 0; i--) { strides[i] = shape[i + 1] * strides[i + 1]; } // Call aclCreateTensor to create an aclTensor. *tensor = aclCreateTensor(shape.data(), shape.size(), dataType, strides.data(), 0, aclFormat::ACL_FORMAT_ND, shape.data(), shape.size(), *deviceAddr); return 0; } int main() { // 1. (Fixed format) Initialize the device and stream. For details, see the acl API reference. // Set deviceId based on the actual device. int32_t deviceId = 0; aclrtStream stream; auto ret = Init(deviceId, &stream); CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("Init acl failed. ERROR: %d\n", ret); return ret); // 2. Construct the input and output based on the API definition. std::vector<int64_t> selfShape = {4, 2}; std::vector<int64_t> outShape = {4, 2}; void* selfDeviceAddr = nullptr; void* outDeviceAddr = nullptr; aclTensor* self = nullptr; aclTensor* out = nullptr; std::vector<float> selfHostData = {1, -1, -1, -2, 2, -2, -3, 3}; std::vector<float> outHostData = {1, -1, -1, -2, 2, -2, -3, 3}; ret = CreateAclTensor(selfHostData, selfShape, &selfDeviceAddr, aclDataType::ACL_FLOAT, &self); CHECK_RET(ret == ACL_SUCCESS, return ret); ret = CreateAclTensor(outHostData, outShape, &outDeviceAddr, aclDataType::ACL_FLOAT, &out); CHECK_RET(ret == ACL_SUCCESS, return ret); // 3. Call the CANN operator library API. Change the API name to the actual one. uint64_t workspaceSize = 0; aclOpExecutor* executor; // Call the first-phase API of aclnnAbs. ret = aclnnAbsGetWorkspaceSize(self, out, &workspaceSize, &executor); CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclnnAbsGetWorkspaceSize failed. ERROR: %d\n", ret); return ret); // Allocate device memory based on workspaceSize calculated by the first-phase API. void* workspaceAddr = nullptr; if (workspaceSize > 0) { ret = aclrtMalloc(&workspaceAddr, workspaceSize, ACL_MEM_MALLOC_HUGE_FIRST); CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("allocate workspace failed. ERROR: %d\n", ret); return ret); } // Call the second-phase API of aclnnAbs. ret = aclnnAbs(workspaceAddr, workspaceSize, executor, stream); CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclnnAbs failed. ERROR: %d\n", ret); return ret); // 4. (Fixed format) Wait until the execution is complete. ret = aclrtSynchronizeStream(stream); CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclrtSynchronizeStream failed. ERROR: %d\n", ret); return ret); // 5. Obtain the output value and copy the result from the device memory to the host. Modify the code based on the API definition. PrintOutResult(outShape, &outDeviceAddr); // 6. Destroy aclTensor. Modify the code based on the API definition. aclDestroyTensor(self); aclDestroyTensor(out); // 7. Destroy device resources. aclrtFree(selfDeviceAddr); aclrtFree(outDeviceAddr); if (workspaceSize > 0) { aclrtFree(workspaceAddr); } aclrtDestroyStream(stream); aclrtResetDevice(deviceId); aclFinalize(); return 0; } - Create the CMakeLists.txt file and write the following content to the file. Modify the content as needed.
# Copyright (c) Huawei Technologies Co., Ltd. 2019. All rights reserved. # CMake lowest version requirement cmake_minimum_required(VERSION 3.14) # Set the project name. project(ACLNN_EXAMPLE) # Compile options add_compile_options(-std=c++11) # Set the build options. set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "./bin") set(CMAKE_CXX_FLAGS_DEBUG "-fPIC -O0 -g -Wall") set(CMAKE_CXX_FLAGS_RELEASE "-fPIC -O2 -Wall") # Set the executable file name (for example, opapi_test) and specify the directory of the .cpp file of the operator to be run. add_executable(opapi_test test_abs.cpp) # Set ASCEND_PATH (CANN package directory) and INCLUDE_BASE_DIR (header file directory). if(NOT "$ENV{ASCEND_HOME_PATH}" STREQUAL "") set(ASCEND_PATH $ENV{ASCEND_HOME_PATH}) else() set(ASCEND_PATH "/usr/local/Ascend/cann") endif() set(INCLUDE_BASE_DIR "${ASCEND_PATH}/include") include_directories( ${INCLUDE_BASE_DIR} ${INCLUDE_BASE_DIR}/aclnn ) # Set the path of the linked library file. target_link_libraries(opapi_test PRIVATE ${ASCEND_PATH}/lib64/libascendcl.so ${ASCEND_PATH}/lib64/libnnopbase.so ${ASCEND_PATH}/lib64/libopapi_math.so) # The executable file is stored in the bin directory of the directory where the CMakeLists file is located. install(TARGETS opapi_test DESTINATION ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}) - In the directory where CMakeLists.txt is located, run the following command to create the build directory for storing the generated build file:
mkdir -p build
- Go to the build directory, run the cmake command to build the file, and then run the make command to generate an executable file.
cd build cmake ../ -DCMAKE_CXX_COMPILER=g++ -DCMAKE_SKIP_RPATH=TRUE make
After the build is successful, the executable file opapi_test is generated in the bin folder in the build directory.
- Go to the bin directory and run the executable file opapi_test.
cd bin ./opapi_test
The following is an example of the execution result of the Abs operator:
mean result[0] is: 1.000000 mean result[1] is: 1.000000 mean result[2] is: 1.000000 mean result[3] is: 2.000000 mean result[4] is: 2.000000 mean result[5] is: 2.000000 mean result[6] is: 3.000000 mean result[7] is: 3.000000