-
Notifications
You must be signed in to change notification settings - Fork 120
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
How can I use QuantumStateGPU.get_vector() to get cupy.array? #290
Comments
Unfortunately, qulacs does not have an interface to get a pointer to state vectors on GPU or directly pass it to other GPU numerical libraries. import qulacs
num_qubit = 10
statevec_on_qulacs = qulacs.QuantumStateGpu(10) # allocate 2^10 complex vector on GPU
statevec_on_cpu = statevec_on_qulacs.get_vector() # copy from GPU -> main ram
statevec_on_cupy = cupy.array(statevec_on_cpu) # copy from main ram -> GPU Qulacs is currently written in C++/CUDA and its functions are exported to python with pybind. So, I think it is hard to provide an interface to directly convert internal state vectors on GPU to Cupy or relevant libraries unless pybind supports it... |
Okay , thank you very much ! I hope one day quantum state can convert to vector directly on Gpu.😭😭😭 |
Hi, a CuPy dev here. May I ask is the difficulty in that the statevector is not stored contiguously in memory? Otherwise there must be a way to get the pointer address and memory size, and CuPy can take from there. |
Hi @leofang .
Therefore, I agree that there is no technical problem in passing the pointer address of memory, and I didn't know CuPy supports wrapping foreign memory address as a CuPy array object. While I couldn't find a simple way to export a function to return CuPy object with pybind11, if it is useful for users, it is easy to implement a function to return the pointer address of state vector on GPU. |
@corryvrequan Yes, I think it'd be useful. At the pybind11 level the pointer address to the start of the state vector (assuming there's no extra requirement in padding / alignment / offset) can be returned as either |
In my experiments , I want to use state vector to do some numeral calculations. So I wish that I can get state vector on GPU directly. Compared to Numpy, Cupy or PyTorch may be better choices. But I can't find out how get_vector() runs. I can only find:
Is there anyway to help me?
The text was updated successfully, but these errors were encountered: