• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright (c) 2020 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 #include "featureHelpers.h"
17 #include "errorHelpers.h"
18 
19 #include <assert.h>
20 #include <string.h>
21 
22 #include <vector>
23 
get_device_cl_c_features(cl_device_id device,OpenCLCFeatures & features)24 int get_device_cl_c_features(cl_device_id device, OpenCLCFeatures& features)
25 {
26     // Initially, all features are unsupported.
27     features = { 0 };
28 
29     // The CL_DEVICE_OPENCL_C_FEATURES query does not exist pre-3.0.
30     const Version version = get_device_cl_version(device);
31     if (version < Version(3, 0))
32     {
33         return TEST_PASS;
34     }
35 
36     cl_int error = CL_SUCCESS;
37 
38     size_t sz = 0;
39     error = clGetDeviceInfo(device, CL_DEVICE_OPENCL_C_FEATURES, 0, NULL, &sz);
40     test_error(error, "Unable to query CL_DEVICE_OPENCL_C_FEATURES size");
41 
42     std::vector<cl_name_version> clc_features(sz / sizeof(cl_name_version));
43     error = clGetDeviceInfo(device, CL_DEVICE_OPENCL_C_FEATURES, sz,
44                             clc_features.data(), NULL);
45     test_error(error, "Unable to query CL_DEVICE_OPENCL_C_FEATURES");
46 
47 #define CHECK_OPENCL_C_FEATURE(_feature)                                       \
48     if (strcmp(clc_feature.name, #_feature) == 0)                              \
49     {                                                                          \
50         features.supports##_feature = true;                                    \
51     }
52 
53     for (const auto& clc_feature : clc_features)
54     {
55         CHECK_OPENCL_C_FEATURE(__opencl_c_3d_image_writes);
56         CHECK_OPENCL_C_FEATURE(__opencl_c_atomic_order_acq_rel);
57         CHECK_OPENCL_C_FEATURE(__opencl_c_atomic_order_seq_cst);
58         CHECK_OPENCL_C_FEATURE(__opencl_c_atomic_scope_device);
59         CHECK_OPENCL_C_FEATURE(__opencl_c_atomic_scope_all_devices);
60         CHECK_OPENCL_C_FEATURE(__opencl_c_device_enqueue);
61         CHECK_OPENCL_C_FEATURE(__opencl_c_generic_address_space);
62         CHECK_OPENCL_C_FEATURE(__opencl_c_fp64);
63         CHECK_OPENCL_C_FEATURE(__opencl_c_images);
64         CHECK_OPENCL_C_FEATURE(__opencl_c_int64);
65         CHECK_OPENCL_C_FEATURE(__opencl_c_pipes);
66         CHECK_OPENCL_C_FEATURE(__opencl_c_program_scope_global_variables);
67         CHECK_OPENCL_C_FEATURE(__opencl_c_read_write_images);
68         CHECK_OPENCL_C_FEATURE(__opencl_c_subgroups);
69         CHECK_OPENCL_C_FEATURE(__opencl_c_work_group_collective_functions);
70     }
71 
72 #undef CHECK_OPENCL_C_FEATURE
73 
74     return TEST_PASS;
75 }
76