Tensor

Tensor#

MIOpen: Tensor

Enumerations

enum  miopenDataType_t {
  miopenHalf = 0 ,
  miopenFloat = 1 ,
  miopenInt32 = 2 ,
  miopenInt8 = 3 ,
  miopenBFloat16 = 5 ,
  miopenDouble = 6 ,
  miopenFloat8 = 7 ,
  miopenBFloat8 = 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. More...
 
 MIOPEN_DECLARE_OBJECT (miopenSeqTensorDescriptor)
 Creates the miopenSeqTensorDescriptor_t type. More...
 
miopenStatus_t miopenCreateTensorDescriptor (miopenTensorDescriptor_t *tensorDesc)
 Create a Tensor Descriptor. More...
 
miopenStatus_t miopenSet4dTensorDescriptor (miopenTensorDescriptor_t tensorDesc, miopenDataType_t dataType, int n, int c, int h, int w)
 Set shape of 4D tensor. More...
 
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. More...
 
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. More...
 
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. More...
 
miopenStatus_t miopenSetTensorDescriptor (miopenTensorDescriptor_t tensorDesc, miopenDataType_t dataType, int nbDims, const int *dimsA, const int *stridesA)
 Set shape of N-dimensional tensor. More...
 
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. More...
 
miopenStatus_t miopenSetTensorCastType (miopenTensorDescriptor_t tensorDesc, miopenDataType_t cast_type)
 Set the tensor cast type. More...
 
miopenStatus_t miopenGetTensorDescriptorSize (miopenTensorDescriptor_t tensorDesc, int *size)
 Set shape of N-dimensional tensor. More...
 
miopenStatus_t miopenGetTensorDescriptor (miopenTensorDescriptor_t tensorDesc, miopenDataType_t *dataType, int *dimsA, int *stridesA)
 Get the details of the N-dimensional tensor descriptor. More...
 
miopenStatus_t miopenDestroyTensorDescriptor (miopenTensorDescriptor_t tensorDesc)
 Destroys the tensor descriptor. More...
 
miopenStatus_t miopenCreateSeqTensorDescriptor (miopenSeqTensorDescriptor_t *tensorDesc)
 Create a Tensor Descriptor for sequence data. More...
 
miopenStatus_t miopenDestroySeqTensorDescriptor (miopenSeqTensorDescriptor_t tensorDesc)
 Destroys the sequence data tensor descriptor. More...
 
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. More...
 
miopenStatus_t miopenSetTensor (miopenHandle_t handle, const miopenTensorDescriptor_t yDesc, void *y, const void *alpha)
 Fills a tensor with a single value. More...
 
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. More...
 
miopenStatus_t miopenGetTensorNumBytes (miopenTensorDescriptor_t tensorDesc, size_t *numBytes)
 Returns number of bytes associated with tensor descriptor. More...
 
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. More...
 

Detailed Description

Enumeration Type Documentation

◆ 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 
miopenBFloat8 
miopenInt64 
Examples
/home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-miopen/checkouts/docs-6.2.2/include/miopen/miopen.h.

◆ 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)

Examples
/home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-miopen/checkouts/docs-6.2.2/include/miopen/miopen.h.

◆ 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

Examples
/home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-miopen/checkouts/docs-6.2.2/include/miopen/miopen.h.

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
tensorDescPointer to a sequence data tensor descriptor type (output)
Returns
miopenStatus_t
Examples
/home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-miopen/checkouts/docs-6.2.2/include/miopen/miopen.h.

◆ miopenCreateTensorDescriptor()

miopenStatus_t miopenCreateTensorDescriptor ( miopenTensorDescriptor_t *  tensorDesc)

Create a Tensor Descriptor.

API for creating an uninitialized tensor descriptor.

Parameters
tensorDescPointer to a tensor descriptor type (output)
Returns
miopenStatus_t
Examples
/home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-miopen/checkouts/docs-6.2.2/include/miopen/miopen.h.

◆ miopenDestroySeqTensorDescriptor()

miopenStatus_t miopenDestroySeqTensorDescriptor ( miopenSeqTensorDescriptor_t  tensorDesc)

Destroys the sequence data tensor descriptor.

Parameters
tensorDescTensor descriptor (input)
Returns
miopenStatus_t
Examples
/home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-miopen/checkouts/docs-6.2.2/include/miopen/miopen.h.

◆ miopenDestroyTensorDescriptor()

miopenStatus_t miopenDestroyTensorDescriptor ( miopenTensorDescriptor_t  tensorDesc)

Destroys the tensor descriptor.

Parameters
tensorDescTensor descriptor (input)
Returns
miopenStatus_t
Examples
/home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-miopen/checkouts/docs-6.2.2/include/miopen/miopen.h.

◆ 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
tensorDescTensor descriptor (input)
dataTypeMIOpen datatype (output)
nMini-batch size (output)
cNumber of channels (output)
hData height dimension size (output)
wData width dimension size (output)
nStrideMini-batch dimension stride (output)
cStrideChannel dimension stride (output)
hStrideHeight dimension stride (output)
wStrideWidth dimension stride (output)
Returns
miopenStatus_t
Examples
/home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-miopen/checkouts/docs-6.2.2/include/miopen/miopen.h.

