Class GPUEASystemFactory
GPUEASystemFactory provides convenient factory methods for creating EASystem
instances
that leverage GPU acceleration through OpenCL for fitness evaluation. This factory extends the
capabilities of the core EA framework to support high-performance computing on graphics processors
and other OpenCL-compatible devices.
The factory handles the integration between GPU-specific configurations and the core EA framework:
- GPU Configuration: Uses
GPUEAConfiguration
with OpenCL program specifications - Device Selection: Leverages
GPUEAExecutionContext
for platform and device filtering - GPU Evaluator: Creates specialized
GPUFitnessEvaluator
for OpenCL fitness computation - Resource Management: Coordinates executor services with OpenCL resource lifecycle
GPU acceleration benefits:
- Massive parallelism: Evaluate hundreds or thousands of individuals simultaneously
- Memory bandwidth: High-throughput data processing for population-based algorithms
- Specialized hardware: Leverage dedicated compute units optimized for parallel operations
- Energy efficiency: Often better performance-per-watt compared to CPU-only execution
Common usage patterns:
// Define OpenCL kernel for fitness evaluation
Program fitnessProgram = Program.ofResource("/kernels/fitness.cl")
.withBuildOption("-DPROBLEM_SIZE=256");
// Configure GPU-specific EA settings
GPUEAConfiguration<Double> gpuConfig = GPUEAConfigurationBuilder.<Double>builder()
.chromosomeSpecs(chromosomeSpec)
.parentSelectionPolicy(Tournament.of(3))
.combinationPolicy(SinglePointCrossover.build())
.mutationPolicies(List.of(RandomMutation.of(0.1)))
.replacementStrategy(Elitism.builder().offspringRatio(0.8).build())
.program(fitnessProgram)
.fitness(myGPUFitness)
.build();
// Configure execution context with device preferences
GPUEAExecutionContext<Double> gpuContext = GPUEAExecutionContextBuilder.<Double>builder()
.populationSize(1000)
.termination(Generations.of(100))
.platformFilter(platform -> platform.profile() == PlatformProfile.FULL_PROFILE)
.deviceFilter(device -> device.type() == DeviceType.GPU)
.build();
// Create GPU-accelerated EA system
EASystem<Double> gpuSystem = GPUEASystemFactory.from(gpuConfig, gpuContext);
// Run evolution on GPU
EvolutionResult<Double> result = gpuSystem.evolve();
OpenCL integration considerations:
- Device compatibility: Ensure target devices support required OpenCL features
- Memory management: GPU memory is typically limited compared to system RAM
- Kernel optimization: GPU performance depends heavily on kernel implementation
- Transfer overhead: Consider data transfer costs between CPU and GPU memory
Performance optimization tips:
- Large populations: GPU acceleration benefits increase with population size
- Complex fitness functions: More computation per individual improves GPU utilization
- Minimize transfers: Keep data on GPU between generations when possible
- Coalesced memory access: Design kernels for optimal memory access patterns
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T extends Comparable<T>>
EASystem<T> from
(GPUEAConfiguration<T> gpuEAConfiguration, GPUEAExecutionContext<T> gpuEAExecutionContext) Creates a GPU-accelerated EA system using the common thread pool.static <T extends Comparable<T>>
EASystem<T> from
(GPUEAConfiguration<T> gpuEAConfiguration, GPUEAExecutionContext<T> gpuEAExecutionContext, ExecutorService executorService) Creates a GPU-accelerated EA system with explicit thread pool management.
-
Constructor Details
-
GPUEASystemFactory
private GPUEASystemFactory()
-
-
Method Details
-
from
public static <T extends Comparable<T>> EASystem<T> from(GPUEAConfiguration<T> gpuEAConfiguration, GPUEAExecutionContext<T> gpuEAExecutionContext, ExecutorService executorService) Creates a GPU-accelerated EA system with explicit thread pool management.This method provides full control over thread pool management while enabling GPU acceleration for fitness evaluation. The provided executor service is used for coordinating between CPU and GPU operations, managing asynchronous OpenCL operations, and handling concurrent access to OpenCL resources.
The factory method performs the following operations:
- Creates a specialized
GPUFitnessEvaluator
configured for OpenCL execution - Integrates the GPU evaluator with the core EA framework
- Ensures proper resource management and cleanup for OpenCL contexts
Use this method when:
- You need explicit control over thread pool configuration and lifecycle
- Integration with existing thread management systems is required
- Custom executor services are needed for performance tuning
- Resource-constrained environments require careful thread pool sizing
- Type Parameters:
T
- the type of fitness values, must be comparable for selection operations- Parameters:
gpuEAConfiguration
- the GPU-specific EA configuration with OpenCL program and fitness functiongpuEAExecutionContext
- the GPU execution context with device selection and population parametersexecutorService
- the thread pool for managing CPU-GPU coordination (caller responsible for shutdown)- Returns:
- a fully configured
EASystem
with GPU acceleration capabilities - Throws:
IllegalArgumentException
- if any parameter is nullRuntimeException
- if OpenCL initialization fails or no compatible devices are found
- Creates a specialized
-
from
public static <T extends Comparable<T>> EASystem<T> from(GPUEAConfiguration<T> gpuEAConfiguration, GPUEAExecutionContext<T> gpuEAExecutionContext) Creates a GPU-accelerated EA system using the common thread pool.This convenience method provides GPU acceleration without requiring explicit thread pool management. It automatically uses
ForkJoinPool.commonPool()
for CPU-GPU coordination, making it ideal for applications where thread pool management is not critical.This method is recommended for:
- Rapid prototyping and experimentation with GPU acceleration
- Applications where default thread pool behavior is sufficient
- Educational purposes and demonstration code
- Simple GPU-accelerated applications without complex threading requirements
The common thread pool provides automatic parallelization and reasonable default behavior for most GPU acceleration scenarios. However, for production systems with specific performance requirements, consider using
from(GPUEAConfiguration, GPUEAExecutionContext, ExecutorService)
with a custom thread pool.- Type Parameters:
T
- the type of fitness values, must be comparable for selection operations- Parameters:
gpuEAConfiguration
- the GPU-specific EA configuration with OpenCL program and fitness functiongpuEAExecutionContext
- the GPU execution context with device selection and population parameters- Returns:
- a fully configured
EASystem
with GPU acceleration using the common thread pool - Throws:
IllegalArgumentException
- if any parameter is nullRuntimeException
- if OpenCL initialization fails or no compatible devices are found
-