• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_templates.h"
19 #include "harness/typeWrappers.h"
20 #include <bitset>
21 
22 namespace {
23 
24 static const char* shuffle_xor_source =
25     "__kernel void test_sub_group_shuffle_xor(const __global Type *in, "
26     "__global int4 *xy, __global Type *out)\n"
27     "{\n"
28     "    int gid = get_global_id(0);\n"
29     "    XY(xy,gid);\n"
30     "    Type x = in[gid];\n"
31     "    out[gid] = sub_group_shuffle_xor(x, xy[gid].z);"
32     "}\n";
33 
34 static const char* shuffle_source =
35     "__kernel void test_sub_group_shuffle(const __global Type *in, __global "
36     "int4 *xy, __global Type *out)\n"
37     "{\n"
38     "    int gid = get_global_id(0);\n"
39     "    XY(xy,gid);\n"
40     "    Type x = in[gid];\n"
41     "    out[gid] = sub_group_shuffle(x, xy[gid].z);"
42     "}\n";
43 
run_shuffle_for_type(RunTestForType rft)44 template <typename T> int run_shuffle_for_type(RunTestForType rft)
45 {
46     int error = rft.run_impl<T, SHF<T, ShuffleOp::shuffle>>(
47         "test_sub_group_shuffle", shuffle_source);
48     error |= rft.run_impl<T, SHF<T, ShuffleOp::shuffle_xor>>(
49         "test_sub_group_shuffle_xor", shuffle_xor_source);
50     return error;
51 }
52 
53 }
54 
test_subgroup_functions_shuffle(cl_device_id device,cl_context context,cl_command_queue queue,int num_elements)55 int test_subgroup_functions_shuffle(cl_device_id device, cl_context context,
56                                     cl_command_queue queue, int num_elements)
57 {
58     std::vector<std::string> required_extensions{ "cl_khr_subgroup_shuffle" };
59     constexpr size_t global_work_size = 2000;
60     constexpr size_t local_work_size = 200;
61     WorkGroupParams test_params(global_work_size, local_work_size,
62                                 required_extensions);
63     RunTestForType rft(device, context, queue, num_elements, test_params);
64 
65     int error = run_shuffle_for_type<cl_int>(rft);
66     error |= run_shuffle_for_type<cl_uint>(rft);
67     error |= run_shuffle_for_type<cl_long>(rft);
68     error |= run_shuffle_for_type<cl_ulong>(rft);
69     error |= run_shuffle_for_type<cl_short>(rft);
70     error |= run_shuffle_for_type<cl_ushort>(rft);
71     error |= run_shuffle_for_type<cl_char>(rft);
72     error |= run_shuffle_for_type<cl_uchar>(rft);
73     error |= run_shuffle_for_type<cl_float>(rft);
74     error |= run_shuffle_for_type<cl_double>(rft);
75     error |= run_shuffle_for_type<subgroups::cl_half>(rft);
76 
77     return error;
78 }
79