# Flux RNN on a GPU - unnecessary copying

**URL:** <https://discourse.julialang.org/t/flux-rnn-on-a-gpu-unnecessary-copying/25190>\
**Category:** Machine Learning\
**Created:** [June 12, 2019, 12:40pm UTC](https://discourse.julialang.org/t/flux-rnn-on-a-gpu-unnecessary-copying/25190 "2019-06-12T12:40:30Z")\
**Posts on this page:** 1\
**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 12, 2019, 12:40pm UTC](https://discourse.julialang.org/t/flux-rnn-on-a-gpu-unnecessary-copying/25190/1 "2019-06-12T12:40:30Z")

</div>

Hello,

A question for someone who has experience writing/debugging GPU code.

Consider something like this:

```julia
using CuArrays, Flux
lstm = LSTM(5, 3) |> gpu
data = [rand(5) for i=1:10]
data = gpu.(data)
out = lstm.(data) # SIC!

```

I need to broadcast the `lstm` call in order to make use of stateful properties of RNN. `data` is a vanilla Vector (not a `CuArray`); each element of `data` is a `CuArray`.

How will this broadcast be handled by `Flux` and `CUDAnative`? Will the RNN be indeed executed on the GPU? Will this cause any unnecessary copying of data from the GPU to CPU and back in between of invocations of individual RNN cells?

Thanks in advance.
