Class PlatformFilters

java.lang.Object
net.bmahe.genetics4j.gpu.spec.PlatformFilters

public class PlatformFilters extends Object
Utility class providing predicate-based filters for selecting OpenCL platforms in GPU-accelerated evolutionary algorithms.

PlatformFilters offers a fluent API for creating platform selection criteria based on platform characteristics such as profile type, supported extensions, and vendor capabilities. These filters are used to automatically select appropriate OpenCL platforms before device enumeration and selection.

Key functionality includes:

  • Profile-based filtering: Select platforms by profile (FULL_PROFILE or EMBEDDED_PROFILE)
  • Extension filtering: Filter platforms based on supported OpenCL extensions
  • Logical combinations: Combine filters using AND and OR operations
  • Predicate composition: Build complex selection criteria from simple predicates

Common usage patterns:


 // Select platforms with full OpenCL profile
 Predicate<Platform> fullProfileFilter = PlatformFilters.ofProfile(PlatformProfile.FULL_PROFILE);
 
 // Select platforms supporting double precision arithmetic
 Predicate<Platform> fp64Filter = PlatformFilters.ofExtension("cl_khr_fp64");
 
 // Select platforms with multiple required extensions
 Set<String> requiredExtensions = Set.of("cl_khr_fp64", "cl_khr_global_int32_base_atomics");
 Predicate<Platform> extensionFilter = PlatformFilters.ofExtensions(requiredExtensions);
 
 // Combine multiple criteria
 Predicate<Platform> advancedFilter = PlatformFilters.and(
     PlatformFilters.ofProfile(PlatformProfile.FULL_PROFILE),
     PlatformFilters.ofExtension("cl_khr_fp64")
 );
 
 // Apply filter to platform selection
 GPUEAExecutionContext context = GPUEAExecutionContext.builder()
     .platformFilters(fullProfileFilter)
     .build();
 

Platform selection workflow:

  1. Platform enumeration: Discover all available OpenCL platforms
  2. Filter application: Apply platform filters to candidate platforms
  3. Platform validation: Validate filtered platforms meet requirements
  4. Device discovery: Enumerate devices on selected platforms

Filter criteria considerations:

  • Profile compatibility: FULL_PROFILE platforms typically offer more features
  • Extension requirements: Filter for extensions required by algorithms
  • Vendor optimization: Consider vendor-specific optimizations and extensions
  • Version requirements: Ensure platforms support required OpenCL versions

Performance considerations:

  • Platform enumeration overhead: Filters are applied during platform discovery
  • Extension validation: Extension checks may have runtime overhead
  • Fallback strategies: Implement fallback filters for limited platform availability
  • Caching: Platform characteristics are typically static during execution
See Also:
  • Constructor Details

    • PlatformFilters

      private PlatformFilters()
  • Method Details

    • ofProfile

      public static Predicate<Platform> ofProfile(PlatformProfile platformProfile)
      Creates a predicate that filters platforms by the specified profile type.
      Parameters:
      platformProfile - the OpenCL profile type to filter for (FULL_PROFILE or EMBEDDED_PROFILE)
      Returns:
      predicate that returns true for platforms with the specified profile
      Throws:
      IllegalArgumentException - if platformProfile is null
    • ofExtension

      public static Predicate<Platform> ofExtension(String extension)
      Creates a predicate that filters platforms supporting the specified OpenCL extension.
      Parameters:
      extension - the OpenCL extension name to filter for (e.g., "cl_khr_fp64")
      Returns:
      predicate that returns true for platforms supporting the extension
      Throws:
      IllegalArgumentException - if extension is null or blank
    • ofExtensions

      public static Predicate<Platform> ofExtensions(Set<String> extensions)
      Creates a predicate that filters platforms supporting all specified OpenCL extensions.
      Parameters:
      extensions - set of OpenCL extension names that must all be supported
      Returns:
      predicate that returns true for platforms supporting all specified extensions
      Throws:
      IllegalArgumentException - if extensions is null
    • or

      public static Predicate<Platform> or(Predicate<Platform>... predicates)
      Creates a predicate that returns true if any of the provided predicates return true (logical OR).
      Parameters:
      predicates - array of platform 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

      public static Predicate<Platform> or(Collection<Predicate<Platform>> predicates)
      Creates a predicate that returns true if any of the provided predicates return true (logical OR).
      Parameters:
      predicates - collection of platform 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

      public static Predicate<Platform> and(Predicate<Platform>... predicates)
      Creates a predicate that returns true only if all provided predicates return true (logical AND).
      Parameters:
      predicates - array of platform 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

      public static Predicate<Platform> and(Collection<Predicate<Platform>> predicates)
      Creates a predicate that returns true only if all provided predicates return true (logical AND).
      Parameters:
      predicates - collection of platform 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