-
Notifications
You must be signed in to change notification settings - Fork 93
GPU optimized symmetry operations #1097
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
using GPUArraysCore | ||
|
||
function accumulate_over_symmetries!(ρaccu::AbstractArray, ρin::AbstractArray, | ||
basis::PlaneWaveBasis{T}, symmetries) where {T} | ||
Gs = reshape(G_vectors(basis), size(ρaccu)) | ||
fft_size = basis.fft_size | ||
|
||
symm_invS = to_device(basis.architecture, [Mat3{Int}(inv(symop.S)) for symop in symmetries]) | ||
symm_τ = to_device(basis.architecture, [symop.τ for symop in symmetries]) | ||
n_symm = length(symmetries) | ||
|
||
map!(ρaccu, Gs) do G | ||
acc = zero(complex(T)) | ||
# Explicit loop over indicies because AMDGPU does not support zip() in map! | ||
for i_symm in 1:n_symm | ||
invS = symm_invS[i_symm] | ||
τ = symm_τ[i_symm] | ||
idx = index_G_vectors(fft_size, invS * G) | ||
acc += isnothing(idx) ? zero(complex(T)) : cis2pi(-T(dot(G, τ))) * ρin[idx] | ||
end | ||
acc | ||
end | ||
ρaccu | ||
end | ||
|
||
function lowpass_for_symmetry!(ρ::AbstractGPUArray, basis::PlaneWaveBasis{T}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The only place where we need this is in Again feel free to make this fused function also the CPU function if this does not hurt performance too much. |
||
symmetries=basis.symmetries) where {T} | ||
all(isone, symmetries) && return ρ | ||
|
||
Gs = reshape(G_vectors(basis), size(ρ)) | ||
fft_size = basis.fft_size | ||
ρtmp = similar(ρ) | ||
|
||
symm_S = to_device(basis.architecture, [symop.S for symop in symmetries]) | ||
|
||
map!(ρtmp, ρ, Gs) do ρ_i, G | ||
acc = ρ_i | ||
for S in symm_S | ||
idx = index_G_vectors(fft_size, S * G) | ||
acc *= isnothing(idx) ? zero(complex(T)) : one(complex(T)) | ||
end | ||
Comment on lines
+37
to
+41
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Formatting off. |
||
acc | ||
end | ||
ρ .= ρtmp | ||
ρ | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Formatting
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, how much worse is this implementation compared to the CPU version ? Can we not just make this the CPU version, too ? It looks like it should not be very much worse than what we have.