1 #ifdef __APPLE__ //Mac OSX has a different name for the header file
2 #include <OpenCL/opencl.h>
3 #else
4 #include <CL/opencl.h>
5 #endif
6
7 #include <stdio.h> // printf
8 #include <stdlib.h> // malloc
9 #include <stdint.h> // UINTMAX_MAX
10 #include <string.h> // strcmp
11
checkErr(cl_int err,const char * name)12 void checkErr(cl_int err, const char * name)
13 {
14 if (err != CL_SUCCESS)
15 {
16 printf("ERROR: %s (%i)\n", name, err);
17 exit( err );
18 }
19 }
20
main(void)21 int main(void)
22 {
23 cl_int CL_err = CL_SUCCESS;
24 cl_uint numPlatforms = 0;
25 cl_int stub_platform_found = CL_FALSE;
26
27 CL_err = clGetPlatformIDs(0, NULL, &numPlatforms);
28 checkErr(CL_err, "clGetPlatformIDs(numPlatforms)");
29
30 if (numPlatforms == 0)
31 {
32 printf("No OpenCL platform detected.\n");
33 exit( -1 );
34 }
35 printf("Found %u platform(s)\n\n", numPlatforms);
36 fflush(NULL);
37
38 cl_platform_id* platforms = (cl_platform_id*)malloc(numPlatforms * sizeof(cl_platform_id));
39 CL_err = clGetPlatformIDs(numPlatforms, platforms, NULL);
40 checkErr(CL_err, "clGetPlatformIDs(platforms)");
41
42 for (cl_uint i = 0; i < numPlatforms; ++i)
43 {
44 size_t vendor_length;
45 CL_err = clGetPlatformInfo(platforms[i], CL_PLATFORM_VENDOR, 0, NULL, &vendor_length);
46 checkErr(CL_err, "clGetPlatformInfo(CL_PLATFORM_VENDOR, NULL, &vendor_length)");
47
48 char* platform_name = (char*)malloc(vendor_length * sizeof(char));
49 CL_err = clGetPlatformInfo(platforms[i], CL_PLATFORM_VENDOR, vendor_length, platform_name, NULL);
50 checkErr(CL_err, "clGetPlatformInfo(CL_PLATFORM_VENDOR, vendor_length, platform_name)");
51
52 printf("%s\n", platform_name);
53
54 if (strcmp(platform_name, "stubvendorxxx") == 0)
55 {
56 stub_platform_found = CL_TRUE;
57 }
58
59 fflush(NULL);
60 free(platform_name);
61 }
62
63 if (!stub_platform_found)
64 {
65 printf("Did not locate stub platform\n");
66 return -1;
67 }
68
69 return 0;
70 }
71