Peter Simpson

Expert
Licensed User
Longtime User
Bringing NVIDIA CUDA acceleration to B4J, hopefully ;)

SS_JCUDA brings native NVIDIA GPU acceleration (via JCuda) directly to B4J projects, letting you offload heavy, parallel number-crunching and calculations from your CPU to thousands of GPU CUDA cores. Your application can move data straight into graphics card memory (VRAM) and run GPU-accelerated functions across millions of values simultaneously.

SS_JCUDA

Author: Peter Simpson
Version: 1.0
  • CUDA
    CUDA Runtime API for GPU device discovery, hardware inspection, memory allocation, host-device transfers, and synchronization.
    • Fields:
      • MEM_ATTACH_GLOBAL As Int
        Unified Memory allocation flag allowing memory to be accessed by any stream on any device.
      • MEM_ATTACH_HOST As Int
        Unified Memory allocation flag restricting access to host CPU threads until explicitly attached to a stream.
      • MEM_ATTACH_SINGLE As Int
        Unified Memory allocation flag restricting access to a single stream specified during attachment.
      • MEMCPY_DEFAULT As Int
        Memory copy direction constant allowing CUDA to automatically infer transfer direction from pointer attributes on systems with Unified Virtual Addressing.
      • MEMCPY_DEVICE_TO_DEVICE As Int
        Memory copy direction constant specifying a transfer from GPU device memory to GPU device memory.
      • MEMCPY_DEVICE_TO_HOST As Int
        Memory copy direction constant specifying a transfer from GPU device memory to host memory.
      • MEMCPY_HOST_TO_DEVICE As Int
        Memory copy direction constant specifying a transfer from host memory to GPU device memory.
      • MEMCPY_HOST_TO_HOST As Int
        Memory copy direction constant specifying a transfer from host memory to host memory.
      • SIZEOF_BYTE As Int
        Byte size of a native 8-bit signed Byte type (1 byte).
      • SIZEOF_DOUBLE As Int
        Byte size of a native 64-bit IEEE 754 Double type (8 bytes).
      • SIZEOF_FLOAT As Int
        Byte size of a native 32-bit IEEE 754 Float type (4 bytes).
      • SIZEOF_INT As Int
        Byte size of a native 32-bit signed Int type (4 bytes).
      • SIZEOF_LONG As Int
        Byte size of a native 64-bit signed Long type (8 bytes).
      • SIZEOF_POINTER As Int
        Byte size of a native memory pointer on the current platform architecture (typically 8 bytes on 64-bit systems).
      • SIZEOF_SHORT As Int
        Byte size of a native 16-bit signed Short type (2 bytes).
    • Functions:
      • DeviceCanAccessPeer (device As Int, peerDevice As Int) As Boolean
        Returns true if a CUDA device can directly access global memory allocations on a peer CUDA device over NVLink or PCIe. (Return only)
        device specifies the zero-based index of the accessing GPU device.
        peerDevice specifies the zero-based index of the target peer GPU device.
      • DeviceDisablePeerAccess (peerDevice As Int) As Int
        Disables direct peer-to-peer memory access from the currently active device to allocations on a peer GPU device.
        peerDevice specifies the zero-based index of the target peer GPU device.
        Returns the CUDA runtime status code (0 indicates cudaSuccess). (Return only)
      • DeviceEnablePeerAccess (peerDevice As Int) As Int
        Enables direct peer-to-peer memory access from the currently active device to allocations on a peer GPU device.
        peerDevice specifies the zero-based index of the target peer GPU device.
        Returns the CUDA runtime status code (0 indicates cudaSuccess). (Return only)
      • DeviceGetAttribute (attribute As Int, device As Int) As Int
        Queries a specific hardware device attribute integer value from the CUDA runtime. (Return only)
        attribute specifies the numeric cudaDeviceAttr identifier to query.
        device specifies the zero-based GPU device index (typically 0).
      • DeviceReset As Int
        Destroys all memory allocations and resets all runtime state on the currently active device in the current process.
        Returns the CUDA runtime status code (0 indicates cudaSuccess). (Return only)
      • DeviceSynchronize As Int
        Blocks host execution until the active CUDA device has completed all preceding requested tasks.
        Returns the CUDA runtime status code (0 indicates cudaSuccess). (Return only)
      • DriverGetVersion As Int
        Returns the latest CUDA version supported by the installed NVIDIA display driver, encoded as (1000 * major + 10 * minor). (Return only)
      • Free (devPtr As CUDAPointer) As Int
        Frees GPU device memory or Unified Memory previously allocated via Malloc or MallocManaged.
        devPtr specifies the CUDAPointer referencing the device or managed memory allocation to release.
        Returns the CUDA runtime status code (0 indicates cudaSuccess). (Return only)
      • FreeHost (hostPtr As CUDAPointer) As Int
        Frees page-locked (pinned) host memory previously allocated via MallocHost.
        hostPtr specifies the CUDAPointer referencing the pinned host memory allocation to release.
        Returns the CUDA runtime status code (0 indicates cudaSuccess). (Return only)
      • GetDevice As Int
        Returns the zero-based device index of the currently active CUDA device for the calling host thread. (Return only)
      • GetDeviceCount As Int
        Returns the number of compute-capable NVIDIA CUDA devices available on the system. (Return only)
      • GetDeviceProperties (device As Int) As Map
        Returns a Map containing detailed hardware specifications and compute capabilities for the specified CUDA device. (Return only)
        device specifies the zero-based GPU device index (typically 0).
        The returned Map includes Name, TotalGlobalMem, SharedMemPerBlock, WarpSize, MaxThreadsPerBlock, Major, Minor, MultiProcessorCount, ClockRate, MemoryBusWidth, L2CacheSize, and ManagedMemory.
      • GetErrorName (error As Int) As String
        Returns the symbolic CUDA error constant name (e.g., "cudaErrorMemoryAllocation") for the specified error code. (Return only)
        error specifies the integer CUDA error code returned by a runtime call.
      • GetErrorString (error As Int) As String
        Returns the human-readable error description string for the specified CUDA error code. (Return only)
        error specifies the integer CUDA error code returned by a runtime call.
      • GetLastError As Int
        Returns the last error code produced by a CUDA runtime call and resets the error state to cudaSuccess (0). (Return only)
      • Initialize
        Initializes the JCuda Runtime wrapper and enables Java CudaException reporting when CUDA runtime errors occur.
      • IsCudaAvailable As Boolean
        Safely checks whether at least one compatible NVIDIA GPU and CUDA driver are available without throwing an exception or UnsatisfiedLinkError on non-NVIDIA systems.
        Returns true if a compatible NVIDIA CUDA device is ready for use, otherwise false. (Return only)
      • Malloc (sizeInBytes As Long) As CUDAPointer
        Allocates linear global memory (VRAM) on the active GPU device and returns a CUDAPointer referencing the allocation. (Return only)
        sizeInBytes specifies the number of bytes to allocate on the GPU.
      • MallocHost (sizeInBytes As Long) As CUDAPointer
        Allocates page-locked (pinned) host memory for high-speed DMA transfers between CPU RAM and GPU VRAM. (Return only)
        sizeInBytes specifies the number of bytes to allocate in pinned host memory.
      • MallocManaged (sizeInBytes As Long, flags As Int) As CUDAPointer
        Allocates Unified Memory that is automatically managed and migrated between CPU host and GPU device by the CUDA runtime. (Return only)
        sizeInBytes specifies the number of bytes to allocate.
        flags specifies the memory attachment scope (MEM_ATTACH_GLOBAL, MEM_ATTACH_HOST, or MEM_ATTACH_SINGLE).
      • Memcpy (dst As CUDAPointer, src As CUDAPointer, byteCount As Long, kind As Int) As Int
        Copies a block of memory between host and device buffers using the specified transfer direction constant.
        dst specifies the destination CUDAPointer.
        src specifies the source CUDAPointer.
        byteCount specifies the number of bytes to copy.
        kind specifies the transfer direction (MEMCPY_HOST_TO_DEVICE, MEMCPY_DEVICE_TO_HOST, MEMCPY_DEVICE_TO_DEVICE, MEMCPY_HOST_TO_HOST, or MEMCPY_DEFAULT).
        Returns the CUDA runtime status code (0 indicates cudaSuccess). (Return only)
      • MemcpyAsync (dst As CUDAPointer, src As CUDAPointer, byteCount As Long, kind As Int, stream As CUDAStream) As Int
        Asynchronously copies a block of memory between host and device buffers on the specified CUDA stream.
        dst specifies the destination CUDAPointer.
        src specifies the source CUDAPointer.
        byteCount specifies the number of bytes to copy.
        kind specifies the transfer direction (MEMCPY_HOST_TO_DEVICE, MEMCPY_DEVICE_TO_HOST, MEMCPY_DEVICE_TO_DEVICE, MEMCPY_HOST_TO_HOST, or MEMCPY_DEFAULT).
        stream specifies the CUDAStream for asynchronous execution, or Null for the default stream.
        Returns the CUDA runtime status code (0 indicates cudaSuccess). (Return only)
      • MemcpyDeviceToDevice (dstDevice As CUDAPointer, srcDevice As CUDAPointer, byteCount As Long) As Int
        Copies a block of memory directly between two GPU device memory allocations.
        dstDevice specifies the destination CUDAPointer allocated on the GPU.
        srcDevice specifies the source CUDAPointer allocated on the GPU.
        byteCount specifies the number of bytes to copy.
        Returns the CUDA runtime status code (0 indicates cudaSuccess). (Return only)
      • MemcpyDeviceToHost (dstHost As CUDAPointer, srcDevice As CUDAPointer, byteCount As Long) As Int
        Copies a block of memory from GPU device memory back to host CPU memory.
        dstHost specifies the destination CUDAPointer referencing host memory.
        srcDevice specifies the source CUDAPointer allocated on the GPU.
        byteCount specifies the number of bytes to copy.
        Returns the CUDA runtime status code (0 indicates cudaSuccess). (Return only)
      • MemcpyHostToDevice (dstDevice As CUDAPointer, srcHost As CUDAPointer, byteCount As Long) As Int
        Copies a block of memory from host CPU memory to GPU device memory.
        dstDevice specifies the destination CUDAPointer allocated on the GPU.
        srcHost specifies the source CUDAPointer referencing host memory.
        byteCount specifies the number of bytes to copy.
        Returns the CUDA runtime status code (0 indicates cudaSuccess). (Return only)
      • MemcpyHostToHost (dstHost As CUDAPointer, srcHost As CUDAPointer, byteCount As Long) As Int
        Copies a block of memory between two host CPU memory allocations.
        dstHost specifies the destination CUDAPointer referencing host memory.
        srcHost specifies the source CUDAPointer referencing host memory.
        byteCount specifies the number of bytes to copy.
        Returns the CUDA runtime status code (0 indicates cudaSuccess). (Return only)
      • MemGetInfo As Map
        Returns a Map containing the available free and total global memory (VRAM) in bytes on the currently active device. (Return only)
        The returned Map contains Free and Total Long keys.
      • Memset (devPtr As CUDAPointer, value As Int, count As Long) As Int
        Fills or initializes a block of GPU device memory with a single byte value.
        devPtr specifies the destination CUDAPointer in device memory.
        value specifies the byte value (0-255) to write into each byte of the target range.
        count specifies the number of bytes to set.
        Returns the CUDA runtime status code (0 indicates cudaSuccess). (Return only)
      • MemsetAsync (devPtr As CUDAPointer, value As Int, count As Long, stream As CUDAStream) As Int
        Asynchronously fills or initializes a block of GPU device memory with a single byte value on the specified CUDA stream.
        devPtr specifies the destination CUDAPointer in device memory.
        value specifies the byte value (0-255) to write into each byte of the target range.
        count specifies the number of bytes to set.
        stream specifies the CUDAStream for asynchronous execution, or Null for the default stream.
        Returns the CUDA runtime status code (0 indicates cudaSuccess). (Return only)
      • PeekAtLastError As Int
        Returns the last error code produced by a CUDA runtime call without resetting the current error state. (Return only)
      • RuntimeGetVersion As Int
        Returns the CUDA Runtime library version, encoded as (1000 * major + 10 * minor). (Return only)
      • SetDevice (device As Int) As Int
        Sets the active CUDA GPU device to be used for subsequent memory allocations and kernel executions.
        device specifies the zero-based GPU device index (typically 0 for the primary GPU).
        Returns the CUDA runtime status code (0 indicates cudaSuccess). (Return only)
      • SetExceptionsEnabled (enabled As Boolean)
        Enables or disables throwing Java CudaException exceptions when a CUDA runtime call returns a non-zero error code.
        enabled specifies true to throw CudaException on errors, or false to return integer status codes silently.
  • CUDADriver
    Low-level CUDA Driver API for managing contexts, loading PTX/CUBIN modules, allocating device memory, and launching CUDA kernels.
    • Functions:
      • CreateContext (deviceOrdinal As Int, flags As Int)
        Creates and binds a new CUDA context on the specified GPU device.
        deviceOrdinal specifies the zero-based GPU device index (typically 0 for the primary GPU).
        flags specifies context creation flags controlling scheduling and memory options (typically 0 for default behavior).
      • CreateKernelParams (params As Object()) As CUDAPointer
        Packs an array of mixed kernel arguments (CUDAPointer device pointers and primitive scalar values) into a CUDAPointer parameter list ready to pass into LaunchKernel. (Return only)
        params specifies the array of kernel arguments in the exact order declared by the CUDA kernel signature.
        Supported argument types: CUDAPointer, Int, Float, Double, Long, Byte, and Short.
      • DestroyContext
        Destroys the active CUDA context created by this instance and releases its associated GPU resources.
      • GetDeviceComputeCapability (deviceOrdinal As Int) As Map
        Returns a Map containing the hardware compute capability version numbers for the specified GPU device. (Return only)
        deviceOrdinal specifies the zero-based GPU device index (typically 0).
        The returned Map contains Major and Minor integer keys.
      • GetDeviceName (deviceOrdinal As Int) As String
        Returns the hardware device name string for the specified GPU device. (Return only)
        deviceOrdinal specifies the zero-based GPU device index (typically 0).
      • GetDevicePCIBusId (deviceOrdinal As Int) As String
        Returns the PCI bus identifier string (e.g. "0000:01:00.0") for the specified GPU device. (Return only)
        deviceOrdinal specifies the zero-based GPU device index (typically 0).
      • GetDeviceTotalMem (deviceOrdinal As Int) As Long
        Returns the total global device memory (VRAM) in bytes for the specified GPU device. (Return only)
        deviceOrdinal specifies the zero-based GPU device index (typically 0).
      • GetDeviceUuid (deviceOrdinal As Int) As String
        Returns the unique 16-byte GPU UUID formatted as a standard hyphenated hexadecimal string (GPU-xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx). (Return only)
        deviceOrdinal specifies the zero-based GPU device index (typically 0).
      • GetFunction (functionName As String)
        Resolves and selects a kernel function handle by name from the currently loaded CUDA module.
        functionName specifies the exact name of the __global__ kernel function (must be declared with extern "C" in CUDA C to avoid name mangling).
        Note: LoadModule or LoadModuleData must be called before invoking this method.
      • GetFunctionAttribute (attribute As Int) As Int
        Queries a specific hardware or compiler attribute for the currently selected kernel function. (Return only)
        attribute specifies a CUfunction_attribute constant (e.g. CU_FUNC_ATTRIBUTE_NUM_REGS, CU_FUNC_ATTRIBUTE_MAX_THREADS_PER_BLOCK).
        Note: GetFunction must be called before invoking this method.
      • GetFunctionInfo As Map
        Returns a Map containing key compiler and hardware resource metrics for the currently selected kernel function. (Return only)
        Keys returned: NumRegs, SharedMemBytes, ConstMemBytes, LocalMemBytes, MaxThreadsPerBlock, BinaryVersion, PtxVersion.
        Note: GetFunction must be called before invoking this method.
      • GetMaxActiveBlocksPerMultiprocessor (blockSize As Int, dynamicSMemSize As Long) As Int
        Returns the maximum number of active thread blocks that can run concurrently per streaming multiprocessor (SM) for the currently selected kernel. (Return only)
        blockSize specifies the number of threads per block planned for kernel launch.
        dynamicSMemSize specifies the per-block dynamic shared memory usage in bytes (typically 0).
      • GetModuleGlobal (symbolName As String) As Map
        Retrieves the device pointer and byte size of a global or constant symbol (__device__ or __constant__) from the currently loaded module. (Return only)
        symbolName specifies the exact name of the global variable declared in the module.
        Returns a Map containing DevicePointer (CUDAPointer) and SizeInBytes (Long) keys.
      • GetPointerAttributes (ptr As CUDAPointer) As Map
        Queries runtime memory attributes for a given pointer (host, device, or managed memory). (Return only)
        ptr specifies the CUDAPointer to inspect.
        Returns a Map containing MemoryType (Int), Device (Int), and IsManaged (Boolean) keys.
      • GetRecommendedBlockSize (dynamicSMemSize As Long, blockSizeLimit As Int) As Map
        Calculates the suggested block size and minimum grid size that maximize GPU occupancy for the currently selected kernel function. (Return only)
        dynamicSMemSize specifies the per-block dynamic shared memory usage in bytes (typically 0).
        blockSizeLimit specifies the maximum block size the kernel is designed to handle (pass 0 for no explicit limit).
        Returns a Map containing RecommendedBlockSize and MinGridSize integer keys.
      • Initialize
        Initializes the CUDA Driver API and enables Java CudaException reporting.
        Note: This must be called before creating a context or invoking any other driver methods.
      • LaunchKernel (gridDimX As Int, gridDimY As Int, gridDimZ As Int, blockDimX As Int, blockDimY As Int, blockDimZ As Int, sharedMemBytes As Int, stream As CUDAStream, kernelParams As CUDAPointer) As Int
        Launches the currently selected kernel function on the GPU across the specified grid and thread block dimensions.
        gridDimX specifies the width of the grid in thread blocks.
        gridDimY specifies the height of the grid in thread blocks (typically 1 for 1D data).
        gridDimZ specifies the depth of the grid in thread blocks (typically 1 for 1D data).
        blockDimX specifies the number of threads per block in the X dimension (e.g., 256).
        blockDimY specifies the number of threads per block in the Y dimension (typically 1).
        blockDimZ specifies the number of threads per block in the Z dimension (typically 1).
        sharedMemBytes specifies the dynamic shared memory size in bytes per thread block (typically 0).
        stream specifies an optional CUDAStream for asynchronous execution, or Null to execute on the default stream.
        kernelParams specifies the CUDAPointer parameter list created via CreateKernelParams or CUDAPointer.InitializeKernelParams.
        Returns the CUDA driver result code (0 indicates CUDA_SUCCESS). (Return only)
      • LoadModule (filePath As String)
        Loads a compiled .ptx or .cubin module file from disk into the current CUDA context.
        filePath specifies the full file path to the compiled .ptx or .cubin file.
      • LoadModuleData (imageBytes As Byte())
        Loads a compiled .ptx or .cubin module from a null-terminated byte array in memory into the current CUDA context.
        imageBytes specifies the null-terminated UTF-8 or binary byte array containing the PTX or CUBIN module data.
      • MemAlloc (sizeInBytes As Long) As CUDAPointer
        Allocates linear device memory (VRAM) via the Driver API and returns a CUDAPointer referencing the allocation. (Return only)
        sizeInBytes specifies the number of bytes to allocate on the GPU.
      • MemcpyDtoD (dstDevice As CUDAPointer, srcDevice As CUDAPointer, byteCount As Long) As Int
        Copies a block of memory directly between two GPU device memory allocations using the Driver API.
        dstDevice specifies the destination CUDAPointer allocated on the GPU via MemAlloc.
        srcDevice specifies the source CUDAPointer allocated on the GPU via MemAlloc.
        byteCount specifies the number of bytes to copy.
        Returns the CUDA driver result code (0 indicates CUDA_SUCCESS). (Return only)
      • MemcpyDtoH (dstHost As CUDAPointer, srcDevice As CUDAPointer, byteCount As Long) As Int
        Copies a block of memory from GPU device memory back to host memory using the Driver API.
        dstHost specifies the destination CUDAPointer referencing host memory.
        srcDevice specifies the source CUDAPointer allocated on the GPU via MemAlloc.
        byteCount specifies the number of bytes to copy.
        Returns the CUDA driver result code (0 indicates CUDA_SUCCESS). (Return only)
      • MemcpyHtoD (dstDevice As CUDAPointer, srcHost As CUDAPointer, byteCount As Long) As Int
        Copies a block of memory from host memory to GPU device memory using the Driver API.
        dstDevice specifies the destination CUDAPointer allocated on the GPU via MemAlloc.
        srcHost specifies the source CUDAPointer referencing host memory.
        byteCount specifies the number of bytes to copy.
        Returns the CUDA driver result code (0 indicates CUDA_SUCCESS). (Return only)
      • MemFree (devPtr As CUDAPointer) As Int
        Frees device memory previously allocated via MemAlloc.
        devPtr specifies the CUDAPointer referencing the device memory allocation to release.
        Returns the CUDA driver result code (0 indicates CUDA_SUCCESS). (Return only)
      • MemGetAddressRange (devPtr As CUDAPointer) As Map
        Returns the base device pointer and total allocation size in bytes for the device memory range containing the specified pointer. (Return only)
        devPtr specifies a CUDAPointer pointing anywhere within a valid device memory allocation.
        Returns a Map containing BasePointer (CUDAPointer) and SizeInBytes (Long) keys.
      • SynchronizeContext As Int
        Blocks host execution until all queued tasks and kernels in the current CUDA context have completed.
        Returns the CUDA driver result code (0 indicates CUDA_SUCCESS). (Return only)
      • UnloadModule
        Unloads the currently loaded CUDA module and frees its driver resources.
  • CUDAEvent
    CUDA event object (cudaEvent_t) used for high-precision GPU kernel timing and stream synchronization.
    • Fields:
      • EVENT_BLOCKING_SYNC As Int
        Event creation flag specifying that Synchronize should block the host thread rather than spin-waiting.
      • EVENT_DEFAULT As Int
        Default event creation flag enabling timing measurements and standard synchronization behavior.
      • EVENT_DISABLE_TIMING As Int
        Event creation flag disabling timing data recording to reduce overhead when used strictly for synchronization.
    • Functions:
      • Destroy As Int
        Destroys this CUDA event and releases its associated native GPU resources.
        Returns the CUDA runtime status code (0 indicates cudaSuccess). (Return only)
      • ElapsedTime (startEvent As CUDAEvent, endEvent As CUDAEvent) As Float
        Computes the elapsed GPU execution time in milliseconds between two recorded CUDAEvent markers. (Return only)
        startEvent specifies the starting CUDAEvent marker recorded before the GPU operation.
        endEvent specifies the ending CUDAEvent marker recorded after the GPU operation.
      • Initialize
        Initializes the CUDAEvent object and creates a new native CUDA event using default flags.
      • InitializeWithFlags (flags As Int)
        Initializes the CUDAEvent object and creates a new native CUDA event using the specified creation flags.
        flags specifies the event creation flag (EVENT_DEFAULT, EVENT_BLOCKING_SYNC, or EVENT_DISABLE_TIMING).
      • IsInitialized As Boolean
      • Query As Int
        Queries whether all GPU work preceding this recorded event has completed without blocking the host thread.
        Returns 0 (cudaSuccess) if the event has been recorded, or a non-zero status code if work is still in progress. (Return only)
      • Record (stream As CUDAStream) As Int
        Records this event into the specified CUDA execution stream after all preceding operations in that stream complete.
        stream specifies the target CUDAStream to record into, or Null to record into the default stream.
        Returns the CUDA runtime status code (0 indicates cudaSuccess). (Return only)
      • Synchronize As Int
        Blocks host execution until all GPU work preceding this recorded event has completed.
        Returns the CUDA runtime status code (0 indicates cudaSuccess). (Return only)
  • CUDAFunction
    CUDA kernel function handle (CUfunction) retrieved from a loaded CUDAModule.
    • Functions:
      • Initialize
        Initializes the CUDAFunction object and prepares its underlying native kernel handle for use.
      • IsInitialized As Boolean
        Returns true if the wrapper has been successfully initialized. (Return only)
  • CUDAMath
    CUDA GPU-accelerated mathematical operations using embedded PTX kernels.
    • Functions:
      • ApplyReLU (deviceData As CUDAPointer, elementCount As Int)
        Applies the Rectified Linear Unit (ReLU) activation function in-place on a device float array, setting all negative values to 0.0 and keeping positive values unchanged.
        deviceData specifies the CUDAPointer referencing the float array in device or unified managed memory.
        elementCount specifies the number of float elements to process.
      • Initialize
        Initializes the CUDAMath object by loading the embedded PTX math module into the active CUDA context and resolving its kernel functions.
        Note: An active CUDA context must be created before calling this method.
  • CUDAModule
    CUDA driver module handle (CUmodule) containing compiled PTX or CUBIN GPU functions.
    • Functions:
      • Initialize
        Initializes the CUDAModule object and prepares its underlying native module handle for use.
      • IsInitialized As Boolean
        Returns true if the wrapper has been successfully initialized. (Return only)
  • CUDAPointer
    CUDA Pointer referencing host arrays, device memory allocations, and kernel argument lists.
    • Functions:
      • GetAddressRange As Map
        Returns the base device pointer and total allocation size in bytes for the device memory range containing this pointer. (Return only)
        Returns a Map containing BasePointer (CUDAPointer) and SizeInBytes (Long) keys.
      • GetAttributes As Map
        Queries runtime memory attributes for this pointer (host, device, or managed memory). (Return only)
        Returns a Map containing MemoryType (Int), Device (Int), and IsManaged (Boolean) keys.
      • GetByteBuffer (byteOffset As Long, byteSize As Long) As Object
        Returns a Java NIO ByteBuffer view of the native memory at the specified byte offset and size. (Return only)
        byteOffset specifies the starting offset in bytes from the base pointer address.
        byteSize specifies the size of the memory region in bytes to expose in the ByteBuffer.
      • GetBytes (count As Int) As Byte()
        Reads a Byte array directly from host-accessible pinned memory or unified managed memory. (Return only)
        count specifies the number of bytes to read from the referenced native memory buffer.
      • GetDoubles (count As Int) As Double()
        Reads a Double array directly from host-accessible pinned memory or unified managed memory. (Return only)
        count specifies the number of Double elements to read from the referenced native memory buffer.
      • GetFloats (count As Int) As Float()
        Reads a Float array directly from host-accessible pinned memory or unified managed memory. (Return only)
        count specifies the number of Float elements to read from the referenced native memory buffer.
      • GetInts (count As Int) As Int()
        Reads an Int array directly from host-accessible pinned memory or unified managed memory. (Return only)
        count specifies the number of Int elements to read from the referenced native memory buffer.
      • GetLongs (count As Int) As Long()
        Reads a Long array directly from host-accessible pinned memory or unified managed memory. (Return only)
        count specifies the number of Long elements to read from the referenced native memory buffer.
      • GetShorts (count As Int) As Short()
        Reads a Short array directly from host-accessible pinned memory or unified managed memory. (Return only)
        count specifies the number of Short elements to read from the referenced native memory buffer.
      • Initialize
        Initializes the CUDAPointer object as a new null native Pointer.
      • InitializeFromByte (value As Byte)
        Initializes the CUDAPointer object referencing a single Byte scalar value (typically used when building kernel parameter lists).
        value specifies the Byte scalar value to wrap.
      • InitializeFromBytes (data As Byte())
        Initializes the CUDAPointer object referencing a Byte array on the host.
        data specifies the Byte array to reference in host memory.
      • InitializeFromDouble (value As Double)
        Initializes the CUDAPointer object referencing a single Double scalar value (typically used when building kernel parameter lists).
        value specifies the Double scalar value to wrap.
      • InitializeFromDoubles (data As Double())
        Initializes the CUDAPointer object referencing a Double array on the host.
        data specifies the Double array to reference in host memory.
      • InitializeFromFloat (value As Float)
        Initializes the CUDAPointer object referencing a single Float scalar value (typically used when building kernel parameter lists).
        value specifies the Float scalar value to wrap.
      • InitializeFromFloats (data As Float())
        Initializes the CUDAPointer object referencing a Float array on the host.
        data specifies the Float array to reference in host memory.
      • InitializeFromInt (value As Int)
        Initializes the CUDAPointer object referencing a single Int scalar value (typically used when building kernel parameter lists).
        value specifies the Int scalar value to wrap.
      • InitializeFromInts (data As Int())
        Initializes the CUDAPointer object referencing an Int array on the host.
        data specifies the Int array to reference in host memory.
      • InitializeFromLong (value As Long)
        Initializes the CUDAPointer object referencing a single Long scalar value (typically used when building kernel parameter lists).
        value specifies the Long scalar value to wrap.
      • InitializeFromLongs (data As Long())
        Initializes the CUDAPointer object referencing a Long array on the host.
        data specifies the Long array to reference in host memory.
      • InitializeFromPointers (pointers As CUDAPointer())
        Initializes the CUDAPointer object referencing an array of existing CUDAPointer instances (used for LaunchKernel kernelParams).
        pointers specifies the array of CUDAPointer objects representing each kernel argument in order.
      • InitializeFromShort (value As Short)
        Initializes the CUDAPointer object referencing a single Short scalar value (typically used when building kernel parameter lists).
        value specifies the Short scalar value to wrap.
      • InitializeFromShorts (data As Short())
        Initializes the CUDAPointer object referencing a Short array on the host.
        data specifies the Short array to reference in host memory.
      • InitializeKernelParams (params As Object())
        Packs an array of mixed kernel arguments (CUDAPointer device pointers and primitive scalar values) into a kernel parameter list ready to pass into CUDADriver.LaunchKernel.
        params specifies the array of kernel arguments in the exact order declared by the CUDA kernel signature.
        Supported argument types: CUDAPointer, Int, Float, Double, Long, Byte, and Short.
      • IsInitialized As Boolean
      • IsNull As Boolean
        Returns true if the underlying native pointer is null or uninitialized. (Return only)
      • SetBytes (data As Byte())
        Writes a Byte array directly into host-accessible pinned memory or unified managed memory.
        data specifies the Byte array to copy into the referenced native memory buffer.
      • SetDoubles (data As Double())
        Writes a Double array directly into host-accessible pinned memory or unified managed memory.
        data specifies the Double array to copy into the referenced native memory buffer.
      • SetFloats (data As Float())
        Writes a Float array directly into host-accessible pinned memory or unified managed memory.
        data specifies the Float array to copy into the referenced native memory buffer.
      • SetInts (data As Int())
        Writes an Int array directly into host-accessible pinned memory or unified managed memory.
        data specifies the Int array to copy into the referenced native memory buffer.
      • SetLongs (data As Long())
        Writes a Long array directly into host-accessible pinned memory or unified managed memory.
        data specifies the Long array to copy into the referenced native memory buffer.
      • SetShorts (data As Short())
        Writes a Short array directly into host-accessible pinned memory or unified managed memory.
        data specifies the Short array to copy into the referenced native memory buffer.
      • WithByteOffset (byteOffset As Long) As CUDAPointer
        Returns a new CUDAPointer offset from the current memory address by the specified number of bytes. (Return only)
        byteOffset specifies the positive or negative offset in bytes from the base pointer address.
  • CUDAStream
    CUDA execution stream (cudaStream_t) used to schedule asynchronous GPU operations.
    • Fields:
      • STREAM_DEFAULT As Int
        Default stream creation flag allowing implicit synchronization with the legacy default stream.
      • STREAM_NON_BLOCKING As Int
        Non-blocking stream creation flag preventing implicit synchronization with the legacy default stream.
    • Functions:
      • Destroy As Int
        Destroys this CUDA stream and releases its associated native GPU resources.
        Returns the CUDA runtime status code (0 indicates cudaSuccess). (Return only)
      • Initialize
        Initializes the CUDAStream object and creates a new asynchronous CUDA execution stream using default flags.
      • InitializeWithFlags (flags As Int)
        Initializes the CUDAStream object and creates a new asynchronous CUDA execution stream using the specified flags.
        flags specifies the stream creation flag (STREAM_DEFAULT or STREAM_NON_BLOCKING).
      • IsInitialized As Boolean
      • Query As Int
        Queries the CUDA stream for completion status without blocking the host thread.
        Returns 0 (cudaSuccess) if all operations in the stream have completed, or a non-zero status code if work is still in progress. (Return only)
      • Synchronize As Int
        Blocks host execution until all queued operations in this CUDA stream have completed.
        Returns the CUDA runtime status code (0 indicates cudaSuccess). (Return only)


