Skip to main content

cutensorMpContract

Function cutensorMpContract 

Source
pub unsafe extern "C" fn cutensorMpContract(
    handle: cutensorMpHandle_t,
    plan: cutensorMpPlan_t,
    alpha: *const c_void,
    A: *const c_void,
    B: *const c_void,
    beta: *const c_void,
    C: *const c_void,
    D: *mut c_void,
    device_workspace: *mut c_void,
    host_workspace: *mut c_void,
) -> cutensorStatus_t
Expand description

Performs a distributed tensor contraction across multiple processes.

This function executes the distributed tensor contraction $D = \alpha \mathcal{A} \mathcal{B} + \beta \mathcal{C}$ according to the execution plan created by cutensorMpCreatePlan. The operation coordinates computation and communication across multiple processes and GPUs to efficiently perform tensor contractions that exceed the capacity of a single device.

The execution involves several phases:

  1. Data redistribution to align tensor blocks for efficient computation
  2. Local tensor contractions using cuTENSOR on each participating device
  3. Communication and aggregation of partial results across processes
  4. Final result assembly in the distributed output tensor

All participating processes in the MPI communicator must call this function with consistent parameters. The input and output tensors must be distributed according to their respective tensor descriptors, with each process providing its local portion of the data.

Remark

calls asynchronous functions, no reentrant, and thread-safe.

§Parameters

  • handle: Opaque handle holding cutensorMp’s library context.
  • plan: Execution plan for the distributed contraction (created by cutensorMpCreatePlan).
  • alpha: Scaling factor for the A*B product. Pointer to host memory with data type determined by the compute descriptor. The data type follows that of cuTENSOR (i.e., the data type of the scalar is deptermined by the data type of C:cudaDataType_t::CUDA_R_16F and cudaDataType_t::CUDA_R_16BF use cudaDataType_t::CUDA_R_32Fscalars, all data types of the scalar are identical to the type of C).
  • A: Pointer to the local portion of distributed tensor A in GPU memory.
  • B: Pointer to the local portion of distributed tensor B in GPU memory.
  • beta: Scaling factor for tensor C. Pointer to host memory with data type determined by the compute descriptor. The data type follows that of cuTENSOR (i.e., the data type of the scalar is deptermined by the data type of C:cudaDataType_t::CUDA_R_16F and cudaDataType_t::CUDA_R_16BF use cudaDataType_t::CUDA_R_32Fscalars, all data types of the scalar are identical to the type of C).
  • C: Pointer to the local portion of distributed tensor C in GPU memory.
  • D: Pointer to the local portion of distributed tensor D in GPU memory (may be identical to C).
  • device_workspace: Pointer to device workspace memory (size determined by cutensorMpPlanGetAttribute with cutensorMpPlanAttribute_t::CUTENSORMP_PLAN_REQUIRED_WORKSPACE_DEVICE).
  • host_workspace: Pointer to host workspace memory (size determined by cutensorMpPlanGetAttribute with cutensorMpPlanAttribute_t::CUTENSORMP_PLAN_REQUIRED_WORKSPACE_HOST).

§Return value