Skip to main content
`Ctrl`+`K`

# TensorReduce

MIOpen: TensorReduce
Macros | Enumerations | Functions
TensorReduce

## Macros

#define | MIOPEN_API_VERSION_REDUCE_TENSOR 1
| Version of TensorReduce API. Applications may use it to ensure backward compatibility with older library versions.

## Enumerations

enum | miopenReduceTensorOp_t { MIOPEN_REDUCE_TENSOR_ADD = 0 , MIOPEN_REDUCE_TENSOR_MUL , MIOPEN_REDUCE_TENSOR_MIN , MIOPEN_REDUCE_TENSOR_MAX , MIOPEN_REDUCE_TENSOR_AMAX , MIOPEN_REDUCE_TENSOR_AVG , MIOPEN_REDUCE_TENSOR_NORM1 , MIOPEN_REDUCE_TENSOR_NORM2 = 7 }
enum | miopenReduceTensorIndices_t { MIOPEN_REDUCE_TENSOR_NO_INDICES = 0 , MIOPEN_REDUCE_TENSOR_FLATTENED_INDICES = 1 }
enum | miopenIndicesType_t { MIOPEN_32BIT_INDICES = 0 , MIOPEN_64BIT_INDICES = 1 , MIOPEN_16BIT_INDICES = 2 , MIOPEN_8BIT_INDICES = 3 }

## Functions

| MIOPEN_DECLARE_OBJECT (miopenReduceTensorDescriptor)
| Creates the miopenReduceTensorDescriptor_t type.
miopenStatus_t | miopenCreateReduceTensorDescriptor (miopenReduceTensorDescriptor_t *reduceTensorDesc)
| Creates the ReduceTensor descriptor object.
miopenStatus_t | miopenDestroyReduceTensorDescriptor (miopenReduceTensorDescriptor_t reduceTensorDesc)
| Destroy the ReduceTensor descriptor object.
miopenStatus_t | miopenSetReduceTensorDescriptor (miopenReduceTensorDescriptor_t reduceTensorDesc, miopenReduceTensorOp_t reduceTensorOp, miopenDataType_t reduceTensorCompType, miopenNanPropagation_t reduceTensorNanOpt, miopenReduceTensorIndices_t reduceTensorIndices, miopenIndicesType_t reduceTensorIndicesType)
| Initialize a ReduceTensor descriptor object.
miopenStatus_t | miopenGetReduceTensorDescriptor (const miopenReduceTensorDescriptor_t reduceTensorDesc, miopenReduceTensorOp_t *reduceTensorOp, miopenDataType_t *reduceTensorCompType, miopenNanPropagation_t *reduceTensorNanOpt, miopenReduceTensorIndices_t *reduceTensorIndices, miopenIndicesType_t *reduceTensorIndicesType)
| Query a ReduceTensor descriptor object.
miopenStatus_t | miopenGetReductionIndicesSize (miopenHandle_t handle, const miopenReduceTensorDescriptor_t reduceTensorDesc, const miopenTensorDescriptor_t aDesc, const miopenTensorDescriptor_t cDesc, size_t *sizeInBytes)
| Helper function to query the minimum index space size required by the ReduceTensor call.
miopenStatus_t | miopenGetReductionWorkspaceSize (miopenHandle_t handle, const miopenReduceTensorDescriptor_t reduceTensorDesc, const miopenTensorDescriptor_t aDesc, const miopenTensorDescriptor_t cDesc, size_t *sizeInBytes)
| Helper function to query the minimum workspace size required by the ReduceTensor call.
miopenStatus_t | miopenReduceTensor (miopenHandle_t handle, const miopenReduceTensorDescriptor_t reduceTensorDesc, void *indices, size_t indicesSizeInBytes, void *workspace, size_t workspaceSizeInBytes, const void *alpha, const miopenTensorDescriptor_t aDesc, const void *A, const void *beta, const miopenTensorDescriptor_t cDesc, void *C)
| TensorReduce function doing reduction on tensor A by implementing C = alpha * reduceOp(A).

## Detailed Description

## Macro Definition Documentation

## ◆ MIOPEN_API_VERSION_REDUCE_TENSOR

#define MIOPEN_API_VERSION_REDUCE_TENSOR 1

Version of TensorReduce API. Applications may use it to ensure backward compatibility with older library versions.

