PlatformFilters.java

1
package net.bmahe.genetics4j.gpu.spec;
2
3
import java.util.Arrays;
4
import java.util.Collection;
5
import java.util.Objects;
6
import java.util.Set;
7
import java.util.function.Predicate;
8
9
import org.apache.commons.collections4.CollectionUtils;
10
import org.apache.commons.lang3.Validate;
11
12
import net.bmahe.genetics4j.gpu.opencl.model.Platform;
13
import net.bmahe.genetics4j.gpu.opencl.model.PlatformProfile;
14
15
/**
16
 * Utility class providing predicate-based filters for selecting OpenCL platforms in GPU-accelerated evolutionary
17
 * algorithms.
18
 * 
19
 * <p>PlatformFilters offers a fluent API for creating platform selection criteria based on platform characteristics
20
 * such as profile type, supported extensions, and vendor capabilities. These filters are used to automatically select
21
 * appropriate OpenCL platforms before device enumeration and selection.
22
 * 
23
 * <p>Key functionality includes:
24
 * <ul>
25
 * <li><strong>Profile-based filtering</strong>: Select platforms by profile (FULL_PROFILE or EMBEDDED_PROFILE)</li>
26
 * <li><strong>Extension filtering</strong>: Filter platforms based on supported OpenCL extensions</li>
27
 * <li><strong>Logical combinations</strong>: Combine filters using AND and OR operations</li>
28
 * <li><strong>Predicate composition</strong>: Build complex selection criteria from simple predicates</li>
29
 * </ul>
30
 * 
31
 * <p>Common usage patterns:
32
 * 
33
 * <pre>{@code
34
 * // Select platforms with full OpenCL profile
35
 * Predicate<Platform> fullProfileFilter = PlatformFilters.ofProfile(PlatformProfile.FULL_PROFILE);
36
 * 
37
 * // Select platforms supporting double precision arithmetic
38
 * Predicate<Platform> fp64Filter = PlatformFilters.ofExtension("cl_khr_fp64");
39
 * 
40
 * // Select platforms with multiple required extensions
41
 * Set<String> requiredExtensions = Set.of("cl_khr_fp64", "cl_khr_global_int32_base_atomics");
42
 * Predicate<Platform> extensionFilter = PlatformFilters.ofExtensions(requiredExtensions);
43
 * 
44
 * // Combine multiple criteria
45
 * Predicate<Platform> advancedFilter = PlatformFilters
46
 * 		.and(PlatformFilters.ofProfile(PlatformProfile.FULL_PROFILE), PlatformFilters.ofExtension("cl_khr_fp64"));
47
 * 
48
 * // Apply filter to platform selection
49
 * GPUEAExecutionContext context = GPUEAExecutionContext.builder().platformFilters(fullProfileFilter).build();
50
 * }</pre>
51
 * 
52
 * <p>Platform selection workflow:
53
 * <ol>
54
 * <li><strong>Platform enumeration</strong>: Discover all available OpenCL platforms</li>
55
 * <li><strong>Filter application</strong>: Apply platform filters to candidate platforms</li>
56
 * <li><strong>Platform validation</strong>: Validate filtered platforms meet requirements</li>
57
 * <li><strong>Device discovery</strong>: Enumerate devices on selected platforms</li>
58
 * </ol>
59
 * 
60
 * <p>Filter criteria considerations:
61
 * <ul>
62
 * <li><strong>Profile compatibility</strong>: FULL_PROFILE platforms typically offer more features</li>
63
 * <li><strong>Extension requirements</strong>: Filter for extensions required by algorithms</li>
64
 * <li><strong>Vendor optimization</strong>: Consider vendor-specific optimizations and extensions</li>
65
 * <li><strong>Version requirements</strong>: Ensure platforms support required OpenCL versions</li>
66
 * </ul>
67
 * 
68
 * <p>Performance considerations:
69
 * <ul>
70
 * <li><strong>Platform enumeration overhead</strong>: Filters are applied during platform discovery</li>
71
 * <li><strong>Extension validation</strong>: Extension checks may have runtime overhead</li>
72
 * <li><strong>Fallback strategies</strong>: Implement fallback filters for limited platform availability</li>
73
 * <li><strong>Caching</strong>: Platform characteristics are typically static during execution</li>
74
 * </ul>
75
 * 
76
 * @see Platform
77
 * @see PlatformProfile
78
 * @see GPUEAExecutionContext
79
 */
