JuliaGPU / JuliaGPU/KernelAbstractions.jl

amd gpu give different results when nested loop is used

Open
#517 18 comments 0 reactions 0 assignees View on GitHub
Dominant language
Julia
Stars
523
Forks
88
Avg merge
1d 11h
Merged PRs (30d)
25

Description

Hi, I noticed that the following script produces different results depending on the backend. On my machine, the output is:

```julia
cpu: [18.0; 18.0; 18.0; 18.0; 18.0; 18.0; 18.0; 18.0; 18.0; 18.0;;;]
cuda: [18.0; 18.0; 18.0; 18.0; 18.0; 18.0; 18.0; 18.0; 18.0; 18.0;;;]
amd: [6.0; 6.0; 6.0; 6.0; 6.0; 6.0; 6.0; 6.0; 6.0; 6.0;;;]
```

Is there a mistake in the kernel function?

```julia
using CUDA
using AMDGPU
using KernelAbstractions

function compute_tensors(tensor, kernel_fun, Nx, Ny, Nz)
kernel! = kernel_fun(get_backend(tensor), 512)
kernel!(tensor, Nx, Ny, Nz; ndrange=size(tensor))
KernelAbstractions.synchronize(get_backend(tensor))
return nothing
end

@kernel function kernel_xx!(tensor, Nx::Int64, Ny::Int64, Nz::Int64)
i, j, k = @index(Global, NTuple)
sum = zero(eltype(tensor))
for p in (-Nx):Nx, q in (-Ny):Ny
sum += 2.0
end
@inbounds tensor[i, j, k] = sum
end

nx, ny, nz = 10, 1, 1
Nx, Ny, Nz = 1, 1, 1
tensor = zeros(Float64, nx, ny, nz)
compute_tensors(tensor, kernel_xx!, Nx, Ny, Nz)
println("cpu:", tensor)

tensor = CUDA.zeros(Float64, nx, ny, nz)
compute_tensors(tensor, kernel_xx!, Nx, Ny, Nz)
println("cuda:", tensor)

tensor = AMDGPU.zeros(Float64, nx, ny, nz)
compute_tensors(tensor, kernel_xx!, Nx, Ny, Nz)
println("amd:", tensor)
```

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by running the supplied Julia reproducer with the CPU, CUDA, and AMDGPU backends, then inspect how KernelAbstractions handles the nested loop in kernel_xx!. There are no files or tests named in the issue; done means determining why AMDGPU produces 6.0 instead of 18.0 and adding a regression test or correction for consistent results.

Written by the indexing model from the issue text.

Assessment

Tech stack
julia
Domain
backend, hpc
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.