Contiguous
Availability
Function Usage
Converts a non-contiguous tensor into a contiguous tensor. This function is a public L0 API.
An input tensor of L2 API may be non-contiguous, while an L0 operator supports only a contiguous tensor as the input. Therefore, the tensor needs to be converted into a contiguous tensor before being used as the input of another L0 operator.
An input tensor can be contiguous, which will be processed in the API for better compatibility.
Prototype
const aclTensor *Contiguous(const aclTensor *x, aclOpExecutor *executor)
Parameters
Parameter |
Input/Output |
Description |
|---|---|---|
x |
Input |
Input tensor to be converted. The data type and format are not restricted. The input does not have to be contiguous memory, but its expressed data must be within the storage range. |
executor |
Input |
Operator executor, containing the operator computation process. |
Returns
Success: A contiguous aclTensor is returned. Failure: nullptr is returned.
Constraints
The input tensor must be valid. The shape and stride data must be within the storage range. For example, if shape = (2, 3), stride = (10, 30), storageSize = 8, the actual data exceeds the storage size (8). Therefore, the tensor is invalid, and nullptr is returned by the Contiguous API.
Example
1 2 3 4 | // (Fixed writing) Create an OpExecutor. auto uniqueExecutor = CREATE_EXECUTOR(); // If self is non-contiguous, conversion is required. auto selfContiguous = l0op::Contiguous(self, executor); |