qmatmul_cupy module
Module providing direct_cupy / algo_cupy computational approaches for quaternion matrix-matrix multiplication. It is meant for additional research / efficiency tests on environments where CuPy is available (especially with tensor cores support). Kept purposely separate from qmatmul.py, but containing twin-like counterparts of functions present there.
- qmatmul_cupy.stack_cupy(E)[source]
(for internal use) cupy counterpart of qmatmul.stack: (R, S, 4) device array -> stacked (4*R, S) device array.
- qmatmul_cupy.a44_cupy(A, a_blocks_signs=array([[1, -1, -1, -1], [1, 1, -1, 1], [1, 1, 1, -1], [1, -1, 1, 1]], dtype=int8), a_blocks_parts=array([[0, 1, 2, 3], [1, 0, 3, 2], [2, 3, 0, 1], [3, 2, 1, 0]], dtype=int8))[source]
(for internal use) cupy counterpart of qmatmul.a44: (M, N, 4) device array -> transformation (4*M, 4*N) device array. Reuses the A_BLOCKS_SIGNS / A_BLOCKS_PARTS constants imported from qmatmul (plain Python-int indexing into them is fine here, since the 4x4 outer loop runs on the host).
- qmatmul_cupy.had4_cupy(E4)[source]
(for internal use) cupy counterpart of qmatmul.had4: Hadamard transform of a stacked (4 * R, S) device array.
- qmatmul_cupy.matmuldiag_cupy(E4, F4, factor)[source]
(for internal use) cupy counterpart of qmatmul.matmuldiag: diagonal product of two stacked device arrays, computed as four independent real-valued GEMMs (one per diagonal block), each dispatched to cuBLAS via cupy’s .dot.
- qmatmul_cupy.permute_cupy(E4, permutation)[source]
(for internal use) cupy counterpart of qmatmul.permute: block-wise permutation of a stacked (4*R, S) device array. permutation is a plain length-4 sequence of Python ints (no need to move it to device, since the loop below runs on the host and only issues device-to-device slice copies).
- qmatmul_cupy.c4_to_c_cupy(C4)[source]
(for internal use) cupy counterpart of qmatmul.c4_to_c: (4*M, P) device array -> unstacked (M, P, 4) device array.
- qmatmul_cupy.qmatmul_direct_cupy(A, B, verbose=False)[source]
Returns the quaternion matrix product of A and B via the “direct_cupy” approach, for input matrices of type either
float64orfloat32. Implements formula (15) as a single real-valued GEMM of the (4M x 4N) transformation matrix against the (4N x P) stacked matrix, dispatched to cuBLAS via cupy’s.dot.