# Broadcasting using slices on the GPU

**URL:** https://discourse.julialang.org/t/broadcasting-using-slices-on-the-gpu/70290
**Category:** GPU
**Tags:** gpu, broadcasting, views
**Created:** [October 24, 2021, 12:37pm UTC](https://discourse.julialang.org/t/broadcasting-using-slices-on-the-gpu/70290 "2021-10-24T12:37:49Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![fedario](https://avatars.discourse-cdn.com/v4/letter/f/f14d63/32.png) [@fedario](https://discourse.julialang.org/u/fedario)
#### Post date: [October 24, 2021, 12:37pm UTC](https://discourse.julialang.org/t/broadcasting-using-slices-on-the-gpu/70290/1 "2021-10-24T12:37:49Z")

</div>

Hi!  
I’m trying to broadcast a two argument function over slices on the second argument like so:

```nohighlight
# using CUDA
# todevice = cu
todevice = identity

x = rand(5) |> todevice
a = rand(2, 5) |> todevice

function kernel(x, a)
    a * x # dummy computation
end

kernel.(x, eachcol(a))

```

This kind of works on the CPU but produces an array of arrays instead of a 2d array. When trying to do the same on the GPU I get the following error:

```julia
ERROR: LoadError: CuArray only supports element types that are stored inline

```

Which I assume is related to the array of arrays issue.

Do you know if there is a way to make this work on the GPU without array mutation, since I also want to compute gradients using Zygote?

---

<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: [October 25, 2021, 10:08am UTC](https://discourse.julialang.org/t/broadcasting-using-slices-on-the-gpu/70290/2 "2021-10-25T10:08:39Z")

</div>

Creating arrays of arrays like that is not supported. And slicing functions like eachcol/eachrow/mapslices generally don’t perform well on the GPU anyway, since they generally result in a kernel being launched for each row/column/slice.
