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

Introduce CUDA extension #77

Merged
merged 11 commits into from
May 17, 2024
Merged

Introduce CUDA extension #77

merged 11 commits into from
May 17, 2024

Conversation

ytdHuang
Copy link
Member

@ytdHuang ytdHuang commented Apr 21, 2024

close #41

Introduce the CUDA extension for QuantumToolbox

TODO list:

  • Define extension module QuantumToolboxCUDAExt
  • support CUDA.cu() for QuantumObject with argument word_size=32 or 64
  • support CUDA.CuArray for QuantumObject with dense vectors and matrices
  • support CUDA.CuSparseVector for QuantumObject with sparse vectors
  • support CUDA.CuSparseMatrixCSC for QuantumObject with sparse matrices
  • support CUDA.CuSparseMatrixCSR for QuantumObject with sparse matrices
  • Apply to JuliaGPU/buildkite for GPU runtests (after the CI config file is done)
  • GPU CI config file (@albertomercurio still need to update encrypted codecov token)
  • runtests for basic functionalities of QuantumToolboxCUDAExt
  • runtests for ODE solvers using CUDA
  • Docstring for the functions in CUDA.jl that supports QuantumObject input

Basic functionalities

Consider a (dense) vector or matrix

using QuantumToolbox
V = Qobj([0, 0])
M = Qobj([0 0; 0 0])
eltype(V) # Int64
eltype(M) # Int64

One can use the following methods to transform QuantumObject into CuArray and also specifying the exact element type (eltype)

using CUDA
CuArray(V)             # eltype = Int64
CuArray{Float32}(V)    # eltype = Float32
CuArray{Float64}(V)    # eltype = Float64
CuArray{ComplexF32}(V) # eltype = ComplexF32
CuArray{ComplexF64}(V) # eltype = ComplexF64

CuArray(M)             # eltype = Int64
CuArray{Float32}(M)    # eltype = Float32
CuArray{Float64}(M)    # eltype = Float64
CuArray{ComplexF32}(M) # eltype = ComplexF32
CuArray{ComplexF64}(M) # eltype = ComplexF64

For the sparse matrices, consider a Pauli-X (sparse) matrix

X = sigmax()
typeof(X) # SparseMatrixCSC{ComplexF64, Int64}

We can do the same thing:

using CUDA.CUSPARSE
CuSparseMatrixCSC(X)             # CuSparseMatrixCSC{ComplexF64, Int32}
CuSparseMatrixCSC{ComplexF32}(X) # CuSparseMatrixCSC{ComplexF32, Int32}
CuSparseMatrixCSR(X)             # CuSparseMatrixCSR{ComplexF64, Int32}
CuSparseMatrixCSR{ComplexF32}(X) # CuSparseMatrixCSR{ComplexF32, Int32}

We can also use CUDA.cu() and specify the keyword argument word_size (default: 32):

# dense vectors
typeof(V)           # Vector{Int64}
cu(V)               # CuArray{Int32, 1} 
cu(V; word_size=64) # CuArray{Int64, 1}

# dense matrices
typeof(M)           # Matrix{Int64}
cu(M)               # CuArray{Int32, 2} 
cu(M; word_size=64) # CuArray{Int64, 2}

# sparse matrices
typeof(X)           # SparseMatrixCSC{ComplexF64, Int64}
cu(X)               # CuSparseMatrixCSC{ComplexF32, Int32} 
cu(X; word_size=64) # CuSparseMatrixCSC{ComplexF64, Int32} 

@ytdHuang ytdHuang marked this pull request as ready for review May 17, 2024 04:14
Copy link

codecov bot commented May 17, 2024

Codecov Report

Attention: Patch coverage is 0% with 18 lines in your changes are missing coverage. Please review.

Project coverage is 91.36%. Comparing base (d04d1da) to head (3bc1f75).

Files Patch % Lines
ext/QuantumToolboxCUDAExt.jl 0.00% 18 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #77      +/-   ##
==========================================
- Coverage   92.31%   91.36%   -0.95%     
==========================================
  Files          19       20       +1     
  Lines        1743     1761      +18     
==========================================
  Hits         1609     1609              
- Misses        134      152      +18     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@albertomercurio
Copy link
Member

Great!

@albertomercurio albertomercurio merged commit 1cdfde0 into main May 17, 2024
11 of 13 checks passed
@ytdHuang ytdHuang deleted the dev/cuda branch May 17, 2024 16:55
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.

CUDA Extension
2 participants