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

cu(::SVector) gives SVector, cu(::MVector) gives CuArray #1262

Closed
islent opened this issue Dec 7, 2021 · 2 comments
Closed

cu(::SVector) gives SVector, cu(::MVector) gives CuArray #1262

islent opened this issue Dec 7, 2021 · 2 comments
Labels
bug Something isn't working

Comments

@islent
Copy link

islent commented Dec 7, 2021

Here's a MWE:

using CUDA, StaticArrays
N = 10
SV = @SVector rand(N);
SA = @SMatrix rand(N,N);
MV = @MVector rand(N);
MA = @MMatrix rand(N,N);

typeof(cu(SV))
typeof(cu(SA))
typeof(cu(MV))
typeof(cu(MA))

Results:

julia> typeof(cu(SV))
SVector{10, Float64} (alias for SArray{Tuple{10}, Float64, 1, 10})

julia> typeof(cu(SA))
SMatrix{10, 10, Float64, 100} (alias for SArray{Tuple{10, 10}, Float64, 2, 100})

julia> typeof(cu(MV))
CuArray{Float32, 1, CUDA.Mem.DeviceBuffer}

julia> typeof(cu(MA))
CuArray{Float32, 2, CUDA.Mem.DeviceBuffer}

Environments:

(@v1.7) pkg> st CUDA
      Status `E:\.julia\environments\v1.7\Project.toml`
  [052768ef] CUDA v3.5.0

(@v1.7) pkg> st StaticArrays
      Status `E:\.julia\environments\v1.7\Project.toml`
  [90137ffa] StaticArrays v1.2.13

julia> versioninfo()
Julia Version 1.7.0
Commit 3bf9d17731 (2021-11-30 12:12 UTC)
Platform Info:
  OS: Windows (x86_64-w64-mingw32)
  CPU: Intel(R) Xeon(R) W-10885M CPU @ 2.40GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-12.0.1 (ORCJIT, skylake)
Environment:
  JULIA_DEPOT_PATH = E:\.julia
  JULIA_NUM_THREADS = 1
  JULIA_EDITOR = code

Is this a bug or feature?

@islent islent added the bug Something isn't working label Dec 7, 2021
@maleadt
Copy link
Member

maleadt commented Dec 9, 2021

A feature; SVector is a bitstype so can be used on the GPU directly. MArray is mutable, so you can't pass it to a kernel, and the fallback definition treating it as an array (so yielding a CuArray) kicks in.

@maleadt maleadt closed this as completed Dec 9, 2021
@maleadt
Copy link
Member

maleadt commented Dec 9, 2021

Although there's something to be said that cu(SVector) should also return a CuArray. But then cu((1,)) will also result in a CuArray, which may be a fairly breaking change. I'm not sure it's worth doing so.

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