AllocTensor

Description

Allocates a tensor on the device. Multiple overloaded functions are provided to specify different attributes.

Prototype

aclTensor *AllocTensor(const op::Shape&shape, op::DataType dataType, op::Format format = op::Format::FORMAT_ND)
aclTensor *AllocTensor(const op::Shape& storageShape, const op::Shape& originShape, op::DataType dataType, op::Format storageFormat, op::Format originFormat)
aclTensor *AllocTensor(op::DataType dataType, op::Format storageFormat, op::Format originFormat)

Parameters

Parameter

Input/Output

Description

shape

Input

Sets both StorageShape and OriginShape of aclTensor to a specified shape.

dataType

Input

Specifies the data type of aclTensor.

format

Input

Sets both 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.

Return Value

Success: allocated aclTensor. Failure: nullptr.

Constraints

The input parameter pointer must not be null.

Examples

1
2
3
4
5
6
7
8
// Allocate an int64 ND tensor with the shape [1, 2, 3, 4, 5].
void Func(aclOpExecutor *executor) {
    gert::Shape newShape;
    for (int64_t i = 1; i <= 5; i++) {
        newShape.AppendDim(i);
    }
    aclTensor *tensor = executor->AllocTensor(newShape, DT_INT64, ge::FORMAT_ND);
}