80
public class PlatformFilters {
81
82
	private PlatformFilters() {
83
84
	}
85
86
	/**
87
	 * Creates a predicate that filters platforms by the specified profile type.
88
	 * 
89
	 * @param platformProfile the OpenCL profile type to filter for (FULL_PROFILE or EMBEDDED_PROFILE)
90
	 * @return predicate that returns true for platforms with the specified profile
91
	 * @throws IllegalArgumentException if platformProfile is null
92
	 */
93
	public static Predicate<Platform> ofProfile(final PlatformProfile platformProfile) {
94
		Objects.requireNonNull(platformProfile);
95
96 5 1. lambda$ofProfile$0 : removed call to net/bmahe/genetics4j/gpu/opencl/model/PlatformProfile::equals → NO_COVERAGE
2. lambda$ofProfile$0 : replaced boolean return with false for net/bmahe/genetics4j/gpu/spec/PlatformFilters::lambda$ofProfile$0 → NO_COVERAGE
3. lambda$ofProfile$0 : replaced boolean return with true for net/bmahe/genetics4j/gpu/spec/PlatformFilters::lambda$ofProfile$0 → NO_COVERAGE
4. ofProfile : replaced return value with null for net/bmahe/genetics4j/gpu/spec/PlatformFilters::ofProfile → NO_COVERAGE
5. lambda$ofProfile$0 : removed call to net/bmahe/genetics4j/gpu/opencl/model/Platform::profile → NO_COVERAGE
		return platform -> platformProfile.equals(platform.profile());
97
	}
98
99
	/**
100
	 * Creates a predicate that filters platforms supporting the specified OpenCL extension.
101
	 * 
102
	 * @param extension the OpenCL extension name to filter for (e.g., "cl_khr_fp64")
103
	 * @return predicate that returns true for platforms supporting the extension
104
	 * @throws IllegalArgumentException if extension is null or blank
105
	 */
106
	public static Predicate<Platform> ofExtension(final String extension) {
107
		Validate.notBlank(extension);
108
109 5 1. lambda$ofExtension$0 : replaced boolean return with true for net/bmahe/genetics4j/gpu/spec/PlatformFilters::lambda$ofExtension$0 → NO_COVERAGE
2. lambda$ofExtension$0 : replaced boolean return with false for net/bmahe/genetics4j/gpu/spec/PlatformFilters::lambda$ofExtension$0 → NO_COVERAGE
3. lambda$ofExtension$0 : removed call to java/util/Set::contains → NO_COVERAGE
4. lambda$ofExtension$0 : removed call to net/bmahe/genetics4j/gpu/opencl/model/Platform::extensions → NO_COVERAGE
5. ofExtension : replaced return value with null for net/bmahe/genetics4j/gpu/spec/PlatformFilters::ofExtension → NO_COVERAGE
		return platform -> platform.extensions().contains(extension);
110
	}
111
112
	/**
113
	 * Creates a predicate that filters platforms supporting all specified OpenCL extensions.
114
	 * 
115
	 * @param extensions set of OpenCL extension names that must all be supported
116
	 * @return predicate that returns true for platforms supporting all specified extensions
117
	 * @throws IllegalArgumentException if extensions is null
118
	 */
119
	public static Predicate<Platform> ofExtensions(final Set<String> extensions) {
120
		Objects.requireNonNull(extensions);
121
122 5 1. lambda$ofExtensions$0 : replaced boolean return with true for net/bmahe/genetics4j/gpu/spec/PlatformFilters::lambda$ofExtensions$0 → NO_COVERAGE
2. lambda$ofExtensions$0 : replaced boolean return with false for net/bmahe/genetics4j/gpu/spec/PlatformFilters::lambda$ofExtensions$0 → NO_COVERAGE
3. ofExtensions : replaced return value with null for net/bmahe/genetics4j/gpu/spec/PlatformFilters::ofExtensions → NO_COVERAGE
4. lambda$ofExtensions$0 : removed call to net/bmahe/genetics4j/gpu/opencl/model/Platform::extensions → NO_COVERAGE
5. lambda$ofExtensions$0 : removed call to org/apache/commons/collections4/CollectionUtils::containsAll → NO_COVERAGE
		return platform -> CollectionUtils.containsAll(platform.extensions(), extensions);
123
	}
124
125
	/**
126
	 * Creates a predicate that returns true if any of the provided predicates return true (logical OR).
127
	 * 
128
	 * @param predicates array of platform predicates to combine with OR logic
129
	 * @return predicate that returns true if any input predicate returns true
130
	 * @throws IllegalArgumentException if predicates is null or empty
131
	 */
132
	public static Predicate<Platform> or(@SuppressWarnings("unchecked") final Predicate<Platform>... predicates) {
133
		Objects.requireNonNull(predicates);
134
		Validate.isTrue(predicates.length > 0);
135
136 8 1. lambda$or$0 : removed call to java/util/Arrays::stream → NO_COVERAGE
2. lambda$or$1 : removed call to java/util/function/Predicate::test → NO_COVERAGE
3. lambda$or$0 : removed call to java/util/stream/Stream::anyMatch → NO_COVERAGE
4. lambda$or$0 : replaced boolean return with false for net/bmahe/genetics4j/gpu/spec/PlatformFilters::lambda$or$0 → NO_COVERAGE
5. or : replaced return value with null for net/bmahe/genetics4j/gpu/spec/PlatformFilters::or → NO_COVERAGE
6. lambda$or$0 : replaced boolean return with true for net/bmahe/genetics4j/gpu/spec/PlatformFilters::lambda$or$0 → NO_COVERAGE
7. lambda$or$1 : replaced boolean return with true for net/bmahe/genetics4j/gpu/spec/PlatformFilters::lambda$or$1 → NO_COVERAGE
8. lambda$or$1 : replaced boolean return with false for net/bmahe/genetics4j/gpu/spec/PlatformFilters::lambda$or$1 → NO_COVERAGE
		return platform -> Arrays.stream(predicates).anyMatch(predicate -> predicate.test(platform));
137
	}
138
139
	/**
140
	 * Creates a predicate that returns true if any of the provided predicates return true (logical OR).
141
	 * 
142
	 * @param predicates collection of platform predicates to combine with OR logic
143
	 * @return predicate that returns true if any input predicate returns true
144
	 * @throws IllegalArgumentException if predicates is null or empty
145
	 */
146
	public static Predicate<Platform> or(final Collection<Predicate<Platform>> predicates) {
147
		Objects.requireNonNull(predicates);
148
		Validate.isTrue(predicates.isEmpty() == false);
149
150 8 1. lambda$or$2 : replaced boolean return with true for net/bmahe/genetics4j/gpu/spec/PlatformFilters::lambda$or$2 → NO_COVERAGE
2. lambda$or$2 : replaced boolean return with false for net/bmahe/genetics4j/gpu/spec/PlatformFilters::lambda$or$2 → NO_COVERAGE
3. lambda$or$3 : removed call to java/util/function/Predicate::test → NO_COVERAGE
4. lambda$or$2 : removed call to java/util/Collection::stream → NO_COVERAGE
5. lambda$or$3 : replaced boolean return with true for net/bmahe/genetics4j/gpu/spec/PlatformFilters::lambda$or$3 → NO_COVERAGE
6. or : replaced return value with null for net/bmahe/genetics4j/gpu/spec/PlatformFilters::or → NO_COVERAGE
7. lambda$or$3 : replaced boolean return with false for net/bmahe/genetics4j/gpu/spec/PlatformFilters::lambda$or$3 → NO_COVERAGE
8. lambda$or$2 : removed call to java/util/stream/Stream::anyMatch → NO_COVERAGE
		return platform -> predicates.stream().anyMatch(predicate -> predicate.test(platform));
151
	}
152
153
	/**
154
	 * Creates a predicate that returns true only if all provided predicates return true (logical AND).
155
	 * 
156
	 * @param predicates array of platform predicates to combine with AND logic
157
	 * @return predicate that returns true only if all input predicates return true
158
	 * @throws IllegalArgumentException if predicates is null or empty
159
	 */
160
	public static Predicate<Platform> and(@SuppressWarnings("unchecked") final Predicate<Platform>... predicates) {
161
		Objects.requireNonNull(predicates);
162
		Validate.isTrue(predicates.length > 0);
163
164 8 1. lambda$and$1 : replaced boolean return with true for net/bmahe/genetics4j/gpu/spec/PlatformFilters::lambda$and$1 → NO_COVERAGE
2. lambda$and$1 : removed call to java/util/function/Predicate::test → NO_COVERAGE
3. lambda$and$1 : replaced boolean return with false for net/bmahe/genetics4j/gpu/spec/PlatformFilters::lambda$and$1 → NO_COVERAGE
4. and : replaced return value with null for net/bmahe/genetics4j/gpu/spec/PlatformFilters::and → NO_COVERAGE
5. lambda$and$0 : removed call to java/util/stream/Stream::allMatch → NO_COVERAGE
6. lambda$and$0 : removed call to java/util/Arrays::stream → NO_COVERAGE
7. lambda$and$0 : replaced boolean return with false for net/bmahe/genetics4j/gpu/spec/PlatformFilters::lambda$and$0 → NO_COVERAGE
8. lambda$and$0 : replaced boolean return with true for net/bmahe/genetics4j/gpu/spec/PlatformFilters::lambda$and$0 → NO_COVERAGE
		return platform -> Arrays.stream(predicates).allMatch(predicate -> predicate.test(platform));
165
	}
166
167
	/**
168
	 * Creates a predicate that returns true only if all provided predicates return true (logical AND).
169
	 * 
170
	 * @param predicates collection of platform predicates to combine with AND logic
171
	 * @return predicate that returns true only if all input predicates return true
172
	 * @throws IllegalArgumentException if predicates is null or empty
173
	 */
174
	public static Predicate<Platform> and(final Collection<Predicate<Platform>> predicates) {
175
		Objects.requireNonNull(predicates);
176
		Validate.isTrue(predicates.isEmpty() == false);
177
178 8 1. lambda$and$3 : replaced boolean return with false for net/bmahe/genetics4j/gpu/spec/PlatformFilters::lambda$and$3 → NO_COVERAGE
2. lambda$and$3 : replaced boolean return with true for net/bmahe/genetics4j/gpu/spec/PlatformFilters::lambda$and$3 → NO_COVERAGE
3. lambda$and$2 : removed call to java/util/Collection::stream → NO_COVERAGE
4. lambda$and$3 : removed call to java/util/function/Predicate::test → NO_COVERAGE
5. lambda$and$2 : replaced boolean return with true for net/bmahe/genetics4j/gpu/spec/PlatformFilters::lambda$and$2 → NO_COVERAGE
6. lambda$and$2 : removed call to java/util/stream/Stream::allMatch → NO_COVERAGE
7. lambda$and$2 : replaced boolean return with false for net/bmahe/genetics4j/gpu/spec/PlatformFilters::lambda$and$2 → NO_COVERAGE
8. and : replaced return value with null for net/bmahe/genetics4j/gpu/spec/PlatformFilters::and → NO_COVERAGE
		return platform -> predicates.stream().allMatch(predicate -> predicate.test(platform));
179
	}
180
181
}

