Interface GPUStorage

All Superinterfaces:
AutoCloseable
All Known Implementing Classes:
CUDAStorage

public interface GPUStorage extends AutoCloseable
Generic interface for GPU memory storage.

Abstracts GPU memory management across different backends (CUDA, OpenCL, Vulkan, etc.). Implementations handle allocation, data transfer, and deallocation of GPU memory.

Implementations:

  • CUDA: CUDAStorage - NVIDIA GPU memory via JCuda
  • OpenCL: OpenCLStorage - Cross-platform GPU memory via JOCL
  • Vulkan: VulkanStorage - Modern GPU memory via LWJGL

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

    Modifier and Type
    Method
    Description
    void
    Frees the GPU memory.
    double[]
    Downloads data from device (GPU) memory to host (CPU) memory.
    Returns the native GPU memory handle.
    int
    Returns the size of the allocated GPU memory in elements.
    default boolean
    Checks if the GPU memory has been freed.
    void
    upload(double[] hostData)
    Uploads data from host (CPU) memory to device (GPU) memory.
  • Method Details

    • getSize

      int getSize()
      Returns the size of the allocated GPU memory in elements.
      Returns:
      number of elements (typically doubles or floats)
    • upload

      void upload(double[] hostData)
      Uploads data from host (CPU) memory to device (GPU) memory.
      Parameters:
      hostData - array of data to upload
      Throws:
      IllegalArgumentException - if data size doesn't match allocated size
    • download

      double[] download()
      Downloads data from device (GPU) memory to host (CPU) memory.
      Returns:
      array of data from GPU
    • getNativeHandle

      Object getNativeHandle()
      Returns the native GPU memory handle.

      The type of this handle is backend-specific:

      • CUDA: jcuda.Pointer
      • OpenCL: org.jocl.cl_mem
      • Vulkan: long (VkDeviceMemory handle)

      Returns:
      native GPU memory handle (type varies by backend)
    • close

      void close()
      Frees the GPU memory.

      This method is called automatically when using try-with-resources. Implementations should be idempotent (safe to call multiple times).

      Specified by:
      close in interface AutoCloseable
    • isClosed

      default boolean isClosed()
      Checks if the GPU memory has been freed.
      Returns:
      true if memory has been freed, false otherwise