kicad2ems.mom25d.gpu_vk¶
mom25d.gpu_vk - the complex64 LU on a Vulkan GPU (slangpy): mom25d.gpu's backend
on AMD, Intel and NVIDIA, Linux and Windows. Vulkan has no LAPACK, so the
factorisation is the hybrid one of MAGMA's getrf:
the CPU factors each panel (N - k0 rows, NB columns) with LAPACK's cgetrf
(partial pivoting, the same pivots and layout as scipy's lu_factor), and
inverts its unit lower triangle (ctrtri);
the GPU applies the panel's row interchanges to the other columns, forms
U12 = L11^-1 A12 (a GEMM with that inverse) and the trailing update
A22 -= L21 U12 (the O(N^3) part: a register-tiled complex GEMM).
With look-ahead: the GPU updates the next panel's columns first and that panel
goes to the CPU while the GPU runs the rest of the trailing update, so the CPU's
panel and the GPU's update overlap.
The matrix is A = Z^T, column-major (Z's rows are its columns, as LAPACK
factors it): column c in buffer c >> sh at (c & mask) * N, the buffers
at most MAX_BUFFER bytes each (Vulkan drivers cap one buffer at 2-4 GB; 16 GB of
matrix is several). The triangular solves of solve() run on the GPU too: blocked
substitution, the diagonal blocks' inverses from the factorisation, the
off-diagonal blocks as matrix-vector products.
b = VulkanBackend()
b.factor(Z)
X = b.solve(R)
lu, piv = b.download()
b.release()
- class kicad2ems.mom25d.gpu_vk.VulkanBackend[source]¶
kicad2ems.mom25d.gpu's backend on a Vulkan GPU: factor (hybrid blocked LU), solve (on the GPU), download.
- download(chunk=268435456)[source]¶
The factor on the host, as scipy.linalg.lu_factor's of A = Z^T: (lu, piv), Fortran order, 0-based.
- factor(Z)[source]¶
Z: host complex64, C-contiguous, equilibrated. Factors A = Z^T in place on the GPU (P L U, LAPACK's pivots), keeping the diagonal blocks' inverses for solve(). Look-ahead: the next panel's columns are updated first and go to the CPU, which factors them while the GPU runs the rest of the trailing update.
- factor_dense(dsc)[source]¶
factor() of put_dense's Z equilibrated by dsc, its complex64 copy made on the GPU (none on the host, nothing more uploaded).
- factor_dense_ldl(dsc)[source]¶
factor_ldl of put_dense's Z equilibrated by dsc, its complex64 half made on the GPU (to_c64_half: nothing more uploaded).
- factor_from_half(H, dsc, chunk=268435456)[source]¶
factor() of the double half H (a host half.Half, complex128) equilibrated by dsc: its rows converted a range at a time into the mapped staging buffers (the core's half_c64_rows) and set at both places of the LU's whole matrix on the GPU (rows_to_mat). The LU of an LDL^T without a factor had made the complex64 half and its whole copy on the host, 12 N^2 beside the double half (a LimeRFE piece of 33k unknowns OOM-killed at 21.9 GB).
- factor_ldl(H, dsc=None)[source]¶
The LDL^T of a host half.Half (complex64, equilibrated; or the double half with dsc, converted on the way up): a gpu_ldl.LDLFactor (raises ZeroDivisionError / FloatingPointError where it has no factor without pivoting).
- fits(N, extra=0.0)[source]¶
Whether an N-unknown LU fits in the free memory (+ extra: what kept factors would give back; policy.gpu_fits). vram_needed counts every device buffer factor() makes and 0.4 GB besides.
- host_buffer(nbytes)[source]¶
Mapped host memory of the caller's (emsdev.vulkan.HostBuffer): a matrix filled there is put_dense's across the bus with no staging (0.14 s against 0.43 s at 14.7k unknowns), and the fill's first touch takes no page faults (np.zeros: 0.33 s).
- mem_free()[source]¶
The device's free memory, and the pool's buffers (idle: _buffer takes them before it allocates).
- mul_dense(V, host=None, share=1.0)[source]¶
Z V in double precision on the GPU (Z: put_dense's or put_dense_half's; V: N x k), SOLVE_RHS columns a submission. host: a function giving Z X on the host: the last (1 - share) of the columns are its, computed while the GPU runs the rest (both hold Z; with many columns the products are bound by double arithmetic, which an RX 7800 XT has about as much of as 8 P-cores). Returns Y, and the seconds (host's, and the GPU's beyond them) where host is given.
- put_dense(Z, host=None)[source]¶
Z (host complex128, C-ordered, N x N) onto the GPU for mul_dense and factor_dense, until drop_dense: 16 N^2 bytes. host: the host_buffer Z is at the start of, read from there.
- put_dense_half(H, cols=None)[source]¶
The double Z by its lower half (a host half.Half, complex128) onto the GPU for mul_dense and factor_dense_ldl, until drop_dense: 8 N^2 bytes (FF, for products of FF_MIN columns or more (cols: the solve's, None: any): made float-float there, in place).
- release()[source]¶
Free the factor and the work arrays (the device memory; the mapped host buffers are kept).
- kicad2ems.mom25d.gpu_vk.tile(device)[source]¶
GT for a GPU (MOM25D_VK_GT overrides it). The update GEMM at k = 256 (2026-11-19, 12.7k x 12.7k): on an RX 7800 XT GT = 6 (96 x 96 tiles) 11.7 TFLOP/s against GT = 4's 10.9 (the LU at 14-20k unknowns 4-5 % faster; GT = 5 11.6, Gauss's three-product form 11.7 at GT = 4 with a larger error, 8.8 at GT = 6); on a GTX 980 Ti (Maxwell) GT = 6 was the slower, its LU 7 %.