Open
Description
When you call wait on both CPU and GPU. The synchronization can be unstable. The error message is
any: Test Failed at /home/leo/jcode/lab/wait_fail.jl:34
Expression: Array(c1) ≈ ones(100)
Evaluated: Float32[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 … 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0] ≈ [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 … 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0]
Stacktrace:
[1] top-level scope at /home/leo/jcode/lab/wait_fail.jl:34
[2] top-level scope at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.4/Test/src/Test.jl:1113
[3] top-level scope at /home/leo/jcode/lab/wait_fail.jl:31
Test Summary: | Pass Fail Total
any | 1 1 2
MWE: you need to try the test for about 10 times, or more
using CuArrays, KernelAbstractions
using Test
@kernel function ba_kernel(x)
i = @index(Global)
x[i] += 1
end
function f1()
nthread=4
a = zeros(100)
event1 = ba_kernel(CPU(), nthread)(a; ndrange=100)
wait(event1)
a
end
function f2()
blockdim=256
x = CuArrays.zeros(100)
event1 = ba_kernel(CUDA(), blockdim)(x; ndrange=100)
wait(event1)
x
end
@testset "fail sometime" begin
r1 = f1()
c1 = f2()
@test r1 ≈ ones(100)
@test Array(c1) ≈ ones(100)
end
@testset "always work" begin
c1 = f2()
@test Array(c1) ≈ ones(100)
end