jj1bdx / sfmt-erlang

sfmt-erlang: SIMD-oriented Fast Mersenne Twister (SFMT) for Erlang
http://jj1bdx.github.io/sfmt-erlang/
Other
70 stars 23 forks source link

Make flags for enabling HiPE compile exhibit problems #30

Closed daveman1010221 closed 3 years ago

daveman1010221 commented 6 years ago

Hello! I have been running some tests using the sfmt project in Elixir. Elixir's default set of random number generators are not good for performance, so I sought out an implementation of Mersenne Twister for Erlang/Elixir. As it turns out, the sfmt implementation is about twice as fast as the default algorithm, but performance was still quite bad on my system, when compared to python or C. In reading through the docs, I attempted to enable the HiPE compiler flags, which claim to perform 40% to 100% faster on 64 bit systems. I could only get the sfmt_pure implementation to compile if I remove the regular sfmt from the compilation set. Even still, when I do this, I get it to compile, but performance is actually about half of what the sfmt implementation performed at. Below is a detail of the compile output for enabling HiPE on my system, before making any other changes. Hopefully this is helpful to someone. :-)

--David

Uncomment this for enabling HiPE

ERLC_OPTS += +native "+{hipe, [o3]}"

multiple_precision$ mix deps.compile warning: module attribute @shortdoc was set but never used multiple_precision/deps/sfmt/mix.exs:2

warning: module attribute @shortdoc was set but never used multiple_precision/deps/sfmt/mix.exs:44

warning: variable "description" does not exist and is being expanded to "description()", please use parentheses to remove the ambiguity or change the variable name multiple_precision/deps/sfmt/mix.exs:60

warning: variable "package" does not exist and is being expanded to "package()", please use parentheses to remove the ambiguity or change the variable name multiple_precision/deps/sfmt/mix.exs:61

warning: variable "deps" does not exist and is being expanded to "deps()", please use parentheses to remove the ambiguity or change the variable name multiple_precision/deps/sfmt/mix.exs:64

DEPEND sfmt.d ERLC sfmt.erl sfmt_pure.erl sfmt_pure_tests.erl sfmt_tests.erl <HiPE (v 3.16.1)> EXITED with reason {'trans_fun/2',on_load} @hipe_beam_to_icode:1164 <HiPE (v 3.16.1)> Error: [hipe:864]: INTERNAL ERROR while compiling sfmt crash reason: {badmatch, {'EXIT', {{hipe_beam_to_icode,1164,{'trans_fun/2',on_load}}, [{hipe_beam_to_icode,trans_fun,2, [{file,"hipe_beam_to_icode.erl"},{line,1164}]}, {hipe_beam_to_icode,trans_fun,2, [{file,"hipe_beam_to_icode.erl"},{line,281}]}, {hipe_beam_to_icode,trans_mfa_code,5, [{file,"hipe_beam_to_icode.erl"},{line,143}]}, {hipe_beam_to_icode,trans_beam_function_chunk,2, [{file,"hipe_beam_to_icode.erl"},{line,128}]}, {hipe_beam_to_icode,'-module/2-lc$^1/1-1-',2, [{file,"hipe_beam_to_icode.erl"},{line,124}]}, {hipe_beam_to_icode,'-module/2-lc$^1/1-1-',2, [{file,"hipe_beam_to_icode.erl"},{line,124}]}, {hipe,get_beam_icode,4,[{file,"hipe.erl"},{line,594}]}, {hipe,'-run_compiler_1/4-fun-0-',5, [{file,"hipe.erl"},{line,669}]}]}}} in function hipe:get_beam_icode/4 (hipe.erl, line 593) in call from hipe:'-run_compiler_1/4-fun-0-'/5 (hipe.erl, line 669) src/sfmt.erl: internal error in native_compile; crash reason: {badmatch, {'EXIT', {{hipe_beam_to_icode,1164,{'trans_fun/2',on_load}}, [{hipe_beam_to_icode,trans_fun,2, [{file,"hipe_beam_to_icode.erl"},{line,1164}]}, {hipe_beam_to_icode,trans_fun,2, [{file,"hipe_beam_to_icode.erl"},{line,281}]}, {hipe_beam_to_icode,trans_mfa_code,5, [{file,"hipe_beam_to_icode.erl"},{line,143}]}, {hipe_beam_to_icode,trans_beam_function_chunk,2, [{file,"hipe_beam_to_icode.erl"},{line,128}]}, {hipe_beam_to_icode,'-module/2-lc$^1/1-1-',2, [{file,"hipe_beam_to_icode.erl"},{line,124}]}, {hipe_beam_to_icode,'-module/2-lc$^1/1-1-',2, [{file,"hipe_beam_to_icode.erl"},{line,124}]}, {hipe,get_beam_icode,4,[{file,"hipe.erl"},{line,594}]}, {hipe,'-run_compiler_1/4-fun-0-',5, [{file,"hipe.erl"},{line,669}]}]}}} make[3]: [ebin/sfmt.app] Error 1 make[2]: [app-build] Error 2 make[1]: [app] Error 2 make: [all] Error 2 ==> sfmt could not compile dependency :sfmt, "mix compile" failed. You can recompile this dependency with "mix deps.compile sfmt", update it with "mix deps.update sfmt" or clean it with "mix deps.clean sfmt" ==> multiple_precision ** (Mix) Could not build the program with make.

jj1bdx commented 6 years ago

@daveman1010221 Thanks for the info. SFMT is computing intensive by handling a relatively lengthy internal state, so if you need speed using NIF is mandatory. And as a general tip, you cannot mix NIFs and HiPE compiler options for the time being. I've written so in the README.md file as

sfmt module is NIFnized so does not coexist with HiPE

Since this is an Erlang general issue, what you can and should do is to build sfmt_pure.erl as an independent module. I suggest you to report this issue to bugs.erlang.org.

jj1bdx commented 3 years ago

Since OTP 24.0, HiPE is removed and no longer relevant. Case closed.