# OpenCL status in Julia

**URL:** <https://discourse.julialang.org/t/opencl-status-in-julia/34442>\
**Category:** General Usage\
**Created:** [February 10, 2020, 11:35pm UTC](https://discourse.julialang.org/t/opencl-status-in-julia/34442 "2020-02-10T23:35:35Z")\
**Posts on this page:** 19\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ronis\_BR](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ronis_br/32/50999_2.png) [@Ronis\_BR](https://discourse.julialang.org/u/Ronis_BR)\
**Post date:** [February 10, 2020, 11:35pm UTC](https://discourse.julialang.org/t/opencl-status-in-julia/34442/1 "2020-02-10T23:35:35Z")

</div>

Hi!

I verified that I can greatly improve my satellite simulator if I use the GPU processing of some parts. It will be a huge change. Since I do not want to lock this feature for NVIDIA users only (I am Mac user, so no nvidia here also…), then I need to use OpenCL.

Question for those who are using OpenCL in Julia: is it stable and maintained for a long-term project? What problems should I expect?

---

<div class="post-metadata">

**Author:** ![Noel\_Araujo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/noel_araujo/32/4862_2.png) [@Noel\_Araujo](https://discourse.julialang.org/u/Noel_Araujo)\
**Post date:** [February 11, 2020, 3:38pm UTC](https://discourse.julialang.org/t/opencl-status-in-julia/34442/2 "2020-02-11T15:38:24Z")

</div>

I’ve played little with OpenCL and it worked well, but if you want to use advanced algorithms I cannot say a word. For me, using [ArrayFire](https://github.com/JuliaGPU/ArrayFire.jl) has been very useful, maybe is useful for you too.

---

<div class="post-metadata">

**Author:** ![DrPapa](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/drpapa/32/6835_2.png) [@DrPapa](https://discourse.julialang.org/u/DrPapa)\
**Post date:** [February 11, 2020, 4:51pm UTC](https://discourse.julialang.org/t/opencl-status-in-julia/34442/3 "2020-02-11T16:51:44Z")

</div>

I can certainly appreciate the desire to not be locked into NVIDIA. I am the same boat with Mac. I require DifferentialEquations.jl’s ensemble GPU support which, as far as I’m aware, only works on NVIDIA GPUs. My solution is to setup a cloud VM and connect to a remote process in the VM with JUNO. It works very well.

---

<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 11, 2020, 8:42pm UTC](https://discourse.julialang.org/t/opencl-status-in-julia/34442/4 "2020-02-11T20:42:47Z")

</div>

OpenCL is not the only option if you’re an AMD GPU owner; Julia has a work-in-progress AMDGPU computing stack which aims to mirror the functionality available in Julia’s CUDA stack. While we only currently support Linux as an OS, I have an open PR to support Macs and Windows machines via the OpenCL runtime (but without having to write OpenCL C kernels).

> **[GitHub - JuliaGPU/AMDGPUnative.jl: Julia interface to AMD/Radeon GPUs](https://github.com/JuliaGPU/AMDGPUnative.jl)**
>
> Julia interface to AMD/Radeon GPUs. Contribute to JuliaGPU/AMDGPUnative.jl development by creating an account on GitHub.

> **[GitHub - JuliaGPU/ROCArrays.jl: Parallel on the ROCks](https://github.com/JuliaGPU/ROCArrays.jl)**
>
> Parallel on the ROCks. Contribute to JuliaGPU/ROCArrays.jl development by creating an account on GitHub.

---

<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:** [February 11, 2020, 8:52pm UTC](https://discourse.julialang.org/t/opencl-status-in-julia/34442/5 "2020-02-11T20:52:56Z")

</div>

> [@DrPapa](#):
>
> I can certainly appreciate the desire to not be locked into NVIDIA. I am the same boat with Mac. I require DifferentialEquations.jl’s ensemble GPU support which, as far as I’m aware, only works on NVIDIA GPUs. My solution is to setup a cloud VM and connect to a remote process in the VM with JUNO. It works very well.

> [@jpsamaroo](#):
>
> OpenCL is not the only option if you’re an AMD GPU owner; Julia has a work-in-progress AMDGPU computing stack which aims to mirror the functionality available in Julia’s CUDA stack. While we only currently support Linux as an OS, I have an open PR to support Macs and Windows machines via the OpenCL runtime (but without having to write OpenCL C kernels).

GPUifyLoops needs support for AMDGPU for that to work. But that could be a nice Julia Lab project 🙂

---

<div class="post-metadata">

**Author:** ![DrPapa](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/drpapa/32/6835_2.png) [@DrPapa](https://discourse.julialang.org/u/DrPapa)\
**Post date:** [February 11, 2020, 8:59pm UTC](https://discourse.julialang.org/t/opencl-status-in-julia/34442/6 "2020-02-11T20:59:38Z")

</div>

> [@ChrisRackauckas](#):
>
> But that could be a nice Julia Lab project

🤔

---

<div class="post-metadata">

**Author:** ![Ronis\_BR](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ronis_br/32/50999_2.png) [@Ronis\_BR](https://discourse.julialang.org/u/Ronis_BR)\
**Post date:** [February 11, 2020, 9:11pm UTC](https://discourse.julialang.org/t/opencl-status-in-julia/34442/7 "2020-02-11T21:11:19Z")

</div>

> [@jpsamaroo](#):
>
> OpenCL is not the only option if you’re an AMD GPU owner;

I like OpenCL because people can use in both systems. I also do not mind writing kernels in C. I did some tests and the OpenCL support seems pretty solid!

---

<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 11, 2020, 9:16pm UTC](https://discourse.julialang.org/t/opencl-status-in-julia/34442/8 "2020-02-11T21:16:32Z")

</div>

Agreed, which is why I opened a PR for this a few months back: [[WIP] Add support for ROCm by jpsamaroo · Pull Request #64 · vchuravy/GPUifyLoops.jl · GitHub](https://github.com/vchuravy/GPUifyLoops.jl/pull/64)

I just need to wire a few more things up and get CI to pass 😄

---

<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:** [February 13, 2020, 6:52am UTC](https://discourse.julialang.org/t/opencl-status-in-julia/34442/9 "2020-02-13T06:52:26Z")

</div>

> [@Ronis\_BR](#):
>
> I also do not mind writing kernels in C.

Most people do. Taking that into account, OpenCL is currently not well supported by any Julia package (Transpiler.jl is dead), and you should use CUDAnative/CuArrays or the ROCM equivalent. If you care about portability, restrict your application to generic array expressions (map, reduce, broadcast). That ensures you can easily switch between platforms by swapping the array type. If you need custom kernels, you can do so using GPUif Loops.

---

<div class="post-metadata">

**Author:** ![Ronis\_BR](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ronis_br/32/50999_2.png) [@Ronis\_BR](https://discourse.julialang.org/u/Ronis_BR)\
**Post date:** [February 13, 2020, 10:35am UTC](https://discourse.julialang.org/t/opencl-status-in-julia/34442/10 "2020-02-13T10:35:25Z")

</div>

But what is my option for AMD? IIUC CLArrays.jl does not work in Julia 1.0.

---

<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 13, 2020, 12:25pm UTC](https://discourse.julialang.org/t/opencl-status-in-julia/34442/11 "2020-02-13T12:25:48Z")

</div>

See my initial post above for links; AMDGPUnative is the sister package to CUDAnative, and ROCArrays is the sister package to CuArrays. We’re actively working on keeping the AMD sister packages closely in sync with the CUDA packages so that users get a similar, seamless experience whether they have an AMD or an NVIDIA GPU available (that’s the goal, at least 😄).

---

<div class="post-metadata">

**Author:** ![Ronis\_BR](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ronis_br/32/50999_2.png) [@Ronis\_BR](https://discourse.julialang.org/u/Ronis_BR)\
**Post date:** [February 13, 2020, 1:23pm UTC](https://discourse.julialang.org/t/opencl-status-in-julia/34442/12 "2020-02-13T13:23:06Z")

</div>

Excellent! I haven’t considered using it because the README says that it is not ready for usage yet.

---

<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 13, 2020, 2:40pm UTC](https://discourse.julialang.org/t/opencl-status-in-julia/34442/13 "2020-02-13T14:40:02Z")

</div>

True, the AMDGPU stack is still in the “experimental” stages. However, if you are able to support the CUDA stack in SatelliteToolbox by using common array operations and generic functions, then I will make sure that the AMD stack works properly on SatelliteToolbox as well. In other words, write things generically, and I’ll do the work to ensure we support your package and users 😄

---

<div class="post-metadata">

**Author:** ![Ronis\_BR](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ronis_br/32/50999_2.png) [@Ronis\_BR](https://discourse.julialang.org/u/Ronis_BR)\
**Post date:** [February 13, 2020, 5:33pm UTC](https://discourse.julialang.org/t/opencl-status-in-julia/34442/14 "2020-02-13T17:33:33Z")

</div>

The idea is awesome and I am very glad that this can work like that! However, I currently do not have a single NVIDIA card to test. I was expecting to develop to AMD and hope that everything would work with NVIDIA 😅

---

<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 14, 2020, 4:49pm UTC](https://discourse.julialang.org/t/opencl-status-in-julia/34442/15 "2020-02-14T16:49:12Z")

</div>

What OS and GPU do you have available?

---

<div class="post-metadata">

**Author:** ![Ronis\_BR](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ronis_br/32/50999_2.png) [@Ronis\_BR](https://discourse.julialang.org/u/Ronis_BR)\
**Post date:** [February 14, 2020, 6:23pm UTC](https://discourse.julialang.org/t/opencl-status-in-julia/34442/16 "2020-02-14T18:23:19Z")

</div>

macOS and AMD Radeon only.

---

<div class="post-metadata">

**Author:** ![felipenoris](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/felipenoris/32/553_2.png) [@felipenoris](https://discourse.julialang.org/u/felipenoris)\
**Post date:** [January 10, 2021, 4:44pm UTC](https://discourse.julialang.org/t/opencl-status-in-julia/34442/17 "2021-01-10T16:44:49Z")

</div>

What about [https://github.com/JuliaGPU/OpenCL.jl](https://github.com/JuliaGPU/OpenCL.jl) package? How does it fit into this discussion?

---

<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:** [January 10, 2021, 7:06pm UTC](https://discourse.julialang.org/t/opencl-status-in-julia/34442/18 "2021-01-10T19:06:30Z")

</div>

OpenCL.jl doesn’t give you much in the way of higher-level abstractions. IMO the biggest hurdle for designing such an API is lack of a good kernel synthesis mechanism. While every other GPU library can compile Julia functions to some device IR, OpenCL requires cobbling together a C kernel with string concatenation because that’s the lowest common denominator amongst different implementations.

If one were to successfully revive CLArrays, the easiest approach would be to get SPIR-V compilation working via GPUCompiler’s OneAPI path and plumbing that into OpenCL.jl. This would dramatically limit what devices are supported, but anything is still \> 0. I looked into this a bit over the holidays, but it’ll likely be a non-trivial effort because of how differently OpenCL.jl (and OpenCL in general) is structured compared to the other GPU compute libraries.

---

<div class="post-metadata">

**Author:** ![LarkyJulia](https://avatars.discourse-cdn.com/v4/letter/l/e9c0ed/32.png) [@LarkyJulia](https://discourse.julialang.org/u/LarkyJulia)\
**Post date:** [December 29, 2021, 11:50pm UTC](https://discourse.julialang.org/t/opencl-status-in-julia/34442/19 "2021-12-29T23:50:06Z")

</div>

I am using nvidia rtx-2080ti, but I find it is not very friendly to linux. The properity driver and cuda works fine, but since it is not open source, sometimes it lead to broken head of linux.  
I actually prefer opencl, open source is always better, my next computer will be amd video cards. I hope your project keep going and reach the goal.
