# CUDA kernel crash very occasionally when MPI.jl is just loaded

**URL:** <https://discourse.julialang.org/t/cuda-kernel-crash-very-occasionally-when-mpi-jl-is-just-loaded/116481>\
**Category:** General Usage\
**Tags:** question\
**Created:** [July 1, 2024, 3:55pm UTC](https://discourse.julialang.org/t/cuda-kernel-crash-very-occasionally-when-mpi-jl-is-just-loaded/116481 "2024-07-01T15:55:03Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![0samuraiE](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/0samuraie/32/209825_2.png) [@0samuraiE](https://discourse.julialang.org/u/0samuraiE)\
**Post date:** [July 1, 2024, 3:55pm UTC](https://discourse.julialang.org/t/cuda-kernel-crash-very-occasionally-when-mpi-jl-is-just-loaded/116481/1 "2024-07-01T15:55:03Z")

</div>

## Title: Feedback Needed on [CUDA kernel crash very occasionally when MPI.jl is just loaded.] (GitHub Issue #2429)

Hello Julia community,

I have encountered an issue “CUDA.jl kernel crash very occasionally when MPI.jl is just loaded.” and have reported it on GitHub.

**GitHub Issue Link:** [GitHub Issue #2429](https://github.com/JuliaGPU/CUDA.jl/issues/2429)

### Reproduce:

You may need to install MPI and run

```julia-auto
julia --project -e 'using Pkg; Pkg.add(["CUDA", "MPIPreferences", "MPI"]); using MPIPreferences; MPIPreferences.use_system_binary()'

```

You can run this code to reproduce.

```julia
using CUDA
using MPI
MPI.versioninfo()

f(i) = i^2
a = CUDA.zeros(Float64, 128^3)

function test(a)
    X = range(0, 1, length(a))

    function _kern()
        idx = (blockIdx().x - 1) * blockDim().x + threadIdx().x - 1

        stx = gridDim().x * blockDim().x

        i = idx + 1
        while i <= length(a)
            a[i] = f(i) * X[i]
            i += stx
        end
        return nothing
    end

    kern = @cuda launch = false _kern()
    config = launch_configuration(kern.fun)
    threads = config.threads
    size = length(a)
    blocks = cld.(size, threads)
    CUDA.@sync kern(; threads, blocks)
end

for i in 1:1000000
    @show i
    test(a)
end

```

### Purpose:

I am posting this here to get additional feedback and insights from the community. Any suggestions, potential workarounds, or similar experiences would be greatly appreciated.

Thank you for your help!

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:** [July 1, 2024, 6:49pm UTC](https://discourse.julialang.org/t/cuda-kernel-crash-very-occasionally-when-mpi-jl-is-just-loaded/116481/2 "2024-07-01T18:49:29Z")

</div>

Please don’t triple-post. Most of us read Github and Discourse and it is not beneficial to bifurcate the discussions into three places.

Let’s use [CUDA kernel very occasionally crash when MPI.jl (only when I use local binary.) is loaded. · Issue #846 · JuliaParallel/MPI.jl · GitHub](https://github.com/JuliaParallel/MPI.jl/issues/846) as the primary touchpoint.

---

<div class="post-metadata">

**Author:** ![0samuraiE](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/0samuraie/32/209825_2.png) [@0samuraiE](https://discourse.julialang.org/u/0samuraiE)\
**Post date:** [July 1, 2024, 10:39pm UTC](https://discourse.julialang.org/t/cuda-kernel-crash-very-occasionally-when-mpi-jl-is-just-loaded/116481/3 "2024-07-01T22:39:43Z")

</div>

I apologize I did not know the manner. Thank you. I will close this topic.
