[object Object][object Object]
  • To compile and execute operator APIs, ensure that the basic environment has been set up, including the driver, firmware, CANN software package, and ops package.
  • For details about the process of calling operator APIs and the compilation and running operations, see "Single-Operator Calling" > "Single-Operator API Execution" > "Sample Code for Calling aclnn APIs" in .
[object Object]

Assume that the development environment and operating environment are deployed on the same server (equipped with the AI processor). In this scenario, code development and code running are performed on the same machine. The following uses the Abs operator as an example. The calling logic, process, and compilation script of other operators are similar to those of the Abs operator. You should modify the API calling script (*.cpp) and compilation script (CMakeLists) as required.

  • Sample code

    The Abs operator is used to calculate the absolute value of each element in a tensor. The calculation formula is y[object Object]i[object Object]=|x[object Object]i[object Object]|. You can obtain the sample code from the aclnnAbs document and name the code file test_abs.cpp.

  • CMakeLists file

    The following is an example of the CMake file, which should be modified as required.

    [object Object]

    Operators with integrated and parallel collective communication and MatMul computation are collectively referred to as merged compute and communication operators (abbreviated as MC2 operators), including AllGatherMatmul, AlltoAllAllGatherBatchMatMul, BatchMatMulReduceScatterAlltoAll, MatmulAllReduce, MatmulAllReduceAddRmsNorm, and MatmulReduceScatter. When these operator APIs are called, multi-threading and Huawei Collective Communication Library (HCCL) are generally involved. Therefore, the following content needs to be imported to the CMake file to ensure successful compilation:

    [object Object]

    You can use the find_package(Threads REQUIRED) of CMake to search for the thread library. The command can automatically link the header files on which the thread library depends or the library files on which the thread library indirectly depends.

[object Object]
  1. Prepare the calling code (*.cpp) and compilation script (CMakeLists.txt) of the operator.

  2. Set environment variables.

    After installing the CANN software, log in to the environment as the CANN running user and run the following command to make the environment variables take effect:

    [object Object]

    ${INSTALL_DIR} indicates the CANN component directory, which should be replaced with the actual directory.

  3. Compile and run the script.

    • Go to the directory where CMakeLists.txt is stored and run the following command to create the build folder to store the generated compilation file.

      [object Object]
    • Go to the build directory, run the cmake command to compile the code, and then run the make command to generate an executable file.

      [object Object]

      After the compilation is successful, the opapi_test executable file is generated in the bin folder in the current directory.

    • Go to the bin directory and run the executable file opapi_test.

      [object Object]

      The following uses the running result of the Abs operator as an example:

      [object Object]

      If an error is reported and the expected result is not displayed, you can call the aclGetRecentErrMsg API to obtain the error information. The following is an example of obtaining the error information when aclnnAbsGetWorkspaceSize is called:

      [object Object]

      The following is an example of the error information obtained when a null pointer is constructed:

      [object Object]