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

#### 产品支持情况

| 产品 | 是否支持 |
| --- | --- |
| 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


#### 功能说明

创建Const算子。


#### 函数原型

- 创建int64类型的Const算子
  1 EsTensorHolder CreateConst(const std::vector<int64_t> &value, const std::vector<int64_t> dims)

- 创建int32类型的Const算子
  1 EsTensorHolder CreateConst(const std::vector<int32_t> &value, const std::vector<int64_t> dims)

- 创建uint64类型的Const算子
  1 EsTensorHolder CreateConst(const std::vector<uint64_t> &value, const std::vector<int64_t> dims)

- 创建uint32类型的Const算子
  1 EsTensorHolder CreateConst(const std::vector<uint32_t> &value, const std::vector<int64_t> dims)

- 创建float类型的Const算子
  1 EsTensorHolder CreateConst(const std::vector<float> &value, const std::vector<int64_t> dims)

- 创建指定类型、格式和维度的Const算子（通用模板方法）
  1 2 template <typename T> EsTensorHolder CreateConst(const std::vector<T> &value, const std::vector<int64_t> &dims, ge::DataType dt,ge::Format format = FORMAT_ND)


#### 参数说明

| 参数名 | 输入/输出 | 说明 |
| --- | --- | --- |
| value | 输入 | 张量数据向量。 |
| dims | 输入 | 张量维度向量。 |
| T | 输入 | 张量数据类型。 |
| dt | 输入 | 张量的数据类型。 |
| format | 输入 | 张量格式，默认为FORMAT\_ND。 |


#### 返回值说明

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


#### 约束说明

无


#### 调用示例

- 创建int64类型的Const算子：
  1 2 3 4 EsGraphBuilder builder("test_graph"); std::vector<int64_t> dims = {3}; std::vector<int64_t> vec64 = {1, 2, 3}; auto c1 = builder.CreateConst(vec64, dims);

- 创建指定类型、格式和维度的Const算子：
  1 2 3 4 EsGraphBuilder builder("test_graph"); std::vector<float> vecf = {1.1, 2.0, 3.2, 4.4}; std::vector<int64_t> dims = {4}; auto c1 = builder.CreateConst<float>(vecf, dims, ge::DT_FLOAT);
