---
title: RunGraphWithStreamAsync
description: "| 产品 | 是否支持 |"
url: https://www.hiascend.com/document/detail/zh/canncommercial/latest/API/ascendgraphapi/atlasgeapi_07_0098.html
sourcePath: /source/zh/canncommercial/900/API/ascendgraphapi/atlasgeapi_07_0098.html
indexId: b210d32a5687bd885a39adb1a1d435411339c802a7175b84b37c63d7242c887372
---
# RunGraphWithStreamAsync

#### 产品支持情况

| 产品 | 是否支持 |
| --- | --- |
| Atlas 350 加速卡 | √ |
| Atlas A3 训练系列产品 / Atlas A3 推理系列产品 | √ |
| Atlas A2 训练系列产品 / Atlas A2 推理系列产品 | √ |
| Atlas 200I/500 A2 推理产品 | x |
| Atlas 推理系列产品 | √ |
| Atlas 训练系列产品 | √ |


#### 头文件/库文件

- 头文件：#include <ge/ge_api.h>
- 库文件：libge_runner.so


#### 功能说明

异步运行指定ID对应的Graph图，输出运行结果。该接口包括了编译，加载和运行Graph的操作。

此函数与RunGraph均为运行指定ID对应的图，并输出结果，区别于RunGraph的是，该接口：

- 异步运行。
- inputs和outputs均为Device上的内存空间，且需要在运行前由用户分配内存大小。
  如下两种情况用户可以不分配输出内存：
  - 用户通过    RegisterExternalAllocator
设置了外置allocator，如果没有分配输出内存，由GE调用外置allocator的接口分配内存，用户需要在外置allocator析构前释放这块内存。
  - 用户没有设置外置allocator，动态图场景，如果没有分配输出内存，GE使用内置allocator分配内存，内存的生命周期与图的生命周期保持一致，用户需要在图卸载前（Session析构前、GEFinalize前）主动释放此内存。


#### 函数原型

```
Status RunGraphWithStreamAsync(uint32_t graph_id, void *stream, const std::vector<Tensor> &inputs,std::vector<Tensor> &outputs)
```


#### 参数说明

| 参数名 | 输入/输出 | 说明 |
| --- | --- | --- |
| graph\_id | 输入 | 子图对应的ID。 |
| stream | 输入 | 指定图在哪个Stream上运行。 |
| inputs | 输入 | 当前子图对应的输入数据，为Device上的内存空间。 如果通过options指定了ge.exec.hostInputIndexes参数，对应索引的Tensor可以为Host上的内存空间。 |
| outputs | 输出 | 当前子图对应的输出数据，为Device上的内存空间。 |


#### 返回值说明

| 参数名 | 类型 | 说明 |
| --- | --- | --- |
| \- | Status | SUCCESS：异步运行图成功。 FAILED：异步运行图失败。 |


#### 约束说明

- 调用该接口前，请先分配好Tensor需要使用的内存。
- Tensor在Device侧的存储地址，必须32字节对齐，否则可能会出现未定义错误。
- 调用该接口前，需要通过acl提供的aclrtCreateStream接口创建Stream，且只支持Stream为默认Context的场景。
- 得到输出运行结果前，需要通过aclrtSynchronizeStream接口保证Stream上的任务已经执行完。
  接口详细说明请参见“Stream管理(https://www.hiascend.comdocument/detail/zh/canncommercial/900/API/runtimeapi/aclcppdevg_03_0065.html)”。


#### 调用示例

请参见异步运行Graph(https://www.hiascend.comdocument/detail/zh/canncommercial/900/programug/graphdevg/atlasag_25_0034.html)。
