Package net.bmahe.genetics4j.gpu.opencl
Class PlatformUtils
java.lang.Object
net.bmahe.genetics4j.gpu.opencl.PlatformUtils
Utility class providing convenient methods for OpenCL platform discovery and information queries.
PlatformUtils encapsulates the low-level OpenCL API calls required for platform enumeration and property retrieval, providing a higher-level interface for GPU-accelerated evolutionary algorithm implementations. This class handles the OpenCL buffer management and type conversions necessary for interacting with the native OpenCL runtime.
Key functionality includes:
- Platform enumeration: Discover available OpenCL platforms in the system
- Property queries: Retrieve platform characteristics and capabilities
- Device counting: Count available devices on each platform
- Buffer management: Handle memory allocation for OpenCL information queries
Common usage patterns:
// Enumerate platforms in the system
int platformCount = PlatformUtils.numPlatforms();
List<cl_platform_id> platformIds = PlatformUtils.platformIds(platformCount);
// Query platform properties
for (cl_platform_id platformId : platformIds) {
String platformName = PlatformUtils.getStringParameter(platformId, CL.CL_PLATFORM_NAME);
String vendor = PlatformUtils.getStringParameter(platformId, CL.CL_PLATFORM_VENDOR);
String version = PlatformUtils.getStringParameter(platformId, CL.CL_PLATFORM_VERSION);
// Count devices on this platform
int deviceCount = PlatformUtils.numDevices(platformId);
int gpuCount = PlatformUtils.numDevices(platformId, CL.CL_DEVICE_TYPE_GPU);
}
Platform discovery workflow:
- System enumeration: Query the number of available platforms
- Platform retrieval: Get platform identifiers for all available platforms
- Property queries: Retrieve platform characteristics for filtering
- Device counting: Determine available devices for each platform
Error handling:
- Parameter validation: Validates all input parameters
- OpenCL error propagation: OpenCL errors are propagated as runtime exceptions
- Memory management: Automatically handles buffer allocation and cleanup
- Empty platform handling: Gracefully handles systems with no OpenCL platforms
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic String
getStringParameter
(org.jocl.cl_platform_id platformId, int platformName) Queries and returns a string property of the specified OpenCL platform.static int
numDevices
(org.jocl.cl_platform_id platformId) Returns the total number of OpenCL devices available on the platform.static int
numDevices
(org.jocl.cl_platform_id platformId, long deviceType) Returns the number of OpenCL devices of the specified type available on the platform.static int
Returns the number of OpenCL platforms available in the system.static List
<org.jocl.cl_platform_id> platformIds
(int numPlatforms) Returns a list of OpenCL platform identifiers for all available platforms.
-
Constructor Details
-
PlatformUtils
private PlatformUtils()
-
-
Method Details
-
numPlatforms
public static int numPlatforms()Returns the number of OpenCL platforms available in the system.- Returns:
- the number of available OpenCL platforms
-
platformIds
Returns a list of OpenCL platform identifiers for all available platforms.- Parameters:
numPlatforms
- the number of platforms to retrieve- Returns:
- list of OpenCL platform identifiers, or empty list if numPlatforms is 0
- Throws:
IllegalArgumentException
- if numPlatforms is negative
-
getStringParameter
Queries and returns a string property of the specified OpenCL platform.This method handles the OpenCL API calls and buffer management required to retrieve string properties from platforms, such as platform name, vendor, or version information.
- Parameters:
platformId
- the OpenCL platform to queryplatformName
- the OpenCL parameter constant (e.g., CL_PLATFORM_NAME, CL_PLATFORM_VENDOR)- Returns:
- the string value of the requested platform property
- Throws:
IllegalArgumentException
- if platformId is null
-
numDevices
public static int numDevices(org.jocl.cl_platform_id platformId, long deviceType) Returns the number of OpenCL devices of the specified type available on the platform.- Parameters:
platformId
- the OpenCL platform to querydeviceType
- the type of devices to count (e.g., CL_DEVICE_TYPE_GPU, CL_DEVICE_TYPE_ALL)- Returns:
- the number of available devices of the specified type
- Throws:
IllegalArgumentException
- if platformId is null
-
numDevices
public static int numDevices(org.jocl.cl_platform_id platformId) Returns the total number of OpenCL devices available on the platform.This is equivalent to calling
numDevices(cl_platform_id, long)
withCL_DEVICE_TYPE_ALL
as the device type.- Parameters:
platformId
- the OpenCL platform to query- Returns:
- the total number of available devices on the platform
- Throws:
IllegalArgumentException
- if platformId is null
-