Skip to main content

cutensorCreateReduction

Function cutensorCreateReduction 

Source
pub unsafe extern "C" fn cutensorCreateReduction(
    handle: cutensorHandle_t,
    desc: *mut cutensorOperationDescriptor_t,
    descA: cutensorTensorDescriptor_t,
    modeA: *const i32,
    opA: cutensorOperator_t,
    descC: cutensorTensorDescriptor_t,
    modeC: *const i32,
    opC: cutensorOperator_t,
    descD: cutensorTensorDescriptor_t,
    modeD: *const i32,
    opReduce: cutensorOperator_t,
    descCompute: cutensorComputeDescriptor_t,
) -> cutensorStatus_t
Expand description

Creates a cutensorOperatorDescriptor_t object that encodes a tensor reduction of the form $D = alpha \* opReduce(opA(A)) + beta \* opC(C)$.

For example this function enables users to reduce an entire tensor to a scalar: C[] = alpha * A[i,j,k];

This function is also able to perform partial reductions; for instance: C[i,j] = alpha * A[k,j,i]; in this case only elements along the k-mode are contracted.

The binary opReduce operator provides extra control over what kind of a reduction ought to be performed. For instance, setting opReduce to cutensorOperator_t::CUTENSOR_OP_ADD reduces element of A via a summation while cutensorOperator_t::CUTENSOR_OP_MAX would find the largest element in A.

Supported data-type combinations are:

typeAtypeBtypeCtypeCompute
cudaDataType_t::CUDA_R_16FcudaDataType_t::CUDA_R_16FcudaDataType_t::CUDA_R_16FCUTENSOR_COMPUTE_DESC_16F
cudaDataType_t::CUDA_R_16FcudaDataType_t::CUDA_R_16FcudaDataType_t::CUDA_R_16FCUTENSOR_COMPUTE_DESC_32F
cudaDataType_t::CUDA_R_16BFcudaDataType_t::CUDA_R_16BFcudaDataType_t::CUDA_R_16BFCUTENSOR_COMPUTE_DESC_16BF
cudaDataType_t::CUDA_R_16BFcudaDataType_t::CUDA_R_16BFcudaDataType_t::CUDA_R_16BFCUTENSOR_COMPUTE_DESC_32F
cudaDataType_t::CUDA_R_32FcudaDataType_t::CUDA_R_32FcudaDataType_t::CUDA_R_32FCUTENSOR_COMPUTE_DESC_32F
cudaDataType_t::CUDA_R_64FcudaDataType_t::CUDA_R_64FcudaDataType_t::CUDA_R_64FCUTENSOR_COMPUTE_DESC_64F
cudaDataType_t::CUDA_C_32FcudaDataType_t::CUDA_C_32FcudaDataType_t::CUDA_C_32FCUTENSOR_COMPUTE_DESC_32F
cudaDataType_t::CUDA_C_64FcudaDataType_t::CUDA_C_64FcudaDataType_t::CUDA_C_64FCUTENSOR_COMPUTE_DESC_64F

§Parameters

  • handle: Opaque handle holding cuTENSOR’s library context.
  • desc: This opaque struct gets allocated and filled with the information that encodes the requested tensor reduction operation.
  • descA: The descriptor that holds the information about the data type, modes and strides of A.
  • modeA: Array with ‘nmodeA’ entries that represent the modes of A. modeA[i] corresponds to extent[i] and stride[i] w.r.t. the arguments provided to cutensorCreateTensorDescriptor. Modes that only appear in modeA but not in modeC are reduced (contracted).
  • opA: Unary operator that will be applied to each element of A before it is further processed. The original data of this tensor remains unchanged.
  • descC: The descriptor that holds the information about the data type, modes and strides of C.
  • modeC: Array with ‘nmodeC’ entries that represent the modes of C. modeC[i] corresponds to extent[i] and stride[i] w.r.t. the arguments provided to cutensorCreateTensorDescriptor.
  • opC: Unary operator that will be applied to each element of C before it is further processed. The original data of this tensor remains unchanged.
  • descD: Must be identical to descC for now.
  • modeD: Must be identical to modeC for now.
  • opReduce: binary operator used to reduce elements of A.

§Return value