Tensors#

Tensor types and functions.

miopenDataType_t#

enum miopenDataType_t#

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

Values:

enumerator miopenHalf#

16-bit floating point (Fully supported)

enumerator miopenFloat#

32-bit floating point (Fully supported)

enumerator miopenInt32#

32-bit int point (Partially supported)

enumerator miopenInt8#

8-bit int point (Partially supported)

enumerator miopenInt8x4#

Pack of four 8-bit int points in NCHW_VECT_C format (Partially supported)

enumerator miopenBFloat16#

16-bit binary floating point (8-bit exponent, 7-bit fraction) (Partially supported)

enumerator miopenDouble#

64-bit floating point (Partially supported)

miopenTensorOp_t#

enum miopenTensorOp_t#

Element-wise tensor operation modes

Values:

enumerator miopenTensorOpAdd#

Add tensors element-wise

enumerator miopenTensorOpMul#

Multiply two tensors element-wise

enumerator miopenTensorOpMin#

Minimum of tensor element pairs

enumerator miopenTensorOpMax#

Maximum of tensor element pairs

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

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 only implements NCHW layout.

Parameters:
  • tensorDesc – Tensor descriptor type (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

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 type (input)

  • dataType – MIOpen datatype (input)

  • 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

miopenSetTensorDescriptor#

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

Set shape of N-dimensional tensor.

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

Parameters:
  • tensorDesc – Tensor descriptor type (input)

  • 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

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 type (input)

  • size – number of elements in tensor described by the descriptor (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 type (input)

  • dataType – MIOpen datatype (input)

  • dimsA – Array containing the size of dimensions (output)

  • stridesA – Array containing the size of stride (output)

Returns:

miopenStatus_t

miopenDestroyTensorDescriptor#

miopenStatus_t miopenDestroyTensorDescriptor(miopenTensorDescriptor_t tensorDesc)#

Destroys the tensor descriptor.

Parameters:

tensorDesc – Tensor descriptor type (input)

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

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

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