# 基础数据结构和接口列表

本文档提供了进行算子开发和图开发时依赖的基础数据结构和接口说明，按照命名空间进行分类：

* ge（Graph Engine）

  ge是Graph Engine的缩写，代表一个通用的命名空间，专注于构图和图编译处理。此命名空间提供了一套丰富的API，用于构建和管理复杂的图结构。它的核心优势在于其通用性和灵活性，能够满足各种图处理需求，无论是在设计阶段还是在编译过程中。
* gert（GE Runtime）

  gert是GE Runtime的缩写，这个命名空间专门为运行时环境而设计，提供了一系列的高性能数据结构，以确保在执行时能够提供最佳性能。

## gert命名空间

**表1** gert命名空间

|分类|数据结构/接口名称|功能描述|
|:----|:----------------------------------------------------------------------------------------------------------------------------------|:-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|类和结构体|[AnchorInstanceInfo](https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/cannkit-anchorinstanceinfo-introduction)|用来描述一个算子的IR定义原型的输入信息与实际输入之间的关系。|
|类和结构体|[CompileTimeTensorDesc](https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/cannkit-compiletimetensordesc-constructor)|用于描述编译时的Tensor描述信息，包含dtype信息以及format信息。|
|类和结构体|[ComputeNodeInfo](https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/cannkit-computenodeinfo-introduction)|用于将算子的相关编译信息进行序列化保存，以便可以在图执行阶段能够高效地获取这些信息。|
|类和结构体|[ContinuousVectorVector](https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/cannkit-continuousvectorvector-introduction)|在内存中开辟一块连续的空间，用于存储数据的描述信息以及实际的数据元素，元素类型为ContinuousVector结构。|
|类和结构体|[ContinuousVector](https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/cannkit-continuousvector-introduction)|本类是一个POD类，在内存中开辟一块连续的空间用于存储描述信息以及实际内存数据。|
|类和结构体|[ExpandDimsType](https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/cannkit-expanddimstype-introduction)|ExpandDimsType类基于补维后的shape，描述了补维规则。|
|类和结构体|[ExtendedKernelContext](https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/cannkit-getinputdesc)|[InferShapeContext](https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/cannkit-infershapecontext-getinputshape)、[TilingContext](https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/cannkit-getinputshape)等的基类，ExtendedKernelContext中提供的方法如获取算子type、name、属性等接口均可以在InferShape、Tiling时调用。|
|类和结构体|[InferDataTypeContext](https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/cannkit-getinputdatatype)|用于datatype推导的上下文结构。|
|类和结构体|[InferShapeContext](https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/cannkit-infershapecontext-getinputshape)|用于shape推导的上下文结构。|
|类和结构体|[InferShapeRangeContext](https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/cannkit-getinputshaperange)|用于shape range推导的上下文结构。|
|类和结构体|[OpImplRegisterV2](https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/cannkit-opimpiregisterv2-construction)|OpImplRegisterV2类作为注册接口类，提供了一系列算子原型注册接口，供开发者注册指定算子类型的Tiling函数、Infershape函数、私有属性等信息。开发者调用算子原型注册接口进行注册时会间接使用到该类。|
|类和结构体|[Range](https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/cannkit-range-introduction)|Range类用于描述一个对象的上下界。|
|类和结构体|[RuntimeAttrs](https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/cannkit-constructor)|用于保存算子属性。|
|类和结构体|[Shape](https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/cannkit-shape-introduction)|Shape结构体用于描述一个tensor的shape。|
|类和结构体|[StorageFormat](https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/cannkit-storageformat-constructor)|StorageFormat格式包括原始格式、运行时格式、补维规则。|
|类和结构体|[StorageShape](https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/cannkit-storageshape-introduction)|该类描述了tensor的shape，包含两个信息：origin_shape以及storage_shape。|
|类和结构体|[TensorPlacementUtils](https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/cannkit-tensorplacementutils)|提供一组函数，用于判断TensorPlacement的位置。|
|类和结构体|[Tensor](https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/cannkit-tensor-constructor)|Tensor类用来描述一个tensor对象的信息以及行为，包含：shape信息、format信息、datatype信息以及tensor数据内容tensordata。|
|类和结构体|[TilingContext](https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/cannkit-getinputshape)|用于算子Tiling的上下文结构。|
|类和结构体|[TilingData](https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/cannkit-tilingdata-constructor)|用于存储Tiling数据。|
|类和结构体|[TypedContinuousVector](https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/cannkit-typedcontinuousvector-introduction)|本类继承自ContinuousVector类，与ContinuousVector类不同的是MutableData和GetData返回的是指定类型的地址，而不是void *。因此称为Typed。|
|枚举|[TensorPlacement](https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/cannkit-tensorplacement)|表达Tensor存储位置的枚举值。|