Mutations

96

1.1
Location : lambda$ofProfile$0
Killed by : none
removed call to net/bmahe/genetics4j/gpu/opencl/model/PlatformProfile::equals → NO_COVERAGE

2.2
Location : lambda$ofProfile$0
Killed by : none
replaced boolean return with false for net/bmahe/genetics4j/gpu/spec/PlatformFilters::lambda$ofProfile$0 → NO_COVERAGE

3.3
Location : lambda$ofProfile$0
Killed by : none
replaced boolean return with true for net/bmahe/genetics4j/gpu/spec/PlatformFilters::lambda$ofProfile$0 → NO_COVERAGE

4.4
Location : ofProfile
Killed by : none
replaced return value with null for net/bmahe/genetics4j/gpu/spec/PlatformFilters::ofProfile → NO_COVERAGE

5.5
Location : lambda$ofProfile$0
Killed by : none
removed call to net/bmahe/genetics4j/gpu/opencl/model/Platform::profile → NO_COVERAGE

109

1.1
Location : lambda$ofExtension$0
Killed by : none
replaced boolean return with true for net/bmahe/genetics4j/gpu/spec/PlatformFilters::lambda$ofExtension$0 → NO_COVERAGE

2.2
Location : lambda$ofExtension$0
Killed by : none
replaced boolean return with false for net/bmahe/genetics4j/gpu/spec/PlatformFilters::lambda$ofExtension$0 → NO_COVERAGE

