SunnySuite / Sunny.jl

Spin dynamics and generalization to SU(N) coherent states
Other
79 stars 19 forks source link

SWT Matrix Vector Optimizations #202

Closed ddahlbom closed 9 months ago

ddahlbom commented 9 months ago

Contains optimizations of SWT matrix-vector multiply, on order of 3-4X for the example I tried. Speedup comes from avoiding repeated calculation of some q-independent data and from eliminating allocations due to reshape. Vectorization is impeded by memory access patterns. Future work could either be directed toward fine-grained memory work to improve access patterns, or possibly by going to real space and doing a sparse matrix-vector multiply.

The allocating functions multiply_by_hamiltonian_dipole(x, swt, qs) and multiply_by_hamiltonian_SUN(x, swt, qs) have been added. These should not be benchmarked directly. Instead, the contents of these functions after allocations should be benched, specifically these lines and their SU(N) analogs:

qphase = map(qs_reshaped) do q  
    (exp(2π*im*q[1]), exp(2π*im*q[2]), exp(2π*im*q[3]))
end
multiply_by_hamiltonian_dipole_aux!(reshape(y, (length(qs_reshaped), size(x, 2))), x, phasebuf, qphase, swt)