RunGraphAsync
产品支持情况
头文件/库文件
- 头文件:#include <ge/ge_api_v2.h>
- 库文件:libge_runner_v2.so
功能说明
异步运行指定ID对应的Graph图,输出运行结果。
- 本接口与RunGraph/RunGraphWithStreamAsync互斥,若在调用本接口前未执行LoadGraph完成图加载,则本接口将自动调用LoadGraph以完成加载。
- 本接口与RunGraph均为执行指定id对应的图,并输出结果,区别于RunGraph的是,该接口:
- 异步运行。
- 用户通过回调函数RunAsyncCallbackV2获取图计算结果,即用户自行定义函数RunAsyncCallbackV2。该回调函数,当Status为SUCCESS时,即可处理数据。
函数原型
Status RunGraphAsync(uint32_t graph_id, const std::vector<gert::Tensor> &inputs, RunAsyncCallbackV2 callback)
参数说明
返回值说明
约束说明
无
调用示例
-
调用接口AddGraph加载子图。
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); -
用户自定义RunAsyncCallbackV2,来决定如何处理数据,例如:
void CallBack(Status result, std::vector<gert::Tensor> &out_tensor) { if(result == ge::SUCCESS) { // 读取out_tensor数据, 用户根据需求处理数据; for(auto &tensor : out_tensor) { auto data = tensor.GetAddr(); int64_t length = tensor.GetSize(); } } } -
定义好指定图的输入数据const std::vectorgert::Tensor\ &inputs。
-
调用接口RunGraphAsync(graph_id, inputs, CallBack)。