AllocHostTensor

Function Usage

Allocates a tensor on the host. Multiple overloaded functions are provided to specify different input attributes, such as different data types.

Prototype

  • Allocate a tensor on the host based on the input information combination.

    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)

  • Allocate a tensor on the host and use the memory of a specified data type as the tensor content.

    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)

Parameters

  • Allocate a tensor on the host based on the input information combination.

    Parameter

    Input/Output

    Description

    shape

    Input

    Sets StorageShape and OriginShape of aclTensor to a specified shape.

    dataType

    Input

    Specifies the data type of aclTensor.

    format

    Input

    Sets StorageFormat and OriginFormat of aclTensor to a specified format.

    storageShape

    Input

    Sets StorageShape of aclTensor to a specified shape.

    originShape

    Input

    Sets OriginShape of aclTensor to a specified shape.

    storageFormat

    Input

    Sets StorageFormat of aclTensor to a specified format.

    originFormat

    Input

    Sets OriginFormat of aclTensor to a specified format.

  • Allocate a tensor on the host and use the memory of a specified data type as the tensor content.

    Parameter

    Input/Output

    Description

    value

    Input

    Pointer to source data of different data types.

    size

    Input

    Number of elements in the source data.

    dataType

    Input

    Destination data type of the source data, which is written to the tensor.

Returns

Success: allocated aclTensor. Failure: nullptr.

Constraints

The input parameter pointer must not be null.

Example

1
2
3
4
5
// Allocate a tensor on the host and copy the data in myArray to the tensor.
void Func(aclOpExecutor *executor) {
    int64_t myArray[10];
    aclTensor *tensor = executor->AllocHostTensor(myArray, 10, DT_INT64);
}