AsStridedOperation
Applicable Products
|
Hardware Model |
Supported |
|---|---|
|
Atlas 350 accelerator cards |
x |
|
|
√ |
|
|
√ |
|
|
√ |
|
|
√ |
|
|
√ |
Description
Creates a view of the data re-arranged based on an existing tensor. Elements can be rearranged by specifying the shape and strides.
Mapping (using the 3 x 3 input shape and 2 x 2 output shape as an example)
- Input
inTensor = [[1, 2, 3], [4, 5, 6], [7, 8, 9]] opParam.size = [2, 2] opParam.stride = [2, 3] opParam.offset = [0]
- Output
outTensor = [[1, 4], [3, 6]]
Mapping: outTensor[i][j] -> v_inTensor[ i * stride[0] + j * stride[1] + offset[0]].
v_inTensor is the 1D vector of the input tensor.
Figure 1 Implementation principle of the AsStrided operator (offset=0)
Operator Context
Definition
1 2 3 4 5 6 |
struct AsStridedParam { SVector<int64_t> size; SVector<int64_t> stride; SVector<int64_t> offset; uint8_t rsv[8] = {0}; }; |
Parameters
|
Member |
Type |
Default Value |
Description |
|---|---|---|---|
|
size |
SVector<int64_t> |
- |
Shape of the output tensor. The length of size must be less than or equal to 8, and each element must be greater than 0. |
|
stride |
SVector<int64_t> |
- |
Stride of each dimension of the output tensor derived based on the input tensor. The length of stride must be the same as that of size, and each element must be greater than or equal to 0. |
|
offset |
SVector<int64_t> |
- |
Offset of the output tensor memory relative to the input tensor memory, which is used as a constant. The length of offset must be 1, and the element must be greater than or equal to 0. |
|
rsv[8] |
uint8_t |
{0} |
Reserved |
Input
|
Parameter |
Dimension |
Data Type |
Format |
Description |
|---|---|---|---|---|
|
x |
[din_0, ..., din_n] |
float16/int64 |
ND |
Input tensor |
Output
|
Parameter |
Dimension |
Data Type |
Format |
Description |
|---|---|---|---|---|
|
y |
[dout_0, ..., dout_m] |
float16/int64 |
ND |
Output tensor |
Constraints
Restrictions on the parameters:
- offset.size() == 1, offset.at(i) ≥ 0.
- size.size() ≤ 8, size.at(i) > 0.
- stride.size() == size.size(), stride.at(i) ≥ 0.
