Native workflow¤
JAXMg accepts ordinary JAX arrays sharded over a one- or two-axis device mesh. However, cuSOLVERMp requires column-major local buffers distributed in a 2D block-cyclic layout. The native backend bridges these layouts inside one fused C++/CUDA FFI call:
Python calculates static metadata such as the process grid, the process-grid slot of every mesh partition, logical matrix size, tile size, and padded local capacity. It needs only the abstract JAX mesh: the native backend places the communicator ranks on the process grid from XLA's device assignment at run time. C++/CUDA owns the data movement, cuSOLVERMp descriptors and workspace, solver calls, and reverse redistribution. Matrix data remains GPU-resident throughout this workflow, and the in-place transformations reuse bounded native scratch storage to minimize memory overhead.
Matrix-valued solver outputs follow the reverse path shown above. The eigenvalues-only SYEVD mode returns the replicated eigenvalue array directly after solver execution.
Scratch allocation¤
The redistribution path uses one native scratch allocation per FFI call. Its size is determined by the largest tile slab used by the 2D block-cyclic stage:
For square solver tiles, \(T_r=T_c=T_A\). The layout-conversion and edge-padding stages reuse this allocation and process data in bounded batches. They do not allocate a second full local matrix.
Memory-distribution stages¤
The memory redistribution is performed in three stages.
Stage 1: local memory layout conversion¤
JAX presents each local matrix shard in row-major physical memory. cuSOLVERMp expects column-major local memory. CUDA kernels apply an in-place rectangular permutation using bounded scratch; the logical matrix is not transposed. This stage is local to each GPU and requires no communicator traffic.
Stage 2: top-left and edge-padding alignment¤
Python provides tile-aligned local capacity. Native horizontal compaction moves real column slabs toward the global left edge, then vertical compaction moves real row slabs toward the global top edge. Padding is consolidated on the global right and bottom edges.
Moves in one horizontal wave are independent across process rows. Moves in one vertical wave are independent across process columns.
Stage 3: 2D block-cyclic redistribution¤
Whole tile slabs are redistributed in two separable phases. The column-owner phase assigns each tile to the correct process column; the row-owner phase then assigns each tile to the correct process row.
Same-rank moves use local CUDA operations. Cross-rank moves use the
NCCL-backed communicator borrowed from XLA. The same communicator supplies
the ncclComm_t used by cuSOLVERMp.
Solver workflows¤
The routines share the forward redistribution stages and then execute the following cuSOLVERMp calls:
potrscallscusolverMpPotrffollowed bycusolverMpPotrs, optionally extractinglog(det(A))from the same factorization.potrfcallscusolverMpPotrfto return the lower Cholesky factor.potricallscusolverMpPotrffollowed bycusolverMpPotri.lu_solvecallscusolverMpGetrffollowed bycusolverMpGetrs.getrfcallscusolverMpGetrfto return the packed LU factor and pivots.getricallscusolverMpGetrffollowed bycusolverMpGetri.least_squarescallscusolverMpGelsfor tall or square systems.qrcallscusolverMpGeqrffollowed bycusolverMpOrgqrto form reduced Q.syevdcallscusolverMpSyevdfor eigenvalues and optional eigenvectors.gesvdcallscusolverMpGesvd, with U and Vh selected independently.polarcallscusolverMpPolarfor the polar factor and optional H.
Buffer reuse and output restoration are described in Solver-specific native work.
Solver setup¤
Each Python process owns one GPU and contributes one rank to the XLA/NCCL and cuSOLVERMp communicators. See Distributed execution for the required launch model.
To avoid repeated initialization, routines share one cached cuSOLVERMp handle per GPU and grids keyed by NCCL communicator handle, process-grid shape, and mapping. Calls sharing a handle are serialized until their CUDA work completes; matrix descriptors and explicit solver workspaces remain local to each call.
The public Collectives FFI has no communicator-retirement callback. Cached
handles and grids are therefore retained until process exit, without running
collective destructors during shutdown. Changing matrix sizes does not add
cache entries, but using new communicators or process grids does. Restart
distributed clients in fresh worker processes: the cache cannot detect a new
communicator reusing an old handle address.
Set JAXMG_CUSOLVERMP_CACHE=0 before starting every process
to disable reuse for timing comparisons or debugging.
Failure handling¤
Numerical failures return NaN results and a nonzero solver status. Fatal handle or grid setup failures, and grid-destruction failures, instead terminate the affected process to avoid further unsafe collective operations. Peer shutdown depends on JAX's failure detection and the launcher.
A setup failure makes the cached context unusable. Restart the distributed job after a fatal failure.
Detailed implementation¤
Memory distribution gives the complete diagrams, layout definitions, dependency waves, permutation cycles, reverse path, and source-code map.