I had a KernelAbstractions.jl based Kernel function with a multi-line expression as below:
using KernelAbstractions
@kernel function karniadakis_update!(
n_eₜ₊₁, n_eₜ, n_eₜ₋₁, n_eₜ₋₂, e_rhsₜ, e_rhsₜ₋₁, e_rhsₜ₋₂,
ν_perp, ∇⁴nₑ
)
i, j = @index(Global, NTuple)
if i <= size(n_eₜ, 1) && j <= size(n_eₜ, 2)
# Karniadakis coefficients
cₜ, cₜ₋₁, cₜ₋₂ = 18/11, 9/11, 2/11
cᵣₕₛ = 6/11
# Electron update
n_eₜ₊₁[i, j] = cₜ * n_eₜ[i, j] - cₜ₋₁ * n_eₜ₋₁[i, j] + cₜ₋₂ * n_eₜ₋₂[i, j]
+ Δt * cᵣₕₛ * (3 * e_rhsₜ[i, j] - 3 * e_rhsₜ₋₁[i, j] + e_rhsₜ₋₂[i, j])
- Δt * cᵣₕₛ * ν_perp * ∇⁴nₑ[i, j]
end
end
and it seems to only compute the first line for some reason, i had buggy code for weeks because of this and I only found it by comparing the implementation to a CPU implementation with regular for loops. Wasted far too much time looking for bugs in my codebase when this was the issue.
Doing it instead the following way seems to fix it:
using KernelAbstractions
@kernel function karniadakis_update!(
n_eₜ₊₁, n_eₜ, n_eₜ₋₁, n_eₜ₋₂, e_rhsₜ, e_rhsₜ₋₁, e_rhsₜ₋₂,
ν_perp, ∇⁴nₑ
)
i, j = @index(Global, NTuple)
if i <= size(n_eₜ, 1) && j <= size(n_eₜ, 2)
# Karniadakis coefficients
cₜ, cₜ₋₁, cₜ₋₂ = 18/11, 9/11, 2/11
cᵣₕₛ = 6/11
# Electron update
n_eₜ₊₁[i, j] = cₜ * n_eₜ[i, j] - cₜ₋₁ * n_eₜ₋₁[i, j] + cₜ₋₂ * n_eₜ₋₂[i, j]
n_eₜ₊₁[i, j] += Δt * cᵣₕₛ * (3 * e_rhsₜ[i, j] - 3 * e_rhsₜ₋₁[i, j] + e_rhsₜ₋₂[i, j])
n_eₜ₊₁[i, j] -= Δt * cᵣₕₛ * ν_perp * ∇⁴nₑ[i, j]
end
end
Is this a well known bug? I hope they fix it soon, because this is the kind of thing one won’t see easily at all.