-
Notifications
You must be signed in to change notification settings - Fork 1
Extending Neureka
Neureka is a lightweight library, meaning that its default backend operations only
support double
based tensors on the CPU and float
based tensors on the GPU.
However, the existing backend of this library adheres to a standardized API
based on which you can easily extend it through a common library context!
First we need the following 3 little imports:
import neureka.Neureka;
import neureka.backend.api.BackendContext;
import neureka.backend.api.Operation;
Then we can start diving towards the backend by first accessing the thread local library context:
Neureka library = Neureka.get();
This in turn contains and exposes the backend context which contains operations and backend extensions!
BackendContext backendContext = library.backend();
Now we can build a custom backend extension and hook it into the default context:
if ( !backendContext.has(MyBackendExtension.class) )
backendContext.set(new MyBackendExtension());
However, we don't have to use this, it's really just a common register for any kind of state.
For example, this is used to register the OpenCL platforms and devices.
If we simply want to create a new type of operation we can just add them to the context like so:
if ( !backendContext.hasOperation("customFunction") )
backendContext.addOperation(new MyCustomFunOperation());
Often times however, we simply want to extend an existing operation, like for example we might want to add
support for other kinds of data types for the +
,*
,/
... operations!
We can simply extend any given operation like so:
Operation plus = backendContext.getOperation("+");
plus.setAlgorithm(new MyAdditionAlgorithm());
For further details take a look at the Algorithm
documentation
as well as the current implementations located in neureka.backend.standard.*