Bumper.jl icon indicating copy to clipboard operation
Bumper.jl copied to clipboard

@no_escape is incompatible with Threads.@threads

Open vuthanho opened this issue 2 years ago • 1 comments

julia> function f1()
           @no_escape begin
               y = @alloc(Int,10)
               Threads.@threads for val in y
                   println(val)
               end
           end
       end
ERROR: LoadError: The `return` keyword is not allowed to be used inside the `@no_escape` macro

I have to nest the for loop inside a function to trick it:

julia> function _f(y)
           Threads.@threads for val in y
               println(y)
           end
       end
_f (generic function with 1 method)
julia> function f2()
           @no_escape begin
               y = @alloc(Int,10)
               _f(y)
           end
       end
f2 (generic function with 1 method)

vuthanho avatar Nov 29 '23 11:11 vuthanho

Any update on this @MasonProtter ? I've found that Polyester.@batch can work inside of the @no_escape block, but that unfortunately it does not always thread the code as it should.

EDIT: By "update" I meant "thought/comment" 😊

AhmedSalih3d avatar Mar 23 '24 01:03 AhmedSalih3d