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

#### 产品支持情况

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


#### 头文件/库文件

- 头文件：#include <ge/es_graph_builder.h>
- 库文件：libeager_style_graph_builder_base.so、libeager_style_graph_builder_base_static.a


#### 功能说明

创建变量节点。


#### 函数原型

```
EsTensorHolder CreateVariable(int32_t index, const char *name)
```


#### 参数说明

| 参数名 | 输入/输出 | 说明 |
| --- | --- | --- |
| index | 输入 | 变量节点索引。 |
| name | 输入 | 变量节点名称，var的名称相同代表共享，因此需要显式指定。 |


#### 返回值说明

| 参数名 | 类型 | 说明 |
| --- | --- | --- |
| \- | EsTensorHolder | 返回创建的变量张量持有者，失败时返回无效的EsTensorHolder。 |


#### 约束说明

无


#### 调用示例

```
EsGraphBuilder builder("test_graph");
auto v1 = builder.CreateVariable(0, "var0");
```