◆ miopenGetTensorDescriptor()

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

Get the details of the N-dimensional tensor descriptor.

Parameters
tensorDescTensor descriptor (input)
dataTypeMIOpen datatype (output)
dimsAArray containing the size of dimensions (output)
stridesAArray containing the size of stride (output)
Returns
miopenStatus_t
Examples
/home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-miopen/checkouts/docs-6.2.2/include/miopen/miopen.h.

◆ 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
tensorDescTensor descriptor (input)
sizenumber of elements in tensor described by the descriptor (output)
Returns
miopenStatus_t
Examples
/home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-miopen/checkouts/docs-6.2.2/include/miopen/miopen.h.

◆ miopenGetTensorNumBytes()

miopenStatus_t miopenGetTensorNumBytes ( miopenTensorDescriptor_t  tensorDesc,
size_t *  numBytes 
)

Returns number of bytes associated with tensor descriptor.

Parameters
tensorDescTensor descriptor (input)
numBytesNumber of bytes associated with tensor descriptor (output)
Returns
miopenStatus_t
Examples
/home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-miopen/checkouts/docs-6.2.2/include/miopen/miopen.h.

◆ 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
handleMIOpen handle (input)
tensorOpOperation from miopenTensorOp_t (input)
alpha1Tensor A's floating point scaling factor, allocated on the host (input)
aDescTensor descriptor for tensor A (input)
ATensor A (input)
alpha2Tensor B's floating point scaling factor, allocated on the host (input)
bDescTensor descriptor for tensor B (input)
BTensor B (input)
betaTensor C's floating point scaling factor, allocated on the host (input)
cDescTensor descriptor for tensor C (input)
CTensor C (input and output)
Returns
miopenStatus_t
Examples
/home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-miopen/checkouts/docs-6.2.2/include/miopen/miopen.h.

◆ 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
handleMIOpen handle (input)
yDescTensor descriptor for tensor y (input)
yTensor y (input and output)
alphaFloating point scaling factor, allocated on the host (input)
Returns
miopenStatus_t
Examples
/home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-miopen/checkouts/docs-6.2.2/include/miopen/miopen.h.

◆ 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
tensorDescTensor descriptor (input/output)
dataTypeMIOpen datatype (input)
nMini-batch size (input)
cNumber of channels (input)
hData height dimension size (input)
wData width dimension size (input)
Returns
miopenStatus_t
Examples
/home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-miopen/checkouts/docs-6.2.2/include/miopen/miopen.h.

◆ 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
tensorDescTensor descriptor (input/output)
dataTypeMIOpen datatype (input)
nMini-batch size (input)
cNumber of channels (input)
hData height dimension size (input)
wData width dimension size (input)
nStrideMini-batch dimension stride (input)
cStrideChannel dimension stride (input)
hStrideHeight dimension stride (input)
wStrideWidth dimension stride (input)
Returns
miopenStatus_t
Examples
/home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-miopen/checkouts/docs-6.2.2/include/miopen/miopen.h.

◆ 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
tensorDescTensor descriptor (input/output)
dataTypeMIOpen datatype (input)
tensorLayoutTensor layout (input)
lensTensor dimensions (input)
num_lensTensor dimension size (input)
Returns
miopenStatus_t
Examples
/home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-miopen/checkouts/docs-6.2.2/include/miopen/miopen.h.

◆ 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
handleMIOpen handle (input)
yDescTensor descriptor for tensor y (input)
yTensor y (input)
alphaPointer to fill value (input)
Returns
miopenStatus_t
Examples
/home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-miopen/checkouts/docs-6.2.2/include/miopen/miopen.h.

◆ 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
tensorDescTensor descriptor type (input)
cast_typeMIOpen datatype (input)
Examples
/home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-miopen/checkouts/docs-6.2.2/include/miopen/miopen.h.

◆ 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
tensorDescTensor descriptor (input/output)
dataTypeMIOpen datatype (input)
nbDimsNumber of dimensions in the dimsA array (input)
dimsAArray containing the size of dimensions (input)
stridesAArray containing the size of stride (input)
Returns
miopenStatus_t
Examples
/home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-miopen/checkouts/docs-6.2.2/include/miopen/miopen.h.

◆ 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
tensorDescTensor descriptor (input/output)
dataTypeMIOpen datatype (input)
nbDimsNumber of dimensions in the dimsA array (input)
dimsAArray containing the size of dimensions (input)
stridesAArray containing the size of stride (input)
Returns
miopenStatus_t
Examples
/home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-miopen/checkouts/docs-6.2.2/include/miopen/miopen.h.

◆ 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
handleMIOpen handle (input)
alphaFloating point scaling factor, allocated on the host (input)
xDescSource Tensor descriptor for tensor x (input)
xSource Tensor x (input)
betaFloating point scaling factor, allocated on the host (input)
yDescDestination Tensor descriptor for tensor y (input)
yDestination Tensor y (output)
Returns
miopenStatus_t
Examples
/home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-miopen/checkouts/docs-6.2.2/include/miopen/miopen.h.