Operator Call Example

For details about the operator call example, see Source Code.

Case Overview

This case is an ATB single-operator example.

This case includes the following parts:

  • Prepare the input tensor of atb::VariantPack.
  • Prepare operator parameters and create an operator.
  • Main function: sets a device ID, creates a context, and configures streams; sets up and executes operators; clears the memory and releases resources.

Directory Structure

atb-linear-demo example project
|-- demo_util.h
|-- linear_demo.cpp

Case Execution

  1. Before the call, set the ascend-toolkit and atb environment variables.
    1
    2
    source ${toolkit installation directory}/set_env.sh # For example, source /usr/local/Ascend/ascend-toolkit/set_env.sh
    source ${nnal installation directory}/atb/set_env.sh # For example, source /usr/local/Ascend/nnal/atb/set_env.sh
    
  2. Perform compilation.
    1
    g++ -I "${ATB_HOME_PATH}/include" -I "${ASCEND_HOME_PATH}/include" -L "${ATB_HOME_PATH}/lib" -L "${ASCEND_HOME_PATH}/lib64" xxxx.cpp demo_util.h -l atb -l ascendcl -o xxxx
    
  3. Execute the case.
    ./xxxx
  • When the HCCL operator is used, the compilation option -D_GLIBCXX_USE_CXX11_ABI=0 needs to be added.
  • When a training operator such as the backward operator is used, the dynamic link "${ATB_HOME_PATH}/lib/libatb_train.so" is required. That is, the compilation command is updated as follows:
    g++ ... demo_util.h "${ATB_HOME_PATH}/lib/libatb_train.so" ...