Basic Data Structures and API List

This document describes the basic data structures and APIs required for operator development and graph development. The data structures and APIs are classified as follows:

  • Graph Engine (ge) namespace

    ge is a general namespace dedicated to graph construction and compilation. It provides a rich set of APIs for building and managing complex graph structures. With universality and flexibility, it can meet various graph processing requirements in the design and compilation processes.

  • GE Runtime (gert) namespace

    gert is the namespace designed for the runtime environment and provides a series of high-performance data structures to ensure optimal performance during execution.

  • C API

    C API is a C language API for operator and graph development.

gert Namespace

Table 1 gert namespace

Category

Data Structure/API

Function

Class and structure

AnchorInstanceInfo

Describes the relationship between the input of the IR prototype definition of the operator and the actual input.

The header file is in include/exe_graph/runtime/compute_node_info.h under the CANN component directory.

CompileTimeTensorDesc

Describes the tensor information during compilation, including the dtype and format information.

The header file is in include/exe_graph/runtime/compute_node_info.h under the CANN component directory.

ComputeNodeInfo

Serializes and saves operator compilation information so that the information can be efficiently obtained during graph execution.

The header file is in include/exe_graph/runtime/compute_node_info.h under the CANN component directory.

ContextHolder

Manages the context for implementing function execution for operators on the host. The constructed context stores only pointers. To facilitate lifecycle and ownership management, the ContextHolder class is provided for resource management.

The header file is in include/base/context_builder/context_holder.h under the CANN component directory.

ContinuousVectorVector

Allocates a continuous space in the memory to store data descriptions and actual data elements. The element type is ContinuousVector.

The header file is in include/exe_graph/runtime/continuous_vector.h under the CANN component directory.

ContinuousVector

This class is a POD class, which allocates a continuous space in the memory to store descriptions and actual memory data.

The header file is in include/exe_graph/runtime/continuous_vector.h under the CANN component directory.

ExpandDimsType

Defines the rules for expanding dimensions based on the shapes resulting from the expansion.

The header file is in include/exe_graph/runtime/expand_dims_type.h under the CANN component directory.

ExtendedKernelContext

Base class of InferShapeContext and TilingContext. The methods provided in ExtendedKernelContext, such as the APIs for obtaining the operator type, name, and attributes, can be called in the InferShape and tiling functions.

The header file is in include/exe_graph/runtime/extended_kernel_context.h under the CANN component directory.

InferDataTypeContext

Context structure used for datatype derivation.

The header file is in include/exe_graph/runtime/infer_datatype_context.h under the CANN component directory.

InferFormatContext

InferFormatContext is inherited from ExtendedKernelContext and is a context class used for format derivation.

The header file is located in include/graph/infer_format_context.h under the CANN component directory.

InferShapeContext

Context structure used for shape derivation.

The header file is in include/exe_graph/runtime/infer_shape_context.h under the CANN component directory.

InferShapeRangeContext

Context structure used for shape range derivation.

The header file is in include/exe_graph/runtime/infer_shape_range_context.h under the CANN component directory.

OpContextBuilderBase

OpContextBuilderBase is the base class of each ContextBuilder. It is used to construct operator information in the subclass Context, including the operator type, name, number of input and output prototypes, number of input and output instances, and attributes.

The header file is in include/base/context_builder/op_context_builder_base.h under the CANN component directory.

OpImplRegisterV2

As a registration API class, OpImplRegisterV2 provides a series of operator prototype registration APIs for users to register information of a specific operator type, including the tiling function, Infershape function, and private attributes. This class is indirectly used when users call the operator prototype registration API for registration.

The header file is in include/register/op_impl_registry.h under the CANN component directory.

OpInferDataTypeContextBuilder

OpInferDataTypeContextBuilder is used to construct InferDataTypeContext. The constructed Context serves as an input parameter during operator data type inference to obtain necessary operator input and output data. After the inference is complete, the result is written back to the context.

The header file is in include/base/context_builder/op_infer_datatype_context_builder.h under the CANN component directory.

OpInferShapeContextBuilder

OpInferShapeContextBuilder is used to construct InferShapeContext. The constructed Context serves as an input parameter during operator Shape inference to obtain necessary operator input and output data. After the inference is complete, the result is written back to the context.

The header file is in include/base/context_builder/op_infer_shape_context_builder.h under the CANN component directory.

OpInferShapeRangeContextBuilder

