# I managed to make Flux.jl work with GPUs again!

**URL:** <https://discourse.julialang.org/t/i-managed-to-make-flux-jl-work-with-gpus-again/19386>\
**Category:** Machine Learning\
**Tags:** flux\
**Created:** [January 8, 2019, 3:10pm UTC](https://discourse.julialang.org/t/i-managed-to-make-flux-jl-work-with-gpus-again/19386 "2019-01-08T15:10:39Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![xiaodai](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xiaodai/32/15937_2.png) [@xiaodai](https://discourse.julialang.org/u/xiaodai)\
**Post date:** [January 8, 2019, 3:10pm UTC](https://discourse.julialang.org/t/i-managed-to-make-flux-jl-work-with-gpus-again/19386/1 "2019-01-08T15:10:39Z")

</div>

If you look at the [model zoo for mnist mlp for Flux.jl](https://github.com/FluxML/model-zoo/blob/master/vision/mnist/mlp.jl) you may notice the line `using CuArrays` is commented out. Presumably, this was because the rest of the code would fail if that line was turned on. Of course, CuArrays.jl is an GPU array library to allow computations to be done on GPU. I am so excited that I got it to work that I’ve decided to write this down right now even though it’s 2am where I live (and I still got a full time of consulting work tomorrow starting at 9am T\_T).

My setup

- Windows 10 Pro
- NVIDIA RTX 2080 grahpics card
- Julia v1.0.3
- Flux.jl v0.6.10

Install

- Visual Studio Community 2015  
\*\* **Important** : Do NOT install 2017 version  
\*\* I am not sure if this is required, but if you want to use Knet.jl as well then you might as well follow this instruction because Knet.jl only works with 2015

You need to install

- [Nvidia driver](http://www.nvidia.com/Download/index.aspx?lang=en-us)  
**update** working for v10  
~~**Important:** I have tested it to work with **v9** , it doesn’t seem to work for me if I install **v10** ,~~  
~~\*\* This might be important but I will test upgrading to v10 now that I am sure it work for v9~~
- [toolkit](https://developer.nvidia.com/cuda-downloads) and
- [cuDNN library](https://developer.nvidia.com/cudnn)

Now re-build the CuArrarys and Flux using

```julia
]build CuArrays
]build Flux

```

Now rerun the model zoo example by uncommenting `using CuArrays` then it should work!

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [January 8, 2019, 8:18pm UTC](https://discourse.julialang.org/t/i-managed-to-make-flux-jl-work-with-gpus-again/19386/2 "2019-01-08T20:18:44Z")

</div>

Yes, `|> gpu` is a no-op unless CuArrays.jl is loaded in, in which case it will make everything go to the GPU. I think a comment should be added to these model zoo examples saying `# Uncomment the following line to use GPUs. Requires CuArrays.jl is installed`.

---

<div class="post-metadata">

**Author:** ![xiaodai](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xiaodai/32/15937_2.png) [@xiaodai](https://discourse.julialang.org/u/xiaodai)\
**Post date:** [January 8, 2019, 8:57pm UTC](https://discourse.julialang.org/t/i-managed-to-make-flux-jl-work-with-gpus-again/19386/3 "2019-01-08T20:57:10Z")

</div>

I think the issue was that it just didn’t work. Even if CuArrays.jl can be installed it didn’t work for me. Maybe it’s a toolkit version thing. I remember doing an interview and the interviewer asked me if Flux’s GPU was working for me.

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [January 8, 2019, 9:07pm UTC](https://discourse.julialang.org/t/i-managed-to-make-flux-jl-work-with-gpus-again/19386/4 "2019-01-08T21:07:38Z")

</div>

Yes, you need to install the drivers, CUDA toolkit, and cuDNN separately. There’s a licensing issue that stops it from being automatic. I think the CUDANative docs mention the first two, while the CuArrays.jl docs mention the last one.

Maybe the Flux.jl docs need to mention this in its installation docs. [Home · Flux](https://fluxml.ai/Flux.jl/stable/#Installation-1) I noticed that’s pretty bare.

---

<div class="post-metadata">

**Author:** ![xiaodai](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xiaodai/32/15937_2.png) [@xiaodai](https://discourse.julialang.org/u/xiaodai)\
**Post date:** [January 11, 2019, 5:01am UTC](https://discourse.julialang.org/t/i-managed-to-make-flux-jl-work-with-gpus-again/19386/5 "2019-01-11T05:01:15Z")

</div>

> [@ChrisRackauckas](#):
>
> Maybe the Flux.jl docs need to mention this in its installation docs.

Hope this [PR](https://github.com/FluxML/Flux.jl/pull/553) helps with that

---

<div class="post-metadata">

**Author:** ![rmz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rmz/32/9861_2.png) [@rmz](https://discourse.julialang.org/u/rmz)\
**Post date:** [February 18, 2020, 10:52am UTC](https://discourse.julialang.org/t/i-managed-to-make-flux-jl-work-with-gpus-again/19386/6 "2020-02-18T10:52:17Z")

</div>

I spent yesterday _not_ getting flux to work on GPUs on AWS ([some details here](https://github.com/la3lma/julia-playground/blob/master/Libcuda%20woes.ipynb)). This kind of thing is very frustrating.

In my humble opinion, it would be very nice if someone ™ had a set of tests that tested compatibility with at least some more or less standard configurations. The FreeBSD project [does this](https://pkg-status.freebsd.org/) for the builds (including unit tests) of their packages. It’s one of those things would be nice for Julia to have, if the funding was available.

(yes I know the combinatorial explosion in configurations makes any kind of “total” test coverage totally infeasible, but the total absence of coverage is also bad).

---

<div class="post-metadata">

**Author:** ![jpsamaroo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jpsamaroo/32/46804_2.png) [@jpsamaroo](https://discourse.julialang.org/u/jpsamaroo)\
**Post date:** [February 18, 2020, 2:14pm UTC](https://discourse.julialang.org/t/i-managed-to-make-flux-jl-work-with-gpus-again/19386/8 "2020-02-18T14:14:21Z")

</div>

The problem with this is that it’s expensive to run all of these compatibility checks as part of CI, especially when testing on proprietary operating systems. The best solution might be to donate money or hardware + software licenses to the appropriate project so that they don’t need to pay out of pocket.