3.3
Location : lambda$ofExtension$0
Killed by : none
removed call to java/util/Set::contains → NO_COVERAGE

4.4
Location : lambda$ofExtension$0
Killed by : none
removed call to net/bmahe/genetics4j/gpu/opencl/model/Platform::extensions → NO_COVERAGE

5.5
Location : ofExtension
Killed by : none
replaced return value with null for net/bmahe/genetics4j/gpu/spec/PlatformFilters::ofExtension → NO_COVERAGE

122

1.1
Location : lambda$ofExtensions$0
Killed by : none
replaced boolean return with true for net/bmahe/genetics4j/gpu/spec/PlatformFilters::lambda$ofExtensions$0 → NO_COVERAGE

2.2
Location : lambda$ofExtensions$0
Killed by : none
replaced boolean return with false for net/bmahe/genetics4j/gpu/spec/PlatformFilters::lambda$ofExtensions$0 → NO_COVERAGE

3.3
Location : ofExtensions
Killed by : none
replaced return value with null for net/bmahe/genetics4j/gpu/spec/PlatformFilters::ofExtensions → NO_COVERAGE

4.4
Location : lambda$ofExtensions$0
Killed by : none
removed call to net/bmahe/genetics4j/gpu/opencl/model/Platform::extensions → NO_COVERAGE

