View Javadoc
1   package net.bmahe.genetics4j.gpu;
2   
3   import java.io.IOException;
4   import java.nio.charset.StandardCharsets;
5   import java.util.ArrayList;
6   import java.util.HashMap;
7   import java.util.List;
8   import java.util.Map;
9   import java.util.Objects;
10  import java.util.Set;
11  import java.util.concurrent.CompletableFuture;
12  import java.util.concurrent.ExecutorService;
13  
14  import org.apache.commons.collections4.ListUtils;
15  import org.apache.commons.io.IOUtils;
16  import org.apache.commons.lang3.Validate;
17  import org.apache.commons.lang3.tuple.Pair;
18  import org.apache.logging.log4j.LogManager;
19  import org.apache.logging.log4j.Logger;
20  import org.jocl.CL;
21  import org.jocl.cl_command_queue;
22  import org.jocl.cl_context;
23  import org.jocl.cl_context_properties;
24  import org.jocl.cl_device_id;
25  import org.jocl.cl_kernel;
26  import org.jocl.cl_platform_id;
27  import org.jocl.cl_program;
28  import org.jocl.cl_queue_properties;
29  
30  import net.bmahe.genetics4j.core.Genotype;
31  import net.bmahe.genetics4j.core.evaluation.FitnessEvaluator;
32  import net.bmahe.genetics4j.gpu.opencl.DeviceReader;
33  import net.bmahe.genetics4j.gpu.opencl.DeviceUtils;
34  import net.bmahe.genetics4j.gpu.opencl.KernelInfoReader;
35  import net.bmahe.genetics4j.gpu.opencl.OpenCLExecutionContext;
36  import net.bmahe.genetics4j.gpu.opencl.PlatformReader;
37  import net.bmahe.genetics4j.gpu.opencl.PlatformUtils;
38  import net.bmahe.genetics4j.gpu.opencl.model.Device;
39  import net.bmahe.genetics4j.gpu.opencl.model.KernelInfo;
40  import net.bmahe.genetics4j.gpu.opencl.model.Platform;
41  import net.bmahe.genetics4j.gpu.spec.GPUEAConfiguration;
42  import net.bmahe.genetics4j.gpu.spec.GPUEAExecutionContext;
43  import net.bmahe.genetics4j.gpu.spec.Program;
44  
45  /**
46   * GPU-accelerated fitness evaluator that leverages OpenCL for high-performance evolutionary algorithm execution.
47   * 
48   * <p>GPUFitnessEvaluator implements the core {@link FitnessEvaluator} interface to provide GPU acceleration for fitness
49   * computation in evolutionary algorithms. This evaluator manages the complete OpenCL lifecycle, from device discovery
50   * and kernel compilation to memory management and resource cleanup.
51   * 
52   * <p>Key responsibilities include:
53   * <ul>
54   * <li><strong>OpenCL initialization</strong>: Platform and device discovery, context creation, and kernel
55   * compilation</li>
56   * <li><strong>Resource management</strong>: Managing OpenCL contexts, command queues, programs, and kernels</li>
57   * <li><strong>Population partitioning</strong>: Distributing work across multiple OpenCL devices</li>
58   * <li><strong>Asynchronous execution</strong>: Coordinating concurrent GPU operations with CPU-side logic</li>
59   * <li><strong>Memory lifecycle</strong>: Ensuring proper cleanup of GPU resources</li>
60   * </ul>
61   * 
62   * <p>Architecture overview:
63   * <ol>
64   * <li><strong>Initialization ({@link #preEvaluation})</strong>: Discover platforms/devices, compile kernels, create
65   * contexts</li>
66   * <li><strong>Evaluation ({@link #evaluate})</strong>: Partition population, execute fitness computation on GPU</li>
67   * <li><strong>Cleanup ({@link #postEvaluation})</strong>: Release all OpenCL resources and contexts</li>
68   * </ol>
69   * 
70   * <p>Multi-device support:
71   * <ul>
72   * <li><strong>Device filtering</strong>: Selects devices based on user-defined criteria (type, capabilities)</li>
73   * <li><strong>Load balancing</strong>: Automatically distributes population across available devices</li>
74   * <li><strong>Parallel execution</strong>: Concurrent fitness evaluation on multiple GPUs or devices</li>
75   * <li><strong>Asynchronous coordination</strong>: Non-blocking execution with CompletableFuture-based results</li>
76   * </ul>
77   * 
78   * <p>Resource management patterns:
79   * <ul>
80   * <li><strong>Lazy initialization</strong>: OpenCL resources created only when needed</li>
81   * <li><strong>Automatic cleanup</strong>: Guaranteed resource release through lifecycle methods</li>
82   * <li><strong>Error recovery</strong>: Robust handling of OpenCL errors and device failures</li>
83   * <li><strong>Memory optimization</strong>: Efficient GPU memory usage and transfer patterns</li>
84   * </ul>
85   * 
86   * <p>Example usage in GPU EA system:
87   * 
88   * <pre>{@code
89   * // GPU configuration with OpenCL kernel
90   * Program fitnessProgram = Program.ofResource("/kernels/optimization.cl");
91   * GPUEAConfiguration<Double> config = GPUEAConfigurationBuilder.<Double>builder()
92   * 		.program(fitnessProgram)
93   * 		.fitness(new MyGPUFitness())
94   * 		// ... other EA configuration
95   * 		.build();
96   * 
97   * // Execution context with device preferences
98   * GPUEAExecutionContext<Double> context = GPUEAExecutionContextBuilder.<Double>builder()
99   * 		.populationSize(2000)
100  * 		.deviceFilter(device -> device.type() == DeviceType.GPU)
101  * 		.platformFilter(platform -> platform.profile() == PlatformProfile.FULL_PROFILE)
102  * 		.build();
103  * 
104  * // Evaluator handles all OpenCL lifecycle automatically
105  * GPUFitnessEvaluator<Double> evaluator = new GPUFitnessEvaluator<>(context, config, executorService);
106  * 
107  * // Used by EA system - lifecycle managed automatically
108  * EASystem<Double> system = EASystemFactory.from(config, context, executorService, evaluator);
109  * }</pre>
110  * 
111  * <p>Performance characteristics:
112  * <ul>
113  * <li><strong>Initialization overhead</strong>: One-time setup cost for OpenCL compilation and context creation</li>
114  * <li><strong>Scalability</strong>: Performance scales with population size and problem complexity</li>
115  * <li><strong>Memory bandwidth</strong>: Optimal for problems with high computational intensity</li>
116  * <li><strong>Concurrency</strong>: Supports concurrent evaluation across multiple devices</li>
117  * </ul>
118  * 
119  * <p>Error handling:
120  * <ul>
121  * <li><strong>Device failures</strong>: Graceful degradation when devices become unavailable</li>
122  * <li><strong>Memory errors</strong>: Proper cleanup and error reporting for GPU memory issues</li>
123  * <li><strong>Compilation errors</strong>: Clear error messages for kernel compilation failures</li>
124  * <li><strong>Resource leaks</strong>: Guaranteed cleanup even in exceptional circumstances</li>
125  * </ul>
126  * 
127  * @param <T> the type of fitness values produced, must be comparable for selection operations
128  * @see FitnessEvaluator
129  * @see GPUEAConfiguration
130  * @see GPUEAExecutionContext
131  * @see OpenCLExecutionContext
132  * @see net.bmahe.genetics4j.gpu.fitness.OpenCLFitness
133  */
134 public class GPUFitnessEvaluator<T extends Comparable<T>> implements FitnessEvaluator<T> {
135 	public static final Logger logger = LogManager.getLogger(GPUFitnessEvaluator.class);
136 
137 	private final GPUEAExecutionContext<T> gpuEAExecutionContext;
138 	private final GPUEAConfiguration<T> gpuEAConfiguration;
139 	private final ExecutorService executorService;
140 
141 	private List<Pair<Platform, Device>> selectedPlatformToDevice;
142 
143 	final List<cl_context> clContexts = new ArrayList<>();
144 	final List<cl_command_queue> clCommandQueues = new ArrayList<>();
145 	final List<cl_program> clPrograms = new ArrayList<>();
146 	final List<Map<String, cl_kernel>> clKernels = new ArrayList<>();
147 	final List<OpenCLExecutionContext> clExecutionContexts = new ArrayList<>();
148 
149 	/**
150 	 * Constructs a GPU fitness evaluator with the specified configuration and execution context.
151 	 * 
152 	 * <p>Initializes the evaluator with GPU-specific configuration and execution parameters. The evaluator will use the
153 	 * provided executor service for coordinating asynchronous operations between CPU and GPU components.
154 	 * 
155 	 * <p>The constructor performs minimal initialization - the actual OpenCL setup occurs during
156 	 * {@link #preEvaluation()} to follow the fitness evaluator lifecycle pattern.
157 	 * 
158 	 * @param _gpuEAExecutionContext the GPU execution context with device filters and population settings
159 	 * @param _gpuEAConfiguration    the GPU EA configuration with OpenCL program and fitness function
160 	 * @param _executorService       the executor service for managing asynchronous operations
161 	 * @throws IllegalArgumentException if any parameter is null
162 	 */
163 	public GPUFitnessEvaluator(final GPUEAExecutionContext<T> _gpuEAExecutionContext,
164 			final GPUEAConfiguration<T> _gpuEAConfiguration,
165 			final ExecutorService _executorService) {
166 		Objects.requireNonNull(_gpuEAExecutionContext);
167 		Objects.requireNonNull(_gpuEAConfiguration);
168 		Objects.requireNonNull(_executorService);
169 
170 		this.gpuEAExecutionContext = _gpuEAExecutionContext;
171 		this.gpuEAConfiguration = _gpuEAConfiguration;
172 		this.executorService = _executorService;
173 
174 		CL.setExceptionsEnabled(true);
175 	}
176 
177 	private String loadResource(final String filename) {
178 		Validate.notBlank(filename);
179 
180 		try {
181 			return IOUtils.resourceToString(filename, StandardCharsets.UTF_8);
182 		} catch (IOException e) {
183 			throw new IllegalStateException("Unable to load resource " + filename, e);
184 		}
185 	}
186 
187 	private List<String> grabProgramSources() {
188 		final Program programSpec = gpuEAConfiguration.program();
189 
190 		logger.info("Load program source: {}", programSpec);
191 
192 		final List<String> sources = new ArrayList<>();
193 
194 		sources.addAll(programSpec.content());
195 
196 		programSpec.resources().stream().map(this::loadResource).forEach(program -> sources.add(program));
197 
198 		return sources;
199 	}
200 
201 	/**
202 	 * Initializes OpenCL resources and prepares GPU devices for fitness evaluation.
203 	 * 
204 	 * <p>This method performs the complete OpenCL initialization sequence:
205 	 * <ol>
206 	 * <li><strong>Platform discovery</strong>: Enumerates available OpenCL platforms</li>
207 	 * <li><strong>Device filtering</strong>: Selects devices based on configured filters</li>
208 	 * <li><strong>Context creation</strong>: Creates OpenCL contexts for selected devices</li>
209 	 * <li><strong>Queue setup</strong>: Creates command queues with profiling and out-of-order execution</li>
210 	 * <li><strong>Program compilation</strong>: Compiles OpenCL kernels from source code</li>
211 	 * <li><strong>Kernel preparation</strong>: Creates kernel objects and queries execution info</li>
212 	 * <li><strong>Fitness initialization</strong>: Calls lifecycle hooks on the fitness function</li>
213 	 * </ol>
214 	 * 
215 	 * <p>Device selection process:
216 	 * <ul>
217 	 * <li>Applies platform filters to discovered OpenCL platforms</li>
218 	 * <li>Enumerates devices for each qualifying platform</li>
219 	 * <li>Applies device filters to select appropriate devices</li>
220 	 * <li>Validates that at least one device is available</li>
221 	 * </ul>
222 	 * 
223 	 * <p>The method creates separate OpenCL contexts for each selected device to enable concurrent execution and optimal
224 	 * resource utilization. Each context includes compiled programs and kernel objects ready for fitness evaluation.
225 	 * 
226 	 * @throws IllegalStateException if no compatible devices are found
227 	 * @throws RuntimeException      if OpenCL initialization, program compilation, or kernel creation fails
228 	 */
229 	@Override
230 	public void preEvaluation() {
231 		logger.trace("Init...");
232 		FitnessEvaluator.super.preEvaluation();
233 
234 		final var platformReader = new PlatformReader();
235 		final var deviceReader = new DeviceReader();
236 		final var kernelInfoReader = new KernelInfoReader();
237 
238 		final int numPlatforms = PlatformUtils.numPlatforms();
239 		logger.info("Found {} platforms", numPlatforms);
240 
241 		final List<cl_platform_id> platformIds = PlatformUtils.platformIds(numPlatforms);
242 
243 		logger.info("Selecting platform and devices");
244 		final var platformFilters = gpuEAExecutionContext.platformFilters();
245 		final var deviceFilters = gpuEAExecutionContext.deviceFilters();
246 
247 		selectedPlatformToDevice = platformIds.stream()
248 				.map(platformReader::read)
249 				.filter(platformFilters)
250 				.flatMap(platform -> {
251 					final var platformId = platform.platformId();
252 					final int numDevices = DeviceUtils.numDevices(platformId);
253 					logger.trace("\tPlatform {}: {} devices", platform.name(), numDevices);
254 
255 					final var deviceIds = DeviceUtils.getDeviceIds(platformId, numDevices);
256 					return deviceIds.stream().map(deviceId -> Pair.of(platform, deviceId));
257 				})
258 				.map(platformToDeviceId -> {
259 					final var platform = platformToDeviceId.getLeft();
260 					final var platformId = platform.platformId();
261 					final var deviceID = platformToDeviceId.getRight();
262 
263 					return Pair.of(platform, deviceReader.read(platformId, deviceID));
264 				})
265 				.filter(platformToDevice -> deviceFilters.test(platformToDevice.getRight()))
266 				.toList();
267 
268 		if (logger.isTraceEnabled()) {
269 			logger.trace("============================");
270 			logger.trace("Selected devices:");
271 			selectedPlatformToDevice.forEach(pd -> {
272 				logger.trace("{}", pd.getLeft());
273 				logger.trace("\t{}", pd.getRight());
274 			});
275 			logger.trace("============================");
276 		}
277 
278 		Validate.isTrue(selectedPlatformToDevice.isEmpty() == false, "No compatible devices found for the given filters");
279 
280 		final List<String> programs = grabProgramSources();
281 		final String[] programsArr = programs.toArray(new String[programs.size()]);
282 
283 		for (final var platformAndDevice : selectedPlatformToDevice) {
284 			final var platform = platformAndDevice.getLeft();
285 			final var device = platformAndDevice.getRight();
286 
287 			logger.info("Processing platform [{}] / device [{}]", platform.name(), device.name());
288 
289 			logger.info("\tCreating context");
290 			cl_context_properties contextProperties = new cl_context_properties();
291 			contextProperties.addProperty(CL.CL_CONTEXT_PLATFORM, platform.platformId());
292 
293 			final cl_context context = CL
294 					.clCreateContext(contextProperties, 1, new cl_device_id[] { device.deviceId() }, null, null, null);
295 
296 			logger.info("\tCreating command queue");
297 			final cl_queue_properties queueProperties = new cl_queue_properties();
298 			queueProperties.addProperty(
299 					CL.CL_QUEUE_PROPERTIES,
300 						CL.CL_QUEUE_PROFILING_ENABLE | CL.CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE);
301 			final cl_command_queue commandQueue = CL
302 					.clCreateCommandQueueWithProperties(context, device.deviceId(), queueProperties, null);
303 
304 			logger.info("\tCreate program");
305 			final cl_program program = CL.clCreateProgramWithSource(context, programsArr.length, programsArr, null, null);
306 
307 			final var programSpec = gpuEAConfiguration.program();
308 			final var buildOptions = programSpec.buildOptions().orElse(null);
309 			logger.info("\tBuilding program with options: {}", buildOptions);
310 			CL.clBuildProgram(program, 0, null, buildOptions, null, null);
311 
312 			final Set<String> kernelNames = gpuEAConfiguration.program().kernelNames();
313 
314 			final Map<String, cl_kernel> kernels = new HashMap<>();
315 			final Map<String, KernelInfo> kernelInfos = new HashMap<>();
316 			for (final String kernelName : kernelNames) {
317 
318 				logger.info("\tCreate kernel {}", kernelName);
319 				final cl_kernel kernel = CL.clCreateKernel(program, kernelName, null);
320 				Objects.requireNonNull(kernel);
321 
322 				kernels.put(kernelName, kernel);
323 
324 				final var kernelInfo = kernelInfoReader.read(device.deviceId(), kernel, kernelName);
325 				logger.trace("\t{}", kernelInfo);
326 				kernelInfos.put(kernelName, kernelInfo);
327 			}
328 
329 			clContexts.add(context);
330 			clCommandQueues.add(commandQueue);
331 			clKernels.add(kernels);
332 			clPrograms.add(program);
333 
334 			final var openCLExecutionContext = OpenCLExecutionContext.builder()
335 					.platform(platform)
336 					.device(device)
337 					.clContext(context)
338 					.clCommandQueue(commandQueue)
339 					.kernels(kernels)
340 					.kernelInfos(kernelInfos)
341 					.clProgram(program)
342 					.build();
343 
344 			clExecutionContexts.add(openCLExecutionContext);
345 		}
346 
347 		final var fitness = gpuEAConfiguration.fitness();
348 		fitness.beforeAllEvaluations();
349 		for (final OpenCLExecutionContext clExecutionContext : clExecutionContexts) {
350 			fitness.beforeAllEvaluations(clExecutionContext, executorService);
351 		}
352 	}
353 
354 	/**
355 	 * Evaluates fitness for a population of genotypes using GPU acceleration.
356 	 * 
357 	 * <p>This method implements the core fitness evaluation logic by distributing the population across available OpenCL
358 	 * devices and executing fitness computation concurrently. The evaluation process follows these steps:
359 	 * 
360 	 * <ol>
361 	 * <li><strong>Population partitioning</strong>: Divides genotypes across available devices</li>
362 	 * <li><strong>Parallel dispatch</strong>: Submits evaluation tasks to each device asynchronously</li>
363 	 * <li><strong>GPU execution</strong>: Executes OpenCL kernels for fitness computation</li>
364 	 * <li><strong>Result collection</strong>: Gathers fitness values from all devices</li>
365 	 * <li><strong>Result aggregation</strong>: Combines results preserving original order</li>
366 	 * </ol>
367 	 * 
368 	 * <p>Load balancing strategy:
369 	 * <ul>
370 	 * <li>Automatically calculates partition size based on population and device count</li>
371 	 * <li>Round-robin assignment of partitions to devices for balanced workload</li>
372 	 * <li>Asynchronous execution allows devices to work at their optimal pace</li>
373 	 * </ul>
374 	 * 
375 	 * <p>The method coordinates with the configured fitness function through lifecycle hooks:
376 	 * <ul>
377 	 * <li>{@code beforeEvaluation()}: Called before each device partition evaluation</li>
378 	 * <li>{@code compute()}: Executes the actual GPU fitness computation</li>
379 	 * <li>{@code afterEvaluation()}: Called after each device partition completes</li>
380 	 * </ul>
381 	 * 
382 	 * <p>Concurrency and performance:
383 	 * <ul>
384 	 * <li>Multiple devices execute evaluation partitions concurrently</li>
385 	 * <li>CompletableFuture-based coordination for non-blocking execution</li>
386 	 * <li>Automatic workload distribution across available GPU resources</li>
387 	 * </ul>
388 	 * 
389 	 * @param generation the current generation number for context and logging
390 	 * @param genotypes  the population of genotypes to evaluate
391 	 * @return fitness values corresponding to each genotype in the same order
392 	 * @throws IllegalArgumentException if genotypes is null or empty
393 	 * @throws RuntimeException         if GPU evaluation fails or OpenCL errors occur
394 	 */
395 	@Override
396 	public List<T> evaluate(final long generation, final List<Genotype> genotypes) {
397 
398 		final var fitness = gpuEAConfiguration.fitness();
399 
400 		/**
401 		 * TODO make it configurable from execution context
402 		 */
403 		final int partitionSize = (int) (Math.ceil((double) genotypes.size() / clExecutionContexts.size()));
404 		final var subGenotypes = ListUtils.partition(genotypes, partitionSize);
405 		logger.debug("Genotype decomposed in {} partition(s)", subGenotypes.size());
406 		if (logger.isTraceEnabled()) {
407 			for (int i = 0; i < subGenotypes.size(); i++) {
408 				final List<Genotype> subGenotype = subGenotypes.get(i);
409 				logger.trace("\tPartition {} with {} elements", i, subGenotype.size());
410 			}
411 		}
412 
413 		final List<CompletableFuture<List<T>>> subResultsCF = new ArrayList<>();
414 		for (int i = 0; i < subGenotypes.size(); i++) {
415 			final var openCLExecutionContext = clExecutionContexts.get(i % clExecutionContexts.size());
416 			final var subGenotype = subGenotypes.get(i);
417 
418 			fitness.beforeEvaluation(generation, subGenotype);
419 			fitness.beforeEvaluation(openCLExecutionContext, executorService, generation, subGenotype);
420 
421 			final var resultsCF = fitness.compute(openCLExecutionContext, executorService, generation, subGenotype)
422 					.thenApply(results -> {
423 
424 						fitness.afterEvaluation(openCLExecutionContext, executorService, generation, subGenotype);
425 						fitness.afterEvaluation(generation, subGenotype);
426 
427 						return results;
428 					});
429 
430 			subResultsCF.add(resultsCF);
431 		}
432 
433 		final List<T> resultsEvaluation = new ArrayList<>(genotypes.size());
434 		for (final CompletableFuture<List<T>> subResultCF : subResultsCF) {
435 			final var fitnessResults = subResultCF.join();
436 			resultsEvaluation.addAll(fitnessResults);
437 		}
438 		return resultsEvaluation;
439 	}
440 
441 	/**
442 	 * Cleans up OpenCL resources and releases GPU memory after evaluation completion.
443 	 * 
444 	 * <p>This method performs comprehensive cleanup of all OpenCL resources in the proper order to prevent memory leaks
445 	 * and ensure clean shutdown. The cleanup sequence follows OpenCL best practices for resource deallocation:
446 	 * 
447 	 * <ol>
448 	 * <li><strong>Fitness cleanup</strong>: Calls lifecycle hooks on the fitness function</li>
449 	 * <li><strong>Kernel release</strong>: Releases all compiled kernel objects</li>
450 	 * <li><strong>Program release</strong>: Releases compiled OpenCL programs</li>
451 	 * <li><strong>Queue release</strong>: Releases command queues and pending operations</li>
452 	 * <li><strong>Context release</strong>: Releases OpenCL contexts and associated memory</li>
453 	 * <li><strong>Reference cleanup</strong>: Clears internal data structures and references</li>
454 	 * </ol>
455 	 * 
456 	 * <p>Resource management guarantees:
457 	 * <ul>
458 	 * <li>All GPU memory allocations are properly released</li>
459 	 * <li>OpenCL objects are released in dependency order to avoid errors</li>
460 	 * <li>No resource leaks occur even if individual cleanup operations fail</li>
461 	 * <li>Evaluator returns to a clean state ready for potential reinitialization</li>
462 	 * </ul>
463 	 * 
464 	 * <p>The method coordinates with the configured fitness function to ensure any fitness-specific resources (buffers,
465 	 * textures, etc.) are also properly cleaned up through the {@code afterAllEvaluations()} lifecycle hooks.
466 	 * 
467 	 * @throws RuntimeException if cleanup operations fail (logged but not propagated to prevent interference with EA
468 	 *                          system shutdown)
469 	 */
470 	@Override
471 	public void postEvaluation() {
472 
473 		final var fitness = gpuEAConfiguration.fitness();
474 
475 		for (final OpenCLExecutionContext clExecutionContext : clExecutionContexts) {
476 			fitness.afterAllEvaluations(clExecutionContext, executorService);
477 		}
478 		fitness.afterAllEvaluations();
479 
480 		logger.debug("Releasing kernels");
481 
482 		for (final Map<String, cl_kernel> kernels : clKernels) {
483 			for (final cl_kernel clKernel : kernels.values()) {
484 				CL.clReleaseKernel(clKernel);
485 			}
486 		}
487 		clKernels.clear();
488 
489 		logger.debug("Releasing programs");
490 		for (final cl_program clProgram : clPrograms) {
491 			CL.clReleaseProgram(clProgram);
492 		}
493 		clPrograms.clear();
494 
495 		logger.debug("Releasing command queues");
496 		for (final cl_command_queue clCommandQueue : clCommandQueues) {
497 			CL.clReleaseCommandQueue(clCommandQueue);
498 		}
499 		clCommandQueues.clear();
500 
501 		logger.debug("Releasing contexts");
502 		for (final cl_context clContext : clContexts) {
503 			CL.clReleaseContext(clContext);
504 		}
505 		clContexts.clear();
506 
507 		clExecutionContexts.clear();
508 		selectedPlatformToDevice = null;
509 
510 		FitnessEvaluator.super.postEvaluation();
511 	}
512 }