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

Support isbits Union Arrays #103

Closed
benchislett opened this issue Dec 30, 2019 · 5 comments · Fixed by #941
Closed

Support isbits Union Arrays #103

benchislett opened this issue Dec 30, 2019 · 5 comments · Fixed by #941
Labels
cuda array Stuff about CuArray. enhancement New feature or request

Comments

@benchislett
Copy link

benchislett commented Dec 30, 2019

Describe the bug
In attempting to move an array of multiple different kinds of structs, I discovered some strange trunctation where they are all forced into the type of one of them.

I initially wanted to use an array of abstract types, but that seemed to work even worse due to their not having a definite size.

To Reproduce
The Minimal Working Example (MWE) for this bug:

julia> using CuArrays

julia> struct Circle
         radius::Int32
       end

julia> struct Square
         width::Int32
         height::Int32
       end

julia> shapes = Array{Union{Circle, Square}}([Circle(4), Square(5, 5)])
2-element Array{Union{Circle, Square},1}:
 Circle(4)   
 Square(5, 5)

julia> cu(shapes)
2-element CuArray{Union{Circle, Square},1,Nothing}:
 Circle(4)
 Circle(5)

Expected behavior
One would think that the structs should come out as they went in.

Build log

julia> Pkg.build()
  Building SpecialFunctions  `~/.julia/packages/SpecialFunctions/ne2iw/deps/build.log`
  Building Conda ─────────── `~/.julia/packages/Conda/kLXeC/deps/build.log`
  Building FFTW ──────────── `~/.julia/packages/FFTW/loJ3F/deps/build.log`
  Building ImageMagick ───── `~/.julia/packages/ImageMagick/vMfoS/deps/build.log`
  Building GR ────────────── `~/.julia/packages/GR/oiZD3/deps/build.log`
  Building FFMPEG ────────── `~/.julia/packages/FFMPEG/guN1x/deps/build.log`
  Building Plots ─────────── `~/.julia/packages/Plots/Ih71u/deps/build.log`
  Building ZipFile ───────── `~/.julia/packages/ZipFile/oD4uG/deps/build.log`
  Building NNlib ─────────── `~/.julia/packages/NNlib/udnNA/deps/build.log`
false

Environment details (please complete this section)
Details on Julia:

Julia Version 1.2.0
Commit c6da87ff4b (2019-08-20 00:03 UTC)
Platform Info:
  OS: Linux (x86_64-pc-linux-gnu)
  CPU: Intel(R) Core(TM) i7-8750H CPU @ 2.20GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-6.0.1 (ORCJIT, skylake)

Julia packages:

  • CuArrays.jl:

CUDA: toolkit and driver version

nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2019 NVIDIA Corporation
Built on Sun_Jul_28_19:07:16_PDT_2019
Cuda compilation tools, release 10.1, V10.1.243

CUDA Version 10.1.243

EDIT: so we basically need https://docs.julialang.org/en/v1/devdocs/isbitsunionarrays/

@maleadt
Copy link
Member

maleadt commented Jan 6, 2020

This one isn't trivial, and needs support across the stack:

@maleadt maleadt changed the title Moving union-typed structure arrays to gpu Support isbits Union Arrays Jan 6, 2020
@maleadt
Copy link
Member

maleadt commented Jan 6, 2020

In the mean time, JuliaGPU/CuArrays.jl#552 will make this code error.

@maleadt maleadt transferred this issue from JuliaGPU/CuArrays.jl May 27, 2020
@maleadt maleadt added cuda array Stuff about CuArray. enhancement New feature or request labels May 27, 2020
@tkf
Copy link
Contributor

tkf commented Mar 5, 2021

FYI, I started working on supporting Union eltype for GPU arrays without explicitly coding for GPU arrays: JuliaFolds/UnionArrays.jl#2

@maleadt
Copy link
Member

maleadt commented Mar 8, 2021

Interesting! I hadn't considered doing this in Julia (well, in regular user code, without extending the arrayref intrinsic).

@maleadt
Copy link
Member

maleadt commented May 27, 2021

By @ViralBShah:

I tried to see what it might take to run DataFrames.jl on GPUs as discussed in JuliaData/DataFrames.jl#2713

Working with the neuro dataset from RDatasets, I could not convert a vector with missing data into a CuArray:

julia> cu(neuro.V1)
ERROR: CuArray does not yet support union bits types
Stacktrace:
  [1] error(s::String)
    @ Base ./error.jl:33
  [2] CuArray{Union{Missing, Float64}, 1}(#unused#::UndefInitializer, dims::Tuple{Int64})
    @ CUDA ~/.julia/packages/CUDA/Zmd60/src/array.jl:18
  [3] (CuArray{Union{Missing, Float64}, N} where N)(#unused#::UndefInitializer, dims::Tuple{Int64})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cuda array Stuff about CuArray. enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants