Skip to content

Commit b262136

Browse files
committed
opencl: Show up to four OpenCL platforms
The old code only allowed one platform. Add also strict error handling. Signed-off-by: Stefan Weil <sw@weilnetz.de>
1 parent 02a6970 commit b262136

File tree

1 file changed

+22
-16
lines changed

1 file changed

+22
-16
lines changed

api/tesseractmain.cpp

+22-16
Original file line numberDiff line numberDiff line change
@@ -63,25 +63,31 @@ void PrintVersionInfo() {
6363
lept_free(versionStrP);
6464

6565
#ifdef USE_OPENCL
66-
cl_platform_id platform;
66+
cl_platform_id platform[4];
6767
cl_uint num_platforms;
68-
cl_device_id devices[2];
69-
cl_uint num_devices;
70-
char info[256];
71-
int i;
7268

7369
printf(" OpenCL info:\n");
74-
clGetPlatformIDs(1, &platform, &num_platforms);
75-
printf(" Found %d platforms.\n", num_platforms);
76-
clGetPlatformInfo(platform, CL_PLATFORM_NAME, 256, info, 0);
77-
printf(" Platform name: %s.\n", info);
78-
clGetPlatformInfo(platform, CL_PLATFORM_VERSION, 256, info, 0);
79-
printf(" Version: %s.\n", info);
80-
clGetDeviceIDs(platform, CL_DEVICE_TYPE_ALL, 2, devices, &num_devices);
81-
printf(" Found %d devices.\n", num_devices);
82-
for (i = 0; i < num_devices; ++i) {
83-
clGetDeviceInfo(devices[i], CL_DEVICE_NAME, 256, info, 0);
84-
printf(" Device %d name: %s.\n", i + 1, info);
70+
if (clGetPlatformIDs(4, platform, &num_platforms) == CL_SUCCESS) {
71+
printf(" Found %u platform(s).\n", num_platforms);
72+
for (unsigned n = 0; n < num_platforms; n++) {
73+
char info[256];
74+
if (clGetPlatformInfo(platform[n], CL_PLATFORM_NAME, 256, info, 0) == CL_SUCCESS) {
75+
printf(" Platform %u name: %s.\n", n + 1, info);
76+
}
77+
if (clGetPlatformInfo(platform[n], CL_PLATFORM_VERSION, 256, info, 0) == CL_SUCCESS) {
78+
printf(" Version: %s.\n", info);
79+
}
80+
cl_device_id devices[2];
81+
cl_uint num_devices;
82+
if (clGetDeviceIDs(platform[n], CL_DEVICE_TYPE_ALL, 2, devices, &num_devices) == CL_SUCCESS) {
83+
printf(" Found %u device(s).\n", num_devices);
84+
for (unsigned i = 0; i < num_devices; ++i) {
85+
if (clGetDeviceInfo(devices[i], CL_DEVICE_NAME, 256, info, 0) == CL_SUCCESS) {
86+
printf(" Device %u name: %s.\n", i + 1, info);
87+
}
88+
}
89+
}
90+
}
8591
}
8692
#endif
8793
}

0 commit comments

Comments
 (0)