OpInferShapeRangeContextBuilder is used to construct InferShapeRangeContext. The constructed context serves as an input parameter during operator ShapeRange inference to obtain necessary operator input and output data. After the inference is complete, the result is written back to the context.

The header file is in include/base/context_builder/op_infer_shape_range_context_builder.h under the CANN component directory.

OpKernelContextBuilder

Constructs a common KernelContext object, which is used as the input context of the operator Host in the actual execution phase.

The header file is in include/base/context_builder/op_kernel_run_context_builder.h under the CANN component directory.

OpTilingContextBuilder

OpTilingContextBuilder is used to construct TilingContext. The constructed context serves as an input parameter during operator tiling computation to obtain necessary data like the operator input and output. After the tilling computation is complete, the result is written back to the context.

The header file is in include/base/context_builder/op_tiling_context_builder.h under the CANN component directory.

OpTilingParseContextBuilder

OpTilingParseContextBuilder is used to construct TilingParseContext. The constructed context serves as an input parameter during operator TilingParse computation to obtain necessary operator input and output data. After the Parser computation is complete, the result is written back to the context.

The header file is in include/base/context_builder/op_tiling_parse_context_builder.h under the CANN component directory.

Range

Describes the upper and lower bounds of an object.

The header file is in include/exe_graph/runtime/range.h under the CANN component directory.

RuntimeAttrs

Stores operator attributes.

The header file is in include/exe_graph/runtime/runtime_attrs.h under the CANN component directory.

Shape

Describes the shape of a tensor.

The header file is in include/exe_graph/runtime/shape.h under the CANN component directory.

StorageFormat

Includes the original format, runtime format, and dimension expansion rule.

The header file is in include/exe_graph/runtime/storage_format.h under the CANN component directory.

StorageShape

Describes shapes of a tensor, including origin_shape and storage_shape.

The header file is in include/exe_graph/runtime/storage_shape.h under the CANN component directory.

TensorData

Stores tensor data.

The header file is in include/exe_graph/runtime/tensor_data.h under the CANN component directory.

TensorPlacementUtils

Provides a group of functions to determine the position of TensorPlacement.

The header file is in include/exe_graph/runtime/tensor_data.h under the CANN component directory.

Tensor

Describes the information and behavior of a tensor object, including the shape, format, datatype, and tensor data.

The header file is in include/exe_graph/runtime/tensor.h under the CANN component directory.

TilingContext

Context structure used for operator tiling.

The header file is in include/exe_graph/runtime/tiling_context.h under the CANN component directory.

TilingData

Stores tiling data.

The header file is in include/exe_graph/runtime/tiling_data.h under the CANN component directory.

TypedContinuousVector

Inherits from the ContinuousVector class. Unlike the ContinuousVector class, MutableData and GetData return addresses of a specified type instead of void *. Therefore, Typed is added to the class name.

The header file is in include/exe_graph/runtime/continuous_vector.h under the CANN component directory.

Enum

TensorPlacement

Enumerates the tensor locations.

The header file is in include/exe_graph/runtime/tensor_data.h under the CANN component directory.

ge Namespace

Table 2 ge namespace

Category

Data Structure/API

Function

Class and structure

Allocator

Supports the external allocator registered by users.

The header file is in include/ge/ge_allocator.h under the CANN component directory.

AscendString

Stores strings.

  • The header file is in include/graph/ascend_string.h under the CANN component directory.
  • Library file: libgraph.so

AutoMappingSubgraphIOIndexFuncRegister

An internal associated API, used during plugin adaptation, is called indirectly and remains imperceptible to developers.

FrameworkRegistry

An internal associated API, used during plugin adaptation, is called indirectly and remains imperceptible to developers.

IntegerChecker

Functions as a template class with template parameter T. It is used to check whether an integer is within the valid range of the specified data type T.

The header file is in include/utils/extern_math_util.h under the CANN component directory.

KernelLaunchInfo

Provides APIs for creating and managing tasks delivered to devices. The APIs allow developers to set or obtain the launch information about the tasks to be delivered to devices.

The header file is in include/graph/kernel_launch_info.h under the CANN component directory.

ListTensorType

Defines the data types supported by the input or output. It is the encapsulation of TensorType and is used to list the multiple supported data types.

The header file is in include/graph/types.h under the CANN component directory.

MemBlock

Used together with the Allocator class to support the external allocator registered by users.

The header file is in include/ge/ge_allocator.h under the CANN component directory.

OpReceiver

Receives the registration information of custom operators for the development of plugins to adapt to AI frameworks.

The header file is in include/register/register.h under the CANN component directory.

