BackendManager#
- class BackendManager[source]#
Bases:
object
Manager for template matching backends.
This class serves as an interface to various computational backends (e.g., CPU, GPU). It allows users to seamlessly swap between different backend implementations while preserving the consistency and functionality of the API. Direct attribute and method calls to the manager are delegated to the current active backend.
- Attributes:
- _BACKEND_REGISTRYdict
A dictionary mapping backend names to their respective classes or instances.
- _backendinstance of MatchingBackend
An instance of the currently active backend.
- _backend_namestr
Name of the current backend.
- _backend_argsDict
Arguments passed to create current backend.
Notes
The backend has to be reinitialzed when using fork-based parallelism.
Examples
>>> from tme.backends import backend >>> backend.multiply(arr1, arr2) # This will use the default NumpyFFTWBackend's multiply method
>>> backend.change_backend("pytorch") >>> backend.multiply(arr1, arr2) # This will use the pytorchs multiply method
>>> backend.available_backends() # Backends available on your system
Methods
BackendManager.add_backend
(backend_name, ...)Adds a custom backend to the registry.
Determines importable backends.
BackendManager.change_backend
(backend_name, ...)Change the backend.