• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef TEST_CONFORMANCE_CLCPP_SG_COMMON_HPP
17 #define TEST_CONFORMANCE_CLCPP_SG_COMMON_HPP
18 
19 #include <string>
20 #include <vector>
21 #include <limits>
22 
23 enum class work_group_op : int {
24     add, min, max
25 };
26 
to_string(work_group_op op)27 std::string to_string(work_group_op op)
28 {
29     switch (op)
30     {
31         case work_group_op::add:
32             return "add";
33         case work_group_op::min:
34             return "min";
35         case work_group_op::max:
36             return "max";
37         default:
38             break;
39     }
40     return "";
41 }
42 
43 template <class CL_INT_TYPE, work_group_op op>
generate_input(size_t count,size_t wg_size)44 std::vector<CL_INT_TYPE> generate_input(size_t count, size_t wg_size)
45 {
46     std::vector<CL_INT_TYPE> input(count, CL_INT_TYPE(1));
47     switch (op)
48     {
49         case work_group_op::add:
50             return input;
51         case work_group_op::min:
52             {
53                 size_t j = wg_size;
54                 for(size_t i = 0; i < count; i++)
55                 {
56                     input[i] = static_cast<CL_INT_TYPE>(j);
57                     j--;
58                     if(j == 0)
59                     {
60                         j = wg_size;
61                     }
62                 }
63             }
64             break;
65         case work_group_op::max:
66             {
67                 size_t j = 0;
68                 for(size_t i = 0; i < count; i++)
69                 {
70                     input[i] = static_cast<CL_INT_TYPE>(j);
71                     j++;
72                     if(j == wg_size)
73                     {
74                         j = 0;
75                     }
76                 }
77             }
78     }
79     return input;
80 }
81 
82 template <class CL_INT_TYPE, work_group_op op>
generate_output(size_t count,size_t wg_size)83 std::vector<CL_INT_TYPE> generate_output(size_t count, size_t wg_size)
84 {
85     switch (op)
86     {
87         case work_group_op::add:
88             return std::vector<CL_INT_TYPE>(count, CL_INT_TYPE(0));
89         case work_group_op::min:
90             return std::vector<CL_INT_TYPE>(count, (std::numeric_limits<CL_INT_TYPE>::max)());
91         case work_group_op::max:
92             return std::vector<CL_INT_TYPE>(count, (std::numeric_limits<CL_INT_TYPE>::min)());
93     }
94     return std::vector<CL_INT_TYPE>(count, CL_INT_TYPE(0));
95 }
96 
97 #endif // TEST_CONFORMANCE_CLCPP_SG_COMMON_HPP
98