Class NativeCUDATensorBackend
java.lang.Object
org.episteme.nativ.mathematics.tensors.backends.NativeCUDATensorBackend
- All Implemented Interfaces:
TensorProvider, AlgorithmProvider, Backend, ComputeBackend, GPUBackend, NativeBackend
@AutoService({Backend.class,ComputeBackend.class,GPUBackend.class,NativeBackend.class,TensorProvider.class})
public class NativeCUDATensorBackend
extends Object
implements TensorProvider, GPUBackend, NativeBackend
CUDA-accelerated Tensor Backend.
Implements Tensor operations using JCuda, producing
CUDATensor instances backed by GPU device memory.
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.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.<T> Tensor<T> create(T[] data, int... shape) Creates an execution context for running operations.voidfreeGPUMemory(long gpuHandle) Frees GPU memory.Returns the type of hardware accelerator used by this backend.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 execution priority (higher is better).booleanChecks if the provider is available in the current environment.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.<T> Tensor<T> doublescore(OperationContext context) Scores this provider for a specific operation context.voidselectDevice(int deviceId) Selects a GPU device for computation.voidshutdown()Called when the provider is no longer needed (e.g., application shutdown).voidSynchronizes GPU execution (waits for all kernels to complete).<T> Tensor<T> Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface AlgorithmProvider
description, getMetadataMethods inherited from interface Backend
getAlgorithmProviders, getStatusMessage, isExplicitlyDisabledMethods inherited from interface ComputeBackend
createBackend, getType, supportsComplexNumbers, supportsFloatingPoint, supportsParallelOpsMethods inherited from interface TensorProvider
getAlgorithmType
-
Constructor Details
-
NativeCUDATensorBackend
public NativeCUDATensorBackend()
-
-
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")
-
getId
-
getName
Description copied from interface:BackendReturns the display name for UI presentation.- Specified by:
getNamein interfaceAlgorithmProvider- Specified by:
getNamein interfaceBackend- Specified by:
getNamein interfaceTensorProvider
-
getDescription
Description copied from interface:BackendReturns a description of the backend.- Specified by:
getDescriptionin interfaceBackend- Specified by:
getDescriptionin interfaceComputeBackend
-
isAvailable
public boolean isAvailable()Description copied from interface:AlgorithmProviderChecks if the provider is available in the current environment.- Specified by:
isAvailablein interfaceAlgorithmProvider- Specified by:
isAvailablein interfaceBackend
-
shutdown
public void shutdown()Description copied from interface:AlgorithmProviderCalled when the provider is no longer needed (e.g., application shutdown). Use this to release local resources or close native segments.- Specified by:
shutdownin interfaceAlgorithmProvider- Specified by:
shutdownin interfaceBackend
-
zeros
- Specified by:
zerosin interfaceTensorProvider
-
ones
- Specified by:
onesin interfaceTensorProvider
-
create
- Specified by:
createin interfaceTensorProvider
-
getPriority
public int getPriority()Description copied from interface:AlgorithmProviderReturns the execution priority (higher is better).- Specified by:
getPriorityin interfaceAlgorithmProvider- Specified by:
getPriorityin interfaceBackend
-
score
Description copied from interface:AlgorithmProviderScores this provider for a specific operation context.Higher scores indicate better suitability. Used by
ProviderSelectorfor context-aware selection.Default implementation returns
AlgorithmProvider.getPriority(), so existing providers behave identically without changes.- Specified by:
scorein interfaceAlgorithmProvider- Parameters:
context- the operation context (data size, hints, etc.)- Returns:
- suitability score (higher = better)
-
getAcceleratorType
Description copied from interface:ComputeBackendReturns the type of hardware accelerator used by this backend.- Specified by:
getAcceleratorTypein interfaceComputeBackend- 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- Returns:
- new execution context
-
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
-