commit 916119045dcb898a6969e6d1217a53b743836c65
parent cfc5f00360bc643c75f543fa730a3a7ccd959975
Author: Christian Grothoff <christian@grothoff.org>
Date: Sat, 18 Nov 2023 19:48:56 +0100
determine available platforms
Diffstat:
1 file changed, 43 insertions(+), 1 deletion(-)
diff --git a/source/rsa-test.c b/source/rsa-test.c
@@ -162,11 +162,53 @@ int verify_with_opencl(DIGIT_T *bases, size_t *b_len,
cl_program program; // compute program
cl_kernel kernel; // compute kernel
+ cl_uint max_platforms = 4;
+ cl_platform_id platforms[max_platforms];
+ cl_uint num_platforms;
+ cl_int rplat;
+
+ rplat = clGetPlatformIDs (max_platforms, platforms, &num_platforms);
+ if (rplat != CL_SUCCESS)
+ {
+ printf("Error: Failed to lookup platforms! (%d)\n", rplat);
+ return EXIT_FAILURE;
+ }
+ printf("Found %u platforms\n", (unsigned int) num_platforms);
+ if (0 == num_platforms)
+ {
+ return EXIT_FAILURE;
+ }
+ for (unsigned int i=0;i<num_platforms;i++)
+ {
+ char buf[128];
+ size_t rbuf;
+ static struct {
+ cl_platform_info cpi;
+ const char *name;
+ } param[] = {
+ { CL_PLATFORM_PROFILE, "profile" },
+ { CL_PLATFORM_VENDOR, "vendor" },
+ { CL_PLATFORM_NAME, "name" },
+ { CL_PLATFORM_EXTENSIONS, "extensions" },
+ { 0, NULL }
+ };
+
+ for (unsigned int j=0;NULL != param[j].name;j++)
+ {
+ err = clGetPlatformInfo (platforms[i], param[j].cpi, sizeof (buf), buf, &rbuf);
+ if (err != CL_SUCCESS)
+ {
+ printf("Error: Failed to get platform info! (%d)\n", err);
+ return EXIT_FAILURE;
+ }
+ printf ("#%u %s %.*s\n", i, param[j].name, (int) rbuf, buf);
+ }
+ }
// Connect to a compute device
//
int gpu = 1;
- err = clGetDeviceIDs(NULL, gpu ? CL_DEVICE_TYPE_GPU : CL_DEVICE_TYPE_CPU, 1, &device_id, NULL);
+ err = clGetDeviceIDs(platforms[0], gpu ? CL_DEVICE_TYPE_GPU : CL_DEVICE_TYPE_CPU, 1, &device_id, NULL);
if (err != CL_SUCCESS)
{
printf("Error: Failed to create a device group! (%d)\n", err);