diff --git a/Project.toml b/Project.toml index 85c8ed0e4..90a297d34 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "KernelAbstractions" uuid = "63c18a36-062a-441e-b654-da1e3ab1ce7c" authors = ["Valentin Churavy and contributors"] -version = "0.9.41" +version = "0.9.42" [deps] Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e" diff --git a/src/cpu.jl b/src/cpu.jl index 7ee786635..f590ff3dd 100644 --- a/src/cpu.jl +++ b/src/cpu.jl @@ -111,13 +111,15 @@ function __run(obj, ndrange, iterspace, args, dynamic, static_threads) if Nthreads == 1 __thread_run(1, len, rem, obj, ndrange, iterspace, args, dynamic) else - if static_threads - Threads.@threads :static for tid in 1:Nthreads - __thread_run(tid, len, rem, obj, ndrange, iterspace, args, dynamic) - end - else - @sync for tid in 1:Nthreads - Threads.@spawn __thread_run(tid, len, rem, obj, ndrange, iterspace, args, dynamic) + let len = len, rem = rem, Nthreads = Nthreads + if static_threads + Threads.@threads :static for tid in 1:Nthreads + __thread_run(tid, len, rem, obj, ndrange, iterspace, args, dynamic) + end + else + @sync for tid in 1:Nthreads + Threads.@spawn __thread_run(tid, len, rem, obj, ndrange, iterspace, args, dynamic) + end end end end diff --git a/test/runtests.jl b/test/runtests.jl index f395b70dc..da102bbab 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -17,6 +17,11 @@ A = zeros(Int, Threads.nthreads()) kern_static(CPU(static = true), (1,))(A, ndrange = length(A)) @test A == 1:Threads.nthreads() +@testset "__run does not box (no per-launch Core.Box)" begin + ci = only(code_lowered(KernelAbstractions.__run, NTuple{6, Any})) + @test !any(e -> occursin("Box", string(e)), ci.code) +end + @kernel cpu = false function my_no_cpu_kernel(a) end @test_throws ErrorException("This kernel is unavailable for backend CPU") my_no_cpu_kernel(CPU())