xref: /aosp_15_r20/external/OpenCL-CTS/test_conformance/subgroups/main.cpp (revision 6467f958c7de8070b317fc65bcb0f6472e388d82)
1 //
2 // Copyright (c) 2017 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 "harness/compat.h"
17 
18 #include <stdio.h>
19 #include <string.h>
20 #include "procs.h"
21 #include "harness/testHarness.h"
22 #include "CL/cl_half.h"
23 
24 MTdata gMTdata;
25 cl_half_rounding_mode g_rounding_mode;
26 
27 test_definition test_list[] = {
28     ADD_TEST_VERSION(sub_group_info_ext, Version(2, 0)),
29     ADD_TEST_VERSION(sub_group_info_core, Version(2, 1)),
30     ADD_TEST_VERSION(work_item_functions_ext, Version(2, 0)),
31     ADD_TEST_VERSION(work_item_functions_core, Version(2, 1)),
32     ADD_TEST_VERSION(subgroup_functions_ext, Version(2, 0)),
33     ADD_TEST_VERSION(subgroup_functions_core, Version(2, 1)),
34     ADD_TEST_VERSION(barrier_functions_ext, Version(2, 0)),
35     ADD_TEST_VERSION(barrier_functions_core, Version(2, 1)),
36     ADD_TEST_VERSION(ifp_ext, Version(2, 0)),
37     ADD_TEST_VERSION(ifp_core, Version(2, 1)),
38     ADD_TEST(subgroup_functions_extended_types),
39     ADD_TEST(subgroup_functions_non_uniform_vote),
40     ADD_TEST(subgroup_functions_non_uniform_arithmetic),
41     ADD_TEST(subgroup_functions_ballot),
42     ADD_TEST(subgroup_functions_clustered_reduce),
43     ADD_TEST(subgroup_functions_shuffle),
44     ADD_TEST(subgroup_functions_shuffle_relative),
45     ADD_TEST(subgroup_functions_rotate),
46 };
47 
48 const int test_num = ARRAY_SIZE(test_list);
49 
InitCL(cl_device_id device)50 static test_status InitCL(cl_device_id device)
51 {
52     auto version = get_device_cl_version(device);
53     test_status ret = TEST_PASS;
54     if (version >= Version(3, 0))
55     {
56         cl_uint max_sub_groups;
57         int error;
58 
59         error = clGetDeviceInfo(device, CL_DEVICE_MAX_NUM_SUB_GROUPS,
60                                 sizeof(max_sub_groups), &max_sub_groups, NULL);
61         if (error != CL_SUCCESS)
62         {
63             print_error(error, "Unable to get max number of subgroups");
64             return TEST_FAIL;
65         }
66 
67         if (max_sub_groups == 0)
68         {
69             ret = TEST_SKIP;
70         }
71     }
72     // Determine the rounding mode to be used in float to half conversions in
73     // init and reference code
74     const cl_device_fp_config fpConfig = get_default_rounding_mode(device);
75 
76     if (fpConfig == CL_FP_ROUND_TO_NEAREST)
77     {
78         g_rounding_mode = CL_HALF_RTE;
79     }
80     else if (fpConfig == CL_FP_ROUND_TO_ZERO && gIsEmbedded)
81     {
82         g_rounding_mode = CL_HALF_RTZ;
83     }
84     else
85     {
86         assert(false && "Unreachable");
87     }
88     return ret;
89 }
90 
main(int argc,const char * argv[])91 int main(int argc, const char *argv[])
92 {
93     gMTdata = init_genrand(0);
94     return runTestHarnessWithCheck(argc, argv, test_num, test_list, false, 0,
95                                    InitCL);
96 }
97