- 0 or undefined - Initial API. Supported operations: ADD, MIN, MIN, MAX.
- 1 - Added AMAX, AVG, NORM1, NORM2 ops.

## Enumeration Type Documentation

## ◆ miopenIndicesType_t

enum miopenIndicesType_t

Reduction Indices types

Enumerator
MIOPEN_32BIT_INDICES | 32-bit unsigned integer indices
MIOPEN_64BIT_INDICES | 64-bit unsigned integer indices
MIOPEN_16BIT_INDICES | 16-bit unsigned integer indices
MIOPEN_8BIT_INDICES | 8-bit unsigned integer indices

## ◆ miopenReduceTensorIndices_t

enum miopenReduceTensorIndices_t

Reduction Indices computation modes

Enumerator
MIOPEN_REDUCE_TENSOR_NO_INDICES | Does not compuate indices
MIOPEN_REDUCE_TENSOR_FLATTENED_INDICES | Compute the relative, flatted indices

## ◆ miopenReduceTensorOp_t

enum miopenReduceTensorOp_t

Tensor Reduction operation types

Nan numbers propagation modes

Enumerator
MIOPEN_REDUCE_TENSOR_ADD | the operation is adding the values of the reduced elements
MIOPEN_REDUCE_TENSOR_MUL | the operation is multiplying the values of the reduced elements
MIOPEN_REDUCE_TENSOR_MIN | the operation is getting the minimum value of the reduced elements
MIOPEN_REDUCE_TENSOR_MAX | the operation is getting the maximum value of the reduced elements
MIOPEN_REDUCE_TENSOR_AMAX | the operation is getting the maximum absolute value of the reduced elements
MIOPEN_REDUCE_TENSOR_AVG | the operation is getting the averaged value of the reduced elements
MIOPEN_REDUCE_TENSOR_NORM1 | the operation is adding the absolute values of the reduced elements
MIOPEN_REDUCE_TENSOR_NORM2 | the operation is getting the square root of the sum of squares of the reduced elements

## Function Documentation

## ◆ MIOPEN_DECLARE_OBJECT()

MIOPEN_DECLARE_OBJECT | ( | miopenReduceTensorDescriptor |  | ) |

Creates the miopenReduceTensorDescriptor_t type.

## ◆ miopenCreateReduceTensorDescriptor()

miopenStatus_t miopenCreateReduceTensorDescriptor | ( | miopenReduceTensorDescriptor_t * | reduceTensorDesc | ) |

Creates the ReduceTensor descriptor object.

Parameters

  reduceTensorDesc | Pointer to a ReduceTensor descriptor type

Returns
  miopenStatus_t

## ◆ miopenDestroyReduceTensorDescriptor()

miopenStatus_t miopenDestroyReduceTensorDescriptor | ( | miopenReduceTensorDescriptor_t | reduceTensorDesc | ) |

Destroy the ReduceTensor descriptor object.

Parameters

  reduceTensorDesc | ReduceTensor descriptor type (input)

Returns
  miopenStatus_t

## ◆ miopenGetReduceTensorDescriptor()

miopenStatus_t miopenGetReduceTensorDescriptor | ( | const miopenReduceTensorDescriptor_t | reduceTensorDesc,
|  | miopenReduceTensorOp_t * | reduceTensorOp,
|  | miopenDataType_t * | reduceTensorCompType,
|  | miopenNanPropagation_t * | reduceTensorNanOpt,
|  | miopenReduceTensorIndices_t * | reduceTensorIndices,
|  | miopenIndicesType_t * | reduceTensorIndicesType )

Query a ReduceTensor descriptor object.

Parameters

  reduceTensorDesc | Pointer to the ReduceTensor descriptor object (input)
  reduceTensorOp | Pointer to enumerant specifying the operation used by ReduceTensor (output)
  reduceTensorCompType | Pointer to enumerant specifying the data type used with ReduceTensor operation (output)
  reduceTensorNanOpt | Pointer to enumerant specifying the Nan number propagation mode (output)
  reduceTensorIndices | Pointer to enumerant specifying the indices modes used by ReduceTensor (output)
  reduceTensorIndicesType | Pointer to enumerant specifying the data type of the indices (output)

Returns
  miopenStatus_t

## ◆ miopenGetReductionIndicesSize()