Enjoy...
 
Last edited:
Does it use Babylon and Hat?
 
Does it use Babylon and Hat?
Hello @Daestrum,

No, it does not use Project Babylon or HAT.

SS_JCUDA wraps JCuda, which uses standard JNI (Java Native Interface) to call NVIDIA's native CUDA Runtime and Driver libraries directly and executes pre-compiled PTX or CUBIN kernels.

I've just done some quick homework on you question.

OpenJDK Project Babylon and HAT rely on experimental code-reflection incubator modules (jdk.incubator.code) to translate annotated Java methods into GPU kernels at runtime, whereas SS_JCUDA uses JCuda's standard JNI bindings to call NVIDIA's native CUDA Runtime and Driver APIs directly via standard JDKs.
 
Last edited:
This library only works with an NVIDIA GPU and needs up-to-date GPU drivers. Older drivers will cause an error, which I found out the hard way.

Sadly I can't test this on my new development laptop as it's an AMD Ryzen AI 9 CPU using an AMD Radeon Gaming GPU. I can't use my old gaming laptop either as that's formatted and ready to be sold. But luckily my current backup development laptop has an NVIDIA GPU.

Even though the speedup multiplier varies from run to run as CPU speeds change (due to workloads), the GPU stays consistently fast. My GPU Speedup results go from 4.1 to 52.7 times faster than the CPU Time, depending on the current CPU workload, not the GPU.

CPU vs GPU Benchmark (10 Million Floats)
GPU Device : NVIDIA GeForce GTX 1650 Ti with Max-Q Design
Elements : 10,000,000
CPU Time : 43 ms
GPU Kernel Time: 1.139 ms
GPU Speedup : 37.8x faster
Verify [50] : CPU=0 | GPU=0 (Negative -> 0)
Verify [150] : CPU=5 | GPU=5 (Positive -> kept)


Enjoy...
 
Last edited:
Back
Top