LCAO GPU Optimization V1 reduce device pointer look up (OpenMP target map) - #5342
Conversation
…nnecessary transfers due to map(to) instead of using is_device_ptr
ye-luo
left a comment
There was a problem hiding this comment.
Please undo changes to dev_ptr so this PR can focus on real optimization.
|
Can you please add some brief specifics on what the CPU/GPU comparison was? e.g. Processor, GPU, which molecule (basis, electron count), batch size? |
I am not understanding this... What do you want me to do? |
See my comment on the source code https://github.com/QMCPACK/qmcpack/pull/5342/files#r1972521897 |
Preparing file with summary. |
…compared to risks of memory corruption
|
I profiled runs with and without this change. This optimization pattern works cross platform (nvidia/intel checked) proposed the difference is that the old code needs a runtime table lookup to find out the dev_ptr and it requires mutex locking the table during lookup and it is a bottleneck. When threads doesn't do the look up frequently, the cost is negligible. The reason of slow LCAO was its small kernels, high call counts nature. The proposed way does have a drawback. Device pointers are exposed in the host code. This may cased segfault if they are not managed correctly, for example de-referenced on the host by accident. For the moment, I think we can take this PR that uses device ptr. Eventually once we change the code computing basis species by species. We can restore the code using the old code pattern. |
ye-luo
left a comment
There was a problem hiding this comment.
Please only keep changes of switching to dev_ptr and run clang-format.
|
Fantastic!!! Thanks Ye. However, I am almost half through isolating per basiset. Will start in a new PR. |
Please make small PRs. large ones are too painful to review. |
There is only one "serious" question to @ye-luo to see if we use auto* SuperTwist_ptr = SuperTwist.data(); and transfer that to the GPU or not. |
OK. Here is what I found. In the current way using |
|
Here is the problem, this affects only pbc.. some other users might need it but obviously I won't be able to touch it then. I don't mind doing it on device right away.. was just not sure of the behavior |
|
My consideration is to get this PR merged timely. So we can look at your other PR that depends on this one.
Right now, the price is being paid regardless of using PBC. If you are willing to address it right away, simply make a new PR. |
ye-luo
left a comment
There was a problem hiding this comment.
Please do a review of your own code using the github web interface to prevent missing requests. There are two conversations being marked resolved without actually being addressed. All the rest LGTM.
|
Test this please |
Proposed changes
First set of optimizations allowing for a 2.2X speed up by reducing device pointer lookup via OpenMP.
The LCAO branch was about 3 to 4X slower than CPU. After investigation, It seemed like it was due to map(to:) not checking if data was already on device. So converted all calls to is_device_ptr which fixed the issue.
Tested on multiple systems, but more specifically "TOU ASN" molecule: O(3) S(1) C(8) N(5) H(17), with 106 electrons and 1185 basis functions.
What type(s) of changes does this code introduce?
Code Optimization
Does this introduce a breaking change?
What systems has this change been tested on?
Checklist
Update the following with a yes where the items apply. If you're unsure about any of them, don't hesitate to ask. This is
simply a reminder of what we are going to look for before merging your code.