Class NativeOpenCLFFTBackend

java.lang.Object
org.episteme.nativ.mathematics.analysis.fft.backends.NativeOpenCLFFTBackend
All Implemented Interfaces:
FFTProvider, AlgorithmProvider, Backend, ComputeBackend, GPUBackend, NativeBackend

@AutoService({FFTProvider.class,GPUBackend.class,ComputeBackend.class,Backend.class,NativeBackend.class}) public class NativeOpenCLFFTBackend extends Object implements FFTProvider, GPUBackend, NativeBackend
OpenCL implementation of FFTProvider using a Direct Fourier Transform (DFT) kernel.

This provides a GPU-accelerated implementation using standard O(N^2) DFT logic for correctness verification. Note: For high performance on large N, an optimized Cooley-Tukey (O(N log N)) kernel is required.

Since:
1.2
Author:
Silvere Martin-Michiellot, Gemini AI (Google DeepMind)
  • Constructor Details

    • NativeOpenCLFFTBackend

      public NativeOpenCLFFTBackend()
  • Method Details

    • isAvailable

      public boolean isAvailable()
      Description copied from interface: AlgorithmProvider
      Checks if the provider is available in the current environment.
      Specified by:
      isAvailable in interface AlgorithmProvider
      Specified by:
      isAvailable in interface Backend
    • isExplicitlyDisabled

      public boolean isExplicitlyDisabled()
      Description copied from interface: Backend
      Checks 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:
      isExplicitlyDisabled in interface Backend
      Returns:
      true if explicitly disabled
    • getId

      public String getId()
      Description copied from interface: Backend
      Returns the unique identifier for this backend (e.g., "javafx", "jmol", "cuda").
      Specified by:
      getId in interface Backend
      Specified by:
      getId in interface ComputeBackend
    • initialize

      public void initialize()
    • getName

      public String getName()
      Description copied from interface: Backend
      Returns the display name for UI presentation.
      Specified by:
      getName in interface AlgorithmProvider
      Specified by:
      getName in interface Backend
      Specified by:
      getName in interface FFTProvider
    • getPriority

      public int getPriority()
      Description copied from interface: AlgorithmProvider
      Returns the execution priority (higher is better).
      Specified by:
      getPriority in interface AlgorithmProvider
      Specified by:
      getPriority in interface Backend
    • getAcceleratorType

      public HardwareAccelerator getAcceleratorType()
      Description copied from interface: ComputeBackend
      Returns the type of hardware accelerator used by this backend.
      Specified by:
      getAcceleratorType in interface ComputeBackend
      Returns:
      the accelerator type
    • getAlgorithmType

      public String getAlgorithmType()
      Description copied from interface: AlgorithmProvider
      Returns the unique category of the algorithm.
      Specified by:
      getAlgorithmType in interface AlgorithmProvider
      Specified by:
      getAlgorithmType in interface FFTProvider
    • getDevices

      public GPUBackend.DeviceInfo[] getDevices()
      Description copied from interface: GPUBackend
      Returns information about available GPU devices.
      Specified by:
      getDevices in interface GPUBackend
    • selectDevice

      public void selectDevice(int deviceId)
      Description copied from interface: GPUBackend
      Selects a GPU device for computation.
      Specified by:
      selectDevice in interface GPUBackend
      Parameters:
      deviceId - Device index (0-based)
    • allocateGPUMemory

      public long allocateGPUMemory(long sizeBytes)
      Description copied from interface: GPUBackend
      Allocates GPU memory and returns a handle.
      Specified by:
      allocateGPUMemory in interface GPUBackend
      Parameters:
      sizeBytes - Size in bytes
      Returns:
      GPU memory handle (opaque pointer)
    • copyToGPU

      public void copyToGPU(long gpuHandle, DoubleBuffer hostBuffer, long sizeBytes)
      Description copied from interface: GPUBackend
      Copies data from host to GPU.
      Specified by:
      copyToGPU in interface GPUBackend
      Parameters:
      gpuHandle - GPU memory handle
      hostBuffer - Host buffer
      sizeBytes - Number of bytes to copy
    • copyFromGPU

      public void copyFromGPU(long gpuHandle, DoubleBuffer hostBuffer, long sizeBytes)
      Description copied from interface: GPUBackend
      Copies data from GPU to host.
      Specified by:
      copyFromGPU in interface GPUBackend
      Parameters:
      gpuHandle - GPU memory handle
      hostBuffer - Host buffer
      sizeBytes - Number of bytes to copy
    • freeGPUMemory

      public void freeGPUMemory(long gpuHandle)
      Description copied from interface: GPUBackend
      Frees GPU memory.
      Specified by:
      freeGPUMemory in interface GPUBackend
      Parameters:
      gpuHandle - GPU memory handle
    • synchronize

      public void synchronize()
      Description copied from interface: GPUBackend
      Synchronizes GPU execution (waits for all kernels to complete).
      Specified by:
      synchronize in interface GPUBackend
    • matrixMultiply

      public void matrixMultiply(DoubleBuffer A, DoubleBuffer B, DoubleBuffer C, int m, int n, int k)
      Description copied from interface: GPUBackend
      Performs matrix multiplication C = A * B on the GPU. Dimensions: A(m x k), B(k x n), C(m x n).
      Specified by:
      matrixMultiply in interface GPUBackend
    • createContext

      public ExecutionContext createContext()
      Description copied from interface: ComputeBackend
      Creates 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:
      createContext in interface ComputeBackend
      Returns:
      new execution context
    • score

      public double score(OperationContext context)
      Context-aware scoring that accounts for GPU data transfer overhead.
      Specified by:
      score in interface AlgorithmProvider
      Parameters:
      context - the operation context (data size, hints, etc.)
      Returns:
      suitability score (higher = better)
    • transform

      public double[][] transform(double[] real, double[] imag)
      Specified by:
      transform in interface FFTProvider
    • inverseTransform

      public double[][] inverseTransform(double[] real, double[] imag)
      Specified by:
      inverseTransform in interface FFTProvider
    • transform

      public Real[][] transform(Real[] real, Real[] imag)
      Specified by:
      transform in interface FFTProvider
    • inverseTransform

      public Real[][] inverseTransform(Real[] real, Real[] imag)
      Specified by:
      inverseTransform in interface FFTProvider
    • transformComplex

      public Complex[] transformComplex(Complex[] data)
      Specified by:
      transformComplex in interface FFTProvider
    • inverseTransformComplex

      public Complex[] inverseTransformComplex(Complex[] data)
      Specified by:
      inverseTransformComplex in interface FFTProvider
    • transform

      public float[][] transform(float[] real, float[] imag)
      Specified by:
      transform in interface FFTProvider
    • inverseTransform

      public float[][] inverseTransform(float[] real, float[] imag)
      Specified by:
      inverseTransform in interface FFTProvider
    • transform2D

      public double[][][] transform2D(double[][] real, double[][] imag)
      Specified by:
      transform2D in interface FFTProvider
    • inverseTransform2D

      public double[][][] inverseTransform2D(double[][] real, double[][] imag)
      Specified by:
      inverseTransform2D in interface FFTProvider
    • transform3D

      public double[][][][] transform3D(double[][][] real, double[][][] imag)
      Specified by:
      transform3D in interface FFTProvider
    • inverseTransform3D

      public double[][][][] inverseTransform3D(double[][][] real, double[][][] imag)
      Specified by:
      inverseTransform3D in interface FFTProvider
    • transform2D

      public Real[][][] transform2D(Real[][] real, Real[][] imag)
      Specified by:
      transform2D in interface FFTProvider
    • inverseTransform2D

      public Real[][][] inverseTransform2D(Real[][] real, Real[][] imag)
      Specified by:
      inverseTransform2D in interface FFTProvider
    • transform3D

      public Real[][][][] transform3D(Real[][][] real, Real[][][] imag)
      Specified by:
      transform3D in interface FFTProvider
    • inverseTransform3D

      public Real[][][][] inverseTransform3D(Real[][][] real, Real[][][] imag)
      Specified by:
      inverseTransform3D in interface FFTProvider
    • transform2D

      public float[][][] transform2D(float[][] real, float[][] imag)
      Specified by:
      transform2D in interface FFTProvider
    • inverseTransform2D

      public float[][][] inverseTransform2D(float[][] real, float[][] imag)
      Specified by:
      inverseTransform2D in interface FFTProvider
    • transform3D

      public float[][][][] transform3D(float[][][] real, float[][][] imag)
      Specified by:
      transform3D in interface FFTProvider
    • inverseTransform3D

      public float[][][][] inverseTransform3D(float[][][] real, float[][][] imag)
      Specified by:
      inverseTransform3D in interface FFTProvider
    • transformComplex2D

      public Complex[][] transformComplex2D(Complex[][] data)
      Specified by:
      transformComplex2D in interface FFTProvider
    • inverseTransformComplex2D

      public Complex[][] inverseTransformComplex2D(Complex[][] data)
      Specified by:
      inverseTransformComplex2D in interface FFTProvider
    • transformComplex3D

      public Complex[][][] transformComplex3D(Complex[][][] data)
      Specified by:
      transformComplex3D in interface FFTProvider
    • inverseTransformComplex3D

      public Complex[][][] inverseTransformComplex3D(Complex[][][] data)
      Specified by:
      inverseTransformComplex3D in interface FFTProvider
    • shutdown

      public void shutdown()
      Description copied from interface: AlgorithmProvider
      Called when the provider is no longer needed (e.g., application shutdown). Use this to release local resources or close native segments.
      Specified by:
      shutdown in interface AlgorithmProvider
      Specified by:
      shutdown in interface Backend
    • isLoaded

      public boolean isLoaded()
      Description copied from interface: NativeBackend
      Checks if the native library is loaded and available.
      Specified by:
      isLoaded in interface NativeBackend
      Returns:
      true if the native library has been successfully loaded
    • getNativeLibraryName

      public String getNativeLibraryName()
      Description copied from interface: NativeBackend
      Returns the name of the native library this backend depends on.
      Specified by:
      getNativeLibraryName in interface NativeBackend
      Returns:
      library name (e.g., "openblas", "cuda", "fftw3")