Using vectors of vectors with CuArrays

Hello,

I am trying to get the blstm example from Flux model zoo to work on GPU. The latest hurdle that I ran into is trying to convert the training data to GPU arrays. The example uses arrays of arrays to store the data, not matrices or tensors). CuArrays blows up when I try to execute Xs = Xs |> gpu with the following error message:

ERROR: LoadError: type does not have a fixed size

A shorter example:

julia> using CuArrays

julia> mx = rand(3, 5)
3×5 Array{Float64,2}:
 0.12203   0.962134  0.619406  0.859975   0.517161
 0.17649   0.540456  0.378313  0.0818683  0.807525
 0.608563  0.924165  0.212063  0.088323   0.749014

julia> cu(mx)
3×5 CuArray{Float32,2}:
 0.12203   0.962134  0.619406  0.859975   0.517161
 0.17649   0.540456  0.378313  0.0818683  0.807525
 0.608563  0.924165  0.212063  0.088323   0.749014

julia> vx = [mx[i, :] for i=1:size(mx, 1)]
3-element Array{Array{Float64,1},1}:
 [0.12203, 0.962134, 0.619406, 0.859975, 0.517161] 
 [0.17649, 0.540456, 0.378313, 0.0818683, 0.807525]
 [0.608563, 0.924165, 0.212063, 0.088323, 0.749014]

julia> cu(vx)
ERROR: type does not have a fixed size

Would the only workaround for this be to rewrite the example for tensors?

My environment is as follows:
Linux CentOS 7
Julia 1.0.3
CUDA 9.1.85
CuArrays 1.0.2
CUDAnative v2.1.3
Flux 0.8.3

Is it something that has been fixed in the recent versions of Julia?

Any help would be highly appreciated.

I am having the same problem…

Adapt, the functionality that underpins cu and gpu, currently only converts the outermost array. You can broadcast cu to convert both levels of arrays:

julia> cu(cu.(vx))
3-element CuArray{CuArray{Float32,1},1}:
 Float32[0.0711257, 0.0993043, 0.618964, 0.938845, 0.417213]
 Float32[0.650274, 0.544968, 0.626481, 0.111535, 0.385071]  
 Float32[0.113344, 0.891208, 0.0257332, 0.90552, 0.250315]

EDIT: it seems like Flux wants an Array of CuArrays, so you probably need to call mapleaves(cu, vx) as per Flux.jl/gpu.md at master · FluxML/Flux.jl · GitHub