OpRegistrationData

Registers the mapping relationship when writing adapter plugins to adapt operators for AI framework integration.

The header file is in include/register/register.h under the CANN component directory.

PassReceiver

Receives the registration information of a custom pass.

  • Header file: /include/register/register_custom_pass.h
  • Library file: libregister.so

PassRegistrationData

Registers the mapping relationship of a custom pass.

  • Header file: /include/register/register_custom_pass.h
  • Library file: libregister.so

Class and structure

Promote

Indicates that the output data type is the promotion type between the data types specified by the input or attribute.

The header file is in include/graph/types.h under the CANN component directory.

Shape

Stores the shape information of a tensor.

  • The header file is in include/graph/tensor.h under the CANN component directory.
  • Library file: libgraph_base.so

TensorDescInfo

Stores the tensor description.

The header file is in include/graph/types.h under the CANN component directory.

TensorDesc

Accesses and manages the tensor description.

  • The header file is in include/graph/tensor.h under the CANN component directory.
  • Library file: libgraph_base.so

TensorType

Defines the data types supported by the input or output.

The header file is in include/graph/types.h under the CANN component directory.

Tensor

Tensor structure.

  • The header file is in include/graph/tensor.h under the CANN component directory.
  • Library file: libgraph_base.so

TypeUtils

Type conversion utility class.

The header file is in include/graph/utils/type_utils.h under the CANN component directory.

Function

AddOverflow

A template function to determine whether overflow occurs when two numbers are added. If no overflow occurs, the correct computation result is returned.

The header file is in include/utils/extern_math_util.h under the CANN component directory.

ConvertToAscendString

A template function to convert strings of different types to those of the AscendString type. Accepts a template argument T and converts it to the AscendString type.

The header file is in include/graph/operator_reg.h under the CANN component directory.

ConvertToListAscendString

Defines a template function ConvertToListAscendString to convert strings of different types to those of the AscendString type.

The header file is in include/graph/operator_reg.h under the CANN component directory.

GetC0Format

Obtains the value of C0 format based on the actual format.

The header file is in include/graph/types.h under the CANN component directory.

GetC0Value

Parses C0 format information from the actual format.

The header file is in include/graph/types.h under the CANN component directory.

GetFormatFromC0

Obtains the actual format based on the input format and C0 format.

The header file is in include/graph/types.h under the CANN component directory.

GetFormatFromSub

Obtains the actual format based on the input primary format and sub-format.

The header file is in include/graph/types.h under the CANN component directory.

GetFormatFromSubAndC0

Obtains the actual format based on the input primary format, sub-format, and C0 format.

The header file is in include/graph/types.h under the CANN component directory.

GetFormatName

Obtains the string description of the format based on the input format type.

The header file is in include/graph/types.h under the CANN component directory.

GetPrimaryFormat

Parses primary format information from the actual format.

The header file is in include/graph/types.h under the CANN component directory.

GetSizeByDataType

Obtains the memory size occupied by the passed data_type.

The header file is in include/graph/types.h under the CANN component directory.

GetSizeInBytes

Obtains the total memory size occupied by data_type (number specified by element_count) based on the input element_count and data_type.

The header file is in include/graph/types.h under the CANN component directory.

GetSubFormat

Parses sub-format information from the actual format.

The header file is in include/graph/types.h under the CANN component directory.

HasC0Format

Returns if the actual format contains a C0 format.

The header file is in include/graph/types.h under the CANN component directory.

HasSubFormat

Returns if the actual format contains a sub-format.

The header file is in include/graph/types.h under the CANN component directory.

MulOverflow

A template function to determine whether overflow occurs when two numbers are multiplied. If no overflow occurs, the correct computation result is returned.

The header file is in include/utils/extern_math_util.h under the CANN component directory.

Type definition

ge::graphStatus

Return code status description.

The header file is in include/graph/ge_error_codes.h under the CANN component directory.

Enum

DataType

Data type enum values.

The header file is in include/graph/types.h under the CANN component directory.

Format

Data format enum values.

The header file is in include/graph/types.h under the CANN component directory.

Macro

DECLARE_ERRORNO

Registers error codes along with their corresponding descriptions.

The header file is in include/register/register_error_codes.h under the CANN component directory.

C API

Data Structure/API

Function

C_DataType

Data type enum values.

The header file is in include/graph/c_types.h under the CANN component directory.

C_Format

Data format enum values.

The header file is in include/graph/c_types.h under the CANN component directory.