RunGraphAsync

Applicability

Product

Supported

Atlas 350 Accelerator Card

Atlas A3 training product/Atlas A3 inference product

Atlas A2 training product/Atlas A2 inference product

Atlas 200I/500 A2 inference product

x

Atlas inference product

Atlas training product

Header File/Library File

  • Header file: #include <ge/ge_api.h>
  • Library file: libge_runner.so

Function Usage

Asynchronously runs the graph of a specified ID and returns the execution result.

Both this API and RunGraph are used to run the graph of a specified ID and output the result. Specifically:

  • This API is asynchronous.
  • The allowed data has the same meaning, but different formats.
  • You can customize the RunAsyncCallback callback function to obtain the computation result of the graph. When the status of the callback function is success, data can be processed.

Prototype

1
Status RunGraphAsync(uint32_t graph_id, const std::vector<ge::Tensor> &inputs, RunAsyncCallback callback)

Parameters

Parameter

Input/Output

Description

graph_id

Input

Subgraph ID.

inputs

Input

Inputs of the subgraph.

When std::vector<Tensor> inputs are used and user inputs enter a data queue, memory must be allocated and copied for each input. A large input size or quantity may result in a performance bottleneck.

callback

Output

Callback function of the subgraph.

1
2
using Status = uint32_t;
using RunAsyncCallback = std::function<void(Status, std::vector<ge::Tensor> &)>;

Returns

Parameter

Type

Description

-

Status

GE_CLI_GE_NOT_INITIALIZED: GE is not initialized.

SUCCESS: The graph is successfully run by using the asynchronous API.

FAILED: The graph fails to be run by using the asynchronous API.

Restrictions

None

Example

  1. Call AddGraph to load a subgraph.
    1
    2
    3
    4
    5
    6
    std::map <AscendString, AscendString> options;
    ge::GeSession *session = new GeSession(options);
    
    uint32_t graph_id = 0;
    ge::Graph graph;
    Status ret = session->AddGraph(graph_id, graph);
    
  2. Customize RunAsyncCallback to process data as follows:
    1
    2
    3
    4
    5
    6
    7
    8
    9
    void CallBack(Status result, std::vector<ge::Tensor> &out_tensor) {
    if(result == ge::SUCCESS) {
    // Read the out_tensor data and process the data as required.
    for(auto &tensor : out_tensor) {
      auto data = tensor.GetData();
      int64_t length = tensor.GetSize();
      }
    }
    }
    
  3. Define the input data of the graph: const std::vector<ge::Tensor> &inputs
  4. Call RunGraphAsync(graph_id, inputs, CallBack).