cuquantum.cutensornet.contract_slices

cuquantum.cutensornet.contract_slices(intptr_t handle, intptr_t plan, raw_data_in, intptr_t raw_data_out, int32_t accumulate_output, intptr_t work_desc, intptr_t slice_group, intptr_t stream)[source]

Performs the actual contraction of the tensor network.

Parameters
  • handle (intptr_t) – Opaque handle holding cuTensorNet’s library context.

  • plan (intptr_t) – Encodes the execution of a tensor network contraction (see create_contraction_plan() and contraction_autotune()). Some internal meta-data may be updated upon contraction.

  • raw_data_in (object) –

    Array of N pointers (N being the number of input tensors specified in create_network_descriptor()): raw_data_in[i] points to the data associated with the i-th input tensor (in device memory). It can be:

    • an int as the pointer address to the array, or

    • a Python sequence of ints (as pointer addresses).

  • raw_data_out (intptr_t) – Points to the raw data of the output tensor (in device memory).

  • accumulate_output (int32_t) – If 0, write the contraction result into raw_data_out; otherwise accumulate the result into raw_data_out.

  • work_desc (intptr_t) – Opaque structure describing the workspace. The provided CUTENSORNET_WORKSPACE_SCRATCH workspace must be valid (the workspace pointer must be device accessible, see cutensornetMemspace_t, and the workspace size must be the same as or larger than both the minimum needed and the value provided at plan creation). See create_contraction_plan(), workspace_get_memory_size() & workspace_set_memory(). The provided CUTENSORNET_WORKSPACE_CACHE workspace must be device accessible, see cutensornetMemspace_t; it can be of any size, the larger the better, up to the size that can be queried with workspace_get_memory_size(). If a device memory handler is set, then work_desc can be set to null, or the memory pointer in work_desc of either the workspace kinds can be set to null, and the workspace size can be set either to a negative value (in which case the “recommended” size is used, see CUTENSORNET_WORKSIZE_PREF_RECOMMENDED) or to a valid size. For a workspace of kind CUTENSORNET_WORKSPACE_SCRATCH, a memory buffer with the specified size will be drawn from the user’s mempool and released back once done. For a workspace of kind CUTENSORNET_WORKSPACE_CACHE, a memory buffer with the specified size will be drawn from the user’s mempool and released back once the work_desc is destroyed, if work_desc != NULL, otherwise, once the plan is destroyed, or an alternative work_desc with a different memory address/size is provided in a subsequent contract_slices() call.

  • slice_group (intptr_t) – Opaque object specifying the slices to be contracted (see create_slice_group_from_id_range() and cutensornetCreateSliceGroupFromIDs()). If set to null, all slices will be contracted..

  • stream (intptr_t) – The CUDA stream on which the computation is performed.