Skip to content

Commit

Permalink
update CUDA (#69)
Browse files Browse the repository at this point in the history
* update CUDA

* cleanup

* update version

Co-authored-by: Roger-Luo <[email protected]>
  • Loading branch information
GiggleLiu and Roger-luo authored May 10, 2021
1 parent 7532cbf commit d6ff74a
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 34 deletions.
6 changes: 3 additions & 3 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "CuYao"
uuid = "b48ca7a8-dd42-11e8-2b8e-1b7706800275"
version = "0.2.9"
version = "0.3.0"

[deps]
BitBasis = "50ba71b6-fa0f-514d-ae9a-0916efc90dcf"
Expand All @@ -16,14 +16,14 @@ Yao = "5872b779-8223-5990-8dd0-5abbb0748c8c"

[compat]
BitBasis = "0.7"
CUDA = "2.0, 3.0"
CUDA = "3.1"
LuxurySparse = "0.6"
Reexport = "0.2, 1.0"
StaticArrays = "0.12, 1.0"
StatsBase = "0.33"
TupleTools = "1"
Yao = "0.6, 0.7"
julia = "1"
julia = "1.6"

[extras]
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
Expand Down
26 changes: 1 addition & 25 deletions src/CUDApatch.jl
Original file line number Diff line number Diff line change
@@ -1,27 +1,3 @@
#import CUDA: _cuview, ViewIndex, NonContiguous
#using CUDA: genperm
# fallback to SubArray when the view is not contiguous

#=
function LinearAlgebra.permutedims!(dest::GPUArray, src::GPUArray, perm) where N
perm isa Tuple || (perm = Tuple(perm))
gpu_call(dest, (dest, src, perm)) do state, dest, src, perm
I = @cartesianidx src state
@inbounds dest[genperm(I, perm)...] = src[I...]
return
end
return dest
end
=#

import CUDA: pow, abs, angle
for (RT, CT) in [(:Float64, :ComplexF64), (:Float32, :ComplexF32)]
@eval cp2c(d::$RT, a::$RT) = CUDA.Complex(d*CUDA.cos(a), d*CUDA.sin(a))
for NT in [RT, :Int32]
@eval CUDA.pow(z::$CT, n::$NT) = CUDA.Complex((CUDA.pow(CUDA.abs(z), n)*CUDA.cos(n*CUDA.angle(z))), (CUDA.pow(CUDA.abs(z), n)*CUDA.sin(n*CUDA.angle(z))))
end
end

@inline function bit_count(x::UInt32)
x = ((x >> 1) & 0b01010101010101010101010101010101) + (x & 0b01010101010101010101010101010101)
x = ((x >> 2) & 0b00110011001100110011001100110011) + (x & 0b00110011001100110011001100110011)
Expand Down Expand Up @@ -95,7 +71,7 @@ end
Computes Kronecker products in-place on the GPU.
The results are stored in 'C', overwriting the existing values of 'C'.
"""
function kron!(C::CuArray{T3}, A::DenseCuArray{T1}, B::DenseCuArray{T2}) where {T1, T2, T3}
function Yao.YaoBase.kron!(C::CuArray{T3}, A::DenseCuArray{T1}, B::DenseCuArray{T2}) where {T1, T2, T3}
@boundscheck (size(C) == (size(A,1)*size(B,1), size(A,2)*size(B,2))) || throw(DimensionMismatch())
CI = Base.CartesianIndices(C)
@inline function kernel(C, A, B)
Expand Down
1 change: 0 additions & 1 deletion src/CuYao.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ using Random

using Yao.YaoArrayRegister
using CUDA
import Yao: kron!
@reexport using Yao

const Ints = NTuple{<:Any, Int}
Expand Down
2 changes: 1 addition & 1 deletion src/kernels.jl
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ end
mask = bmask(Int32, bits...)
1<<nbit,@inline function kernel(state, inds)
i = inds[1]
piecewise(state, inds)[i] *= CUDA.pow(d, bit_count(Int32(i-1)&mask))
piecewise(state, inds)[i] *= d ^ bit_count(Int32(i-1)&mask)
return
end
end
Expand Down
4 changes: 2 additions & 2 deletions test/CUDApatch.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ end
@testset "Complex pow" begin
for T in [ComplexF64, ComplexF32]
a = CuArray(randn(T, 4, 4))
@test Array(CUDA.pow.(a, Int32(3))) Array(a).^3
@test Array(CUDA.pow.(a, real(T)(3))) Array(a).^3
@test Array(a .^ Int32(3)) Array(a).^3
@test Array(a .^ real(T)(3)) Array(a).^3
end
end

Expand Down
4 changes: 2 additions & 2 deletions test/GPUReg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,9 @@ end
c = zeros(12,8)
ca, cb, cc = cu(a), cu(b), cu(c)
@test kron(ca, cb) |> Array kron(a, b)
@test kron!(cc, ca, cb) |> Array kron(a,b)
@test Yao.YaoBase.kron!(cc, ca, cb) |> Array kron(a,b)

kron!(c,a,b)
Yao.YaoBase.kron!(c,a,b)
@test cc |> Array c

v = randn(100) |> cu
Expand Down

2 comments on commit d6ff74a

@Roger-luo
Copy link
Member

Choose a reason for hiding this comment

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

Released via Ion CLI
@JuliaRegistrator register

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

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

Registration pull request created: JuliaRegistries/General/36396

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.3.0 -m "<description of version>" d6ff74af18f3aeb5833153e6bf39ba129f700521
git push origin v0.3.0

Please sign in to comment.