CreateConst

Applicable Products

All processors

Header File/Library File

  • Header file: #include <ge/es_graph_builder.h>
  • Library files: libeager_style_graph_builder_base.so and libeager_style_graph_builder_base_static.a

Function Usage

Creates a Const operator.

Prototype

  • Create a Const operator of the int64 type.
    1
    EsTensorHolder CreateConst(const std::vector<int64_t> &value, const std::vector<int64_t> dims)
    
  • Create a Const operator of the int32 type.
    1
    EsTensorHolder CreateConst(const std::vector<int32_t> &value, const std::vector<int64_t> dims)
    
  • Create a Const operator of the uint64 type.
    1
    EsTensorHolder CreateConst(const std::vector<uint64_t> &value, const std::vector<int64_t> dims)
    
  • Create a Const operator of the uint32 type.
    1
    EsTensorHolder CreateConst(const std::vector<uint32_t> &value, const std::vector<int64_t> dims)
    
  • Create a Const operator of the float type.
    1
    EsTensorHolder CreateConst(const std::vector<float> &value, const std::vector<int64_t> dims)
    
  • Create a Const operator of a specified type, format, and dimension (using a general template). This prototype will be deprecated in the future. You are advised to use CreateConstV2.
    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)
    

    The general template method of CreateConst uses the IrDefOutputs or IrDefAttrs API internally. The IR definition structure contains the std::string field, and the compatibility between different C++ ABI configurations is not guaranteed. This API is reserved for compatibility with old software packages.

    If ABI security is required, use CreateConstV2 (see CreateConstV2). CreateConstV2 requires that the runtime software package support the CompliantNodeBuilder V2 API.

Parameters

Parameter

Input/Output

Description

value

Input

Tensor data vector.

dims

Input

Tensor dimension vector.

T

Input

Tensor data type.

dt

Input

Tensor data type.

format

Input

Tensor format. The default value is FORMAT_ND.

Returns

Parameter

Type

Description

-

EsTensorHolder

Tensor holder operator of the created Const. If the operation fails, an invalid EsTensorHolder is returned.

Restrictions

None

Example

  • Create a Const operator of the int64 type.
    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);
    
  • Create a Const operator of a specified type, format, and dimension (using a general template).
    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);