Class NativeOpenCLLatticeBoltzmannBackend

java.lang.Object
org.episteme.nativ.physics.classical.matter.fluids.backends.NativeOpenCLLatticeBoltzmannBackend
All Implemented Interfaces:
AlgorithmProvider, Backend, ComputeBackend, GPUBackend, LatticeBoltzmannProvider

@AutoService({LatticeBoltzmannProvider.class,GPUBackend.class,ComputeBackend.class,Backend.class}) public class NativeOpenCLLatticeBoltzmannBackend extends Object implements LatticeBoltzmannProvider, GPUBackend
GPU-accelerated Lattice Boltzmann Method (LBM) backend using OpenCL.
Since:
1.2
Author:
Silvere Martin-Michiellot, Gemini AI (Google DeepMind)
  • Constructor Details

    • NativeOpenCLLatticeBoltzmannBackend

      public NativeOpenCLLatticeBoltzmannBackend()
  • Method Details

    • 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 LatticeBoltzmannProvider
    • 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
    • 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
    • initialize

      public void initialize()
    • 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
    • score

      public double score(OperationContext context)
      Context-aware scoring that accounts for GPU data transfer overhead.

      LBM is inherently parallelizable, so GPU benefits kick in at relatively small grid sizes.

      Specified by:
      score in interface AlgorithmProvider
      Parameters:
      context - the operation context (data size, hints, etc.)
      Returns:
      suitability score (higher = better)
    • evolve

      public void evolve(float[][][] f, boolean[][] obstacle, float omega)
      Specified by:
      evolve in interface LatticeBoltzmannProvider
    • evolve

      public void evolve(double[][][] f, boolean[][] obstacle, double omega)
      Specified by:
      evolve in interface LatticeBoltzmannProvider
    • evolve

      public void evolve(Real[][][] f, boolean[][] obstacle, Real omega)
      Specified by:
      evolve in interface LatticeBoltzmannProvider
    • 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 LatticeBoltzmannProvider
    • 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