# Migrating CUDA.jl atomic operations to ParallelStencil.jl using Atomix.jl?

**URL:** https://discourse.julialang.org/t/migrating-cuda-jl-atomic-operations-to-parallelstencil-jl-using-atomix-jl/136710
**Category:** GPU
**Tags:** atomic, cudajl
**Created:** [April 14, 2026, 1:35pm UTC](https://discourse.julialang.org/t/migrating-cuda-jl-atomic-operations-to-parallelstencil-jl-using-atomix-jl/136710 "2026-04-14T13:35:24Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Ludovic\_Dumoulin](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ludovic_dumoulin/32/22414_2.png) [@Ludovic\_Dumoulin](https://discourse.julialang.org/u/Ludovic_Dumoulin)
#### Post date: [April 14, 2026, 1:35pm UTC](https://discourse.julialang.org/t/migrating-cuda-jl-atomic-operations-to-parallelstencil-jl-using-atomix-jl/136710/1 "2026-04-14T13:35:24Z")

</div>

Hello,

I am currently porting my code from CUDA.jl to ParallelStencil.jl. While I have successfully managed the transition for mixed Float64 and ComplexF64 types, I have run into a challenge replacing CUDA-specific atomic operations, specifically:

`CUDA.@atomic F[i, j, 1] += ...`

Based on the KernelAbstractions.jl documentation, I am considering using Atomix.jl, but I am unclear on how the integration works in practice. Specifically:

1. If I initialize my setup with `@init_parallel_stencil(CUDA, Float64, 2, inbounds=true)`, will Atomix.jl automatically utilize the correct CUDA atomic instructions?
2. Are there specific steps or wrappers required to ensure Atomix.jl works seamlessly within a ParallelStencil kernel?

I have looked through the Atomix.jl documentation, but it is quite sparse. Any guidance or examples would be greatly appreciated!

Best regards

---

<div class="post-metadata">

### Author: ![vchuravy](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/vchuravy/32/8_2.png) [@vchuravy](https://discourse.julialang.org/u/vchuravy)
#### Post date: [April 14, 2026, 1:44pm UTC](https://discourse.julialang.org/t/migrating-cuda-jl-atomic-operations-to-parallelstencil-jl-using-atomix-jl/136710/2 "2026-04-14T13:44:22Z")

</div>

ParallelStencil will remain unaware of atomic operations, but the mapping to the correct operations (when available) will happen in the backend of Atomix.

So essentially, there is [Atomix.jl/ext/AtomixCUDAExt.jl at main · JuliaConcurrent/Atomix.jl · GitHub](https://github.com/JuliaConcurrent/Atomix.jl/blob/main/ext/AtomixCUDAExt.jl) and UnsafeAtomics.jl together provide the infrastructure, and the use is transparent to KernelAbstractions and ParallelStencil.

---

<div class="post-metadata">

### Author: ![Ludovic\_Dumoulin](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ludovic_dumoulin/32/22414_2.png) [@Ludovic\_Dumoulin](https://discourse.julialang.org/u/Ludovic_Dumoulin)
#### Post date: [April 14, 2026, 1:57pm UTC](https://discourse.julialang.org/t/migrating-cuda-jl-atomic-operations-to-parallelstencil-jl-using-atomix-jl/136710/3 "2026-04-14T13:57:33Z")

</div>

Thank you for your help !
