1 //
2 // Copyright (c) 2022 The Khronos Group Inc.
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16
17 #include <CL/cl.h>
18 #include <CL/cl_ext.h>
19 #include "harness/testHarness.h"
20 #include <iostream>
21 #include <string>
22
23 typedef struct
24 {
25 cl_uint info;
26 const char *name;
27 } _info;
28
29 _info platform_info_table[] = {
30 #define STRING(x) \
31 { \
32 x, #x \
33 }
34 STRING(CL_PLATFORM_EXTERNAL_MEMORY_IMPORT_HANDLE_TYPES_KHR),
35 STRING(CL_PLATFORM_SEMAPHORE_EXPORT_HANDLE_TYPES_KHR),
36 STRING(CL_PLATFORM_SEMAPHORE_IMPORT_HANDLE_TYPES_KHR)
37 #undef STRING
38 };
39
40 _info device_info_table[] = {
41 #define STRING(x) \
42 { \
43 x, #x \
44 }
45 STRING(CL_DEVICE_SEMAPHORE_IMPORT_HANDLE_TYPES_KHR),
46 STRING(CL_DEVICE_SEMAPHORE_EXPORT_HANDLE_TYPES_KHR),
47 STRING(CL_DEVICE_EXTERNAL_MEMORY_IMPORT_HANDLE_TYPES_KHR)
48 #undef STRING
49 };
50
test_platform_info(cl_device_id deviceID,cl_context _context,cl_command_queue _queue,int num_elements)51 int test_platform_info(cl_device_id deviceID, cl_context _context,
52 cl_command_queue _queue, int num_elements)
53 {
54 cl_uint num_platforms;
55 cl_uint i, j;
56 cl_platform_id *platforms;
57 cl_int errNum;
58 cl_uint *handle_type;
59 size_t handle_type_size = 0;
60 cl_uint num_handles = 0;
61
62 // get total # of platforms
63 errNum = clGetPlatformIDs(0, NULL, &num_platforms);
64 test_error(errNum, "clGetPlatformIDs (getting count) failed");
65
66 platforms =
67 (cl_platform_id *)malloc(num_platforms * sizeof(cl_platform_id));
68 if (!platforms)
69 {
70 printf("error allocating memory\n");
71 exit(1);
72 }
73 log_info("%d platforms available\n", num_platforms);
74 errNum = clGetPlatformIDs(num_platforms, platforms, NULL);
75 test_error(errNum, "clGetPlatformIDs (getting IDs) failed");
76
77 for (i = 0; i < num_platforms; i++)
78 {
79 log_info("Platform%d (id %lu) info:\n", i, (unsigned long)platforms[i]);
80 for (j = 0;
81 j < sizeof(platform_info_table) / sizeof(platform_info_table[0]);
82 j++)
83 {
84 errNum =
85 clGetPlatformInfo(platforms[i], platform_info_table[j].info, 0,
86 NULL, &handle_type_size);
87 test_error(errNum, "clGetPlatformInfo failed");
88 num_handles = handle_type_size / sizeof(cl_uint);
89 handle_type = (cl_uint *)malloc(handle_type_size);
90 errNum =
91 clGetPlatformInfo(platforms[i], platform_info_table[j].info,
92 handle_type_size, handle_type, NULL);
93 test_error(errNum, "clGetPlatformInfo failed");
94
95 log_info("%s: \n", platform_info_table[j].name);
96 while (num_handles--)
97 {
98 log_info("%x \n", handle_type[num_handles]);
99 }
100 if (handle_type)
101 {
102 free(handle_type);
103 }
104 }
105 }
106 if (platforms)
107 {
108 free(platforms);
109 }
110 return TEST_PASS;
111 }
112
test_device_info(cl_device_id deviceID,cl_context _context,cl_command_queue _queue,int num_elements)113 int test_device_info(cl_device_id deviceID, cl_context _context,
114 cl_command_queue _queue, int num_elements)
115 {
116 cl_uint j;
117 cl_uint *handle_type;
118 size_t handle_type_size = 0;
119 cl_uint num_handles = 0;
120 cl_int errNum = CL_SUCCESS;
121 for (j = 0; j < sizeof(device_info_table) / sizeof(device_info_table[0]);
122 j++)
123 {
124 errNum = clGetDeviceInfo(deviceID, device_info_table[j].info, 0, NULL,
125 &handle_type_size);
126 test_error(errNum, "clGetDeviceInfo failed");
127
128 num_handles = handle_type_size / sizeof(cl_uint);
129 handle_type = (cl_uint *)malloc(handle_type_size);
130
131 errNum = clGetDeviceInfo(deviceID, device_info_table[j].info,
132 handle_type_size, handle_type, NULL);
133 test_error(errNum, "clGetDeviceInfo failed");
134
135 log_info("%s: \n", device_info_table[j].name);
136 while (num_handles--)
137 {
138 log_info("%x \n", handle_type[num_handles]);
139 }
140 if (handle_type)
141 {
142 free(handle_type);
143 }
144 }
145 return TEST_PASS;
146 }
147