## ge命名空间

**表2** ge命名空间

|分类|数据结构/接口名称|功能描述|
|:----|:-----------------------------------------------------------------------------------------------------------------------------------------------------|:-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|类和结构体|[Allocator](https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/cannkit-allocator-construction-and-destructor)|支持使用开发者注册的外置allocator功能，所在头文件位于CANN软件安装后文件存储路径下的"include/ge/ge_allocator.h"路径。|
|类和结构体|[AscendString](https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/cannkit-ascendstring-construction-and-destructor)|用于存储字符串。 - 头文件位于CANN软件安装后文件存储路径下的include/graph/ascend_string.h - 库文件：libgraph.so|
|类和结构体|[AttrValue](https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/cannkit-attrvalue-construction-and-destructor)|用于存储属性值。 - 头文件位于CANN软件安装后文件存储路径下的include/graph/attr_value.h - 库文件：libgraph_base.so|
|类和结构体|[AutoMappingSubgraphIOIndexFuncRegister](https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/cannkit-automappingsubgraphioindexfuncregister)|内部关联接口，插件适配API调用时间接调用，开发者不直接感知。|
|类和结构体|[FrameworkRegistry](https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/cannkit-frameworkregistry-construction)|内部关联接口，插件适配API调用时间接调用，开发者不直接感知。|
|类和结构体|[InferenceContext](https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/cannkit-inferencecontext-construction)|获取推理上下文对象，并设置相应对象的形状和数据类型，主要用于资源类算子。|
|类和结构体|[InferFormatFuncRegister](https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/cannkit-inferformatfuncregister)|算子InferFormat函数注册接口，此接口被其他头文件引用，一般不用由算子开发者直接调用。|
|类和结构体|[InferShapeFuncRegister](https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/cannkit-infershapefuncregister)|算子InferShape函数注册接口，此接口被其他头文件引用，一般不用由算子开发者直接调用。|
|类和结构体|[InferValueRangeFuncRegister](https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/cannkit-infervaluerangefuncregister)|算子InferValueRangeFuncRegister函数注册接口，此接口被其他头文件引用，一般不由算子开发者直接调用。|
|类和结构体|[ListTensorType](https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/cannkit-listtensortype)|ListTensorType类用以定义输入或者输出支持的数据类型，是TensorType的封装，用于标识支持多个数据类型的情况。|
|类和结构体|[MemBlock](https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/cannkit-memblock-construction-and-destructor)|配合[Allocator](https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/cannkit-allocator-construction-and-destructor)类使用，支持使用开发者注册的外置allocator功能，所在头文件位于CANN软件安装后文件存储路径下的"include/ge/ge_allocator.h"路径。|
|类和结构体|[OperatorCreatorRegister](https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/cannkit-operatorcreatorregister)|算子注册接口，注册一个算子原型，此接口被其他头文件引用，一般不用由算子开发者直接调用。|
|类和结构体|[OperatorFactory](https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/cannkit-createoperator)|内部关联接口，此接口被其他头文件引用，一般不用由算子开发者直接调用。|
|类和结构体|[Operator](https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/cannkit-operator-construction-and-destructor)|算子类。 - 头文件位于CANN软件安装后文件存储路径下的include/graph/operator.h - 库文件：libgraph.so|
|类和结构体|[OpReceiver](https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/cannkit-opreceiver)|用于算子编写适配插件进行AI框架适配时，进行映射关系注册。|
|类和结构体|[OpRegistrationData](https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/cannkit-general-description)|用于算子编写适配插件进行AI框架适配时，进行映射关系注册。|
|类和结构体|[Promote](https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/cannkit-promote)|Promote类用于表示输出数据类型为输入或属性指定的数据类型间的提升类型。|
|类和结构体|[ShapeAndType](https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/cannkit-shapeandtype-construction-and-destructor)|可设置、获取相应对象的形状和数据类型。|
|类和结构体|[Shape](https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/cannkit-shape-construction-and-destructor)|用于存储Tensor的shape信息。 - 头文件位于CANN软件安装后文件存储路径下的include/graph/tensor.h - 库文件：libgraph_base.so|
|类和结构体|[TensorDescInfo](https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/cannkit-tensordescinfo)|存储Tensor描述信息。|
|类和结构体|[TensorDesc](https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/cannkit-tensordesc-construction-and-destructor)|用于存取、管理Tensor描述信息。 - 头文件位于CANN软件安装后文件存储路径下的include/graph/tensor.h - 库文件：libgraph_base.so|
|类和结构体|[TensorType](https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/cannkit-tensortype)|TensorType类用以定义输入或者输出支持的数据类型。|
|类和结构体|[Tensor](https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/cannkit-tensor-construction-and-destructor)|Tensor结构。 - 头文件位于CANN软件安装后文件存储路径下的include/graph/tensor.h - 库文件：libgraph_base.so|
|类和结构体|[TypeUtils](https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/cannkit-datatypetoascendstring)|类型转换工具类。|
|类和结构体|[VerifyFuncRegister](https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/cannkit-verifyfuncregister)|算子verifyFunc函数注册接口，此接口被其他头文件引用，一般不用由算子开发者直接调用。|
|函数|[ConvertToAscendString](https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/cannkit-converttoascendstring)|模板函数，接受一个模板参数T，并将其转换为AscendString类型。这个函数的主要功能是将不同类型的字符串转换为AscendString类型。|
|函数|[ConvertToListAscendString](https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/cannkit-converttolistascendstring)|定义了一个模板函数ConvertToListAscendString，用于将不同类型的字符串列表转换为AscendString类型的列表。|
|函数|[GetC0Format](https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/cannkit-getc0format)|根据实际format获取C0 format的值。|
|函数|[GetC0Value](https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/cannkit-getc0value)|从实际format中解析出c0 format信息。|
|函数|[GetFormatFromC0](https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/cannkit-getformatfromc0)|根据传入的format和c0format信息得到实际的format。|
|函数|[GetFormatFromSub](https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/cannkit-getformatfromsub)|根据传入的主format和子format信息得到实际的format。|
|函数|[GetFormatFromSubAndC0](https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/cannkit-getformatfromsubandc0)|根据传入的主format，子format和c0format信息得到实际的format。|
|函数|[GetFormatName](https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/cannkit-getformatname)|根据传入的format类型，获取format的字符串描述。|
|函数|[GetPrimaryFormat](https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/cannkit-getprimaryformat)|从实际format中解析出主format信息。|
|函数|[GetSizeByDataType](https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/cannkit-getsizebydatatype)|根据传入的data_type，获取该data_type所占用的内存大小。|
|函数|[GetSizeInBytes](https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/cannkit-getsizeinbytes)|根据传入的element_count和data_type，获取element_count个该data_type所占用的内存总大小。|
|函数|[GetSubFormat](https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/cannkit-getsubformat)|从实际format中解析出子format信息。|
|函数|[HasC0Format](https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/cannkit-hasc0format)|判断实际format中是否包含C0 format。|
|函数|[HasSubFormat](https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/cannkit-hassubformat)|判断实际format中是否包含子format。|
|类型定义|[ge::graphStatus](https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/cannkit-gegraphstatus)|返回码状态说明。|
|枚举|[DataType](https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/cannkit-ge-datatype)|数据类型枚举值。|
|枚举|[Format](https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/cannkit-ge-format)|数据格式枚举值|
|宏|[BROADCAST_INFER](https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/cannkit-broadcast-infer)|提供公共函数宏封装，供算子开发者开发InferShape函数。该函数基于2个输入的shape，设置输出的shape。该宏只是设置shape，未设置dtype。|
|宏|[COMMON_INFER_FUNC_REG](https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/cannkit-common-infer-func-reg)|注册算子的InferShape函数。|
|宏|[DECLARE_ERRORNO](https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/cannkit-declare-errorno)|错误码及描述注册宏。|
|宏|[ELMTWISE_INFER_SHAPEANDTYPE](https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/cannkit-elmtwise-infer-shapeandtype)|提供公共函数宏封装，供算子开发者开发InferShape函数。该函数基于输入的shape和dtype，设置输出的shape和dtype。|
|宏|[IMPLEMT_COMMON_INFERFUNC](https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/cannkit-implemt-common-inferfunc)|封装算子的Common_InferShape函数。|
|宏|[IMPLEMT_INFERFORMAT_FUNC](https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/cannkit-implemt-inferformat-func)|封装算子的inferFormat函数。|
|宏|[IMPLEMT_INFERFUNC](https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/cannkit-implemt-inferfunc)|封装算子的InferShape函数。|
|宏|[IMPLEMT_VERIFIER](https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/cannkit-implemt-verifier)|封装算子的Verify函数。|
|宏|[INFER_FORMAT_FUNC_REG](https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/cannkit-infer-format-func-reg)|注册算子的InferFormat实现。|
|宏|[INFER_FUNC_REG](https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/cannkit-infer-func-reg)|注册算子的InferShape函数。|
|宏|[原型定义接口（REG_OP）](https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/cannkit-prototype-definition-api)|原型定义接口。|
|宏|[原型定义衍生接口说明](https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/cannkit-prototype-definition-derivative-api)|原型定义衍生接口。|
|宏|[VERIFY_FUNC_REG](https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/cannkit-verify-func-reg)|注册算子的Verify函数。|

