Search code examples
cerlanghardware-accelerationerlang-nif

Creating a hardware accelleration pipeline for BEAM


I have a conceptual idea for a pipeline enabling GPU acceleration in Erlang. The API would consist of higher order functions that take a fun, a binary and some flags, do a runtime check on the BEAM bytecode to see if the fun can be compiled to OpenCL, cache the result and then work similarly to higher order functions from the lists module. If the fun cannot be converted to OpenCL the process would fail.

All operations would be done on binaries as cons lists are not represented contiguously in memory, leading to a great deal of work to move them to and from GPU memory. There would be options to interpret the binary as floats, doubles, integers or a mix, and to have a varying size of input and output for the fun. Is it possible to do this in pure Erlang or C without hacking on BEAM? If it is, links to relevant resources would be appreciated.


Solution

  • erlang:fun_info/1 returns a list containing the tuple {env, ...} which contains an AST. I can leverage this sto create my OpenCL code, and use an existing OpenCL binding and use an ETS table in a gen_server for caching, covering the while pipeline in pure Erlang.