Skip to main content

singe_cutensor_sys/
mp_20600.rs

1/* automatically generated by rust-bindgen 0.72.1 */
2
3pub const CUTENSORMP_MAJOR: u32 = 0;
4pub const CUTENSORMP_MINOR: u32 = 1;
5pub const CUTENSORMP_PATCH: u32 = 0;
6pub const CUTENSORMP_VERSION: u32 = 100;
7#[repr(u32)]
8#[derive(
9    Debug,
10    Copy,
11    Clone,
12    Hash,
13    PartialOrd,
14    Ord,
15    PartialEq,
16    Eq,
17    TryFromPrimitive,
18    IntoPrimitive,
19)]
20pub enum cutensorMpAlgo_t {
21    /// Default algorithm.
22    CUTENSORMP_ALGO_DEFAULT = 0,
23}
24#[repr(u32)]
25#[derive(
26    Debug,
27    Copy,
28    Clone,
29    Hash,
30    PartialOrd,
31    Ord,
32    PartialEq,
33    Eq,
34    TryFromPrimitive,
35    IntoPrimitive,
36)]
37pub enum cutensorMpPlanAttribute_t {
38    /// uint64_t: exact required workspace in bytes that is needed to execute the plan.
39    CUTENSORMP_PLAN_REQUIRED_WORKSPACE_DEVICE = 0,
40    /// uint64_t: exact required workspace in bytes that is needed to execute the plan.
41    CUTENSORMP_PLAN_REQUIRED_WORKSPACE_HOST = 1,
42}
43#[repr(C)]
44#[derive(Debug, Copy, Clone)]
45pub struct cuTensorMpHandle {
46    _unused: [u8; 0],
47}
48pub type cutensorMpHandle_t = *mut cuTensorMpHandle;
49#[repr(C)]
50#[derive(Debug, Copy, Clone)]
51pub struct cuTensorMpTensorDescriptor {
52    _unused: [u8; 0],
53}
54pub type cutensorMpTensorDescriptor_t = *mut cuTensorMpTensorDescriptor;
55#[repr(C)]
56#[derive(Debug, Copy, Clone)]
57pub struct cuTensorMpPlanPreference {
58    _unused: [u8; 0],
59}
60pub type cutensorMpPlanPreference_t = *mut cuTensorMpPlanPreference;
61#[repr(C)]
62#[derive(Debug, Copy, Clone)]
63pub struct cuTensorMpPlan {
64    _unused: [u8; 0],
65}
66pub type cutensorMpPlan_t = *mut cuTensorMpPlan;
67#[repr(C)]
68#[derive(Debug, Copy, Clone)]
69pub struct cuTensorMpOperationDescriptor {
70    _unused: [u8; 0],
71}
72pub type cutensorMpOperationDescriptor_t = *mut cuTensorMpOperationDescriptor;
73#[repr(C)]
74#[derive(Debug, Copy, Clone)]
75pub struct cuTensorMpContractionDescriptor {
76    _unused: [u8; 0],
77}
78pub type cutensorMpContractionDescriptor_t = *mut cuTensorMpContractionDescriptor;
79#[repr(C)]
80#[derive(Debug, Copy, Clone)]
81pub struct cuTensorMpContractionPlan {
82    _unused: [u8; 0],
83}
84pub type cutensorMpContractionPlan_t = *mut cuTensorMpContractionPlan;
85unsafe extern "C" {
86    /// Initializes the cutensorMp library and creates a handle for distributed tensor operations.
87    ///
88    /// This function creates a cutensorMp handle that serves as the context for all distributed tensor operations. The handle is associated with a specific MPI communicator, local CUDA device, and CUDA stream. This allows cutensorMp to coordinate tensor operations across multiple processes and GPUs.
89    ///
90    /// The communicator defines the group of processes that will participate in distributed tensor operations. The local device ID specifies which CUDA device on the current process will be used for computations. The CUDA stream enables asynchronous execution and synchronization with other CUDA operations.
91    ///
92    /// The user is responsible for calling cutensorMpDestroy to free the resources associated with the handle.
93    ///
94    /// Remark
95    ///
96    /// non-blocking, no reentrant, and thread-safe.
97    ///
98    /// # Parameters
99    ///
100    /// - `handle`: Pointer to cutensorMpHandle_t that will hold the created handle.
101    /// - `comm`: NCCL communicator that defines the group of processes for distributed operations.
102    /// - `local_device_id`: CUDA device ID to use on the current process (must be valid and accessible).
103    /// - `stream`: CUDA stream for asynchronous operations.
104    pub fn cutensorMpCreate(
105        handle: *mut cutensorMpHandle_t,
106        comm: ncclComm_t,
107        local_device_id: ::core::ffi::c_int,
108        stream: cudaStream_t,
109    ) -> cutensorStatus_t;
110}
111unsafe extern "C" {
112    /// Frees all resources associated with the provided cutensorMp handle.
113    ///
114    /// This function deallocates all memory and resources associated with a cutensorMp handle that was previously created by cutensorMpCreate. After calling this function, the handle becomes invalid and should not be used in subsequent cutensorMp operations.
115    ///
116    /// Remark
117    ///
118    /// blocking, no reentrant, and thread-safe.
119    pub fn cutensorMpDestroy(handle: cutensorMpHandle_t) -> cutensorStatus_t;
120}
121unsafe extern "C" {
122    /// Creates a distributed tensor descriptor for multi-process tensor operations.
123    ///
124    /// This function creates a tensor descriptor that defines the structure and distribution of a multi-dimensional tensor across multiple processes. Unlike regular cuTENSOR tensor descriptors, this descriptor includes information about how the tensor is partitioned and distributed across different processes in the MPI communicator.
125    ///
126    /// The tensor is described by its modes (dimensions), extents (sizes along each mode), and strides for elements and blocks. The distribution is specified through block sizes, block strides, and nranks-per-mode, which determine how the tensor data is partitioned across the participating processes.
127    ///
128    /// The user is responsible for calling cutensorMpDestroyTensorDescriptor to free the resources associated with the descriptor once it is no longer needed.
129    ///
130    /// Remark
131    ///
132    /// non-blocking, no reentrant, and thread-safe.
133    ///
134    /// # Parameters
135    ///
136    /// - `handle`: Opaque handle holding cutensorMp’s library context.
137    /// - `desc`: Pointer to the address where the allocated tensor descriptor object will be stored.
138    /// - `numModes`: Number of modes (dimensions) in the tensor (must be greater than zero).
139    /// - `extent`: Extent (size) of each mode (size: numModes, all values must be greater than zero).
140    /// - `elementStride`: Stride between consecutive elements in each mode (size: numModes).
141    /// - `blockSize`: Size of each block along each mode for distribution (size: numModes), passing null will using extent\[i\]/nranksPerMode\[i\].
142    /// - `blockStride`: Stride between consecutive blocks in each mode (size: numModes).
143    /// - `nranksPerMode`: Number of processes along each mode (size: numModes).
144    /// - `nranks`: Total number of ranks (processes) participating in the tensor distribution.
145    /// - `ranks`: Array of rank IDs for each participating process (size: nranks), passing null will use the range [0, nranks).
146    /// - `dataType`: Data type of the tensor elements.
147    ///
148    /// # Return value
149    ///
150    /// - [`cutensorStatus_t::CUTENSOR_STATUS_INVALID_VALUE`]: if some input data is invalid (this typically indicates a user error).
151    /// - [`cutensorStatus_t::CUTENSOR_STATUS_NOT_INITIALIZED`]: if the handle is not initialized.
152    /// - [`cutensorStatus_t::CUTENSOR_STATUS_NOT_SUPPORTED`]: if the requested descriptor configuration is not supported.
153    /// - [`cutensorStatus_t::CUTENSOR_STATUS_SUCCESS`]: The operation completed successfully.
154    pub fn cutensorMpCreateTensorDescriptor(
155        handle: cutensorMpHandle_t,
156        desc: *mut cutensorMpTensorDescriptor_t,
157        numModes: u32,
158        extent: *const i64,
159        elementStride: *const i64,
160        blockSize: *const i64,
161        blockStride: *const i64,
162        nranksPerMode: *const i64,
163        nranks: u32,
164        ranks: *const i32,
165        dataType: cudaDataType_t,
166    ) -> cutensorStatus_t;
167}
168unsafe extern "C" {
169    /// Frees all resources related to the provided distributed tensor descriptor.
170    ///
171    /// This function deallocates all memory and resources associated with a cutensorMp tensor descriptor that was previously created by cutensorMpCreateTensorDescriptor. After calling this function, the descriptor becomes invalid and should not be used in subsequent cutensorMp operations.
172    ///
173    /// Remark
174    ///
175    /// blocking, no reentrant, and thread-safe.
176    pub fn cutensorMpDestroyTensorDescriptor(
177        desc: cutensorMpTensorDescriptor_t,
178    ) -> cutensorStatus_t;
179}
180unsafe extern "C" {
181    /// Creates an operation descriptor that encodes a distributed tensor contraction.
182    ///
183    /// This function creates an operation descriptor for distributed tensor contractions of the form $D = \alpha \mathcal{A} \mathcal{B} + \beta \mathcal{C}$, where the tensors A, B, C, and D are distributed across multiple processes as specified by their respective tensor descriptors.
184    ///
185    /// The distributed contraction leverages both intra-process cuTENSOR operations and inter-process communication to efficiently compute tensor contractions that exceed the memory capacity or computational resources of a single GPU. The operation automatically handles data redistribution, local contractions, and result aggregation across the participating processes.
186    ///
187    /// The user is responsible for calling cutensorMpDestroyOperationDescriptor to free the resources associated with the descriptor once it is no longer needed.
188    ///
189    /// Remark
190    ///
191    /// non-blocking, no reentrant, and thread-safe.
192    ///
193    /// # Parameters
194    ///
195    /// - `handle`: Opaque handle holding cutensorMp’s library context.
196    /// - `desc`: Pointer to the operation descriptor that will be created and filled with information encoding the distributed contraction operation.
197    /// - `descA`: Distributed tensor descriptor for input tensor A.
198    /// - `modesA`: Modes of the input tensor A.
199    /// - `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.
200    /// - `descB`: Distributed tensor descriptor for input tensor B.
201    /// - `modesB`: Modes of the input tensor B.
202    /// - `opB`: Unary operator that will be applied to each element of B before it is further processed. The original data of this tensor remains unchanged.
203    /// - `descC`: Distributed tensor descriptor for input tensor C.
204    /// - `modesC`: Modes of the input tensor C.
205    /// - `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.
206    /// - `descD`: Distributed tensor descriptor for output tensor D (currently must be identical to descC).
207    /// - `modesD`: Modes of the output tensor D.
208    /// - `descCompute`: Compute descriptor that determines the precision for the operation.
209    ///
210    /// # Return value
211    ///
212    /// - [`cutensorStatus_t::CUTENSOR_STATUS_INVALID_VALUE`]: if some input data is invalid (this typically indicates a user error).
213    /// - [`cutensorStatus_t::CUTENSOR_STATUS_NOT_INITIALIZED`]: if the handle is not initialized.
214    /// - [`cutensorStatus_t::CUTENSOR_STATUS_NOT_SUPPORTED`]: if the combination of tensor configurations is not supported.
215    /// - [`cutensorStatus_t::CUTENSOR_STATUS_SUCCESS`]: The operation completed successfully.
216    pub fn cutensorMpCreateContraction(
217        handle: cutensorMpHandle_t,
218        desc: *mut cutensorMpOperationDescriptor_t,
219        descA: cutensorMpTensorDescriptor_t,
220        modesA: *const i32,
221        opA: cutensorOperator_t,
222        descB: cutensorMpTensorDescriptor_t,
223        modesB: *const i32,
224        opB: cutensorOperator_t,
225        descC: cutensorMpTensorDescriptor_t,
226        modesC: *const i32,
227        opC: cutensorOperator_t,
228        descD: cutensorMpTensorDescriptor_t,
229        modesD: *const i32,
230        descCompute: cutensorComputeDescriptor_t,
231    ) -> cutensorStatus_t;
232}
233unsafe extern "C" {
234    /// Frees all resources related to the provided distributed contraction descriptor.
235    ///
236    /// This function deallocates all memory and resources associated with a cutensorMp operation descriptor that was previously created by cutensorMpCreateContraction. After calling this function, the descriptor becomes invalid and should not be used in subsequent cutensorMp operations.
237    ///
238    /// Remark
239    ///
240    /// blocking, no reentrant, and thread-safe.
241    pub fn cutensorMpDestroyOperationDescriptor(
242        desc: cutensorMpOperationDescriptor_t,
243    ) -> cutensorStatus_t;
244}
245unsafe extern "C" {
246    /// Creates a plan preference object for controlling distributed tensor operation planning.
247    ///
248    /// This function creates a preference object that allows users to control various aspects of the execution plan for distributed tensor operations. The preferences include algorithm selection, workspace size limits, and JIT compilation options that affect both the underlying cuTENSOR operations and the distributed communication patterns.
249    ///
250    /// The plan preference provides fine-grained control over:
251    ///
252    /// * Local cuTENSOR algorithm selection and JIT mode
253    /// * Distributed algorithm strategy (non-packing, packing with permutation, or packing with P2P)
254    /// * Workspace size limits for both device and host memory
255    /// * cuTENSOR workspace preferences
256    ///
257    /// The user is responsible for calling cutensorMpDestroyPlanPreference to free the resources associated with the preference object.
258    ///
259    /// Remark
260    ///
261    /// non-blocking, no reentrant, and thread-safe.
262    ///
263    /// # Parameters
264    ///
265    /// - `handle`: Opaque handle holding cutensorMp’s library context.
266    /// - `pref`: Pointer to the plan preference object that will be created.
267    /// - `cutensormp_algo`: Algorithm selection for distributed communication patterns.
268    /// - `cutensormp_workspace_size_device`: Maximum device workspace size for cutensorMp operations (bytes), minimum 2GB is required.
269    /// - `cutensormp_workspace_size_host`: Maximum host workspace size for cutensorMp operations (bytes).
270    ///
271    /// # Return value
272    ///
273    /// - [`cutensorStatus_t::CUTENSOR_STATUS_INVALID_VALUE`]: if some input data is invalid (this typically indicates a user error).
274    /// - [`cutensorStatus_t::CUTENSOR_STATUS_NOT_INITIALIZED`]: if the handle is not initialized.
275    /// - [`cutensorStatus_t::CUTENSOR_STATUS_SUCCESS`]: The operation completed successfully.
276    pub fn cutensorMpCreatePlanPreference(
277        handle: cutensorMpHandle_t,
278        pref: *mut cutensorMpPlanPreference_t,
279        cutensormp_algo: cutensorMpAlgo_t,
280        cutensormp_workspace_size_device: u64,
281        cutensormp_workspace_size_host: u64,
282    ) -> cutensorStatus_t;
283}
284unsafe extern "C" {
285    /// Frees all resources related to the provided plan preference object.
286    ///
287    /// This function deallocates all memory and resources associated with a cutensorMp plan preference object that was previously created by cutensorMpCreatePlanPreference. After calling this function, the preference object becomes invalid and should not be used in subsequent cutensorMp operations.
288    ///
289    /// Remark
290    ///
291    /// blocking, no reentrant, and thread-safe.
292    pub fn cutensorMpDestroyPlanPreference(
293        pref: cutensorMpPlanPreference_t,
294    ) -> cutensorStatus_t;
295}
296unsafe extern "C" {
297    /// Creates an execution plan for distributed tensor contractions.
298    ///
299    /// This function creates an optimized execution plan for the distributed tensor contraction encoded by the operation descriptor. The plan selects the most appropriate algorithms and communication strategies based on the tensor distributions, available resources, and user preferences.
300    ///
301    /// The planning process analyzes the distributed tensor layout, communication requirements, and computational resources to determine an efficient execution strategy. This may involve data redistribution, local contractions, and result aggregation phases that minimize communication overhead while maximizing computational efficiency.
302    ///
303    /// The user is responsible for calling cutensorMpDestroyPlan to free the resources associated with the plan once it is no longer needed.
304    ///
305    /// Remark
306    ///
307    /// calls asynchronous functions, no reentrant, and thread-safe.
308    ///
309    /// # Parameters
310    ///
311    /// - `handle`: Opaque handle holding cutensorMp’s library context.
312    /// - `plan`: Pointer to the execution plan object that will be created.
313    /// - `desc`: Operation descriptor encoding the distributed contraction (created by cutensorMpCreateContraction).
314    /// - `pref`: Plan preference object specifying algorithm and workspace preferences (may be NULL for default preferences).
315    ///
316    /// # Return value
317    ///
318    /// - [`cutensorStatus_t::CUTENSOR_STATUS_INVALID_VALUE`]: if some input data is invalid (this typically indicates a user error).
319    /// - [`cutensorStatus_t::CUTENSOR_STATUS_NOT_INITIALIZED`]: if the handle is not initialized.
320    /// - [`cutensorStatus_t::CUTENSOR_STATUS_NOT_SUPPORTED`]: if no viable execution plan could be found.
321    /// - [`cutensorStatus_t::CUTENSOR_STATUS_SUCCESS`]: The operation completed successfully.
322    pub fn cutensorMpCreatePlan(
323        handle: cutensorMpHandle_t,
324        plan: *mut cutensorMpPlan_t,
325        desc: cutensorMpOperationDescriptor_t,
326        pref: cutensorMpPlanPreference_t,
327    ) -> cutensorStatus_t;
328}
329unsafe extern "C" {
330    /// Frees all resources related to the provided distributed contraction plan.
331    ///
332    /// This function deallocates all memory and resources associated with a cutensorMp execution plan that was previously created by cutensorMpCreatePlan. After calling this function, the plan becomes invalid and should not be used in subsequent cutensorMp operations.
333    ///
334    /// Remark
335    ///
336    /// blocking, no reentrant, and thread-safe.
337    pub fn cutensorMpDestroyPlan(plan: cutensorMpPlan_t) -> cutensorStatus_t;
338}
339unsafe extern "C" {
340    /// Retrieves information about an already-created plan (see [`cutensorPlanAttribute_t`]).
341    ///
342    /// # Parameters
343    ///
344    /// - `plan`: Denotes an already-created plan (e.g., via cutensorMpCreatePlan).
345    /// - `buf`: On successful exit: Holds the information of the requested attribute.
346    /// - `sizeInBytes`: size of `buf` in bytes.
347    ///
348    /// # Return value
349    ///
350    /// - [`cutensorStatus_t::CUTENSOR_STATUS_INVALID_VALUE`]: if some input data is invalid (this typically indicates an user error).
351    /// - [`cutensorStatus_t::CUTENSOR_STATUS_SUCCESS`]: The operation completed successfully.
352    pub fn cutensorMpPlanGetAttribute(
353        handle: cutensorMpHandle_t,
354        plan: cutensorMpPlan_t,
355        attribute: cutensorMpPlanAttribute_t,
356        buf: *mut ::core::ffi::c_void,
357        sizeInBytes: size_t,
358    ) -> cutensorStatus_t;
359}
360unsafe extern "C" {
361    /// Performs a distributed tensor contraction across multiple processes.
362    ///
363    /// 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.
364    ///
365    /// The execution involves several phases:
366    ///
367    /// 1. Data redistribution to align tensor blocks for efficient computation
368    /// 2. Local tensor contractions using cuTENSOR on each participating device
369    /// 3. Communication and aggregation of partial results across processes
370    /// 4. Final result assembly in the distributed output tensor
371    ///
372    /// 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.
373    ///
374    /// Remark
375    ///
376    /// calls asynchronous functions, no reentrant, and thread-safe.
377    ///
378    /// # Parameters
379    ///
380    /// - `handle`: Opaque handle holding cutensorMp’s library context.
381    /// - `plan`: Execution plan for the distributed contraction (created by cutensorMpCreatePlan).
382    /// - `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_32F`]scalars, all data types of the scalar are identical to the type of `C`).
383    /// - `A`: Pointer to the local portion of distributed tensor A in GPU memory.
384    /// - `B`: Pointer to the local portion of distributed tensor B in GPU memory.
385    /// - `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_32F`]scalars, all data types of the scalar are identical to the type of `C`).
386    /// - `C`: Pointer to the local portion of distributed tensor C in GPU memory.
387    /// - `D`: Pointer to the local portion of distributed tensor D in GPU memory (may be identical to C).
388    /// - `device_workspace`: Pointer to device workspace memory (size determined by cutensorMpPlanGetAttribute with [`cutensorMpPlanAttribute_t::CUTENSORMP_PLAN_REQUIRED_WORKSPACE_DEVICE`]).
389    /// - `host_workspace`: Pointer to host workspace memory (size determined by cutensorMpPlanGetAttribute with [`cutensorMpPlanAttribute_t::CUTENSORMP_PLAN_REQUIRED_WORKSPACE_HOST`]).
390    ///
391    /// # Return value
392    ///
393    /// - [`cutensorStatus_t::CUTENSOR_STATUS_ARCH_MISMATCH`]: if the plan was created for a different device architecture.
394    /// - [`cutensorStatus_t::CUTENSOR_STATUS_CUDA_ERROR`]: if a CUDA error occurred during execution.
395    /// - [`cutensorStatus_t::CUTENSOR_STATUS_INSUFFICIENT_WORKSPACE`]: if the provided workspace is insufficient.
396    /// - [`cutensorStatus_t::CUTENSOR_STATUS_INVALID_VALUE`]: if some input data is invalid (this typically indicates a user error).
397    /// - [`cutensorStatus_t::CUTENSOR_STATUS_NOT_INITIALIZED`]: if the handle is not initialized.
398    /// - [`cutensorStatus_t::CUTENSOR_STATUS_NOT_SUPPORTED`]: if the operation is not supported with the given configuration.
399    /// - [`cutensorStatus_t::CUTENSOR_STATUS_SUCCESS`]: The operation completed successfully.
400    pub fn cutensorMpContract(
401        handle: cutensorMpHandle_t,
402        plan: cutensorMpPlan_t,
403        alpha: *const ::core::ffi::c_void,
404        A: *const ::core::ffi::c_void,
405        B: *const ::core::ffi::c_void,
406        beta: *const ::core::ffi::c_void,
407        C: *const ::core::ffi::c_void,
408        D: *mut ::core::ffi::c_void,
409        device_workspace: *mut ::core::ffi::c_void,
410        host_workspace: *mut ::core::ffi::c_void,
411    ) -> cutensorStatus_t;
412}