AllocHostTensor
【免费下载链接】opbase本项目是CANN算子库的基础框架库,为算子提供公共依赖文件和基础调度能力。项目地址: https://gitcode.com/cann/opbase
功能说明
申请一个host侧tensor,提供多个重载函数,可以指定不同的输入属性,如不同的数据类型。
函数原型
根据不同的输入信息组合,申请一个host侧tensor
aclTensor *AllocHostTensor(const op::Shape &shape, op::DataType datatype, op::Format format = op::Format::FORMAT_ND)aclTensor *AllocHostTensor(const op::Shape &storageShape, const op::Shape &originShape, op::DataType dataType, op::Format storageFormat, op::Format originFormat)申请一个host侧tensor,将指定数据类型的内存作为该tensor内容
aclTensor *AllocHostTensor(const int64_t *value, uint64_t size, op::DataType dataType)aclTensor *AllocHostTensor(const uint64_t *value, uint64_t size, op::DataType dataType)aclTensor *AllocHostTensor(const bool *value, uint64_t size, op::DataType dataType)aclTensor *AllocHostTensor(const char *value, uint64_t size, op::DataType dataType)aclTensor *AllocHostTensor(const int32_t *value, uint64_t size, op::DataType dataType)aclTensor *AllocHostTensor(const uint32_t *value, uint64_t size, op::DataType dataType)aclTensor *AllocHostTensor(const int16_t *value, uint64_t size, op::DataType dataType)aclTensor *AllocHostTensor(const uint16_t *value, uint64_t size, op::DataType dataType)aclTensor *AllocHostTensor(const int8_t *value, uint64_t size, op::DataType dataType)aclTensor *AllocHostTensor(const uint8_t *value, uint64_t size, op::DataType dataType)aclTensor *AllocHostTensor(const double *value, uint64_t size, op::DataType dataType)aclTensor *AllocHostTensor(const float *value, uint64_t size, op::DataType dataType)aclTensor *AllocHostTensor(const fp16_t *value, uint64_t size, op::DataType dataType)aclTensor *AllocHostTensor(const bfloat16 *value, uint64_t size, op::DataType dataType)
参数说明
根据不同的输入信息组合,申请一个host侧tensor。
参数 输入/输出 说明 shape 输入 将aclTensor的StorageShape和OriginShape都设置为指定的shape。 dataType 输入 指定aclTensor的数据类型。 format 输入 将aclTensor的StorageFormat和OriginFormat都设置为指定的format。 storageShape 输入 将aclTensor的StorageShape设置为指定shape。 originShape 输入 将aclTensor的OriginShape设置为指定shape。 storageFormat 输入 将aclTensor的StorageFormat设置为指定format。 originFormat 输入 将aclTensor的OriginFormat设置为指定format。 申请一个host侧tensor,将指定数据类型的内存作为该tensor内容。
参数 输入/输出 说明 value 输入 指向不同数据类型的源数据。 size 输入 源数据的元素个数。 dataType 输入 将源数据转为dataType指定的数据类型后,写入tensor。
返回值说明
返回申请得到的aclTensor,申请失败则返回nullptr。
约束说明
入参指针不能为空。
调用示例
// 申请一个host侧tensor,并将myArray中的数据拷贝到tensor中 void Func(aclOpExecutor *executor) { int64_t myArray[10]; aclTensor *tensor = executor->AllocHostTensor(myArray, 10, DT_INT64); }【免费下载链接】opbase本项目是CANN算子库的基础框架库,为算子提供公共依赖文件和基础调度能力。项目地址: https://gitcode.com/cann/opbase
创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考