5.5
Location : lambda$ofExtensions$0
Killed by : none
removed call to org/apache/commons/collections4/CollectionUtils::containsAll → NO_COVERAGE

136

1.1
Location : lambda$or$0
Killed by : none
removed call to java/util/Arrays::stream → NO_COVERAGE

2.2
Location : lambda$or$1
Killed by : none
removed call to java/util/function/Predicate::test → NO_COVERAGE

3.3
Location : lambda$or$0
Killed by : none
removed call to java/util/stream/Stream::anyMatch → NO_COVERAGE

4.4
Location : lambda$or$0
Killed by : none
replaced boolean return with false for net/bmahe/genetics4j/gpu/spec/PlatformFilters::lambda$or$0 → NO_COVERAGE

5.5
Location : or
Killed by : none
replaced return value with null for net/bmahe/genetics4j/gpu/spec/PlatformFilters::or → NO_COVERAGE

6.6
Location : lambda$or$0
Killed by : none
replaced boolean return with true for net/bmahe/genetics4j/gpu/spec/PlatformFilters::lambda$or$0 → NO_COVERAGE

7.7
Location : lambda$or$1
Killed by : none
replaced boolean return with true for net/bmahe/genetics4j/gpu/spec/PlatformFilters::lambda$or$1 → NO_COVERAGE

8.8
Location : lambda$or$1
Killed by : none
replaced boolean return with false for net/bmahe/genetics4j/gpu/spec/PlatformFilters::lambda$or$1 → NO_COVERAGE

150

