# Flux with AMD GPU(s)?

**URL:** https://discourse.julialang.org/t/flux-with-amd-gpu-s/85218
**Category:** Machine Learning
**Tags:** flux, amdgpu
**Created:** [August 3, 2022, 8:12am UTC](https://discourse.julialang.org/t/flux-with-amd-gpu-s/85218 "2022-08-03T08:12:10Z")
**Posts on this page:** 15
**Page:** 2

<div class="post-metadata">

### Author: ![davide445](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/davide445/32/33681_2.png) [@davide445](https://discourse.julialang.org/u/davide445)
#### Post date: [December 12, 2022, 6:18pm UTC](https://discourse.julialang.org/t/flux-with-amd-gpu-s/85218/21 "2022-12-12T18:18:13Z")

</div>

I can order that 6700 even if I doubt will be able to help so much, except if the community is so thin will make some difference (happy to).  
My doubt is if Flux so far is not able to select AMDGPU at all will be with no use.

---

<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: [December 12, 2022, 6:36pm UTC](https://discourse.julialang.org/t/flux-with-amd-gpu-s/85218/22 "2022-12-12T18:36:54Z")

</div>

Flux support is basically there, we (probably) just need to wire up NNlib with NNlibROC.jl as a weak dependency (new in Julia 1.9, should be present in RC2) so that loading Flux and AMDGPU causes the right support code to be loaded (@ToucheSir is working on [Re-integrate NNlibCUDA as a package extension by ToucheSir · Pull Request #445 · FluxML/NNlib.jl · GitHub](https://github.com/FluxML/NNlib.jl/pull/445) which is the equivalent work for NNlibCUDA.jl).

FYI, @pxl-th and I test on RX 6700s, so we can reproduce any bugs or performance issues you might find (and we’ve already squashed quite a few Navi2-related bugs in just the past 2 months). So far, we haven’t found any show-stopping bugs specific to Navi2, so it’s probably a good purchase if you’re looking for a non-Instinct AMD card.

---

<div class="post-metadata">

### Author: ![davide445](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/davide445/32/33681_2.png) [@davide445](https://discourse.julialang.org/u/davide445)
#### Post date: [December 12, 2022, 6:38pm UTC](https://discourse.julialang.org/t/flux-with-amd-gpu-s/85218/23 "2022-12-12T18:38:39Z")

</div>

Ok I count to have it next week and let’s see how I can help.

---

<div class="post-metadata">

### Author: ![ToucheSir](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/touchesir/32/14411_2.png) [@ToucheSir](https://discourse.julialang.org/u/ToucheSir)
#### Post date: [December 12, 2022, 8:59pm UTC](https://discourse.julialang.org/t/flux-with-amd-gpu-s/85218/24 "2022-12-12T20:59:36Z")

</div>

To add onto what Julian said, the biggest missing piece for running common DL models on AMDGPU is wrapping MIOpen functions for pooling. Once that’s done, my hope is we’ll have the NNlib CUDA extension working and integrating NNlibROC should be trivial. No guarantee anything will be bug-free, but given I also have a 6700 XT there is plenty of desire to get this tested and working soon.

---

<div class="post-metadata">

### Author: ![RoyiAvital](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/royiavital/32/571_2.png) [@RoyiAvital](https://discourse.julialang.org/u/RoyiAvital)
#### Post date: [December 12, 2022, 10:46pm UTC](https://discourse.julialang.org/t/flux-with-amd-gpu-s/85218/25 "2022-12-12T22:46:34Z")

</div>

It doesn’t support `conda` and limited to Linux (As it is based on `ROCm`).  
The idea was making giving something which is not achievable in other frameworks / languages.

It might be an herculean effort, but it also should bring the eco system to the front, as a leader and not just chasing others.

---

<div class="post-metadata">

### Author: ![pxl-th](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pxl-th/32/31939_2.png) [@pxl-th](https://discourse.julialang.org/u/pxl-th)
#### Post date: [December 13, 2022, 11:28am UTC](https://discourse.julialang.org/t/flux-with-amd-gpu-s/85218/26 "2022-12-13T11:28:49Z")

</div>

> It doesn’t support `conda`

With Julia there are now artifacts for most of the ROCm stuff, [including](https://github.com/JuliaPackaging/Yggdrasil/tree/master/M/MIOpen) MIOpen, so you can just `]add MIOpen_jll` and start using it.  
I never manually install any of the ROCm packages and rely only artifacts (same for CUDA).

---

<div class="post-metadata">

### Author: ![davide445](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/davide445/32/33681_2.png) [@davide445](https://discourse.julialang.org/u/davide445)
#### Post date: [December 20, 2022, 7:10am UTC](https://discourse.julialang.org/t/flux-with-amd-gpu-s/85218/27 "2022-12-20T07:10:52Z")

</div>

> [@davide445](#):
>
> Ok I count to have it next week and let’s see how I can help.

Just to tell it’s all shifted to beginning next year. In the meantime will learn on Flux so will be able to contribute a bit more.

---

<div class="post-metadata">

### Author: ![RaSi96](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rasi96/32/46267_2.png) [@RaSi96](https://discourse.julialang.org/u/RaSi96)
#### Post date: [February 7, 2023, 3:08am UTC](https://discourse.julialang.org/t/flux-with-amd-gpu-s/85218/28 "2023-02-07T03:08:29Z")

</div>

Hello everyone,

Apologies for the (necro?)bump, but it seems that this is the most recent discussion there has been on Flux for AMD GPUs via ROCm. I own an RX 6600 and I’ve been following AMDGPU.jl for a while now (thanks to this thread; I currently moved to Julia 1.9 to further give it some exercise), so if I may politely ask: how might I go about setting up a stack to test ROCm with?

I have a couple of projects I would like to try working through purely in Julia, but the only question mark is whether I can use Flux with AMDGPU.jl or not. One of the specific questions is would Flux automatically understand that I’m working with AMD silicon, such that all I need use is something like `@cuda` (similar to PyTorch)?

I would love to try to test this as much as possible and I read that @jpsamaroo has been testing Flux on RX 6700s, but I’m unsure about how to set up a usage pipeline for myself. Thank you in advance for your time!

**Edit:** I have Julia 1.9, AMDGPU.jl, Flux.jl and a ROCm stack installed and working on Arch Linux 6.1.9. Should I also perhaps ask the same question as an issue over at Flux’s GitHub repository?

---

<div class="post-metadata">

### Author: ![ToucheSir](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/touchesir/32/14411_2.png) [@ToucheSir](https://discourse.julialang.org/u/ToucheSir)
#### Post date: [February 7, 2023, 3:12am UTC](https://discourse.julialang.org/t/flux-with-amd-gpu-s/85218/29 "2023-02-07T03:12:21Z")

</div>

We’re currently at the “integrating NNlibROC” step mentioned above. If you want to follow this progress, check out [Add AMDGPU extension by pxl-th · Pull Request #470 · FluxML/NNlib.jl · GitHub](https://github.com/FluxML/NNlib.jl/pull/470) and any future linked issues/PRs there.

---

<div class="post-metadata">

### Author: ![pxl-th](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pxl-th/32/31939_2.png) [@pxl-th](https://discourse.julialang.org/u/pxl-th)
#### Post date: [February 7, 2023, 7:21am UTC](https://discourse.julialang.org/t/flux-with-amd-gpu-s/85218/30 "2023-02-07T07:21:48Z")

</div>

By default AMDGPU.jl will install and use its own ROCm 5.3 stack (which is compatible with Julia 1.9), so you don’t even need to install it manually. You can verify it with:  
`AMDGPU.versioninfo()`

And I suspect that you need to launch Julia with `HSA_OVERRIDE_GFX_VERSION=10.3.0` env variable, like so:  
`HSA_OVERRIDE_GFX_VERSION=10.3.0 julia --threads=auto --project=.'`  
Because ROCm for Navi 2 only supports Navi 21 (gfx1030), but yours is Navi 23 (gfx1032).  
That said all Navi 2 have identical ISA, so you shouldn’t notice a difference (I guess).

* * *

And as @ToucheSir said, AMDGPU support for Flux is being actively developed and I hope it won’t take long.

---

<div class="post-metadata">

### Author: ![RaSi96](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rasi96/32/46267_2.png) [@RaSi96](https://discourse.julialang.org/u/RaSi96)
#### Post date: [February 7, 2023, 9:21am UTC](https://discourse.julialang.org/t/flux-with-amd-gpu-s/85218/31 "2023-02-07T09:21:12Z")

</div>

Indeed you are correct:

- `using AMDGPU; AMDGPU.versioninfo()` does indeed detect my GPU and CPU correctly, though I can’t know for sure whether it’s using its own ROCm stack or the one I installed (5.4).
- Using the HSA override `HSA_OVERRIDE_GFX_VERSION=10.3.0` is necessary and works perfectly fine even though my GPU is gfx1032. FWIW, I also use this for PyTorch.

I have yet to try training a network on my card (and if I understand this correctly it shouldn’t be too dissimilar to PyTorch’s approach for ROCm), but I have to say I am quite amazed at how quickly not only AMDGPU.jl progressed, but also its integration with Flux thanks to the hard work and hours put in by you kind people. I don’t think it’s that far off either; I look forward to testing a lot of the upcoming releases and helping out where I can.

---

<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 8, 2023, 8:49pm UTC](https://discourse.julialang.org/t/flux-with-amd-gpu-s/85218/32 "2023-02-08T20:49:15Z")

</div>

`AMDGPU.versioninfo` probably could stand to show if artifacts (JLLs) are being used or the system; hence [versioninfo: Indicate if using JLLs or System by jpsamaroo · Pull Request #381 · JuliaGPU/AMDGPU.jl · GitHub](https://github.com/JuliaGPU/AMDGPU.jl/pull/381). If you see paths that point to `/home/myusername/.julia/artifacts/...`, you’re using JLL-provided ROCm artifacts; otherwise, you’re using a system install of ROCm.

Once AMDGPU support is merged into NNlib, we’ll need to also look at some way of moving Flux’s models to the GPU (which is trivial to implement, we just need a function to do it).

---

<div class="post-metadata">

### Author: ![RaSi96](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rasi96/32/46267_2.png) [@RaSi96](https://discourse.julialang.org/u/RaSi96)
#### Post date: [February 15, 2023, 10:56am UTC](https://discourse.julialang.org/t/flux-with-amd-gpu-s/85218/33 "2023-02-15T10:56:39Z")

</div>

Apologies for the very late reply; yes, it seems that I’m using JLL provided artefacts for AMDGPU since all of the paths for (most) ROCm requirements point to `~/.julia/artifacts/...`.

I say _some_ because some of them also report as missing (`rocSOLVER`, `rocALUTION`, `rocFFT` and `MIOpen`), and from what I’ve seen across the `AMDGPU` and `NNLib` repos, I understand that these are the ones that are currently being worked on, so in short - everything is working as expected!

---

<div class="post-metadata">

### Author: ![pxl-th](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pxl-th/32/31939_2.png) [@pxl-th](https://discourse.julialang.org/u/pxl-th)
#### Post date: [February 15, 2023, 12:57pm UTC](https://discourse.julialang.org/t/flux-with-amd-gpu-s/85218/34 "2023-02-15T12:57:03Z")

</div>

MIOpen is available as an artifact, but is not installed by default.  
You can `]add MIOpen_jll` to install it, but you probably need to `]dev AMDGPU` and execute that command from `.julia/dev/AMDGPU` directory to trigger the detection (for now).

* * *

You can track [this](https://github.com/FluxML/Flux.jl/pull/2189) PR which will add initial support for AMDGPU in Flux.jl.

---

<div class="post-metadata">

### Author: ![RaSi96](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rasi96/32/46267_2.png) [@RaSi96](https://discourse.julialang.org/u/RaSi96)
#### Post date: [February 15, 2023, 1:09pm UTC](https://discourse.julialang.org/t/flux-with-amd-gpu-s/85218/35 "2023-02-15T13:09:03Z")

</div>

Oops, I seem to have missed [this earlier comment of yours](https://discourse.julialang.org/t/flux-with-amd-gpu-s/85218/26) explaining the same thing. As an aside, it’s awesome to see the recent PR under Flux’s repo directly, and also to see that [the changes in pull #470](https://github.com/FluxML/NNlib.jl/pull/470#pullrequestreview-1294983838) have been merged! Just fantastic!

[Previous page](https://discourse.julialang.org/t/flux-with-amd-gpu-s/85218.md?page=1)
