Class NativeOpenCLVisionBackend
java.lang.Object
org.episteme.nativ.media.vision.backends.NativeOpenCLVisionBackend
- All Implemented Interfaces:
VisionAlgorithmProvider<BufferedImage>, VisionBackend, AlgorithmProvider, Backend, ComputeBackend, GPUBackend, NativeBackend
@AutoService({Backend.class,ComputeBackend.class,VisionBackend.class,VisionAlgorithmProvider.class,GPUBackend.class,NativeBackend.class})
public class NativeOpenCLVisionBackend
extends Object
implements VisionBackend, GPUBackend, NativeBackend
OpenCL-accelerated Vision Backend.
This class handles GPU-accelerated image processing using OpenCL.
Implements GPUBackend and NativeBackend.
- Since:
- 2.0
- Author:
- Silvere Martin-Michiellot, Gemini AI (Google DeepMind)
-
Nested Class Summary
Nested classes/interfaces inherited from interface GPUBackend
GPUBackend.DeviceInfo -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionlongallocateGPUMemory(long sizeBytes) Allocates GPU memory and returns a handle.apply(BufferedImage image, ImageOp<BufferedImage> op) Applies a generic operation to an image.voidcopyFromGPU(long gpuHandle, DoubleBuffer hostBuffer, long sizeBytes) Copies data from GPU to host.voidcopyToGPU(long gpuHandle, DoubleBuffer hostBuffer, long sizeBytes) Copies data from host to GPU.Creates an execution context for running operations.createImage(Object data, int width, int height) Creates a new image from the given data.detectMotion(float[][] prev, float[][] curr, float threshold) voidfreeGPUMemory(long gpuHandle) Frees GPU memory.Returns the type of hardware accelerator used by this backend.Returns the friendly name of this backend instance.Returns a description of the backend.Returns information about available GPU devices.getId()Returns the unique identifier for this backend (e.g., "javafx", "jmol", "cuda").getName()Returns the display name for UI presentation.Returns the name of the native library this backend depends on.intReturns the priority for auto-selection (higher = preferred).getType()Returns the backend type category (e.g., "plotting", "molecular", "tensor", "math").booleanChecks if this backend is currently available (libraries loaded, etc.).booleanChecks if this backend is specifically disabled via a system property:"episteme.backend.disable." + getId().booleanisLoaded()Checks if the native library is loaded and available.voidmatrixMultiply(DoubleBuffer A, DoubleBuffer B, DoubleBuffer C, int m, int n, int k) Performs matrix multiplication C = A * B on the GPU.voidselectDevice(int deviceId) Selects a GPU device for computation.voidshutdown()Called when the application is shutting down or the backend is being replaced.voidSynchronizes GPU execution (waits for all kernels to complete).Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface AlgorithmProvider
description, getMetadata, scoreMethods inherited from interface Backend
getAlgorithmProviders, getStatusMessageMethods inherited from interface ComputeBackend
supportsComplexNumbers, supportsFloatingPoint, supportsParallelOpsMethods inherited from interface VisionAlgorithmProvider
getAlgorithmTypeMethods inherited from interface VisionBackend
createBackend
-
Constructor Details
-
NativeOpenCLVisionBackend
public NativeOpenCLVisionBackend()
-
-
Method Details
-
isLoaded
public boolean isLoaded()Description copied from interface:NativeBackendChecks if the native library is loaded and available.- Specified by:
isLoadedin interfaceNativeBackend- Returns:
- true if the native library has been successfully loaded
-
getNativeLibraryName
Description copied from interface:NativeBackendReturns the name of the native library this backend depends on.- Specified by:
getNativeLibraryNamein interfaceNativeBackend- Returns:
- library name (e.g., "openblas", "cuda", "fftw3")
-
getType
Description copied from interface:BackendReturns the backend type category (e.g., "plotting", "molecular", "tensor", "math").- Specified by:
getTypein interfaceBackend- Specified by:
getTypein interfaceComputeBackend- Specified by:
getTypein interfaceVisionBackend
-
getId
Description copied from interface:BackendReturns the unique identifier for this backend (e.g., "javafx", "jmol", "cuda").- Specified by:
getIdin interfaceBackend- Specified by:
getIdin interfaceComputeBackend- Specified by:
getIdin interfaceVisionBackend
-
getDescription
Description copied from interface:BackendReturns a description of the backend.- Specified by:
getDescriptionin interfaceBackend- Specified by:
getDescriptionin interfaceComputeBackend- Specified by:
getDescriptionin interfaceVisionBackend
-
isAvailable
public boolean isAvailable()Description copied from interface:BackendChecks if this backend is currently available (libraries loaded, etc.).Default implementation checks
Backend.isExplicitlyDisabled()and returns false if it is.- Specified by:
isAvailablein interfaceAlgorithmProvider- Specified by:
isAvailablein interfaceBackend- Specified by:
isAvailablein interfaceVisionBackend
-
isExplicitlyDisabled
public boolean isExplicitlyDisabled()Description copied from interface:BackendChecks if this backend is specifically disabled via a system property:"episteme.backend.disable." + getId().It also checks specialized properties like
"episteme.linearalgebra.disable." + getId().- Specified by:
isExplicitlyDisabledin interfaceBackend- Returns:
- true if explicitly disabled
-
shutdown
public void shutdown()Description copied from interface:BackendCalled when the application is shutting down or the backend is being replaced. Use this to release hardware resources, close file handles, or stop background threads.- Specified by:
shutdownin interfaceAlgorithmProvider- Specified by:
shutdownin interfaceBackend- Specified by:
shutdownin interfaceVisionBackend
-
apply
Description copied from interface:VisionAlgorithmProviderApplies a generic operation to an image.- Specified by:
applyin interfaceVisionAlgorithmProvider<BufferedImage>
-
createImage
Description copied from interface:VisionAlgorithmProviderCreates a new image from the given data.- Specified by:
createImagein interfaceVisionAlgorithmProvider<BufferedImage>
-
getBackendName
Description copied from interface:VisionBackendReturns the friendly name of this backend instance.- Specified by:
getBackendNamein interfaceVisionBackend
-
getName
Description copied from interface:BackendReturns the display name for UI presentation.- Specified by:
getNamein interfaceAlgorithmProvider- Specified by:
getNamein interfaceBackend- Specified by:
getNamein interfaceVisionAlgorithmProvider<BufferedImage>- Specified by:
getNamein interfaceVisionBackend
-
getPriority
public int getPriority()Description copied from interface:BackendReturns the priority for auto-selection (higher = preferred). Used when multiple backends are available.- Specified by:
getPriorityin interfaceAlgorithmProvider- Specified by:
getPriorityin interfaceBackend- Specified by:
getPriorityin interfaceVisionBackend
-
getAcceleratorType
Description copied from interface:ComputeBackendReturns the type of hardware accelerator used by this backend.- Specified by:
getAcceleratorTypein interfaceComputeBackend- Specified by:
getAcceleratorTypein interfaceVisionBackend- Returns:
- the accelerator type
-
createContext
Description copied from interface:ComputeBackendCreates an execution context for running operations.The context should be used within a try-with-resources block to ensure proper cleanup of resources.
- Specified by:
createContextin interfaceComputeBackend- Specified by:
createContextin interfaceVisionBackend- Returns:
- new execution context
-
detectMotion
public SceneTransitionDetector.Transition detectMotion(float[][] prev, float[][] curr, float threshold) -
getDevices
Description copied from interface:GPUBackendReturns information about available GPU devices.- Specified by:
getDevicesin interfaceGPUBackend
-
selectDevice
public void selectDevice(int deviceId) Description copied from interface:GPUBackendSelects a GPU device for computation.- Specified by:
selectDevicein interfaceGPUBackend- Parameters:
deviceId- Device index (0-based)
-
allocateGPUMemory
public long allocateGPUMemory(long sizeBytes) Description copied from interface:GPUBackendAllocates GPU memory and returns a handle.- Specified by:
allocateGPUMemoryin interfaceGPUBackend- Parameters:
sizeBytes- Size in bytes- Returns:
- GPU memory handle (opaque pointer)
-
copyToGPU
Description copied from interface:GPUBackendCopies data from host to GPU.- Specified by:
copyToGPUin interfaceGPUBackend- Parameters:
gpuHandle- GPU memory handlehostBuffer- Host buffersizeBytes- Number of bytes to copy
-
copyFromGPU
Description copied from interface:GPUBackendCopies data from GPU to host.- Specified by:
copyFromGPUin interfaceGPUBackend- Parameters:
gpuHandle- GPU memory handlehostBuffer- Host buffersizeBytes- Number of bytes to copy
-
freeGPUMemory
public void freeGPUMemory(long gpuHandle) Description copied from interface:GPUBackendFrees GPU memory.- Specified by:
freeGPUMemoryin interfaceGPUBackend- Parameters:
gpuHandle- GPU memory handle
-
synchronize
public void synchronize()Description copied from interface:GPUBackendSynchronizes GPU execution (waits for all kernels to complete).- Specified by:
synchronizein interfaceGPUBackend
-
matrixMultiply
Description copied from interface:GPUBackendPerforms matrix multiplication C = A * B on the GPU. Dimensions: A(m x k), B(k x n), C(m x n).- Specified by:
matrixMultiplyin interfaceGPUBackend
-