Skip to content
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

Minor optimization of FFTGrid initialization #1062

Merged
merged 4 commits into from
Feb 19, 2025

Conversation

abussy
Copy link
Collaborator

@abussy abussy commented Feb 14, 2025

With PR #1056 and #1061, the bottleneck of PlaneWaveBasis instantiation becomes the creation of r_vectors at FFTGrid initialization. For systems with high cutoffs, this is non-negligible.

This PR enables the calculation of the r_vectors on the GPU. Additionally, it greatly speeds-up the CPU version by precomputing and recasting the inverse of fft_size.

@mfherbst
Copy link
Member

Looking at the diff of this PR again, I wonder ... what does this PR actually do ? I mean is it just taking out the fac from the inner loop and that's it ?

@abussy
Copy link
Collaborator Author

abussy commented Feb 17, 2025

Not exactly. My tests have shown that simply taking out fac from the original construct, i.e.

VT = value_type(T)
fac = 1 ./ VT.(fft_size)
r_vectors = [(Vec3{VT}(idx.I) .- (1, 1, 1)) .* fac for idx in CartesianIndices(fft_size)]

is considerably slower than the proposed change (factor ~5x). I am not sure why that is, but I suspect it has to do with with creating a Vec3{VT} as the last step. In fact, the following is as efficient as the map construct I initially proposed:

fac = 1 ./ VT.(fft_size)
r_vectors = [Vec3{VT}(fac .* (idx.I .- (1, 1, 1))) for idx in CartesianIndices(fft_size)]

I am happy to switch to the above, if that keeps the code clearer

@mfherbst
Copy link
Member

In my opinion it does, yes.

@mfherbst mfherbst enabled auto-merge (squash) February 17, 2025 17:45
@mfherbst mfherbst disabled auto-merge February 19, 2025 15:23
@mfherbst mfherbst merged commit f1304ef into JuliaMolSim:master Feb 19, 2025
7 of 8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants