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/conversions.h"
21 #include "harness/typeWrappers.h"
22
23 namespace {
24
run_shuffle_relative_for_type(RunTestForType rft)25 template <typename T> int run_shuffle_relative_for_type(RunTestForType rft)
26 {
27 int error =
28 rft.run_impl<T, SHF<T, ShuffleOp::shuffle_up>>("sub_group_shuffle_up");
29 error |= rft.run_impl<T, SHF<T, ShuffleOp::shuffle_down>>(
30 "sub_group_shuffle_down");
31 return error;
32 }
33
34 }
35
test_subgroup_functions_shuffle_relative(cl_device_id device,cl_context context,cl_command_queue queue,int num_elements)36 int test_subgroup_functions_shuffle_relative(cl_device_id device,
37 cl_context context,
38 cl_command_queue queue,
39 int num_elements)
40 {
41 if (!is_extension_available(device, "cl_khr_subgroup_shuffle_relative"))
42 {
43 log_info("cl_khr_subgroup_shuffle_relative is not supported on this "
44 "device, skipping test.\n");
45 return TEST_SKIPPED_ITSELF;
46 }
47
48 constexpr size_t global_work_size = 2000;
49 constexpr size_t local_work_size = 200;
50 WorkGroupParams test_params(global_work_size, local_work_size);
51 test_params.save_kernel_source(sub_group_generic_source);
52 RunTestForType rft(device, context, queue, num_elements, test_params);
53
54 int error = run_shuffle_relative_for_type<cl_int>(rft);
55 error |= run_shuffle_relative_for_type<cl_uint>(rft);
56 error |= run_shuffle_relative_for_type<cl_long>(rft);
57 error |= run_shuffle_relative_for_type<cl_ulong>(rft);
58 error |= run_shuffle_relative_for_type<cl_short>(rft);
59 error |= run_shuffle_relative_for_type<cl_ushort>(rft);
60 error |= run_shuffle_relative_for_type<cl_char>(rft);
61 error |= run_shuffle_relative_for_type<cl_uchar>(rft);
62 error |= run_shuffle_relative_for_type<cl_float>(rft);
63 error |= run_shuffle_relative_for_type<cl_double>(rft);
64 error |= run_shuffle_relative_for_type<subgroups::cl_half>(rft);
65
66 return error;
67 }
68