基础数据结构和接口列表
本文档提供了进行算子开发和图开发时依赖的基础数据结构和接口说明,分类如下:
-
ge(Graph Engine) 命名空间
ge是Graph Engine的缩写,此命名空间专注于构图和图编译处理,提供了一套丰富的API,用于构建和管理复杂的图结构。
-
gert(GE Runtime) 命名空间
gert是GE Runtime的缩写,这个命名空间专门为运行时环境而设计,提供了一系列的高性能数据结构,以确保在执行时能够提供最佳性能。
-
C接口
用于算子和图开发的C语言接口。
ge命名空间
表 1 ge命名空间
KernelLaunchInfo类为开发者提供创建和管理下发给Device的任务接口,允许开发者设置或者获取当前待下发Device任务的相关Launch信息。 |
||
ListTensorType类用以定义输入或者输出支持的数据类型,是TensorType的封装,用于标识支持多个数据类型的情况。 |
||
配合Allocator类使用,支持使用用户注册的外置allocator功能。 |
||
|
||
|
||
模板函数,接受一个模板参数T,并将其转换为AscendString类型。这个函数的主要功能是将不同类型的字符串转换为AscendString类型。 |
||
定义了一个模板函数ConvertToListAscendString,用于将不同类型的字符串列表转换为AscendString类型的列表。 |
||
根据传入的element_count和data_type,获取element_count个该data_type所占用的内存总大小。 |
||
|
头文件位于CANN toolkit安装路径下的include/register/register_error_codes.h。 |
gert命名空间
表 2 gert命名空间
用来描述一个算子的IR原型定义的输入信息与实际输入之间的关系。 头文件位于CANN toolkit安装路径下的include/exe_graph/runtime/compute_node_info.h。 |
||
用于描述编译时的Tensor描述信息,包含dtype信息以及format信息。 头文件位于CANN toolkit安装路径下的include/exe_graph/runtime/compute_node_info.h。 |
||
用于将算子的相关编译信息进行序列化保存,以便可以在图执行阶段能够高效地获取这些信息。 头文件位于CANN toolkit安装路径下的include/exe_graph/runtime/compute_node_info.h。 |
||
Context是算子Host侧实现函数执行时的上下文,由于构造出来的Context存储的都是指针类型,为了方便进行生命周期和所有权管理,提供ContextHolder类进行资源管理。 头文件位于CANN toolkit安装路径下的include/base/context_builder/context_holder.h。 |
||
在内存中开辟一块连续的空间,用于存储数据的描述信息以及实际的数据元素,元素类型为ContinuousVector结构。 头文件位于CANN toolkit安装路径下的include/exe_graph/runtime/continuous_vector.h。 |
||
本类是一个POD类,在内存中开辟一块连续的空间用于存储描述信息以及实际内存数据。 头文件位于CANN toolkit安装路径下的include/exe_graph/runtime/continuous_vector.h。 |
||
CtInferShapeContext继承自InferShapeContext,用于编译期Shape推导,提供编译期使用的接口。 头文件位于CANN toolkit安装路径下的include/graph/ct_infer_shape_context.h。 |
||
CtInferShapeRangeContext继承自InferShapeRangeContext,用于编译期ShapeRange推导,提供编译期使用的接口。 头文件位于CANN toolkit安装路径下的include/graph/ct_infer_shape_range_context.h。 |
||
ExpandDimsType类基于补维后的shape,描述了补维规则。 头文件位于CANN toolkit安装路径下的include/exe_graph/runtime/expand_dims_type.h。 |
||
InferShapeContext、TilingContext等的基类,ExtendedKernelContext中提供的方法如获取算子type、name、属性等接口均可以在InferShape、Tiling时调用。 头文件位于CANN toolkit安装路径下的include/exe_graph/runtime/extended_kernel_context.h。 |
||
|
头文件位于CANN toolkit安装路径下的include/exe_graph/runtime/infer_datatype_context.h。 |
||
InferFormatContext继承自ExtendedKernelContext,是一个用于Format推导的上下文类。 |
||
|
头文件位于CANN toolkit安装路径下的include/exe_graph/runtime/infer_shape_context.h。 |
||
|
头文件位于CANN toolkit安装路径下的include/exe_graph/runtime/infer_shape_range_context.h。 |
||
OpContextBuilderBase是各ContextBuilder的基类,用于构造子类context中算子信息,包括算子类型、名称、输入输出原型个数、输入输出实例个数、属性等信息。 头文件位于CANN toolkit安装路径下的include/base/context_builder/op_context_builder_base.h。 |
||
OpImplRegisterV2类作为注册接口类,提供了一系列算子原型注册接口,供用户注册指定算子类型的Tiling函数、Infershape函数、私有属性等信息。用户调用算子原型注册接口进行注册时会间接使用到该类。 |
||
OpInferDataTypeContextBuilder用于构建InferDataTypeContext 。构造出的Context在算子数据类型推导过程中作为入参,用于获取必要的算子输入输出数据。推导完成后,结果会被写入回上下文中。 头文件位于CANN toolkit安装路径下的include/base/context_builder/op_infer_datatype_context_builder.h。 |
||
OpInferShapeContextBuilder用于构建InferShapeContext。构造出的Context在算子Shape推导过程中作为入参,用于获取必要的算子输入输出数据。推导完成后,结果会被写入回上下文中。 头文件位于CANN toolkit安装路径下的include/base/context_builder/op_infer_shape_context_builder.h。 |
||
OpInferShapeRangeContextBuilder用于构建InferShapeRangeContext。构造出的Context在算子ShapeRange推导过程中作为输入,用于获取必要的算子输入输出数据。推导完成后,结果会被写回上下文中。 头文件位于CANN toolkit安装路径下的include/base/context_builder/op_infer_shape_range_context_builder.h。 |
||
用于构建一个通用的KernelContext对象,该上下文作为算子Host实现实际执行阶段的输入上下文。 头文件位于CANN toolkit安装路径下的include/base/context_builder/op_kernel_run_context_builder.h。 |
||
OpTilingContextBuilder用于构建TilingContext。构造出的Context在算子Tiling计算过程中作为入参,用于获取必要的算子输入输出等数据。Tiling计算完成后,结果会被写回上下文中。 头文件位于CANN toolkit安装路径下的include/base/context_builder/op_tiling_context_builder.h。 |
||
OpTilingParseContextBuilder用于构建TilingParseContext。构造出的Context在算子TilingParse计算过程中作为输入,用于获取必要的算子输入输出数据。完成Parser计算后,结果会被写回到上下文中。 头文件位于CANN toolkit安装路径下的include/base/context_builder/op_tiling_parse_context_builder.h。 |
||
|
头文件位于CANN toolkit安装路径下的include/exe_graph/runtime/runtime_attrs.h。 |
||
StorageFormat格式包括原始格式、运行时格式、补维规则。 头文件位于CANN toolkit安装路径下的include/exe_graph/runtime/storage_format.h。 |
||
该类描述了tensor的shape,包含两个信息:origin_shape以及storage_shape。 头文件位于CANN toolkit安装路径下的include/exe_graph/runtime/storage_shape.h。 |
||
|
头文件位于CANN toolkit安装路径下的include/exe_graph/runtime/tensor_data.h。 |
||
提供一组函数,用于判断TensorPlacement的位置。 头文件位于CANN toolkit安装路径下的include/exe_graph/runtime/tensor_data.h。 |
||
Tensor类用来描述一个tensor对象的信息以及行为,包含:shape信息、format信息、datatype信息以及tensor数据内容tensordata。 |
||
|
头文件位于CANN toolkit安装路径下的include/exe_graph/runtime/tiling_context.h。 |
||
|
头文件位于CANN toolkit安装路径下的include/exe_graph/runtime/tiling_data.h。 |
||
本类继承自ContinuousVector类,与ContinuousVector类不同的是MutableData和GetData返回的是指定类型的地址,而不是void *。因此称为Typed。 头文件位于CANN toolkit安装路径下的include/exe_graph/runtime/continuous_vector.h。 |
||
|
头文件位于CANN toolkit安装路径下的include/exe_graph/runtime/tensor_data.h。 |