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

CuYao compiles depending on value, not depending on type #362

Closed
jlbosse opened this issue Apr 20, 2022 · 5 comments
Closed

CuYao compiles depending on value, not depending on type #362

jlbosse opened this issue Apr 20, 2022 · 5 comments
Labels
bug Something isn't working

Comments

@jlbosse
Copy link
Contributor

jlbosse commented Apr 20, 2022

It seems like CuYao recompiles apply! every time the parameters of a circuit are changed, even though the circuit is still the same. This is in contrast to running a circuit on the CPU and and not on the GPU where compilation happens only once when running a circuit for the first time and then all future runs are fast when changing the parameters. See the following MWE:

using Yao, Yao.AD, Yao.EasyBuild
using CuYao
import CUDA

n = 10
d = 5
circuit = variational_circuit(n, d)

cureg = zero_state(n) |> cu
reg = zero_state(n) 

# every time this block gets run the first `apply!()` takes much longer than the second `appply!()`
begin
    cureg.state .= 0.
    @CUDA.allowscalar cureg.state[1] = 1.
    dispatch!(circuit, :random)
    @time apply!(cureg, circuit)
    @time apply!(cureg, circuit)
end

# only the very first time this block gets run the first `apply!()` invokes a compilation pass, after
# that the first `apply!()` and the second apply always take roughly the same time.
begin
    reg.state .= 0.
    reg.state[1] = 1.
    dispatch!(circuit, :random)
    @time apply!(reg, circuit)
    @time apply!(reg, circuit)
end
@GiggleLiu
Copy link
Member

Just confirmed this issue, it was due to the use of closure when writing kernel functions, will fix it later today. Thanks for reporting the bug!

@GiggleLiu
Copy link
Member

You issue will be fixed by this PR: QuantumBFS/CuYao.jl#74
Thanks again for the bug report!

@jlbosse
Copy link
Contributor Author

jlbosse commented Apr 21, 2022

Great, and thank you for providing a fix that quickly!

@GiggleLiu
Copy link
Member

The PR in CuYao has been merged and is being tagged, I will close this issue for now. Feel free to reopen it if the patch does not fix your issue.

@jlbosse
Copy link
Contributor Author

jlbosse commented Apr 22, 2022

Worked perfectly, thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants