Skip to main content
`Ctrl`+`K`

# Tensor

MIOpen: Tensor
Enumerations | Functions
Tensor

## Enumerations

enum | miopenDataType_t { miopenHalf = 0 , miopenFloat = 1 , miopenInt32 = 2 , miopenInt8 = 3 , miopenBFloat16 = 5 , miopenDouble = 6 , miopenFloat8_fnuz = 7 , miopenBFloat8_fnuz = 8 , miopenInt64 = 9 }
enum | miopenTensorLayout_t { miopenTensorNCHW = 0 , miopenTensorNHWC = 1 , miopenTensorCHWN = 2 , miopenTensorNCHWc4 = 3 , miopenTensorNCHWc8 = 4 , miopenTensorCHWNc4 = 5 , miopenTensorCHWNc8 = 6 , miopenTensorNCDHW = 7 , miopenTensorNDHWC = 8 }
enum | miopenTensorOp_t { miopenTensorOpAdd = 0 , miopenTensorOpMul = 1 , miopenTensorOpMin = 2 , miopenTensorOpMax = 3 }

## Functions

| MIOPEN_DECLARE_OBJECT (miopenTensorDescriptor)
| Creates the miopenTensorDescriptor_t type.
| MIOPEN_DECLARE_OBJECT (miopenSeqTensorDescriptor)
| Creates the miopenSeqTensorDescriptor_t type.
miopenStatus_t | miopenCreateTensorDescriptor (miopenTensorDescriptor_t *tensorDesc)
| Create a Tensor Descriptor.
miopenStatus_t | miopenSet4dTensorDescriptor (miopenTensorDescriptor_t tensorDesc, miopenDataType_t dataType, int n, int c, int h, int w)
| Set shape of 4D tensor.
miopenStatus_t | miopenSetNdTensorDescriptorWithLayout (miopenTensorDescriptor_t tensorDesc, miopenDataType_t dataType, miopenTensorLayout_t tensorLayout, const int *lens, int num_lens)
| Set shape of ND tensor with specific layout.
miopenStatus_t | miopenSet4dTensorDescriptorEx (miopenTensorDescriptor_t tensorDesc, miopenDataType_t dataType, int n, int c, int h, int w, int nStride, int cStride, int hStride, int wStride)
| Set shape and stride of 4D tensor.
miopenStatus_t | miopenGet4dTensorDescriptor (miopenTensorDescriptor_t tensorDesc, miopenDataType_t *dataType, int *n, int *c, int *h, int *w, int *nStride, int *cStride, int *hStride, int *wStride)
| Get the details of the tensor descriptor.
miopenStatus_t | miopenSetTensorDescriptor (miopenTensorDescriptor_t tensorDesc, miopenDataType_t dataType, int nbDims, const int *dimsA, const int *stridesA)
| Set shape of N-dimensional tensor.
miopenStatus_t | miopenSetTensorDescriptorV2 (miopenTensorDescriptor_t tensorDesc, miopenDataType_t dataType, int nbDims, const size_t *dimsA, const size_t *stridesA)
| Set shape of N-dimensional tensor.
miopenStatus_t | miopenSetTensorCastType (miopenTensorDescriptor_t tensorDesc, miopenDataType_t cast_type)
| Set the tensor cast type.
miopenStatus_t | miopenGetTensorDescriptorSize (miopenTensorDescriptor_t tensorDesc, int *size)
| Set shape of N-dimensional tensor.
miopenStatus_t | miopenGetTensorDescriptor (miopenTensorDescriptor_t tensorDesc, miopenDataType_t *dataType, int *dimsA, int *stridesA)
| Get the details of the N-dimensional tensor descriptor.
miopenStatus_t | miopenDestroyTensorDescriptor (miopenTensorDescriptor_t tensorDesc)
| Destroys the tensor descriptor.
miopenStatus_t | miopenCreateSeqTensorDescriptor (miopenSeqTensorDescriptor_t *tensorDesc)
| Create a Tensor Descriptor for sequence data.
miopenStatus_t | miopenDestroySeqTensorDescriptor (miopenSeqTensorDescriptor_t tensorDesc)
| Destroys the sequence data tensor descriptor.
miopenStatus_t | miopenOpTensor (miopenHandle_t handle, miopenTensorOp_t tensorOp, const void *alpha1, const miopenTensorDescriptor_t aDesc, const void *A, const void *alpha2, const miopenTensorDescriptor_t bDesc, const void *B, const void *beta, const miopenTensorDescriptor_t cDesc, void *C)
| Execute element-wise tensor operations.
miopenStatus_t | miopenSetTensor (miopenHandle_t handle, const miopenTensorDescriptor_t yDesc, void *y, const void *alpha)
| Fills a tensor with a single value.
miopenStatus_t | miopenScaleTensor (miopenHandle_t handle, const miopenTensorDescriptor_t yDesc, void *y, const void *alpha)
| Scales all elements in a tensor by a single value.
miopenStatus_t | miopenGetTensorNumBytes (miopenTensorDescriptor_t tensorDesc, size_t *numBytes)
| Returns number of bytes associated with tensor descriptor.
miopenStatus_t | miopenTransformTensor (miopenHandle_t handle, const void *alpha, const miopenTensorDescriptor_t xDesc, const void *x, const void *beta, const miopenTensorDescriptor_t yDesc, void *y)
| Copies one tensor to another tensor with a different layout/scale.

