AllocTensor

Function Usage

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

Prototype

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

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

aclTensor *AllocTensor(DataType dataType, Format storageFormat, Format originFormat)

Parameters

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.

Returns

Success: allocated aclTensor. Failure: nullptr.

Constraints

The input parameter pointer must not be null.

Example

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);
}