Class KernelInfoUtils

java.lang.Object
net.bmahe.genetics4j.gpu.opencl.KernelInfoUtils

public class KernelInfoUtils extends Object
Utility class providing convenient methods for querying OpenCL kernel work group information.

KernelInfoUtils encapsulates the low-level OpenCL API calls required for retrieving kernel-specific execution characteristics on target devices. This information is essential for optimizing kernel launch parameters and ensuring efficient resource utilization in GPU-accelerated evolutionary algorithms.

Key functionality includes:

  • Work group queries: Retrieve kernel-specific work group size limits and preferences
  • Memory usage queries: Query local and private memory requirements per work-item
  • Performance optimization: Access preferred work group size multiples for optimal execution
  • Resource validation: Obtain kernel resource requirements for launch parameter validation

Common usage patterns:


 // Query kernel work group characteristics
 long maxWorkGroupSize = KernelInfoUtils.getKernelWorkGroupInfoLong(
     deviceId, kernel, CL.CL_KERNEL_WORK_GROUP_SIZE);
 
 long preferredMultiple = KernelInfoUtils.getKernelWorkGroupInfoLong(
     deviceId, kernel, CL.CL_KERNEL_PREFERRED_WORK_GROUP_SIZE_MULTIPLE);
 
 // Query memory requirements
 long localMemSize = KernelInfoUtils.getKernelWorkGroupInfoLong(
     deviceId, kernel, CL.CL_KERNEL_LOCAL_MEM_SIZE);
 
 long privateMemSize = KernelInfoUtils.getKernelWorkGroupInfoLong(
     deviceId, kernel, CL.CL_KERNEL_PRIVATE_MEM_SIZE);
 
 // Optimize work group size based on kernel characteristics
 long optimalWorkGroupSize = (maxWorkGroupSize / preferredMultiple) * preferredMultiple;
 

Kernel optimization workflow:

  1. Kernel compilation: Compile kernel for target device
  2. Characteristic query: Retrieve kernel-specific execution parameters
  3. Launch optimization: Configure work group sizes based on kernel requirements
  4. Resource validation: Ensure memory requirements don't exceed device limits

Error handling:

  • Parameter validation: Validates all input parameters
  • OpenCL error propagation: OpenCL errors are propagated as runtime exceptions
  • Memory management: Automatically handles buffer allocation and cleanup
See Also:
  • Constructor Details

    • KernelInfoUtils

      private KernelInfoUtils()
  • Method Details

    • getKernelWorkGroupInfoLong

      public static long getKernelWorkGroupInfoLong(org.jocl.cl_device_id deviceId, org.jocl.cl_kernel kernel, int parameter)
      Queries and returns a long value for kernel work group information on the specified device.

      This method retrieves kernel-specific execution characteristics that vary by device, such as maximum work group size, preferred work group size multiples, and memory usage requirements. This information is essential for optimizing kernel launch parameters.

      Parameters:
      deviceId - the OpenCL device to query
      kernel - the compiled OpenCL kernel
      parameter - the OpenCL parameter constant (e.g., CL_KERNEL_WORK_GROUP_SIZE, CL_KERNEL_LOCAL_MEM_SIZE)
      Returns:
      the long value of the requested kernel work group property
      Throws:
      IllegalArgumentException - if deviceId or kernel is null