## Detailed Description

## Enumeration Type Documentation

## ◆ miopenDataType_t

enum miopenDataType_t

MIOpen floating point datatypes. Both 32-bit and 16-bit floats are supported in MIOpen.

Enumerator
miopenHalf | 16-bit floating point (Fully supported)
miopenFloat | 32-bit floating point (Fully supported)
miopenInt32 | 32-bit integer (Partially supported)
miopenInt8 | 8-bit integer (Partially supported)
miopenBFloat16 | 16-bit binary floating point (8-bit exponent, 7-bit fraction) (Partially supported)
miopenDouble | 64-bit floating point (Partially supported)
miopenFloat8_fnuz |
miopenBFloat8_fnuz |
miopenInt64 |

## ◆ miopenTensorLayout_t

enum miopenTensorLayout_t

Tensor layouts supported by MIOpen. miopenTensorCHWNc4 and miopenTensorCHWNc8 layout only support weight tensor.

Enumerator
miopenTensorNCHW | NCHW memory layout (Fully supported)
miopenTensorNHWC | NHWC memory layout (Fully supported)
miopenTensorCHWN | CHWN memory layout (Not supported)
miopenTensorNCHWc4 | NCHWc4 memory layout (Partially supported)
miopenTensorNCHWc8 | NCHWc8 memory layout (Partially supported)
miopenTensorCHWNc4 | CHWNc4 memory layout (Partially supported)
miopenTensorCHWNc8 | CHWNc8 memory layout (Partially supported)
miopenTensorNCDHW | NCDHW memory layout (Fully supported)
miopenTensorNDHWC | NCDHW memory layout (Fully supported)

## ◆ miopenTensorOp_t

enum miopenTensorOp_t

Element-wise tensor operation modes

Enumerator
miopenTensorOpAdd | Add tensors element-wise
miopenTensorOpMul | Multiply two tensors element-wise
miopenTensorOpMin | Minimum of tensor element pairs
miopenTensorOpMax | Maximum of tensor element pairs

## Function Documentation

## ◆ MIOPEN_DECLARE_OBJECT() [1/2]

MIOPEN_DECLARE_OBJECT | ( | miopenSeqTensorDescriptor |  | ) |

Creates the miopenSeqTensorDescriptor_t type.

SeqTensor descriptor is an object that allows the user to specify tensor with sequence dimension.

## ◆ MIOPEN_DECLARE_OBJECT() [2/2]

MIOPEN_DECLARE_OBJECT | ( | miopenTensorDescriptor |  | ) |

Creates the miopenTensorDescriptor_t type.

Tensor descriptor is an object that allows the user to specify a layer's size for each dimension and dimension strides.

