MasonProtter / Bumper.jl

Bring Your Own Stack
MIT License
152 stars 6 forks source link

@no_escape is incompatible with Threads.@threads #32

Open vuthanho opened 8 months ago

vuthanho commented 8 months ago
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)
AhmedSalih3d commented 4 months ago

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" 😊