Package net.bmahe.genetics4j.gpu.spec
Class DeviceFilters
java.lang.Object
net.bmahe.genetics4j.gpu.spec.DeviceFilters
Utility class providing predicate-based filters for selecting OpenCL devices in GPU-accelerated evolutionary algorithms.
DeviceFilters offers a fluent API for creating device selection criteria based on device characteristics such as type, capabilities, and performance metrics. These filters are used to automatically select appropriate OpenCL devices for GPU-accelerated evolutionary algorithm execution.
Key functionality includes:
- Type-based filtering: Select devices by type (GPU, CPU, accelerator)
- Logical combinations: Combine filters using AND and OR operations
- Performance filtering: Filter devices based on computational capabilities
- Predicate composition: Build complex selection criteria from simple predicates
Common usage patterns:
// Select GPU devices only
Predicate<Device> gpuFilter = DeviceFilters.ofGPU();
// Select CPU devices only
Predicate<Device> cpuFilter = DeviceFilters.ofCPU();
// Select GPU or accelerator devices
Predicate<Device> computeFilter = DeviceFilters.or(
DeviceFilters.ofGPU(),
DeviceFilters.ofType(DeviceType.ACCELERATOR)
);
// Select high-performance GPU devices
Predicate<Device> highPerformanceGPU = DeviceFilters.and(
DeviceFilters.ofGPU(),
device -> device.maxComputeUnits() >= 8,
device -> device.maxWorkGroupSize() >= 256
);
// Apply filter to device selection
GPUEAExecutionContext context = GPUEAExecutionContext.builder()
.deviceFilters(gpuFilter)
.build();
Device selection workflow:
- Platform discovery: Enumerate available OpenCL platforms
- Device enumeration: Discover devices on selected platforms
- Filter application: Apply device filters to candidate devices
- Device selection: Select filtered devices for EA execution
Filter composition patterns:
- Type filtering: Select devices by computational type
- Capability filtering: Filter by device computational capabilities
- Performance filtering: Select devices meeting performance criteria
- Logical combinations: Combine multiple criteria using boolean logic
Performance considerations:
- Device enumeration overhead: Filters are applied during device discovery
- Capability validation: Ensure selected devices meet algorithm requirements
- Load balancing: Consider device performance when selecting multiple devices
- Fallback strategies: Implement fallback filters for systems with limited devices
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionand
(Collection<Predicate<Device>> predicates) Creates a predicate that returns true only if all provided predicates return true (logical AND).Creates a predicate that returns true only if all provided predicates return true (logical AND).ofCPU()
Creates a predicate that filters for CPU devices only.ofGPU()
Creates a predicate that filters for GPU devices only.ofType
(DeviceType deviceType) Creates a predicate that filters devices by the specified device type.or
(Collection<Predicate<Device>> predicates) Creates a predicate that returns true if any of the provided predicates return true (logical OR).Creates a predicate that returns true if any of the provided predicates return true (logical OR).
-
Constructor Details
-
DeviceFilters
private DeviceFilters()
-
-
Method Details
-
ofType
Creates a predicate that filters devices by the specified device type.- Parameters:
deviceType
- the OpenCL device type to filter for- Returns:
- predicate that returns true for devices of the specified type
- Throws:
IllegalArgumentException
- if deviceType is null
-
ofGPU
Creates a predicate that filters for GPU devices only.This is a convenience method equivalent to
ofType(DeviceType.GPU)
.- Returns:
- predicate that returns true for GPU devices
-
ofCPU
Creates a predicate that filters for CPU devices only.This is a convenience method equivalent to
ofType(DeviceType.CPU)
.- Returns:
- predicate that returns true for CPU devices
-
or
Creates a predicate that returns true if any of the provided predicates return true (logical OR).- Parameters:
predicates
- array of device predicates to combine with OR logic- Returns:
- predicate that returns true if any input predicate returns true
- Throws:
IllegalArgumentException
- if predicates is null or empty
-
or
Creates a predicate that returns true if any of the provided predicates return true (logical OR).- Parameters:
predicates
- collection of device predicates to combine with OR logic- Returns:
- predicate that returns true if any input predicate returns true
- Throws:
IllegalArgumentException
- if predicates is null or empty
-
and
Creates a predicate that returns true only if all provided predicates return true (logical AND).- Parameters:
predicates
- array of device predicates to combine with AND logic- Returns:
- predicate that returns true only if all input predicates return true
- Throws:
IllegalArgumentException
- if predicates is null or empty
-
and
Creates a predicate that returns true only if all provided predicates return true (logical AND).- Parameters:
predicates
- collection of device predicates to combine with AND logic- Returns:
- predicate that returns true only if all input predicates return true
- Throws:
IllegalArgumentException
- if predicates is null or empty
-