## ◆ miopenCreateSeqTensorDescriptor()

miopenStatus_t miopenCreateSeqTensorDescriptor | ( | miopenSeqTensorDescriptor_t * | tensorDesc | ) |

Create a Tensor Descriptor for sequence data.

API for creating an uninitialized sequence data tensor descriptor.

Parameters

  tensorDesc | Pointer to a sequence data tensor descriptor type (output)

Returns
  miopenStatus_t

## ◆ miopenCreateTensorDescriptor()

miopenStatus_t miopenCreateTensorDescriptor | ( | miopenTensorDescriptor_t * | tensorDesc | ) |

Create a Tensor Descriptor.

API for creating an uninitialized tensor descriptor.

Parameters

  tensorDesc | Pointer to a tensor descriptor type (output)

Returns
  miopenStatus_t

## ◆ miopenDestroySeqTensorDescriptor()

miopenStatus_t miopenDestroySeqTensorDescriptor | ( | miopenSeqTensorDescriptor_t | tensorDesc | ) |

Destroys the sequence data tensor descriptor.

Parameters

  tensorDesc | Tensor descriptor (input)

Returns
  miopenStatus_t

## ◆ miopenDestroyTensorDescriptor()

miopenStatus_t miopenDestroyTensorDescriptor | ( | miopenTensorDescriptor_t | tensorDesc | ) |

Destroys the tensor descriptor.

Parameters

  tensorDesc | Tensor descriptor (input)

Returns
  miopenStatus_t

## ◆ miopenGet4dTensorDescriptor()

miopenStatus_t miopenGet4dTensorDescriptor | ( | miopenTensorDescriptor_t | tensorDesc,
|  | miopenDataType_t * | dataType,
|  | int * | n,
|  | int * | c,
|  | int * | h,
|  | int * | w,
|  | int * | nStride,
|  | int * | cStride,
|  | int * | hStride,
|  | int * | wStride )

Get the details of the tensor descriptor.

Interface to query the 4-D tensor shape.

Parameters

  tensorDesc | Tensor descriptor (input)
  dataType | MIOpen datatype (output)
  n | Mini-batch size (output)
  c | Number of channels (output)
  h | Data height dimension size (output)
  w | Data width dimension size (output)
  nStride | Mini-batch dimension stride (output)
  cStride | Channel dimension stride (output)
  hStride | Height dimension stride (output)
  wStride | Width dimension stride (output)

Returns
  miopenStatus_t

## ◆ miopenGetTensorDescriptor()

miopenStatus_t miopenGetTensorDescriptor | ( | miopenTensorDescriptor_t | tensorDesc,
|  | miopenDataType_t * | dataType,
|  | int * | dimsA,
|  | int * | stridesA )

Get the details of the N-dimensional tensor descriptor.

Parameters

  tensorDesc | Tensor descriptor (input)
  dataType | MIOpen datatype (output)
  dimsA | Array containing the size of dimensions (output)
  stridesA | Array containing the size of stride (output)

Returns
  miopenStatus_t

## ◆ miopenGetTensorDescriptorSize()

miopenStatus_t miopenGetTensorDescriptorSize | ( | miopenTensorDescriptor_t | tensorDesc,
|  | int * | size )

Set shape of N-dimensional tensor.

Interface for querying tensor size. MIOpen has support for 1, 2, 3, 4, 5 dimensional tensor of layout.

Parameters

  tensorDesc | Tensor descriptor (input)
  size | number of elements in tensor described by the descriptor (output)

Returns
  miopenStatus_t

## ◆ miopenGetTensorNumBytes()

miopenStatus_t miopenGetTensorNumBytes | ( | miopenTensorDescriptor_t | tensorDesc,
|  | size_t * | numBytes )

Returns number of bytes associated with tensor descriptor.

Parameters

  tensorDesc | Tensor descriptor (input)
  numBytes | Number of bytes associated with tensor descriptor (output)

Returns
  miopenStatus_t

## ◆ miopenOpTensor()