1.1
Location : lambda$or$2
Killed by : none
replaced boolean return with true for net/bmahe/genetics4j/gpu/spec/PlatformFilters::lambda$or$2 → NO_COVERAGE

2.2
Location : lambda$or$2
Killed by : none
replaced boolean return with false for net/bmahe/genetics4j/gpu/spec/PlatformFilters::lambda$or$2 → NO_COVERAGE

3.3
Location : lambda$or$3
Killed by : none
removed call to java/util/function/Predicate::test → NO_COVERAGE

4.4
Location : lambda$or$2
Killed by : none
removed call to java/util/Collection::stream → NO_COVERAGE

5.5
Location : lambda$or$3
Killed by : none
replaced boolean return with true for net/bmahe/genetics4j/gpu/spec/PlatformFilters::lambda$or$3 → NO_COVERAGE

6.6
Location : or
Killed by : none
replaced return value with null for net/bmahe/genetics4j/gpu/spec/PlatformFilters::or → NO_COVERAGE

7.7
Location : lambda$or$3
Killed by : none
replaced boolean return with false for net/bmahe/genetics4j/gpu/spec/PlatformFilters::lambda$or$3 → NO_COVERAGE

8.8
Location : lambda$or$2
Killed by : none
removed call to java/util/stream/Stream::anyMatch → NO_COVERAGE

164

1.1
Location : lambda$and$1
Killed by : none
replaced boolean return with true for net/bmahe/genetics4j/gpu/spec/PlatformFilters::lambda$and$1 → NO_COVERAGE

2.2
Location : lambda$and$1
Killed by : none
removed call to java/util/function/Predicate::test → NO_COVERAGE

3.3
Location : lambda$and$1
Killed by : none
replaced boolean return with false for net/bmahe/genetics4j/gpu/spec/PlatformFilters::lambda$and$1 → NO_COVERAGE

4.4
Location : and
Killed by : none
replaced return value with null for net/bmahe/genetics4j/gpu/spec/PlatformFilters::and → NO_COVERAGE

5.5
Location : lambda$and$0
Killed by : none
removed call to java/util/stream/Stream::allMatch → NO_COVERAGE

6.6
Location : lambda$and$0
Killed by : none
removed call to java/util/Arrays::stream → NO_COVERAGE

7.7
Location : lambda$and$0
Killed by : none
replaced boolean return with false for net/bmahe/genetics4j/gpu/spec/PlatformFilters::lambda$and$0 → NO_COVERAGE

8.8
Location : lambda$and$0
Killed by : none
replaced boolean return with true for net/bmahe/genetics4j/gpu/spec/PlatformFilters::lambda$and$0 → NO_COVERAGE

178

1.1
Location : lambda$and$3
Killed by : none
replaced boolean return with false for net/bmahe/genetics4j/gpu/spec/PlatformFilters::lambda$and$3 → NO_COVERAGE

2.2
Location : lambda$and$3
Killed by : none
replaced boolean return with true for net/bmahe/genetics4j/gpu/spec/PlatformFilters::lambda$and$3 → NO_COVERAGE

3.3
Location : lambda$and$2
Killed by : none
removed call to java/util/Collection::stream → NO_COVERAGE

4.4
Location : lambda$and$3
Killed by : none
removed call to java/util/function/Predicate::test → NO_COVERAGE

5.5
Location : lambda$and$2
Killed by : none
replaced boolean return with true for net/bmahe/genetics4j/gpu/spec/PlatformFilters::lambda$and$2 → NO_COVERAGE

6.6
Location : lambda$and$2
Killed by : none
removed call to java/util/stream/Stream::allMatch → NO_COVERAGE

7.7
Location : lambda$and$2
Killed by : none
replaced boolean return with false for net/bmahe/genetics4j/gpu/spec/PlatformFilters::lambda$and$2 → NO_COVERAGE

8.8
Location : and
Killed by : none
replaced return value with null for net/bmahe/genetics4j/gpu/spec/PlatformFilters::and → NO_COVERAGE

Active mutators

Tests examined


Report generated by PIT 1.25.7 support