Class GPUEAExecutionContext<T extends Comparable<T>>

java.lang.Object
net.bmahe.genetics4j.core.spec.AbstractEAExecutionContext<T>
net.bmahe.genetics4j.gpu.spec.GPUEAExecutionContext<T>
Type Parameters:
T - the type of fitness values used in the evolutionary algorithm
Direct Known Subclasses:
ImmutableGPUEAExecutionContext

@Immutable public abstract class GPUEAExecutionContext<T extends Comparable<T>> extends AbstractEAExecutionContext<T>
GPU-specific execution context that extends the core EA framework with OpenCL device selection capabilities.

GPUEAExecutionContext extends AbstractEAExecutionContext to include GPU-specific execution parameters required for OpenCL device discovery and selection. This context combines traditional EA execution settings (population size, termination criteria) with GPU-specific device filtering capabilities.

Key GPU-specific additions:

  • Platform filtering: Predicates for selecting appropriate OpenCL platforms
  • Device filtering: Predicates for selecting compatible OpenCL devices
  • Multi-device support: Automatic discovery and utilization of multiple GPU devices
  • Hardware abstraction: Device-agnostic configuration with runtime device selection

Device selection workflow:

  1. Platform discovery: Enumerate all available OpenCL platforms
  2. Platform filtering: Apply platform predicates to select compatible platforms
  3. Device enumeration: Discover devices for each selected platform
  4. Device filtering: Apply device predicates to select suitable devices
  5. Context creation: Create OpenCL contexts for selected devices

Common filtering patterns:


 // Select only GPU devices with sufficient memory
 GPUEAExecutionContext<Double> context = GPUEAExecutionContext.<Double>builder()
     .populationSize(2000)
     .termination(Generations.of(100))
     
     // Platform filtering - prefer full OpenCL profiles
     .platformFilter(platform -> platform.profile() == PlatformProfile.FULL_PROFILE)
     
     // Device filtering - GPU devices with at least 2GB memory
     .deviceFilter(device -> 
         device.type() == DeviceType.GPU && 
         device.globalMemSize() >= 2L * 1024 * 1024 * 1024)
     
     .build();
 
 // Select any available compute device (GPUs or CPUs)
 GPUEAExecutionContext<Double> flexibleContext = GPUEAExecutionContext.<Double>builder()
     .populationSize(1000)
     .termination(FitnessTarget.of(0.95))
     
     // Accept any platform
     .platformFilter(platform -> true)
     
     // Prefer GPUs but accept CPUs as fallback
     .deviceFilter(device -> 
         device.type() == DeviceType.GPU || 
         device.type() == DeviceType.CPU)
     
     .build();
 

Performance optimization through device selection:

  • Compute capability: Filter devices by OpenCL version and feature support
  • Memory capacity: Ensure devices have sufficient memory for population size
  • Compute units: Prefer devices with more parallel processing units
  • Memory bandwidth: Select devices optimized for data-intensive operations

Multi-device strategies:

  • Load balancing: Automatic population distribution across selected devices
  • Heterogeneous computing: Utilize both GPU and CPU devices simultaneously
  • Fault tolerance: Graceful degradation when devices become unavailable
  • Resource optimization: Efficient utilization of available compute resources

Default behavior:

  • Platform acceptance: All platforms accepted by default
  • Device acceptance: All devices accepted by default
  • Discovery process: Automatic enumeration of available hardware
  • Validation: Runtime validation ensures at least one device is selected
See Also:
  • Constructor Details

    • GPUEAExecutionContext

      public GPUEAExecutionContext()
  • Method Details

    • platformFilters

      @Default public Predicate<Platform> platformFilters()
      Returns the predicate used to filter OpenCL platforms during device discovery.

      Platform filtering allows selective use of OpenCL platforms based on vendor, version, profile, or other platform characteristics. This enables optimization for specific hardware configurations or requirements.

      Common filtering criteria:

      • Profile support: Filter by FULL_PROFILE vs EMBEDDED_PROFILE
      • Vendor preference: Select platforms from specific vendors
      • Version requirements: Ensure minimum OpenCL version support
      • Extension support: Filter platforms with required extensions
      Returns:
      the platform filtering predicate (default accepts all platforms)
    • deviceFilters

      @Default public Predicate<Device> deviceFilters()
      Returns the predicate used to filter OpenCL devices during device discovery.

      Device filtering enables selection of appropriate compute devices based on type, capabilities, memory, and performance characteristics. This allows optimization for specific workload requirements and hardware constraints.

      Common filtering criteria:

      • Device type: GPU, CPU, ACCELERATOR, or combinations
      • Memory capacity: Minimum global or local memory requirements
      • Compute units: Minimum parallel processing capability
      • OpenCL version: Required feature support level
      • Extensions: Specific OpenCL extension requirements
      Returns:
      the device filtering predicate (default accepts all devices)
    • builder

      public static <U extends Comparable<U>> ImmutableGPUEAExecutionContext.Builder<U> builder()
      Creates a new builder for constructing GPU EA execution contexts.

      The builder provides a fluent interface for specifying both core EA execution parameters and GPU-specific device selection criteria. Type safety is ensured through generic parameterization.

      Type Parameters:
      U - the type of fitness values for the execution context
      Returns:
      a new builder instance for creating GPU EA execution contexts