Class GPUEAExecutionContext<T extends Comparable<T>>
- Type Parameters:
T
- the type of fitness values used in the evolutionary algorithm
- Direct Known Subclasses:
ImmutableGPUEAExecutionContext
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:
- Platform discovery: Enumerate all available OpenCL platforms
- Platform filtering: Apply platform predicates to select compatible platforms
- Device enumeration: Discover devices for each selected platform
- Device filtering: Apply device predicates to select suitable devices
- 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:
-
Field Summary
Fields inherited from class net.bmahe.genetics4j.core.spec.AbstractEAExecutionContext
DEFAULT_POPULATION_SIZE
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <U extends Comparable<U>>
ImmutableGPUEAExecutionContext.Builder<U> builder()
Creates a new builder for constructing GPU EA execution contexts.Returns the predicate used to filter OpenCL devices during device discovery.Returns the predicate used to filter OpenCL platforms during device discovery.Methods inherited from class net.bmahe.genetics4j.core.spec.AbstractEAExecutionContext
chromosomeCombinatorHandlerFactories, chromosomeCombinatorHandlers, chromosomeFactoryProvider, chromosomeMutationPolicyHandlerFactories, chromosomeMutationPolicyHandlers, defaultChromosomeCombinatorHandlers, defaultChromosomeMutationPolicyHandlers, defaultMutationPolicyHandlers, defaultReplacementStrategyHandlers, defaultSelectionPolicyHandlers, evolutionListeners, mutationPolicyHandlerFactories, mutationPolicyHandlers, populationSize, randomGenerator, replacementStrategyHandlerFactories, replacementStrategyHandlers, selectionPolicyHandlerFactories, selectionPolicyHandlers
-
Constructor Details
-
GPUEAExecutionContext
public GPUEAExecutionContext()
-
-
Method Details
-
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
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
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
-