xref: /aosp_15_r20/external/OpenCL-CTS/test_conformance/subgroups/test_subgroup_shuffle.cpp (revision 6467f958c7de8070b317fc65bcb0f6472e388d82)
1 //
2 // Copyright (c) 2021 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 "procs.h"
17 #include "subhelpers.h"
18 #include "subgroup_common_kernels.h"
19 #include "subgroup_common_templates.h"
20 #include "harness/typeWrappers.h"
21 #include <bitset>
22 
23 namespace {
24 
run_shuffle_for_type(RunTestForType rft)25 template <typename T> int run_shuffle_for_type(RunTestForType rft)
26 {
27     int error =
28         rft.run_impl<T, SHF<T, ShuffleOp::shuffle>>("sub_group_shuffle");
29     error |= rft.run_impl<T, SHF<T, ShuffleOp::shuffle_xor>>(
30         "sub_group_shuffle_xor");
31     return error;
32 }
33 
34 }
35 
test_subgroup_functions_shuffle(cl_device_id device,cl_context context,cl_command_queue queue,int num_elements)36 int test_subgroup_functions_shuffle(cl_device_id device, cl_context context,
37                                     cl_command_queue queue, int num_elements)
38 {
39     if (!is_extension_available(device, "cl_khr_subgroup_shuffle"))
40     {
41         log_info("cl_khr_subgroup_shuffle is not supported on this device, "
42                  "skipping test.\n");
43         return TEST_SKIPPED_ITSELF;
44     }
45 
46     constexpr size_t global_work_size = 2000;
47     constexpr size_t local_work_size = 200;
48     WorkGroupParams test_params(global_work_size, local_work_size);
49     test_params.save_kernel_source(sub_group_generic_source);
50     RunTestForType rft(device, context, queue, num_elements, test_params);
51 
52     int error = run_shuffle_for_type<cl_int>(rft);
53     error |= run_shuffle_for_type<cl_uint>(rft);
54     error |= run_shuffle_for_type<cl_long>(rft);
55     error |= run_shuffle_for_type<cl_ulong>(rft);
56     error |= run_shuffle_for_type<cl_short>(rft);
57     error |= run_shuffle_for_type<cl_ushort>(rft);
58     error |= run_shuffle_for_type<cl_char>(rft);
59     error |= run_shuffle_for_type<cl_uchar>(rft);
60     error |= run_shuffle_for_type<cl_float>(rft);
61     error |= run_shuffle_for_type<cl_double>(rft);
62     error |= run_shuffle_for_type<subgroups::cl_half>(rft);
63 
64     return error;
65 }
66