View Source tflite_beam_delegate (tflite_beam v1.0.0)
TfLite delegates: graph accelerators an interpreter builder can be given.
Summary
Functions
Which delegate kinds this build of the library can construct.
A delegate from a plugin library, with no options.
Load a delegate from a shared library that implements TfLite's delegate plugin interface -- tflite_plugin_create_delegate and tflite_plugin_destroy_delegate. That covers Edge TPU, a GPU delegate built elsewhere, and any vendor delegate, without this library having to know anything about them.
An XNNPACK delegate with XNNPACK's own defaults.
Create an XNNPACK delegate.
Functions
-spec available() -> [atom()].
Which delegate kinds this build of the library can construct.
This answers "was it compiled in", not "is a device present" -- the two have different answers on the same binary. Whether a device is there is discovered by trying to create the delegate and getting {error, Reason} back.
Note that an interpreter, and any delegate attached to it, belongs to one process at a time. See tflite_beam_interpreter_builder:add_delegate/2.
A delegate from a plugin library, with no options.
Load a delegate from a shared library that implements TfLite's delegate plugin interface -- tflite_plugin_create_delegate and tflite_plugin_destroy_delegate. That covers Edge TPU, a GPU delegate built elsewhere, and any vendor delegate, without this library having to know anything about them.
The path is resolved to an absolute one before loading, because the loader is asked for exactly the file named: a bare libfoo.so would otherwise be looked up along the system search path, which is not where anyone means.
Options are handed to the plugin as strings, since that is the whole of the plugin ABI -- atoms and integers are converted, and at most 256 pairs fit. What the keys mean is the plugin's business.
{ok, Delegate} = tflite_beam_delegate:external("/opt/lib/libvendor_delegate.so",
#{device => 0, precision => fp16}),
ok = tflite_beam_interpreter_builder:add_delegate(Builder, Delegate).The library is never unloaded, which is what TfLite does too -- an interpreter outliving a closed plugin would be considerably worse than a loader reference held to the end of the VM's life.
Note that an interpreter, and any delegate attached to it, belongs to one process at a time.
An XNNPACK delegate with XNNPACK's own defaults.
Create an XNNPACK delegate.
XNNPACK is compiled into every target except armv6 and armv7l; available/0 is what says so, and this returns {error, Reason} where it is not.