ankane / torch.rb

Deep learning for Ruby, powered by LibTorch
Other
704 stars 30 forks source link

torch.rb does not work on TruffleRuby #45

Closed mtortonesi closed 1 year ago

mtortonesi commented 1 year ago

I am trying to get torch.rb working with TruffleRuby (version truffleruby+graalvm-23.0.0 installed with rbenv+ruby_build on a M1 MacBookPro), but unfortunately when I launch the following TensorOption instantiation command:

bundle exec ruby -e 'require "torch"; Torch::TensorOptions.new(1,2,3)'

I get the following error:

/Users/mauro/code/test/truffleruby/reinforce/vendor/bundle/truffleruby/3.1.3.23.0.0/gems/rice-4.1.0/include/rice/rice.hpp:4094:in `call': External LLVMFunction rb_frame_method_id_and_class cannot be found. (Polyglot::ForeignException)
    from /Users/mauro/.rbenv/versions/truffleruby+graalvm-23.0.0/graalvm/Contents/Home/languages/ruby/lib/truffle/truffle/cext_ruby.rb:41:in `'
    from /Users/mauro/.rbenv/versions/truffleruby+graalvm-23.0.0/graalvm/Contents/Home/languages/ruby/lib/truffle/truffle/cext_ruby.rb:41:in `Torch::TensorOptions#initialize'

I would like to help fixing this, but I really wouldn't know where to start. Any suggestions?

(Cross-reference with this issue on the TruffleRuby repo.)

ankane commented 1 year ago

Hi @mtortonesi, TruffleRuby isn't supported, and I don't really have the expertise to help with this. I think the first step would be getting Rice working with TruffleRuby, as the test suite currently fails.

mtortonesi commented 8 months ago

FYI, I just submitted oracle/truffleruby#3363, that implements the rb_frame_method_id_and_class in Truffleruby. The patch seems to get rice, and in turn torch.rb, to work with Truffleruby.

(See also https://github.com/oracle/truffleruby/issues/3357.)

ankane commented 8 months ago

Great, thanks @mtortonesi