miopenStatus_t miopenOpTensor | ( | miopenHandle_t | handle,
|  | miopenTensorOp_t | tensorOp,
|  | const void * | alpha1,
|  | const miopenTensorDescriptor_t | aDesc,
|  | const void * | A,
|  | const void * | alpha2,
|  | const miopenTensorDescriptor_t | bDesc,
|  | const void * | B,
|  | const void * | beta,
|  | const miopenTensorDescriptor_t | cDesc,
|  | void * | C )

Execute element-wise tensor operations.

This function implements: \( C = op ( alpha1[0] * A, alpha2[0] * B ) + beta[0] * C \)

For Forward Bias one can also use, miopenConvolutionForwardBias()

Parameters

  handle | MIOpen handle (input)
  tensorOp | Operation from miopenTensorOp_t (input)
  alpha1 | Tensor A's floating point scaling factor, allocated on the host (input)
  aDesc | Tensor descriptor for tensor A (input)
  A | Tensor A (input)
  alpha2 | Tensor B's floating point scaling factor, allocated on the host (input)
  bDesc | Tensor descriptor for tensor B (input)
  B | Tensor B (input)
  beta | Tensor C's floating point scaling factor, allocated on the host (input)
  cDesc | Tensor descriptor for tensor C (input)
  C | Tensor C (input and output)

Returns
  miopenStatus_t

## ◆ miopenScaleTensor()

miopenStatus_t miopenScaleTensor | ( | miopenHandle_t | handle,
|  | const miopenTensorDescriptor_t | yDesc,
|  | void * | y,
|  | const void * | alpha )

Scales all elements in a tensor by a single value.

Supported datatypes are fp32 and fp16

Parameters

  handle | MIOpen handle (input)
  yDesc | Tensor descriptor for tensor y (input)
  y | Tensor y (input and output)
  alpha | Floating point scaling factor, allocated on the host (input)

Returns
  miopenStatus_t

## ◆ miopenSet4dTensorDescriptor()

miopenStatus_t miopenSet4dTensorDescriptor | ( | miopenTensorDescriptor_t | tensorDesc,
|  | miopenDataType_t | dataType,
|  | int | n,
|  | int | c,
|  | int | h,
|  | int | w )

Set shape of 4D tensor.

Interface for setting 4-D tensor shape. MIOpen currently implements NCHW and NHWC layout.

Parameters

  tensorDesc | Tensor descriptor (input/output)
  dataType | MIOpen datatype (input)
  n | Mini-batch size (input)
  c | Number of channels (input)
  h | Data height dimension size (input)
  w | Data width dimension size (input)

Returns
  miopenStatus_t

## ◆ miopenSet4dTensorDescriptorEx()

miopenStatus_t miopenSet4dTensorDescriptorEx | ( | miopenTensorDescriptor_t | tensorDesc,
|  | miopenDataType_t | dataType,
|  | int | n,
|  | int | c,
|  | int | h,
|  | int | w,
|  | int | nStride,
|  | int | cStride,
|  | int | hStride,
|  | int | wStride )

Set shape and stride of 4D tensor.

Interface for setting 4-D tensor shape and stride. It allows to create the non-packed tensor. A non-packed tensor refers to the tensor where the elements are not compressed or packed in any specific way. Each element in the tensor is stored individually, and there is no special compression applied to the storage.

Parameters

  tensorDesc | Tensor descriptor (input/output)
  dataType | MIOpen datatype (input)
  n | Mini-batch size (input)
  c | Number of channels (input)
  h | Data height dimension size (input)
  w | Data width dimension size (input)
  nStride | Mini-batch dimension stride (input)
  cStride | Channel dimension stride (input)
  hStride | Height dimension stride (input)
  wStride | Width dimension stride (input)

Returns
  miopenStatus_t

## ◆ miopenSetNdTensorDescriptorWithLayout()

miopenStatus_t miopenSetNdTensorDescriptorWithLayout | ( | miopenTensorDescriptor_t | tensorDesc,
|  | miopenDataType_t | dataType,
|  | miopenTensorLayout_t | tensorLayout,
|  | const int * | lens,
|  | int | num_lens )

