Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for cfunction + closures on Apple M1 chip #72

Open
JakobAsslaender opened this issue Mar 11, 2022 · 2 comments
Open

Support for cfunction + closures on Apple M1 chip #72

JakobAsslaender opened this issue Mar 11, 2022 · 2 comments
Labels
bug Something isn't working

Comments

@JakobAsslaender
Copy link

Hi everyone,

it seems that the @batch macro in combination with closures does not on the arm64-apple-darwin21.2.0 platform (Apple silicon). Any chance this could be fixed?

Here is a MWE:

using Polyester

function test1()
    a = 5
    function test2()
        return a
    end
    @batch for _ = 1:100
        test2()
    end
    return nothing
end

test1()

which produces this error message:

ERROR: cfunction: closures are not supported on this platform
Stacktrace:

batch_closure at [~/.julia/packages/Polyester/4Q0NM/src/batch.jl]()

macro expansion at [~/.julia/packages/Polyester/4Q0NM/src/batch.jl]()

#_batch_no_reserve#5 at [~/.julia/packages/Polyester/4Q0NM/src/batch.jl]()

(::Polyester.var"#_batch_no_reserve##kw")(::NamedTuple{(:threadlocal,), Tuple{Val{false}}}, ::typeof(Polyester._batch_no_reserve), ::var"#9#11"{var"#test2#10"{Int64}}, ::Tuple{UInt8}, ::Tuple{UInt32}, ::Tuple{UInt8}, ::UInt64, ::UInt64, ::UInt64, ::Static.StaticInt{1}, ::Static.StaticInt{1}, ::Polyester.NoLoop, ::Polyester.CombineIndices) at [~/.julia/packages/Polyester/4Q0NM/src/batch.jl]()

#batch#7 at [~/.julia/packages/Polyester/4Q0NM/src/batch.jl]()

batch at [~/.julia/packages/Polyester/4Q0NM/src/batch.jl]()

macro expansion at [~/.julia/packages/Polyester/4Q0NM/src/closure.jl]()

test1() at [./Untitled-1]()

top-level scope at [Untitled-1]()

ERROR: cfunction: closures are not supported on this platform
Stacktrace:

batch_closure at [~/.julia/packages/Polyester/4Q0NM/src/batch.jl]()

macro expansion at [~/.julia/packages/Polyester/4Q0NM/src/batch.jl]()

#_batch_no_reserve#5 at [~/.julia/packages/Polyester/4Q0NM/src/batch.jl]()

(::Polyester.var"#_batch_no_reserve##kw")(::NamedTuple{(:threadlocal,), Tuple{Val{false}}}, ::typeof(Polyester._batch_no_reserve), ::var"#9#11"{var"#test2#10"{Int64}}, ::Tuple{UInt8}, ::Tuple{UInt32}, ::Tuple{UInt8}, ::UInt64, ::UInt64, ::UInt64, ::Static.StaticInt{1}, ::Static.StaticInt{1}, ::Polyester.NoLoop, ::Polyester.CombineIndices) at [~/.julia/packages/Polyester/4Q0NM/src/batch.jl]()

#batch#7 at [~/.julia/packages/Polyester/4Q0NM/src/batch.jl]()

batch at [~/.julia/packages/Polyester/4Q0NM/src/batch.jl]()

macro expansion at [~/.julia/packages/Polyester/4Q0NM/src/closure.jl]()

test1() at [./Untitled-1]()

top-level scope at [Untitled-1]()

running on this system/Julia version:

julia> versioninfo()
Julia Version 1.8.0-beta1
Commit 7b711ce699 (2022-02-23 15:09 UTC)
Platform Info:
  OS: macOS (arm64-apple-darwin21.2.0)
  CPU: 8 × Apple M1
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-13.0.1 (ORCJIT, apple-m1)
  Threads: 4 on 4 virtual cores
Environment:
  JULIA_EDITOR = code
  JULIA_NUM_THREADS = 4

Thanks a bunch for looking into this!

@kylebeggs
Copy link

kylebeggs commented Apr 13, 2022

I get this same error, but intermittent. If I re-run the function to compile it works sometimes. Like, literally do nothing else, just re-run 2 times in a row and it'll work the second time. Weird

@chriselrod chriselrod added the bug Something isn't working label Apr 13, 2022
@chriselrod
Copy link
Member

Yeah, this isn't great. The M1 is popular and ARM is probably going to only get more popular in the future.

I think this should be less frequent in Polyester 0.6.8, as it should now be avoiding CFunctions when it succeeded in hoisting everything that would've been captured into the closure out and turning them into function arguments.
If you have examples of this error on 0.6.8+, a work around would perhaps be to strengthen this hoisting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants