昇腾社区首页
中文
注册

AllocHostTensor

函数功能

申请一个host侧tensor,提供多个重载函数,可以指定不同的输入属性,如不同的数据类型。

函数原型

  • 根据不同的输入信息组合,申请一个host侧tensor。

    aclTensor *AllocHostTensor(const Shape &shape, DataType dataType, Format format = FORMAT_ND)

    aclTensor *AllocHostTensor(const Shape &storageShape, const Shape &originShape, DataType dataType, Format storageFormat, Format originFormat)

  • 申请一个host侧tensor,将指定数据类型的内存作为该tensor内容。

    aclTensor *AllocHostTensor(const int64_t *value, uint64_t size, DataType dataType)

    aclTensor *AllocHostTensor(const uint64_t *value, uint64_t size, DataType dataType)

    aclTensor *AllocHostTensor(const bool *value, uint64_t size, DataType dataType)

    aclTensor *AllocHostTensor(const char *value, uint64_t size, DataType dataType)

    aclTensor *AllocHostTensor(const int32_t *value, uint64_t size, DataType dataType)

    aclTensor *AllocHostTensor(const uint32_t *value, uint64_t size, DataType dataType)

    aclTensor *AllocHostTensor(const int16_t *value, uint64_t size, DataType dataType)

    aclTensor *AllocHostTensor(const uint16_t *value, uint64_t size, DataType dataType)

    aclTensor *AllocHostTensor(const int8_t *value, uint64_t size, DataType dataType)

    aclTensor *AllocHostTensor(const uint8_t *value, uint64_t size, DataType dataType)

    aclTensor *AllocHostTensor(const double *value, uint64_t size, DataType dataType)

    aclTensor *AllocHostTensor(const float *value, uint64_t size, DataType dataType)

    aclTensor *AllocHostTensor(const fp16_t *value, uint64_t size, DataType dataType)

    aclTensor *AllocHostTensor(const bfloat16 *value, uint64_t size, DataType dataType)

参数说明

  • 根据不同的输入信息组合,申请一个host侧tensor。

    参数

    输入/输出

    说明

    shape

    输入

    将aclTensor的StorageShapeOriginShape都设置为指定的shape。

    dataType

    输入

    指定aclTensor的数据类型。

    format

    输入

    将aclTensor的StorageFormatOriginFormat都设置为指定的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);
}