Set shape of ND tensor with specific layout.

Interface for setting N-D packed tensor shape. This interface support NHWC, NCHW, NCHWc*, CHWNc*

Parameters

  tensorDesc | Tensor descriptor (input/output)
  dataType | MIOpen datatype (input)
  tensorLayout | Tensor layout (input)
  lens | Tensor dimensions (input)
  num_lens | Tensor dimension size (input)

Returns
  miopenStatus_t

## ◆ miopenSetTensor()

miopenStatus_t miopenSetTensor | ( | miopenHandle_t | handle,
|  | const miopenTensorDescriptor_t | yDesc,
|  | void * | y,
|  | const void * | alpha )

Fills a tensor with a single value.

Supported datatypes are fp32, fp16, and bfp16

Parameters

  handle | MIOpen handle (input)
  yDesc | Tensor descriptor for tensor y (input)
  y | Tensor y (input)
  alpha | Pointer to fill value (input)

Returns
  miopenStatus_t

## ◆ miopenSetTensorCastType()

miopenStatus_t miopenSetTensorCastType | ( | miopenTensorDescriptor_t | tensorDesc,
|  | miopenDataType_t | cast_type )

Set the tensor cast type.

For tensors where the cast_type attribute is set, the tensor elements would be converted to the target type before the target operation is applied. Currently, only supported for convolution operations targeting the FP8 datatype

Parameters

  tensorDesc | Tensor descriptor type (input)
  cast_type | MIOpen datatype (input)

## ◆ miopenSetTensorDescriptor()

miopenStatus_t miopenSetTensorDescriptor | ( | miopenTensorDescriptor_t | tensorDesc,
|  | miopenDataType_t | dataType,
|  | int | nbDims,
|  | const int * | dimsA,
|  | const int * | stridesA )

Set shape of N-dimensional tensor.

Interface for setting non-packed tensor shape.

Parameters

  tensorDesc | Tensor descriptor (input/output)
  dataType | MIOpen datatype (input)
  nbDims | Number of dimensions in the dimsA array (input)
  dimsA | Array containing the size of dimensions (input)
  stridesA | Array containing the size of stride (input)

Returns
  miopenStatus_t

## ◆ miopenSetTensorDescriptorV2()

miopenStatus_t miopenSetTensorDescriptorV2 | ( | miopenTensorDescriptor_t | tensorDesc,
|  | miopenDataType_t | dataType,
|  | int | nbDims,
|  | const size_t * | dimsA,
|  | const size_t * | stridesA )

Set shape of N-dimensional tensor.

Interface for setting non-packed tensor shape.

Parameters

  tensorDesc | Tensor descriptor (input/output)
  dataType | MIOpen datatype (input)
  nbDims | Number of dimensions in the dimsA array (input)
  dimsA | Array containing the size of dimensions (input)
  stridesA | Array containing the size of stride (input)

Returns
  miopenStatus_t

## ◆ miopenTransformTensor()

miopenStatus_t miopenTransformTensor | ( | miopenHandle_t | handle,
|  | const void * | alpha,
|  | const miopenTensorDescriptor_t | xDesc,
|  | const void * | x,
|  | const void * | beta,
|  | const miopenTensorDescriptor_t | yDesc,
|  | void * | y )

Copies one tensor to another tensor with a different layout/scale.

This function implements:

1. \( Y = alpha * X + beta * Y \) for fp32 and fp16 datatype
2. Vectorize/de-vectorize along channel dimension C for int8 datatype

Currently this is used for transforming from int8 to int8x4 vector datatypes

Parameters

  handle | MIOpen handle (input)
  alpha | Floating point scaling factor, allocated on the host (input)
  xDesc | Source Tensor descriptor for tensor x (input)
  x | Source Tensor x (input)
  beta | Floating point scaling factor, allocated on the host (input)
  yDesc | Destination Tensor descriptor for tensor y (input)
  y | Destination Tensor y (output)

Returns
  miopenStatus_t