miopenStatus_t miopenGetReductionIndicesSize | ( | miopenHandle_t | handle,
|  | const miopenReduceTensorDescriptor_t | reduceTensorDesc,
|  | const miopenTensorDescriptor_t | aDesc,
|  | const miopenTensorDescriptor_t | cDesc,
|  | size_t * | sizeInBytes )

Helper function to query the minimum index space size required by the ReduceTensor call.

Parameters

  handle | MIOpen Handle (input)
  reduceTensorDesc | Pointer to the ReduceTensor descriptor object (input)
  aDesc | Pointer to the input tensor descriptor (input)
  cDesc | Pointer to the output tensor descriptor (input)
  sizeInBytes | Pointer to data to return the minimum index space size

Returns
  miopenStatus_t

## ◆ miopenGetReductionWorkspaceSize()

miopenStatus_t miopenGetReductionWorkspaceSize | ( | miopenHandle_t | handle,
|  | const miopenReduceTensorDescriptor_t | reduceTensorDesc,
|  | const miopenTensorDescriptor_t | aDesc,
|  | const miopenTensorDescriptor_t | cDesc,
|  | size_t * | sizeInBytes )

Helper function to query the minimum workspace size required by the ReduceTensor call.

Parameters

  handle | MIOpen Handle (input)
  reduceTensorDesc | Pointer to the ReduceTensor descriptor object (input)
  aDesc | Pointer to the input tensor descriptor (input)
  cDesc | Pointer to the output tensor descriptor (input)
  sizeInBytes | Pointer to data to return the minimum workspace size

Returns
  miopenStatus_t

## ◆ miopenReduceTensor()

miopenStatus_t miopenReduceTensor | ( | miopenHandle_t | handle,
|  | const miopenReduceTensorDescriptor_t | reduceTensorDesc,
|  | void * | indices,
|  | size_t | indicesSizeInBytes,
|  | void * | workspace,
|  | size_t | workspaceSizeInBytes,
|  | const void * | alpha,
|  | const miopenTensorDescriptor_t | aDesc,
|  | const void * | A,
|  | const void * | beta,
|  | const miopenTensorDescriptor_t | cDesc,
|  | void * | C )

TensorReduce function doing reduction on tensor A by implementing C = alpha * reduceOp(A).

- beta * C

The length of each dimension of output tensor C must match the length of the corresponding dimension of input tensor A or must be equal to 1. The dimensions with length equal to 1 indicate the dimensions of A to be reduced.

Parameters

  handle | MIOpen Handle (input)
  reduceTensorDesc | Pointer to the ReduceTensor descriptor object (input)
  indices | Address of the allocated indices data space (output)
  indicesSizeInBytes | Size in bytes of the allocated indices data space (input)
  workspace | Address of the allocated workspace data (input)
  workspaceSizeInBytes | Size in bytes of the allocated workspace data (input)
  alpha | Pointer to scale factor for data in input tensor A (input)
  aDesc | Pointer to the tensor descriptor for input tensor A (input)
  A | Pointer to the data of input tensor A (input)
  beta | Pointer to scale factor for data in output tensor C (input)
  cDesc | Pointer to the tensor descriptor for output tensor C (input)
  C | Pointer to the data of output tensor C (output)

Returns
  miopenStatus_t

## ◆ miopenSetReduceTensorDescriptor()

miopenStatus_t miopenSetReduceTensorDescriptor | ( | miopenReduceTensorDescriptor_t | reduceTensorDesc,
|  | miopenReduceTensorOp_t | reduceTensorOp,
|  | miopenDataType_t | reduceTensorCompType,
|  | miopenNanPropagation_t | reduceTensorNanOpt,
|  | miopenReduceTensorIndices_t | reduceTensorIndices,
|  | miopenIndicesType_t | reduceTensorIndicesType )

Initialize a ReduceTensor descriptor object.

Parameters

  reduceTensorDesc | Pointer to the ReduceTensor descriptor object (output)
  reduceTensorOp | Enumerant specifying the operation used by ReduceTensor (input)
  reduceTensorCompType | Enumerant specifying the data type used with ReduceTensor operation (input)
  reduceTensorNanOpt | Enumerant specifying the Nan number propagation mode (input)
  reduceTensorIndices | Enumerant specifying the indices modes used by ReduceTensor (input)
  reduceTensorIndicesType | Enumerant specifying the data type of the indices (input)

Returns
  miopenStatus_t