# Using vectors of vectors with CuArrays

**URL:** <https://discourse.julialang.org/t/using-vectors-of-vectors-with-cuarrays/25042>\
**Category:** GPU\
**Created:** [June 7, 2019, 12:08pm UTC](https://discourse.julialang.org/t/using-vectors-of-vectors-with-cuarrays/25042 "2019-06-07T12:08:12Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![tanhevg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tanhevg/32/12025_2.png) [@tanhevg](https://discourse.julialang.org/u/tanhevg)\
**Post date:** [June 7, 2019, 12:08pm UTC](https://discourse.julialang.org/t/using-vectors-of-vectors-with-cuarrays/25042/1 "2019-06-07T12:08:13Z")

</div>

Hello,

I am trying to get the [blstm example from Flux model zoo](https://github.com/FluxML/model-zoo/tree/master/audio/speech-blstm) 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:

```julia
ERROR: LoadError: type does not have a fixed size

```

A shorter example:

```julia
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.

---

<div class="post-metadata">

**Author:** ![feboccaccio](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/feboccaccio/32/9240_2.png) [@feboccaccio](https://discourse.julialang.org/u/feboccaccio)\
**Post date:** [July 8, 2019, 12:54pm UTC](https://discourse.julialang.org/t/using-vectors-of-vectors-with-cuarrays/25042/2 "2019-07-08T12:54:48Z")

</div>

I am having the same problem…

---

<div class="post-metadata">

**Author:** ![maleadt](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/maleadt/32/10097_2.png) [@maleadt](https://discourse.julialang.org/u/maleadt)\
**Post date:** [July 9, 2019, 8:43am UTC](https://discourse.julialang.org/t/using-vectors-of-vectors-with-cuarrays/25042/3 "2019-07-09T08:43:34Z")

</div>

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
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 `CuArray`s, so you probably need to call `mapleaves(cu, vx)` as per [Flux.jl/gpu.md at master · FluxML/Flux.jl · GitHub](https://github.com/FluxML/Flux.jl/blob/master/docs/src/gpu.md)
