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

[RFC] Handle device pointer for state initialization #1982

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

sacpis
Copy link
Collaborator

@sacpis sacpis commented Jul 21, 2024

Fixes #1788

This PR checks if the pointer is a device pointer and then does memcpy from device to device.

Copy link

CUDA Quantum Docs Bot: A preview of the documentation can be found here.

github-actions bot pushed a commit that referenced this pull request Jul 21, 2024
github-actions bot pushed a commit that referenced this pull request Jul 21, 2024
Copy link

CUDA Quantum Docs Bot: A preview of the documentation can be found here.

Copy link
Collaborator

@bmhowe23 bmhowe23 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change LGTM, but it would be good for @1tnguyen to review as well. I don't know if #1788 was documenting the desire to avoid a memory copy entirely (similar to a std::move()) or not.

@sacpis sacpis force-pushed the handle_device_pointer branch from 0269611 to 1678dee Compare July 22, 2024 16:16
github-actions bot pushed a commit that referenced this pull request Jul 22, 2024
Copy link

CUDA Quantum Docs Bot: A preview of the documentation can be found here.

@sacpis
Copy link
Collaborator Author

sacpis commented Jul 23, 2024

@1tnguyen May I please request for you review?

Copy link
Collaborator

@1tnguyen 1tnguyen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍 Thanks, @sacpis.

@sacpis sacpis enabled auto-merge (squash) July 23, 2024 20:50
@sacpis sacpis disabled auto-merge July 23, 2024 20:55
Copy link

CUDA Quantum Docs Bot: A preview of the documentation can be found here.

github-actions bot pushed a commit that referenced this pull request Jul 24, 2024
Copy link
Collaborator

@bmhowe23 bmhowe23 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just capturing the offline discussion amongst the 4 of us...

int currentDevice;
HANDLE_CUDA_ERROR(cudaGetDevice(&currentDevice));

if (attributes.device != currentDevice) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was discussed offline, but just to capture it here, we think it would be good to add a multi-GPU test somewhere to exercise this new code in this if branch; otherwise, the code in here would never have been tested, and there is some question about whether or not the calls to cudaSetDevice would work as intended here.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another alternative would be to throw an "unsupported" error message here, but I think we should still add a test for the "same GPU" functionality as well.

int currentDevice;
HANDLE_CUDA_ERROR(cudaGetDevice(&currentDevice));

if (attributes.device != currentDevice) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment here.

@sacpis
Copy link
Collaborator Author

sacpis commented Jul 25, 2024

Here I am blocked on including nvqir/CircuitSimulator in get_state_tester. Seems like the builder is not happy including it in the file as it throws the below error.

In file included from /workspaces/cuda-quantum/runtime/common/Logger.h:14,
                 from /workspaces/cuda-quantum/runtime/nvqir/CircuitSimulator.h:13,
                 from /workspaces/cuda-quantum/unittests/gpu/get_state_tester.cu:12:
/workspaces/cuda-quantum/runtime/common/FmtCore.h:16:10: fatal error: fmt/chrono.h: No such file or directory
   16 | #include <fmt/chrono.h>
      |          ^~~~~~~~~~~~~~
compilation terminated.

@bmhowe23
Copy link
Collaborator

Here I am blocked on including nvqir/CircuitSimulator in get_state_tester. Seems like the builder is not happy including it in the file as it throws the below error.

In file included from /workspaces/cuda-quantum/runtime/common/Logger.h:14,
                 from /workspaces/cuda-quantum/runtime/nvqir/CircuitSimulator.h:13,
                 from /workspaces/cuda-quantum/unittests/gpu/get_state_tester.cu:12:
/workspaces/cuda-quantum/runtime/common/FmtCore.h:16:10: fatal error: fmt/chrono.h: No such file or directory
   16 | #include <fmt/chrono.h>
      |          ^~~~~~~~~~~~~~
compilation terminated.

Thanks, Sachin. I'm definitely open to any other ideas for testing here. I just think that we need to have some sort of test to prove that code changes are working as intended. If a unit test isn't working out, perhaps an application-level test (one where the user is providing a pointer to GPU memory) would work better than a unit test?

@sacpis
Copy link
Collaborator Author

sacpis commented Aug 1, 2024

Just had a call with @1tnguyen regarding passing the pointer to GPU memory. Putting this PR into the draft mode and adding RFC here.

Seems like it might involve introduction of some new APIs to qvector, something like these

  qubit::qubit(const vector<complex<double>>&);
  qubit::qubit(const initializer_list<complex<double>>&);
  qvector::qvector(const vector<complex<double>>&);
  qvector::qvector(const initializer_list<complex<double>>&);

in order to support passing a pointer to the GPU memory.
This is related to issue #1086.

@1tnguyen @amccaskey Would you please add your thoughts here?

@sacpis sacpis marked this pull request as draft August 1, 2024 22:20
@sacpis sacpis changed the title Handle device pointer for state initialization [RFC] Handle device pointer for state initialization Aug 1, 2024
@sacpis sacpis force-pushed the handle_device_pointer branch from d162912 to 4c6f33b Compare August 1, 2024 22:21
Copy link

github-actions bot commented Aug 1, 2024

CUDA Quantum Docs Bot: A preview of the documentation can be found here.

github-actions bot pushed a commit that referenced this pull request Aug 1, 2024
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.

[StateHandling] Implement custatevec state initialization from state vector in device memory
4 participants