• 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 #include "harness/compat.h"
17 
18 #include <assert.h>
19 #include <iomanip>
20 #include <iostream>
21 #include <sstream>
22 #include <stdio.h>
23 #include <string.h>
24 #include <string>
25 #include <sys/stat.h>
26 #include <sys/types.h>
27 
28 #include "procs.h"
29 #include "kernels.h"
30 #include "harness/errorHelpers.h"
31 
32 #ifndef uchar
33 typedef unsigned char uchar;
34 #endif
35 
36 typedef struct{
37     char    a;
38     int        b;
39 } TestStruct;
40 
41 #define STRING_LENGTH  1024
42 
43 static int useWorkgroupReserve = 0;
44 static int useSubgroupReserve = 0;
45 static int useConvenienceBuiltIn = 0;
46 
47 static const char* int_kernel_name[] = { "test_pipe_write_int", "test_pipe_read_int", "test_pipe_write_int2", "test_pipe_read_int2", "test_pipe_write_int4", "test_pipe_read_int4", "test_pipe_write_int8", "test_pipe_read_int8", "test_pipe_write_int16", "test_pipe_read_int16" };
48 static const char* uint_kernel_name[] = { "test_pipe_write_uint", "test_pipe_read_uint", "test_pipe_write_uint2", "test_pipe_read_uint2", "test_pipe_write_uint4", "test_pipe_read_uint4", "test_pipe_write_uint8", "test_pipe_read_uint8", "test_pipe_write_uint16", "test_pipe_read_uint16" };
49 static const char* long_kernel_name[] = { "test_pipe_write_long", "test_pipe_read_long", "test_pipe_write_long2", "test_pipe_read_long2", "test_pipe_write_long4", "test_pipe_read_long4", "test_pipe_write_long8", "test_pipe_read_long8", "test_pipe_write_long16", "test_pipe_read_long16" };
50 static const char* ulong_kernel_name[] = { "test_pipe_write_ulong", "test_pipe_read_ulong", "test_pipe_write_ulong2", "test_pipe_read_ulong2", "test_pipe_write_ulong4", "test_pipe_read_ulong4", "test_pipe_write_ulong8", "test_pipe_read_ulong8", "test_pipe_write_ulong16", "test_pipe_read_ulong16" };
51 static const char* char_kernel_name[] = { "test_pipe_write_char", "test_pipe_read_char", "test_pipe_write_char2", "test_pipe_read_char2", "test_pipe_write_char4", "test_pipe_read_char4", "test_pipe_write_char8", "test_pipe_read_char8", "test_pipe_write_char16", "test_pipe_read_char16" };
52 static const char* uchar_kernel_name[] = { "test_pipe_write_uchar", "test_pipe_read_uchar", "test_pipe_write_uchar2", "test_pipe_read_uchar2", "test_pipe_write_uchar4", "test_pipe_read_uchar4", "test_pipe_write_uchar8", "test_pipe_read_uchar8", "test_pipe_write_uchar16", "test_pipe_read_uchar16" };
53 static const char* short_kernel_name[] = { "test_pipe_write_short", "test_pipe_read_short", "test_pipe_write_short2", "test_pipe_read_short2", "test_pipe_write_short4", "test_pipe_read_short4", "test_pipe_write_short8", "test_pipe_read_short8", "test_pipe_write_short16", "test_pipe_read_short16" };
54 static const char* ushort_kernel_name[] = { "test_pipe_write_ushort", "test_pipe_read_ushort", "test_pipe_write_ushort2", "test_pipe_read_ushort2", "test_pipe_write_ushort4", "test_pipe_read_ushort4", "test_pipe_write_ushort8", "test_pipe_read_ushort8", "test_pipe_write_ushort16", "test_pipe_read_ushort16" };
55 static const char* float_kernel_name[] = { "test_pipe_write_float", "test_pipe_read_float", "test_pipe_write_float2", "test_pipe_read_float2", "test_pipe_write_float4", "test_pipe_read_float4", "test_pipe_write_float8", "test_pipe_read_float8", "test_pipe_write_float16", "test_pipe_read_float16" };
56 static const char* half_kernel_name[] = { "test_pipe_write_half", "test_pipe_read_half", "test_pipe_write_half2", "test_pipe_read_half2", "test_pipe_write_half4", "test_pipe_read_half4", "test_pipe_write_half8", "test_pipe_read_half8", "test_pipe_write_half16", "test_pipe_read_half16" };
57 static const char* double_kernel_name[] = { "test_pipe_write_double", "test_pipe_read_double", "test_pipe_write_double2", "test_pipe_read_double2", "test_pipe_write_double4", "test_pipe_read_double4", "test_pipe_write_double8", "test_pipe_read_double8", "test_pipe_write_double16", "test_pipe_read_double16" };
58 
59 static const char* workgroup_int_kernel_name[] = { "test_pipe_workgroup_write_int", "test_pipe_workgroup_read_int", "test_pipe_workgroup_write_int2", "test_pipe_workgroup_read_int2", "test_pipe_workgroup_write_int4", "test_pipe_workgroup_read_int4", "test_pipe_workgroup_write_int8", "test_pipe_workgroup_read_int8", "test_pipe_workgroup_write_int16", "test_pipe_workgroup_read_int16" };
60 static const char* workgroup_uint_kernel_name[] = { "test_pipe_workgroup_write_uint", "test_pipe_workgroup_read_uint", "test_pipe_workgroup_write_uint2", "test_pipe_workgroup_read_uint2", "test_pipe_workgroup_write_uint4", "test_pipe_workgroup_read_uint4", "test_pipe_workgroup_write_uint8", "test_pipe_workgroup_read_uint8", "test_pipe_workgroup_write_uint16", "test_pipe_workgroup_read_uint16" };
61 static const char* workgroup_long_kernel_name[] = { "test_pipe_workgroup_write_long", "test_pipe_workgroup_read_long", "test_pipe_workgroup_write_long2", "test_pipe_workgroup_read_long2", "test_pipe_workgroup_write_long4", "test_pipe_workgroup_read_long4", "test_pipe_workgroup_write_long8", "test_pipe_workgroup_read_long8", "test_pipe_workgroup_write_long16", "test_pipe_workgroup_read_long16" };
62 static const char* workgroup_ulong_kernel_name[] = { "test_pipe_workgroup_write_ulong", "test_pipe_workgroup_read_ulong", "test_pipe_workgroup_write_ulong2", "test_pipe_workgroup_read_ulong2", "test_pipe_workgroup_write_ulong4", "test_pipe_workgroup_read_ulong4", "test_pipe_workgroup_write_ulong8", "test_pipe_workgroup_read_ulong8", "test_pipe_workgroup_write_ulong16", "test_pipe_workgroup_read_ulong16" };
63 static const char* workgroup_char_kernel_name[] = { "test_pipe_workgroup_write_char", "test_pipe_workgroup_read_char", "test_pipe_workgroup_write_char2", "test_pipe_workgroup_read_char2", "test_pipe_workgroup_write_char4", "test_pipe_workgroup_read_char4", "test_pipe_workgroup_write_char8", "test_pipe_workgroup_read_char8", "test_pipe_workgroup_write_char16", "test_pipe_workgroup_read_char16" };
64 static const char* workgroup_uchar_kernel_name[] = { "test_pipe_workgroup_write_uchar", "test_pipe_workgroup_read_uchar", "test_pipe_workgroup_write_uchar2", "test_pipe_workgroup_read_uchar2", "test_pipe_workgroup_write_uchar4", "test_pipe_workgroup_read_uchar4", "test_pipe_workgroup_write_uchar8", "test_pipe_workgroup_read_uchar8", "test_pipe_workgroup_write_uchar16", "test_pipe_workgroup_read_uchar16" };
65 static const char* workgroup_short_kernel_name[] = { "test_pipe_workgroup_write_short", "test_pipe_workgroup_read_short", "test_pipe_workgroup_write_short2", "test_pipe_workgroup_read_short2", "test_pipe_workgroup_write_short4", "test_pipe_workgroup_read_short4", "test_pipe_workgroup_write_short8", "test_pipe_workgroup_read_short8", "test_pipe_workgroup_write_short16", "test_pipe_workgroup_read_short16" };
66 static const char* workgroup_ushort_kernel_name[] = { "test_pipe_workgroup_write_ushort", "test_pipe_workgroup_read_ushort", "test_pipe_workgroup_write_ushort2", "test_pipe_workgroup_read_ushort2", "test_pipe_workgroup_write_ushort4", "test_pipe_workgroup_read_ushort4", "test_pipe_workgroup_write_ushort8", "test_pipe_workgroup_read_ushort8", "test_pipe_workgroup_write_ushort16", "test_pipe_workgroup_read_ushort16" };
67 static const char* workgroup_float_kernel_name[] = { "test_pipe_workgroup_write_float", "test_pipe_workgroup_read_float", "test_pipe_workgroup_write_float2", "test_pipe_workgroup_read_float2", "test_pipe_workgroup_write_float4", "test_pipe_workgroup_read_float4", "test_pipe_workgroup_write_float8", "test_pipe_workgroup_read_float8", "test_pipe_workgroup_write_float16", "test_pipe_workgroup_read_float16" };
68 static const char* workgroup_half_kernel_name[] = { "test_pipe_workgroup_write_half", "test_pipe_workgroup_read_half", "test_pipe_workgroup_write_half2", "test_pipe_workgroup_read_half2", "test_pipe_workgroup_write_half4", "test_pipe_workgroup_read_half4", "test_pipe_workgroup_write_half8", "test_pipe_workgroup_read_half8", "test_pipe_workgroup_write_half16", "test_pipe_workgroup_read_half16" };
69 static const char* workgroup_double_kernel_name[] = { "test_pipe_workgroup_write_double", "test_pipe_workgroup_read_double", "test_pipe_workgroup_write_double2", "test_pipe_workgroup_read_double2", "test_pipe_workgroup_write_double4", "test_pipe_workgroup_read_double4", "test_pipe_workgroup_write_double8", "test_pipe_workgroup_read_double8", "test_pipe_workgroup_write_double16", "test_pipe_workgroup_read_double16" };
70 
71 static const char* subgroup_int_kernel_name[] = { "test_pipe_subgroup_write_int", "test_pipe_subgroup_read_int", "test_pipe_subgroup_write_int2", "test_pipe_subgroup_read_int2", "test_pipe_subgroup_write_int4", "test_pipe_subgroup_read_int4", "test_pipe_subgroup_write_int8", "test_pipe_subgroup_read_int8", "test_pipe_subgroup_write_int16", "test_pipe_subgroup_read_int16" };
72 static const char* subgroup_uint_kernel_name[] = { "test_pipe_subgroup_write_uint", "test_pipe_subgroup_read_uint", "test_pipe_subgroup_write_uint2", "test_pipe_subgroup_read_uint2", "test_pipe_subgroup_write_uint4", "test_pipe_subgroup_read_uint4", "test_pipe_subgroup_write_uint8", "test_pipe_subgroup_read_uint8", "test_pipe_subgroup_write_uint16", "test_pipe_subgroup_read_uint16" };
73 static const char* subgroup_long_kernel_name[] = { "test_pipe_subgroup_write_long", "test_pipe_subgroup_read_long", "test_pipe_subgroup_write_long2", "test_pipe_subgroup_read_long2", "test_pipe_subgroup_write_long4", "test_pipe_subgroup_read_long4", "test_pipe_subgroup_write_long8", "test_pipe_subgroup_read_long8", "test_pipe_subgroup_write_long16", "test_pipe_subgroup_read_long16" };
74 static const char* subgroup_ulong_kernel_name[] = { "test_pipe_subgroup_write_ulong", "test_pipe_subgroup_read_ulong", "test_pipe_subgroup_write_ulong2", "test_pipe_subgroup_read_ulong2", "test_pipe_subgroup_write_ulong4", "test_pipe_subgroup_read_ulong4", "test_pipe_subgroup_write_ulong8", "test_pipe_subgroup_read_ulong8", "test_pipe_subgroup_write_ulong16", "test_pipe_subgroup_read_ulong16" };
75 static const char* subgroup_char_kernel_name[] = { "test_pipe_subgroup_write_char", "test_pipe_subgroup_read_char", "test_pipe_subgroup_write_char2", "test_pipe_subgroup_read_char2", "test_pipe_subgroup_write_char4", "test_pipe_subgroup_read_char4", "test_pipe_subgroup_write_char8", "test_pipe_subgroup_read_char8", "test_pipe_subgroup_write_char16", "test_pipe_subgroup_read_char16" };
76 static const char* subgroup_uchar_kernel_name[] = { "test_pipe_subgroup_write_uchar", "test_pipe_subgroup_read_uchar", "test_pipe_subgroup_write_uchar2", "test_pipe_subgroup_read_uchar2", "test_pipe_subgroup_write_uchar4", "test_pipe_subgroup_read_uchar4", "test_pipe_subgroup_write_uchar8", "test_pipe_subgroup_read_uchar8", "test_pipe_subgroup_write_uchar16", "test_pipe_subgroup_read_uchar16" };
77 static const char* subgroup_short_kernel_name[] = { "test_pipe_subgroup_write_short", "test_pipe_subgroup_read_short", "test_pipe_subgroup_write_short2", "test_pipe_subgroup_read_short2", "test_pipe_subgroup_write_short4", "test_pipe_subgroup_read_short4", "test_pipe_subgroup_write_short8", "test_pipe_subgroup_read_short8", "test_pipe_subgroup_write_short16", "test_pipe_subgroup_read_short16" };
78 static const char* subgroup_ushort_kernel_name[] = { "test_pipe_subgroup_write_ushort", "test_pipe_subgroup_read_ushort", "test_pipe_subgroup_write_ushort2", "test_pipe_subgroup_read_ushort2", "test_pipe_subgroup_write_ushort4", "test_pipe_subgroup_read_ushort4", "test_pipe_subgroup_write_ushort8", "test_pipe_subgroup_read_ushort8", "test_pipe_subgroup_write_ushort16", "test_pipe_subgroup_read_ushort16" };
79 static const char* subgroup_float_kernel_name[] = { "test_pipe_subgroup_write_float", "test_pipe_subgroup_read_float", "test_pipe_subgroup_write_float2", "test_pipe_subgroup_read_float2", "test_pipe_subgroup_write_float4", "test_pipe_subgroup_read_float4", "test_pipe_subgroup_write_float8", "test_pipe_subgroup_read_float8", "test_pipe_subgroup_write_float16", "test_pipe_subgroup_read_float16" };
80 static const char* subgroup_half_kernel_name[] = { "test_pipe_subgroup_write_half", "test_pipe_subgroup_read_half", "test_pipe_subgroup_write_half2", "test_pipe_subgroup_read_half2", "test_pipe_subgroup_write_half4", "test_pipe_subgroup_read_half4", "test_pipe_subgroup_write_half8", "test_pipe_subgroup_read_half8", "test_pipe_subgroup_write_half16", "test_pipe_subgroup_read_half16" };
81 static const char* subgroup_double_kernel_name[] = { "test_pipe_subgroup_write_double", "test_pipe_subgroup_read_double", "test_pipe_subgroup_write_double2", "test_pipe_subgroup_read_double2", "test_pipe_subgroup_write_double4", "test_pipe_subgroup_read_double4", "test_pipe_subgroup_write_double8", "test_pipe_subgroup_read_double8", "test_pipe_subgroup_write_double16", "test_pipe_subgroup_read_double16" };
82 
83 
84 static const char* convenience_int_kernel_name[] = { "test_pipe_convenience_write_int", "test_pipe_convenience_read_int", "test_pipe_convenience_write_int2", "test_pipe_convenience_read_int2", "test_pipe_convenience_write_int4", "test_pipe_convenience_read_int4", "test_pipe_convenience_write_int8", "test_pipe_convenience_read_int8", "test_pipe_convenience_write_int16", "test_pipe_convenience_read_int16" };
85 static const char* convenience_uint_kernel_name[] = { "test_pipe_convenience_write_uint", "test_pipe_convenience_read_uint", "test_pipe_convenience_write_uint2", "test_pipe_convenience_read_uint2", "test_pipe_convenience_write_uint4", "test_pipe_convenience_read_uint4", "test_pipe_convenience_write_uint8", "test_pipe_convenience_read_uint8", "test_pipe_convenience_write_uint16", "test_pipe_convenience_read_uint16" };
86 static const char* convenience_long_kernel_name[] = { "test_pipe_convenience_write_long", "test_pipe_convenience_read_long", "test_pipe_convenience_write_long2", "test_pipe_convenience_read_long2", "test_pipe_convenience_write_long4", "test_pipe_convenience_read_long4", "test_pipe_convenience_write_long8", "test_pipe_convenience_read_long8", "test_pipe_convenience_write_long16", "test_pipe_convenience_read_long16" };
87 static const char* convenience_ulong_kernel_name[] = { "test_pipe_convenience_write_ulong", "test_pipe_convenience_read_ulong", "test_pipe_convenience_write_ulong2", "test_pipe_convenience_read_ulong2", "test_pipe_convenience_write_ulong4", "test_pipe_convenience_read_ulong4", "test_pipe_convenience_write_ulong8", "test_pipe_convenience_read_ulong8", "test_pipe_convenience_write_ulong16", "test_pipe_convenience_read_ulong16" };
88 static const char* convenience_char_kernel_name[] = { "test_pipe_convenience_write_char", "test_pipe_convenience_read_char", "test_pipe_convenience_write_char2", "test_pipe_convenience_read_char2", "test_pipe_convenience_write_char4", "test_pipe_convenience_read_char4", "test_pipe_convenience_write_char8", "test_pipe_convenience_read_char8", "test_pipe_convenience_write_char16", "test_pipe_convenience_read_char16" };
89 static const char* convenience_uchar_kernel_name[] = { "test_pipe_convenience_write_uchar", "test_pipe_convenience_read_uchar", "test_pipe_convenience_write_uchar2", "test_pipe_convenience_read_uchar2", "test_pipe_convenience_write_uchar4", "test_pipe_convenience_read_uchar4", "test_pipe_convenience_write_uchar8", "test_pipe_convenience_read_uchar8", "test_pipe_convenience_write_uchar16", "test_pipe_convenience_read_uchar16" };
90 static const char* convenience_short_kernel_name[] = { "test_pipe_convenience_write_short", "test_pipe_convenience_read_short", "test_pipe_convenience_write_short2", "test_pipe_convenience_read_short2", "test_pipe_convenience_write_short4", "test_pipe_convenience_read_short4", "test_pipe_convenience_write_short8", "test_pipe_convenience_read_short8", "test_pipe_convenience_write_short16", "test_pipe_convenience_read_short16" };
91 static const char* convenience_ushort_kernel_name[] = { "test_pipe_convenience_write_ushort", "test_pipe_convenience_read_ushort", "test_pipe_convenience_write_ushort2", "test_pipe_convenience_read_ushort2", "test_pipe_convenience_write_ushort4", "test_pipe_convenience_read_ushort4", "test_pipe_convenience_write_ushort8", "test_pipe_convenience_read_ushort8", "test_pipe_convenience_write_ushort16", "test_pipe_convenience_read_ushort16" };
92 static const char* convenience_float_kernel_name[] = { "test_pipe_convenience_write_float", "test_pipe_convenience_read_float", "test_pipe_convenience_write_float2", "test_pipe_convenience_read_float2", "test_pipe_convenience_write_float4", "test_pipe_convenience_read_float4", "test_pipe_convenience_write_float8", "test_pipe_convenience_read_float8", "test_pipe_convenience_write_float16", "test_pipe_convenience_read_float16" };
93 static const char* convenience_half_kernel_name[] = { "test_pipe_convenience_write_half", "test_pipe_convenience_read_half", "test_pipe_convenience_write_half2", "test_pipe_convenience_read_half2", "test_pipe_convenience_write_half4", "test_pipe_convenience_read_half4", "test_pipe_convenience_write_half8", "test_pipe_convenience_read_half8", "test_pipe_convenience_write_half16", "test_pipe_convenience_read_half16" };
94 static const char* convenience_double_kernel_name[] = { "test_pipe_convenience_write_double", "test_pipe_convenience_read_double", "test_pipe_convenience_write_double2", "test_pipe_convenience_read_double2", "test_pipe_convenience_write_double4", "test_pipe_convenience_read_double4", "test_pipe_convenience_write_double8", "test_pipe_convenience_read_double8", "test_pipe_convenience_write_double16", "test_pipe_convenience_read_double16" };
95 
insertPragmaForHalfType(std::stringstream & stream,char * type)96 static void insertPragmaForHalfType(std::stringstream &stream, char *type)
97 {
98     if (strncmp(type, "half", 4) == 0)
99     {
100         stream << "#pragma OPENCL EXTENSION cl_khr_fp16 : enable\n";
101     }
102 }
103 
createKernelSource(std::stringstream & stream,char * type)104 void createKernelSource(std::stringstream &stream, char *type)
105 {
106     insertPragmaForHalfType(stream, type);
107 
108     // clang-format off
109     stream << R"(
110         __kernel void test_pipe_write_)" << type << "(__global " << type << " *src, __write_only pipe " << type << R"( out_pipe)
111         {
112             int gid = get_global_id(0);
113             reserve_id_t res_id;
114 
115             res_id = reserve_write_pipe(out_pipe, 1);
116             if(is_valid_reserve_id(res_id))
117             {
118                 write_pipe(out_pipe, res_id, 0, &src[gid]);
119                 commit_write_pipe(out_pipe, res_id);
120             }
121         }
122 
123         __kernel void test_pipe_read_)" << type << "(__read_only pipe " << type << " in_pipe, __global " << type << R"( *dst)
124         {
125             int gid = get_global_id(0);
126             reserve_id_t res_id;
127 
128             res_id = reserve_read_pipe(in_pipe, 1);
129             if(is_valid_reserve_id(res_id))
130             {
131                 read_pipe(in_pipe, res_id, 0, &dst[gid]);
132                 commit_read_pipe(in_pipe, res_id);
133             }
134         }
135         )";
136     // clang-format on
137 }
138 
createKernelSourceWorkGroup(std::stringstream & stream,char * type)139 void createKernelSourceWorkGroup(std::stringstream &stream, char *type)
140 {
141     insertPragmaForHalfType(stream, type);
142 
143     // clang-format off
144     stream << R"(
145         __kernel void test_pipe_workgroup_write_)" << type << "(__global " << type << " *src, __write_only pipe " << type << R"( out_pipe)
146         {
147             int gid = get_global_id(0);
148             __local reserve_id_t res_id;
149 
150             res_id = work_group_reserve_write_pipe(out_pipe, get_local_size(0));
151             if(is_valid_reserve_id(res_id))
152             {
153                 write_pipe(out_pipe, res_id, get_local_id(0), &src[gid]);
154                 work_group_commit_write_pipe(out_pipe, res_id);
155             }
156         }
157 
158         __kernel void test_pipe_workgroup_read_)" << type << "(__read_only pipe " << type << " in_pipe, __global " << type << R"( *dst)
159         {
160             int gid = get_global_id(0);
161             __local reserve_id_t res_id;
162 
163             res_id = work_group_reserve_read_pipe(in_pipe, get_local_size(0));
164             if(is_valid_reserve_id(res_id))
165             {
166                 read_pipe(in_pipe, res_id, get_local_id(0), &dst[gid]);
167                 work_group_commit_read_pipe(in_pipe, res_id);
168             }
169         }
170         )";
171     // clang-format on
172 }
173 
createKernelSourceSubGroup(std::stringstream & stream,char * type)174 void createKernelSourceSubGroup(std::stringstream &stream, char *type)
175 {
176     insertPragmaForHalfType(stream, type);
177 
178     // clang-format off
179     stream << R"(
180         #pragma OPENCL EXTENSION cl_khr_subgroups : enable
181         __kernel void test_pipe_subgroup_write_)" << type << "(__global " << type << " *src, __write_only pipe " << type << R"( out_pipe)
182         {
183             int gid = get_global_id(0);
184             reserve_id_t res_id;
185 
186             res_id = sub_group_reserve_write_pipe(out_pipe, get_sub_group_size());
187             if(is_valid_reserve_id(res_id))
188             {
189                 write_pipe(out_pipe, res_id, get_sub_group_local_id(), &src[gid]);
190                 sub_group_commit_write_pipe(out_pipe, res_id);
191             }
192         }
193 
194         __kernel void test_pipe_subgroup_read_)" << type << "(__read_only pipe " << type << " in_pipe, __global " << type << R"( *dst)
195         {
196             int gid = get_global_id(0);
197             reserve_id_t res_id;
198 
199             res_id = sub_group_reserve_read_pipe(in_pipe, get_sub_group_size());
200             if(is_valid_reserve_id(res_id))
201             {
202                 read_pipe(in_pipe, res_id, get_sub_group_local_id(), &dst[gid]);
203                 sub_group_commit_read_pipe(in_pipe, res_id);
204             }
205         }
206         )";
207     // clang-format on
208 }
209 
createKernelSourceConvenience(std::stringstream & stream,char * type)210 void createKernelSourceConvenience(std::stringstream &stream, char *type)
211 {
212     insertPragmaForHalfType(stream, type);
213 
214     // clang-format off
215     stream << R"(
216         __kernel void test_pipe_convenience_write_)" << type << "(__global " << type << " *src, __write_only pipe " << type << R"( out_pipe)
217         {
218             int gid = get_global_id(0);
219             write_pipe(out_pipe, &src[gid]);
220         }
221 
222         __kernel void test_pipe_convenience_read_)" << type << "(__read_only pipe " << type << " in_pipe, __global " << type << R"( *dst)
223         {
224             int gid = get_global_id(0);
225             read_pipe(in_pipe, &dst[gid]);
226         }
227         )";
228     // clang-format on
229 }
230 
231 // verify functions
verify_readwrite_int(void * ptr1,void * ptr2,int n)232 static int verify_readwrite_int(void *ptr1, void *ptr2, int n)
233 {
234     int     i;
235     int        sum_input = 0, sum_output = 0;
236     cl_int  *inptr = (cl_int *)ptr1;
237     cl_int  *outptr = (cl_int *)ptr2;
238 
239     for(i = 0; i < n; i++)
240     {
241         sum_input += inptr[i];
242         sum_output += outptr[i];
243     }
244     if(sum_input != sum_output){
245         return -1;
246     }
247 
248     return 0;
249 }
250 
verify_readwrite_uint(void * ptr1,void * ptr2,int n)251 static int verify_readwrite_uint(void *ptr1, void *ptr2, int n)
252 {
253     int     i;
254     int        sum_input = 0, sum_output = 0;
255     cl_uint *inptr = (cl_uint *)ptr1;
256     cl_uint *outptr = (cl_uint *)ptr2;
257 
258     for(i = 0; i < n; i++)
259     {
260         sum_input += inptr[i];
261         sum_output += outptr[i];
262     }
263     if(sum_input != sum_output){
264         return -1;
265     }
266 
267     return 0;
268 }
269 
verify_readwrite_short(void * ptr1,void * ptr2,int n)270 static int verify_readwrite_short(void *ptr1, void *ptr2, int n)
271 {
272     int            i;
273     int            sum_input = 0, sum_output = 0;
274     cl_short    *inptr = (cl_short *)ptr1;
275     cl_short    *outptr = (cl_short *)ptr2;
276 
277     for(i = 0; i < n; i++)
278     {
279         sum_input += inptr[i];
280         sum_output += outptr[i];
281     }
282     if(sum_input != sum_output){
283         return -1;
284     }
285     return 0;
286 }
287 
verify_readwrite_ushort(void * ptr1,void * ptr2,int n)288 static int verify_readwrite_ushort(void *ptr1, void *ptr2, int n)
289 {
290     int            i;
291     int            sum_input = 0, sum_output = 0;
292     cl_ushort    *inptr = (cl_ushort *)ptr1;
293     cl_ushort    *outptr = (cl_ushort *)ptr2;
294 
295     for(i = 0; i < n; i++)
296     {
297         sum_input += inptr[i];
298         sum_output += outptr[i];
299     }
300     if(sum_input != sum_output){
301         return -1;
302     }
303     return 0;
304 }
305 
verify_readwrite_char(void * ptr1,void * ptr2,int n)306 static int verify_readwrite_char(void *ptr1, void *ptr2, int n)
307 {
308     int     i;
309     int        sum_input = 0, sum_output = 0;
310     cl_char    *inptr = (cl_char *)ptr1;
311     cl_char    *outptr = (cl_char *)ptr2;
312 
313     for(i = 0; i < n; i++)
314     {
315         sum_input += inptr[i];
316         sum_output += outptr[i];
317     }
318     if(sum_input != sum_output){
319         return -1;
320     }
321     return 0;
322 }
323 
verify_readwrite_uchar(void * ptr1,void * ptr2,int n)324 static int verify_readwrite_uchar(void *ptr1, void *ptr2, int n)
325 {
326     int            i;
327     int            sum_input = 0, sum_output = 0;
328     cl_uchar    *inptr = (cl_uchar *)ptr1;
329     cl_uchar    *outptr = (cl_uchar *)ptr2;
330 
331     for(i = 0; i < n; i++)
332     {
333         sum_input += inptr[i];
334         sum_output += outptr[i];
335     }
336     if(sum_input != sum_output){
337         return -1;
338     }
339     return 0;
340 }
341 
verify_readwrite_float(void * ptr1,void * ptr2,int n)342 static int verify_readwrite_float(void *ptr1, void *ptr2, int n)
343 {
344     int     i;
345     int        sum_input = 0, sum_output = 0;
346     int        *inptr = (int *)ptr1;
347     int        *outptr = (int *)ptr2;
348 
349     for(i = 0; i < n; i++)
350     {
351         sum_input += inptr[i];
352         sum_output += outptr[i];
353     }
354     if(sum_input != sum_output){
355         return -1;
356     }
357     return 0;
358 }
359 
verify_readwrite_half(void * ptr1,void * ptr2,int n)360 static int verify_readwrite_half(void *ptr1, void *ptr2, int n)
361 {
362     int            i;
363     int            sum_input = 0, sum_output = 0;
364     cl_half *inptr = (cl_half *)ptr1;
365     cl_half *outptr = (cl_half *)ptr2;
366 
367     for(i = 0; i < n; i++)
368     {
369         sum_input += inptr[i];
370         sum_output += outptr[i];
371     }
372     if(sum_input != sum_output){
373         return -1;
374     }
375     return 0;
376 }
377 
verify_readwrite_long(void * ptr1,void * ptr2,int n)378 static int verify_readwrite_long(void *ptr1, void *ptr2, int n)
379 {
380     int            i;
381     cl_long        sum_input = 0, sum_output = 0;
382     cl_long        *inptr = (cl_long *)ptr1;
383     cl_long        *outptr = (cl_long *)ptr2;
384 
385     for(i = 0; i < n; i++)
386     {
387         sum_input += inptr[i];
388         sum_output += outptr[i];
389     }
390     if(sum_input != sum_output){
391         return -1;
392     }
393     return 0;
394 }
395 
verify_readwrite_ulong(void * ptr1,void * ptr2,int n)396 static int verify_readwrite_ulong(void *ptr1, void *ptr2, int n)
397 {
398     int            i;
399     cl_ulong    sum_input = 0, sum_output = 0;
400     cl_ulong    *inptr = (cl_ulong *)ptr1;
401     cl_ulong    *outptr = (cl_ulong *)ptr2;
402 
403     for(i = 0; i < n; i++)
404     {
405         sum_input += inptr[i];
406         sum_output += outptr[i];
407     }
408     if(sum_input != sum_output){
409         return -1;
410     }
411     return 0;
412 }
413 
verify_readwrite_double(void * ptr1,void * ptr2,int n)414 static int verify_readwrite_double(void *ptr1, void *ptr2, int n)
415 {
416     int                i;
417     cl_long sum_input = 0, sum_output = 0;
418     cl_long *inptr = (cl_long *)ptr1;
419     cl_long *outptr = (cl_long *)ptr2;
420 
421     for(i = 0; i < n; i++)
422     {
423         sum_input += inptr[i];
424         sum_output += outptr[i];
425     }
426     if(sum_input != sum_output){
427         return -1;
428     }
429     return 0;
430 }
431 
verify_readwrite_struct(void * ptr1,void * ptr2,int n)432 static int verify_readwrite_struct(void *ptr1, void *ptr2, int n)
433 {
434     int            i;
435     int            sum_input_char = 0, sum_output_char = 0;
436     int            sum_input_int = 0, sum_output_int = 0;
437     TestStruct    *inptr = (TestStruct *)ptr1;
438     TestStruct    *outptr = (TestStruct *)ptr2;
439 
440     for(i = 0; i < n; i++)
441     {
442         sum_input_char += inptr[i].a;
443         sum_input_int += inptr[i].b;
444         sum_output_char += outptr[i].a;
445         sum_output_int += outptr[i].b;
446     }
447     if( (sum_input_char != sum_output_char) && (sum_input_int != sum_output_int) ){
448         return -1;
449     }
450 
451     return 0;
452 }
453 
test_pipe_readwrite(cl_device_id deviceID,cl_context context,cl_command_queue queue,int num_elements,size_t size,char * type,int loops,void * inptr[5],const char * kernelName[],int (* fn)(void *,void *,int))454 int test_pipe_readwrite( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements, size_t size, char *type, int loops,
455                          void *inptr[5], const char *kernelName[], int (*fn)(void *, void *, int) )
456 {
457     clMemWrapper pipes[5];
458     clMemWrapper buffers[10];
459     void *outptr[5];
460     BufferOwningPtr<cl_int> BufferOutPtr[5];
461     clProgramWrapper program[5];
462     clKernelWrapper kernel[10];
463     size_t global_work_size[3];
464     size_t local_work_size[3];
465     cl_int err;
466     int i, ii;
467     size_t ptrSizes[5];
468     int total_errors = 0;
469     clEventWrapper producer_sync_event[5];
470     clEventWrapper consumer_sync_event[5];
471     std::stringstream sourceCode[5];
472     char vector_type[10];
473 
474     size_t min_alignment = get_min_alignment(context);
475 
476     global_work_size[0] = (cl_uint)num_elements;
477 
478     ptrSizes[0] = size;
479     ptrSizes[1] = ptrSizes[0] << 1;
480     ptrSizes[2] = ptrSizes[1] << 1;
481     ptrSizes[3] = ptrSizes[2] << 1;
482     ptrSizes[4] = ptrSizes[3] << 1;
483 
484     for (i = 0; i < loops; i++)
485     {
486         ii = i << 1;
487 
488         buffers[ii] =
489             clCreateBuffer(context, CL_MEM_COPY_HOST_PTR,
490                            ptrSizes[i] * num_elements, inptr[i], &err);
491         test_error_ret(err, " clCreateBuffer failed", -1);
492 
493         outptr[i] = align_malloc(ptrSizes[i] * num_elements, min_alignment);
494         BufferOutPtr[i].reset(outptr[i], nullptr, 0, size, true);
495         buffers[ii + 1] =
496             clCreateBuffer(context, CL_MEM_USE_HOST_PTR,
497                            ptrSizes[i] * num_elements, outptr[i], &err);
498         test_error_ret(err, " clCreateBuffer failed", -1);
499 
500         // Creating pipe with non-power of 2 size
501         pipes[i] = clCreatePipe(context, CL_MEM_HOST_NO_ACCESS, ptrSizes[i],
502                                 num_elements + 3, NULL, &err);
503         test_error_ret(err, " clCreatePipe failed", -1);
504 
505         switch (i)
506         {
507             case 0: sprintf(vector_type, "%s", type); break;
508             case 1: sprintf(vector_type, "%s%d", type, 2); break;
509             case 2: sprintf(vector_type, "%s%d", type, 4); break;
510             case 3: sprintf(vector_type, "%s%d", type, 8); break;
511             case 4: sprintf(vector_type, "%s%d", type, 16); break;
512         }
513 
514         if (useWorkgroupReserve == 1)
515         {
516             createKernelSourceWorkGroup(sourceCode[i], vector_type);
517         }
518         else if (useSubgroupReserve == 1)
519         {
520             createKernelSourceSubGroup(sourceCode[i], vector_type);
521         }
522         else if (useConvenienceBuiltIn == 1)
523         {
524             createKernelSourceConvenience(sourceCode[i], vector_type);
525         }
526         else
527         {
528             createKernelSource(sourceCode[i], vector_type);
529         }
530 
531         std::string kernel_source = sourceCode[i].str();
532         const char *sources[] = { kernel_source.c_str() };
533         // Create producer kernel
534         err = create_single_kernel_helper(context, &program[i], &kernel[ii], 1,
535                                           sources, kernelName[ii]);
536 
537         test_error_ret(err, " Error creating program", -1);
538 
539         // Create consumer kernel
540         kernel[ii + 1] = clCreateKernel(program[i], kernelName[ii + 1], &err);
541         test_error_ret(err, " Error creating kernel", -1);
542 
543         err =
544             clSetKernelArg(kernel[ii], 0, sizeof(cl_mem), (void *)&buffers[ii]);
545         err |= clSetKernelArg(kernel[ii], 1, sizeof(cl_mem), (void *)&pipes[i]);
546         err |= clSetKernelArg(kernel[ii + 1], 0, sizeof(cl_mem),
547                               (void *)&pipes[i]);
548         err |= clSetKernelArg(kernel[ii + 1], 1, sizeof(cl_mem),
549                               (void *)&buffers[ii + 1]);
550         test_error_ret(err, " clSetKernelArg failed", -1);
551 
552         if (useWorkgroupReserve == 1 || useSubgroupReserve == 1)
553         {
554             err = get_max_common_work_group_size(
555                 context, kernel[ii], global_work_size[0], &local_work_size[0]);
556             test_error(err, "Unable to get work group size to use");
557             // Launch Producer kernel
558             err = clEnqueueNDRangeKernel(queue, kernel[ii], 1, NULL,
559                                          global_work_size, local_work_size, 0,
560                                          NULL, &producer_sync_event[i]);
561             test_error_ret(err, " clEnqueueNDRangeKernel failed", -1);
562         }
563         else
564         {
565             // Launch Producer kernel
566             err = clEnqueueNDRangeKernel(queue, kernel[ii], 1, NULL,
567                                          global_work_size, NULL, 0, NULL,
568                                          &producer_sync_event[i]);
569             test_error_ret(err, " clEnqueueNDRangeKernel failed", -1);
570         }
571 
572         if (useWorkgroupReserve == 1 || useSubgroupReserve == 1)
573         {
574             err = get_max_common_work_group_size(context, kernel[ii + 1],
575                                                  global_work_size[0],
576                                                  &local_work_size[0]);
577             test_error(err, "Unable to get work group size to use");
578 
579             // Launch Consumer kernel
580             err = clEnqueueNDRangeKernel(queue, kernel[ii + 1], 1, NULL,
581                                          global_work_size, local_work_size, 1,
582                                          &producer_sync_event[i],
583                                          &consumer_sync_event[i]);
584             test_error_ret(err, " clEnqueueNDRangeKernel failed", -1);
585         }
586         else
587         {
588             // Launch Consumer kernel
589             err = clEnqueueNDRangeKernel(
590                 queue, kernel[ii + 1], 1, NULL, global_work_size, NULL, 1,
591                 &producer_sync_event[i], &consumer_sync_event[i]);
592             test_error_ret(err, " clEnqueueNDRangeKernel failed", -1);
593         }
594 
595         err = clEnqueueReadBuffer(queue, buffers[ii + 1], true, 0,
596                                   ptrSizes[i] * num_elements, outptr[i], 1,
597                                   &consumer_sync_event[i], NULL);
598         test_error_ret(err, " clEnqueueReadBuffer failed", -1);
599 
600         if (fn(inptr[i], outptr[i],
601                (int)(ptrSizes[i] * (size_t)num_elements / ptrSizes[0])))
602         {
603             log_error("%s%d test failed\n", type, 1 << i);
604             total_errors++;
605         }
606         else
607         {
608             log_info("%s%d test passed\n", type, 1 << i);
609         }
610     }
611 
612     return total_errors;
613 }
614 
test_pipe_readwrite_struct_generic(cl_device_id deviceID,cl_context context,cl_command_queue queue,int num_elements,const char * kernelCode,const char * kernelName[])615 int test_pipe_readwrite_struct_generic( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements,
616                                 const char *kernelCode, const char *kernelName[])
617 {
618     clMemWrapper buffers[2];
619     clMemWrapper pipe;
620     void *outptr;
621     TestStruct *inptr;
622     BufferOwningPtr<cl_int> BufferInPtr;
623     BufferOwningPtr<TestStruct> BufferOutPtr;
624     clProgramWrapper program;
625     clKernelWrapper kernel[2];
626     size_t size = sizeof(TestStruct);
627     size_t global_work_size[3];
628     cl_int err;
629     int i;
630     MTdataHolder d(gRandomSeed);
631     clEventWrapper producer_sync_event = NULL;
632     clEventWrapper consumer_sync_event = NULL;
633 
634     size_t min_alignment = get_min_alignment(context);
635 
636     global_work_size[0] = (size_t)num_elements;
637 
638     inptr = (TestStruct *)align_malloc(size * num_elements, min_alignment);
639 
640     for (i = 0; i < num_elements; i++)
641     {
642         inptr[i].a = (char)genrand_int32(d);
643         inptr[i].b = genrand_int32(d);
644     }
645     BufferInPtr.reset(inptr, nullptr, 0, size, true);
646 
647     buffers[0] = clCreateBuffer(context, CL_MEM_COPY_HOST_PTR, size * num_elements, inptr, &err);
648     test_error_ret(err, " clCreateBuffer failed", -1);
649 
650     outptr = align_malloc( size * num_elements, min_alignment);
651     BufferOutPtr.reset(outptr, nullptr, 0, size, true);
652 
653     buffers[1] = clCreateBuffer(context, CL_MEM_USE_HOST_PTR,  size * num_elements, outptr, &err);
654     test_error_ret(err, " clCreateBuffer failed", -1);
655 
656     pipe = clCreatePipe(context, CL_MEM_HOST_NO_ACCESS, size, num_elements, NULL, &err);
657     test_error_ret(err, " clCreatePipe failed", -1);
658 
659     // Create producer kernel
660     err = create_single_kernel_helper(context, &program, &kernel[0], 1,
661                                       &kernelCode, kernelName[0]);
662     test_error_ret(err, " Error creating program", -1);
663 
664     //Create consumer kernel
665     kernel[1] = clCreateKernel(program, kernelName[1], &err);
666     test_error_ret(err, " Error creating kernel", -1);
667 
668     err = clSetKernelArg(kernel[0], 0, sizeof(cl_mem), (void*)&buffers[0]);
669     err |= clSetKernelArg(kernel[0], 1, sizeof(cl_mem), (void*)&pipe);
670     err |= clSetKernelArg(kernel[1], 0, sizeof(cl_mem), (void*)&pipe);
671     err |= clSetKernelArg(kernel[1], 1, sizeof(cl_mem), (void*)&buffers[1]);
672     test_error_ret(err, " clSetKernelArg failed", -1);
673 
674     // Launch Producer kernel
675     err = clEnqueueNDRangeKernel( queue, kernel[0], 1, NULL, global_work_size, NULL, 0, NULL, &producer_sync_event );
676     test_error_ret(err, " clEnqueueNDRangeKernel failed", -1);
677 
678     // Launch Consumer kernel
679     err = clEnqueueNDRangeKernel( queue, kernel[1], 1, NULL, global_work_size, NULL, 1, &producer_sync_event, &consumer_sync_event );
680     test_error_ret(err, " clEnqueueNDRangeKernel failed", -1);
681 
682     err = clEnqueueReadBuffer(queue, buffers[1], true, 0, size*num_elements, outptr, 1, &consumer_sync_event, NULL);
683     test_error_ret(err, " clEnqueueReadBuffer failed", -1);
684 
685     if( verify_readwrite_struct( inptr, outptr, num_elements)){
686         log_error("struct_readwrite test failed\n");
687         return -1;
688     }
689     else {
690         log_info("struct_readwrite test passed\n");
691     }
692 
693     return 0;
694 }
695 
696 
test_pipe_readwrite_int(cl_device_id deviceID,cl_context context,cl_command_queue queue,int num_elements)697 int test_pipe_readwrite_int( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements )
698 {
699     cl_int  *inptr[5];
700     size_t  ptrSizes[5];
701     int     i, err;
702     cl_uint j;
703     int     (*foo)(void *,void *,int);
704     MTdata  d = init_genrand( gRandomSeed );
705 
706     size_t  min_alignment = get_min_alignment(context);
707 
708     foo = verify_readwrite_int;
709 
710     ptrSizes[0] = sizeof(cl_int);
711     ptrSizes[1] = ptrSizes[0] << 1;
712     ptrSizes[2] = ptrSizes[1] << 1;
713     ptrSizes[3] = ptrSizes[2] << 1;
714     ptrSizes[4] = ptrSizes[3] << 1;
715 
716     for ( i = 0; i < 5; i++ ){
717         inptr[i] = (cl_int *)align_malloc(ptrSizes[i] * num_elements, min_alignment);
718 
719         for ( j = 0; j < ptrSizes[i] * num_elements / ptrSizes[0]; j++ )
720             inptr[i][j] = (int)genrand_int32(d);
721     }
722 
723     if(useWorkgroupReserve == 1){
724         err = test_pipe_readwrite( deviceID, context, queue, num_elements, sizeof( cl_int ), (char*)"int", 5, (void**)inptr,
725                                    workgroup_int_kernel_name, foo);
726     }
727     else if(useSubgroupReserve == 1){
728         err = test_pipe_readwrite( deviceID, context, queue, num_elements, sizeof( cl_int ), (char*)"int", 5, (void**)inptr,
729                                    subgroup_int_kernel_name, foo);
730     }
731     else if(useConvenienceBuiltIn == 1) {
732         err = test_pipe_readwrite( deviceID, context, queue, num_elements, sizeof( cl_int ), (char*)"int", 5, (void**)inptr,
733                                    convenience_int_kernel_name, foo);
734     }
735     else {
736         err = test_pipe_readwrite( deviceID, context, queue, num_elements, sizeof( cl_int ), (char*)"int", 5, (void**)inptr,
737                                    int_kernel_name, foo);
738     }
739 
740 
741     for ( i = 0; i < 5; i++ ){
742         align_free( (void *)inptr[i] );
743     }
744     free_mtdata(d);
745 
746     return err;
747 
748 }
749 
test_pipe_readwrite_uint(cl_device_id deviceID,cl_context context,cl_command_queue queue,int num_elements)750 int test_pipe_readwrite_uint( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements )
751 {
752     cl_uint     *inptr[5];
753     size_t  ptrSizes[5];
754     int     i, err;
755     cl_uint j;
756     int     (*foo)(void *,void *,int);
757     MTdata  d = init_genrand( gRandomSeed );
758 
759     size_t  min_alignment = get_min_alignment(context);
760 
761     foo = verify_readwrite_uint;
762 
763     ptrSizes[0] = sizeof(cl_uint);
764     ptrSizes[1] = ptrSizes[0] << 1;
765     ptrSizes[2] = ptrSizes[1] << 1;
766     ptrSizes[3] = ptrSizes[2] << 1;
767     ptrSizes[4] = ptrSizes[3] << 1;
768 
769     for ( i = 0; i < 5; i++ ){
770         inptr[i] = (cl_uint *)align_malloc(ptrSizes[i] * num_elements, min_alignment);
771 
772         for ( j = 0; j < ptrSizes[i] * num_elements / ptrSizes[0]; j++ )
773             inptr[i][j] = (cl_uint)genrand_int32(d);
774     }
775 
776     if(useWorkgroupReserve == 1){
777         err = test_pipe_readwrite( deviceID, context, queue, num_elements, sizeof( cl_uint ), (char*)"uint", 5, (void**)inptr,
778                                    workgroup_uint_kernel_name, foo);
779     }
780     else if(useSubgroupReserve == 1){
781         err = test_pipe_readwrite( deviceID, context, queue, num_elements, sizeof( cl_uint ), (char*)"uint", 5, (void**)inptr,
782                                    subgroup_uint_kernel_name, foo);
783     }
784     else if(useConvenienceBuiltIn == 1) {
785         err = test_pipe_readwrite( deviceID, context, queue, num_elements, sizeof( cl_uint ), (char*)"uint", 5, (void**)inptr,
786                                    convenience_uint_kernel_name, foo);
787     }
788     else {
789         err = test_pipe_readwrite( deviceID, context, queue, num_elements, sizeof( cl_uint ), (char*)"uint", 5, (void**)inptr,
790                                    uint_kernel_name, foo);
791     }
792 
793     for ( i = 0; i < 5; i++ ){
794         align_free( (void *)inptr[i] );
795     }
796     free_mtdata(d);
797 
798     return err;
799 
800 }
801 
test_pipe_readwrite_short(cl_device_id deviceID,cl_context context,cl_command_queue queue,int num_elements)802 int test_pipe_readwrite_short( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements )
803 {
804     cl_short     *inptr[5];
805     size_t  ptrSizes[5];
806     int     i, err;
807     cl_uint j;
808     int     (*foo)(void *,void *,int);
809     MTdata  d = init_genrand( gRandomSeed );
810 
811     size_t  min_alignment = get_min_alignment(context);
812 
813     foo = verify_readwrite_short;
814 
815     ptrSizes[0] = sizeof(cl_short);
816     ptrSizes[1] = ptrSizes[0] << 1;
817     ptrSizes[2] = ptrSizes[1] << 1;
818     ptrSizes[3] = ptrSizes[2] << 1;
819     ptrSizes[4] = ptrSizes[3] << 1;
820 
821     for ( i = 0; i < 5; i++ ){
822         inptr[i] = (cl_short *)align_malloc(ptrSizes[i] * num_elements, min_alignment);
823 
824         for ( j = 0; j < ptrSizes[i] * num_elements / ptrSizes[0]; j++ )
825             inptr[i][j] = (cl_short)genrand_int32(d);
826     }
827 
828     if(useWorkgroupReserve == 1){
829         err = test_pipe_readwrite( deviceID, context, queue, num_elements, sizeof( cl_short ), (char*)"short", 5, (void**)inptr,
830                                    workgroup_short_kernel_name, foo);
831     }
832     else if(useSubgroupReserve == 1){
833         err = test_pipe_readwrite( deviceID, context, queue, num_elements, sizeof( cl_short ), (char*)"short", 5, (void**)inptr,
834                                    subgroup_short_kernel_name, foo);
835     }
836     else if(useConvenienceBuiltIn == 1){
837         err = test_pipe_readwrite( deviceID, context, queue, num_elements, sizeof( cl_short ), (char*)"short", 5, (void**)inptr,
838                                    convenience_short_kernel_name, foo);
839     }
840     else{
841         err = test_pipe_readwrite( deviceID, context, queue, num_elements, sizeof( cl_short ), (char*)"short", 5, (void**)inptr,
842                                    short_kernel_name, foo);
843     }
844 
845     for ( i = 0; i < 5; i++ ){
846         align_free( (void *)inptr[i] );
847     }
848     free_mtdata(d);
849 
850     return err;
851 
852 }
853 
test_pipe_readwrite_ushort(cl_device_id deviceID,cl_context context,cl_command_queue queue,int num_elements)854 int test_pipe_readwrite_ushort( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements )
855 {
856     cl_ushort     *inptr[5];
857     size_t  ptrSizes[5];
858     int     i, err;
859     cl_uint j;
860     int     (*foo)(void *,void *,int);
861     MTdata  d = init_genrand( gRandomSeed );
862 
863     size_t  min_alignment = get_min_alignment(context);
864 
865     foo = verify_readwrite_ushort;
866 
867     ptrSizes[0] = sizeof(cl_ushort);
868     ptrSizes[1] = ptrSizes[0] << 1;
869     ptrSizes[2] = ptrSizes[1] << 1;
870     ptrSizes[3] = ptrSizes[2] << 1;
871     ptrSizes[4] = ptrSizes[3] << 1;
872 
873     for ( i = 0; i < 5; i++ ){
874         inptr[i] = (cl_ushort *)align_malloc(ptrSizes[i] * num_elements, min_alignment);
875 
876         for ( j = 0; j < ptrSizes[i] * num_elements / ptrSizes[0]; j++ )
877             inptr[i][j] = (cl_ushort)genrand_int32(d);
878     }
879 
880     if(useWorkgroupReserve == 1){
881         err = test_pipe_readwrite( deviceID, context, queue, num_elements, sizeof( cl_ushort ), (char*)"ushort", 5, (void**)inptr,
882                                    workgroup_ushort_kernel_name, foo);
883     }
884     else if(useSubgroupReserve == 1){
885         err = test_pipe_readwrite( deviceID, context, queue, num_elements, sizeof( cl_ushort ), (char*)"ushort", 5, (void**)inptr,
886                                    subgroup_ushort_kernel_name, foo);
887     }
888     else if(useConvenienceBuiltIn == 1){
889         err = test_pipe_readwrite( deviceID, context, queue, num_elements, sizeof( cl_ushort ), (char*)"ushort", 5, (void**)inptr,
890                                    convenience_ushort_kernel_name, foo);
891     }
892     else{
893         err = test_pipe_readwrite( deviceID, context, queue, num_elements, sizeof( cl_ushort ), (char*)"ushort", 5, (void**)inptr,
894                                    ushort_kernel_name, foo);
895     }
896 
897 
898     for ( i = 0; i < 5; i++ ){
899         align_free( (void *)inptr[i] );
900     }
901     free_mtdata(d);
902 
903     return err;
904 
905 }
906 
test_pipe_readwrite_char(cl_device_id deviceID,cl_context context,cl_command_queue queue,int num_elements)907 int test_pipe_readwrite_char( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements )
908 {
909     cl_char *inptr[5];
910     size_t  ptrSizes[5];
911     int     i, err;
912     cl_uint j;
913     int     (*foo)(void *,void *,int);
914     MTdata  d = init_genrand( gRandomSeed );
915 
916     size_t  min_alignment = get_min_alignment(context);
917 
918     foo = verify_readwrite_char;
919 
920     ptrSizes[0] = sizeof(cl_char);
921     ptrSizes[1] = ptrSizes[0] << 1;
922     ptrSizes[2] = ptrSizes[1] << 1;
923     ptrSizes[3] = ptrSizes[2] << 1;
924     ptrSizes[4] = ptrSizes[3] << 1;
925 
926     for ( i = 0; i < 5; i++ ){
927         inptr[i] = (cl_char *)align_malloc(ptrSizes[i] * num_elements, min_alignment);
928 
929         for ( j = 0; j < ptrSizes[i] * num_elements / ptrSizes[0]; j++ )
930             inptr[i][j] = (char)genrand_int32(d);
931     }
932 
933     if(useWorkgroupReserve == 1){
934         err = test_pipe_readwrite( deviceID, context, queue, num_elements, sizeof( cl_char ), (char*)"char", 5, (void**)inptr,
935                                    workgroup_char_kernel_name, foo);
936     }
937     else if(useSubgroupReserve == 1){
938         err = test_pipe_readwrite( deviceID, context, queue, num_elements, sizeof( cl_char ), (char*)"char", 5, (void**)inptr,
939                                    subgroup_char_kernel_name, foo);
940     }
941     else if(useConvenienceBuiltIn == 1){
942         err = test_pipe_readwrite( deviceID, context, queue, num_elements, sizeof( cl_char ), (char*)"char", 5, (void**)inptr,
943                                    convenience_char_kernel_name, foo);
944     }
945     else{
946         err = test_pipe_readwrite( deviceID, context, queue, num_elements, sizeof( cl_char ), (char*)"char", 5, (void**)inptr,
947                                    char_kernel_name, foo);
948     }
949 
950 
951     for ( i = 0; i < 5; i++ ){
952         align_free( (void *)inptr[i] );
953     }
954     free_mtdata(d);
955 
956     return err;
957 
958 }
959 
test_pipe_readwrite_uchar(cl_device_id deviceID,cl_context context,cl_command_queue queue,int num_elements)960 int test_pipe_readwrite_uchar( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements )
961 {
962     cl_uchar    *inptr[5];
963     size_t        ptrSizes[5];
964     int            i, err;
965     cl_uint        j;
966     int            (*foo)(void *,void *,int);
967     MTdata        d = init_genrand( gRandomSeed );
968 
969     size_t  min_alignment = get_min_alignment(context);
970 
971     foo = verify_readwrite_uchar;
972 
973     ptrSizes[0] = sizeof(cl_uchar);
974     ptrSizes[1] = ptrSizes[0] << 1;
975     ptrSizes[2] = ptrSizes[1] << 1;
976     ptrSizes[3] = ptrSizes[2] << 1;
977     ptrSizes[4] = ptrSizes[3] << 1;
978 
979     for ( i = 0; i < 5; i++ ){
980         inptr[i] = (cl_uchar *)align_malloc(ptrSizes[i] * num_elements, min_alignment);
981 
982         for ( j = 0; j < ptrSizes[i] * num_elements / ptrSizes[0]; j++ )
983             inptr[i][j] = (uchar)genrand_int32(d);
984     }
985 
986     if(useWorkgroupReserve == 1){
987         err = test_pipe_readwrite( deviceID, context, queue, num_elements, sizeof( cl_uchar ), (char*)"uchar", 5, (void**)inptr,
988                                    workgroup_uchar_kernel_name, foo);
989     }
990     else if(useSubgroupReserve == 1){
991         err = test_pipe_readwrite( deviceID, context, queue, num_elements, sizeof( cl_uchar ), (char*)"uchar", 5, (void**)inptr,
992                                    subgroup_uchar_kernel_name, foo);
993     }
994     else if(useConvenienceBuiltIn == 1){
995         err = test_pipe_readwrite( deviceID, context, queue, num_elements, sizeof( cl_uchar ), (char*)"uchar", 5, (void**)inptr,
996                                    convenience_uchar_kernel_name, foo);
997     }
998     else{
999         err = test_pipe_readwrite( deviceID, context, queue, num_elements, sizeof( cl_uchar ), (char*)"uchar", 5, (void**)inptr,
1000                                    uchar_kernel_name, foo);
1001     }
1002     for ( i = 0; i < 5; i++ ){
1003         align_free( (void *)inptr[i] );
1004     }
1005     free_mtdata(d);
1006 
1007     return err;
1008 
1009 }
1010 
test_pipe_readwrite_float(cl_device_id deviceID,cl_context context,cl_command_queue queue,int num_elements)1011 int test_pipe_readwrite_float( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements )
1012 {
1013     float     *inptr[5];
1014     size_t  ptrSizes[5];
1015     int     i, err;
1016     cl_uint j;
1017     int     (*foo)(void *,void *,int);
1018     MTdata  d = init_genrand( gRandomSeed );
1019 
1020     size_t  min_alignment = get_min_alignment(context);
1021 
1022     foo = verify_readwrite_float;
1023 
1024     ptrSizes[0] = sizeof(cl_float);
1025     ptrSizes[1] = ptrSizes[0] << 1;
1026     ptrSizes[2] = ptrSizes[1] << 1;
1027     ptrSizes[3] = ptrSizes[2] << 1;
1028     ptrSizes[4] = ptrSizes[3] << 1;
1029 
1030     for ( i = 0; i < 5; i++ ){
1031         inptr[i] = (float *)align_malloc(ptrSizes[i] * num_elements, min_alignment);
1032 
1033         for ( j = 0; j < ptrSizes[i] * num_elements / ptrSizes[0]; j++ )
1034             inptr[i][j] = get_random_float( -32, 32, d );
1035     }
1036 
1037     if(useWorkgroupReserve == 1){
1038         err = test_pipe_readwrite( deviceID, context, queue, num_elements, sizeof( cl_float ), (char*)"float", 5, (void**)inptr,
1039                                    workgroup_float_kernel_name, foo);
1040     }
1041     else if(useSubgroupReserve == 1){
1042         err = test_pipe_readwrite( deviceID, context, queue, num_elements, sizeof( cl_float ), (char*)"float", 5, (void**)inptr,
1043                                    subgroup_float_kernel_name, foo);
1044     }
1045     else if(useConvenienceBuiltIn == 1){
1046         err = test_pipe_readwrite( deviceID, context, queue, num_elements, sizeof( cl_float ), (char*)"float", 5, (void**)inptr,
1047                                    convenience_float_kernel_name, foo);
1048     }
1049     else{
1050         err = test_pipe_readwrite( deviceID, context, queue, num_elements, sizeof( cl_float ), (char*)"float", 5, (void**)inptr,
1051                                    float_kernel_name, foo);
1052     }
1053 
1054     for ( i = 0; i < 5; i++ ){
1055         align_free( (void *)inptr[i] );
1056     }
1057     free_mtdata(d);
1058 
1059     return err;
1060 
1061 }
1062 
test_pipe_readwrite_half(cl_device_id deviceID,cl_context context,cl_command_queue queue,int num_elements)1063 int test_pipe_readwrite_half( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements )
1064 {
1065     float   *inptr[5];
1066     size_t  ptrSizes[5];
1067     int     i, err;
1068     cl_uint j;
1069     int     (*foo)(void *,void *,int);
1070     MTdata  d = init_genrand( gRandomSeed );
1071 
1072     size_t  min_alignment = get_min_alignment(context);
1073 
1074     foo = verify_readwrite_half;
1075 
1076     if(!is_extension_available(deviceID, "cl_khr_fp16"))
1077     {
1078         log_info(
1079             "cl_khr_fp16 is not supported on this platform. Skipping test.\n");
1080         return CL_SUCCESS;
1081     }
1082     ptrSizes[0] = sizeof(cl_float) / 2;
1083     ptrSizes[1] = ptrSizes[0] << 1;
1084     ptrSizes[2] = ptrSizes[1] << 1;
1085     ptrSizes[3] = ptrSizes[2] << 1;
1086     ptrSizes[4] = ptrSizes[3] << 1;
1087 
1088     for ( i = 0; i < 5; i++ ){
1089         inptr[i] = (float *)align_malloc(ptrSizes[i] * num_elements, min_alignment);
1090 
1091         for ( j = 0; j < ptrSizes[i] * num_elements / (ptrSizes[0] * 2); j++ )
1092             inptr[i][j] = get_random_float( -32, 32, d );
1093     }
1094 
1095     if(useWorkgroupReserve == 1){
1096         err = test_pipe_readwrite( deviceID, context, queue, num_elements, sizeof( cl_half ), (char*)"half", 5, (void**)inptr,
1097                                     workgroup_half_kernel_name, foo);
1098     }
1099     else if(useSubgroupReserve == 1){
1100         err = test_pipe_readwrite( deviceID, context, queue, num_elements, sizeof( cl_half ), (char*)"half", 5, (void**)inptr,
1101                                     subgroup_half_kernel_name, foo);
1102     }
1103     else if(useConvenienceBuiltIn == 1){
1104         err = test_pipe_readwrite( deviceID, context, queue, num_elements, sizeof( cl_half ), (char*)"half", 5, (void**)inptr,
1105                                     convenience_half_kernel_name, foo);
1106     }
1107     else{
1108         err = test_pipe_readwrite( deviceID, context, queue, num_elements, sizeof( cl_half ), (char*)"half", 5, (void**)inptr,
1109                                     half_kernel_name, foo);
1110     }
1111 
1112     for ( i = 0; i < 5; i++ ){
1113         align_free( (void *)inptr[i] );
1114     }
1115     free_mtdata(d);
1116 
1117     return err;
1118 }
1119 
test_pipe_readwrite_long(cl_device_id deviceID,cl_context context,cl_command_queue queue,int num_elements)1120 int test_pipe_readwrite_long( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements )
1121 {
1122     cl_long *inptr[5];
1123     size_t  ptrSizes[5];
1124     int     i, err;
1125     cl_uint j;
1126     int     (*foo)(void *,void *,int);
1127     MTdata  d = init_genrand( gRandomSeed );
1128 
1129     size_t  min_alignment = get_min_alignment(context);
1130 
1131     foo = verify_readwrite_long;
1132 
1133     ptrSizes[0] = sizeof(cl_long);
1134     ptrSizes[1] = ptrSizes[0] << 1;
1135     ptrSizes[2] = ptrSizes[1] << 1;
1136     ptrSizes[3] = ptrSizes[2] << 1;
1137     ptrSizes[4] = ptrSizes[3] << 1;
1138 
1139     //skip devices that don't support long
1140     if (! gHasLong )
1141     {
1142         log_info( "Device does not support 64-bit integers. Skipping test.\n" );
1143         return CL_SUCCESS;
1144     }
1145 
1146     for ( i = 0; i < 5; i++ ){
1147         inptr[i] = (cl_long *)align_malloc(ptrSizes[i] * num_elements, min_alignment);
1148 
1149         for ( j = 0; j < ptrSizes[i] * num_elements / ptrSizes[0]; j++ )
1150             inptr[i][j] = (cl_long) genrand_int32(d) ^ ((cl_long) genrand_int32(d) << 32);
1151     }
1152 
1153     if(useWorkgroupReserve == 1){
1154         err = test_pipe_readwrite( deviceID, context, queue, num_elements, sizeof( cl_long ), (char*)"long", 5, (void**)inptr,
1155                                    workgroup_long_kernel_name, foo);
1156     }
1157     else if(useSubgroupReserve == 1){
1158         err = test_pipe_readwrite( deviceID, context, queue, num_elements, sizeof( cl_long ), (char*)"long", 5, (void**)inptr,
1159                                    subgroup_long_kernel_name, foo);
1160     }
1161     else if(useConvenienceBuiltIn == 1){
1162         err = test_pipe_readwrite( deviceID, context, queue, num_elements, sizeof( cl_long ), (char*)"long", 5, (void**)inptr,
1163                                    convenience_long_kernel_name, foo);
1164     }
1165     else{
1166         err = test_pipe_readwrite( deviceID, context, queue, num_elements, sizeof( cl_long ), (char*)"long", 5, (void**)inptr,
1167                                    long_kernel_name, foo);
1168     }
1169 
1170     for ( i = 0; i < 5; i++ ){
1171         align_free( (void *)inptr[i] );
1172     }
1173     free_mtdata(d);
1174 
1175     return err;
1176 
1177 }
1178 
test_pipe_readwrite_ulong(cl_device_id deviceID,cl_context context,cl_command_queue queue,int num_elements)1179 int test_pipe_readwrite_ulong( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements )
1180 {
1181     cl_ulong *inptr[5];
1182     size_t  ptrSizes[5];
1183     int     i, err;
1184     cl_uint j;
1185     int     (*foo)(void *,void *,int);
1186     MTdata  d = init_genrand( gRandomSeed );
1187 
1188     size_t  min_alignment = get_min_alignment(context);
1189 
1190     foo = verify_readwrite_ulong;
1191 
1192     ptrSizes[0] = sizeof(cl_ulong);
1193     ptrSizes[1] = ptrSizes[0] << 1;
1194     ptrSizes[2] = ptrSizes[1] << 1;
1195     ptrSizes[3] = ptrSizes[2] << 1;
1196     ptrSizes[4] = ptrSizes[3] << 1;
1197 
1198     //skip devices that don't support long
1199     if (! gHasLong )
1200     {
1201         log_info( "Device does not support 64-bit integers. Skipping test.\n" );
1202         return CL_SUCCESS;
1203     }
1204 
1205     for ( i = 0; i < 5; i++ ){
1206         inptr[i] = (cl_ulong *)align_malloc(ptrSizes[i] * num_elements, min_alignment);
1207 
1208         for ( j = 0; j < ptrSizes[i] * num_elements / ptrSizes[0]; j++ )
1209             inptr[i][j] = (cl_ulong) genrand_int32(d) | ((cl_ulong) genrand_int32(d) << 32);
1210     }
1211 
1212     if(useWorkgroupReserve == 1){
1213         err = test_pipe_readwrite( deviceID, context, queue, num_elements, sizeof( cl_ulong ), (char*)"ulong", 5, (void**)inptr,
1214                                    workgroup_ulong_kernel_name, foo);
1215     }
1216     else if(useSubgroupReserve == 1){
1217         err = test_pipe_readwrite( deviceID, context, queue, num_elements, sizeof( cl_ulong ), (char*)"ulong", 5, (void**)inptr,
1218                                    subgroup_ulong_kernel_name, foo);
1219     }
1220     else if(useConvenienceBuiltIn == 1){
1221         err = test_pipe_readwrite( deviceID, context, queue, num_elements, sizeof( cl_ulong ), (char*)"ulong", 5, (void**)inptr,
1222                                    convenience_ulong_kernel_name, foo);
1223     }
1224     else{
1225         err = test_pipe_readwrite( deviceID, context, queue, num_elements, sizeof( cl_ulong ), (char*)"ulong", 5, (void**)inptr,
1226                                    ulong_kernel_name, foo);
1227     }
1228 
1229     for ( i = 0; i < 5; i++ ){
1230         align_free( (void *)inptr[i] );
1231     }
1232     free_mtdata(d);
1233 
1234     return err;
1235 
1236 }
1237 
test_pipe_readwrite_double(cl_device_id deviceID,cl_context context,cl_command_queue queue,int num_elements)1238 int test_pipe_readwrite_double( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements )
1239 {
1240     cl_double *inptr[5];
1241     size_t  ptrSizes[5];
1242     int     i, err;
1243     cl_uint j;
1244     int     (*foo)(void *,void *,int);
1245     MTdata  d = init_genrand( gRandomSeed );
1246 
1247     size_t  min_alignment = get_min_alignment(context);
1248 
1249     foo = verify_readwrite_double;
1250 
1251     ptrSizes[0] = sizeof(cl_double);
1252     ptrSizes[1] = ptrSizes[0] << 1;
1253     ptrSizes[2] = ptrSizes[1] << 1;
1254     ptrSizes[3] = ptrSizes[2] << 1;
1255     ptrSizes[4] = ptrSizes[3] << 1;
1256 
1257     //skip devices that don't support double
1258     if(!is_extension_available(deviceID, "cl_khr_fp64"))
1259     {
1260         log_info(
1261             "cl_khr_fp64 is not supported on this platform. Skipping test.\n");
1262         return CL_SUCCESS;
1263     }
1264 
1265     for ( i = 0; i < 5; i++ ){
1266         inptr[i] = (cl_double *)align_malloc(ptrSizes[i] * num_elements, min_alignment);
1267 
1268         for ( j = 0; j < ptrSizes[i] * num_elements / ptrSizes[0]; j++ )
1269             inptr[i][j] = get_random_double( -32, 32, d );
1270     }
1271 
1272     if(useWorkgroupReserve == 1){
1273         err = test_pipe_readwrite( deviceID, context, queue, num_elements, sizeof( cl_double ), (char*)"double", 5, (void**)inptr,
1274                                    workgroup_double_kernel_name, foo);
1275     }
1276     else if(useSubgroupReserve == 1){
1277         err = test_pipe_readwrite( deviceID, context, queue, num_elements, sizeof( cl_double ), (char*)"double", 5, (void**)inptr,
1278                                    subgroup_double_kernel_name, foo);
1279     }
1280     else if(useConvenienceBuiltIn == 1){
1281         err = test_pipe_readwrite( deviceID, context, queue, num_elements, sizeof( cl_double ), (char*)"double", 5, (void**)inptr,
1282                                    convenience_double_kernel_name, foo);
1283     }
1284     else{
1285         err = test_pipe_readwrite( deviceID, context, queue, num_elements, sizeof( cl_double ), (char*)"double", 5, (void**)inptr,
1286                                    double_kernel_name, foo);
1287     }
1288 
1289     for ( i = 0; i < 5; i++ ){
1290         align_free( (void *)inptr[i] );
1291     }
1292     free_mtdata(d);
1293 
1294     return err;
1295 
1296 }
1297 
test_pipe_readwrite_struct(cl_device_id deviceID,cl_context context,cl_command_queue queue,int num_elements)1298 int test_pipe_readwrite_struct( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements )
1299 {
1300     const char *kernelNames[] = {"test_pipe_write_struct","test_pipe_read_struct"};
1301     return test_pipe_readwrite_struct_generic(deviceID, context, queue, num_elements, pipe_readwrite_struct_kernel_code, kernelNames);
1302 }
1303 
1304 // Work-group functions for pipe reserve/commits
test_pipe_workgroup_readwrite_int(cl_device_id deviceID,cl_context context,cl_command_queue queue,int num_elements)1305 int test_pipe_workgroup_readwrite_int( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements )
1306 {
1307     useWorkgroupReserve = 1;
1308     useSubgroupReserve = 0;
1309     useConvenienceBuiltIn = 0;
1310     return test_pipe_readwrite_int(deviceID, context, queue, num_elements);
1311 }
1312 
test_pipe_workgroup_readwrite_uint(cl_device_id deviceID,cl_context context,cl_command_queue queue,int num_elements)1313 int test_pipe_workgroup_readwrite_uint( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements )
1314 {
1315     useWorkgroupReserve = 1;
1316     useSubgroupReserve = 0;
1317     useConvenienceBuiltIn = 0;
1318     return test_pipe_readwrite_uint(deviceID, context, queue, num_elements);
1319 }
1320 
test_pipe_workgroup_readwrite_short(cl_device_id deviceID,cl_context context,cl_command_queue queue,int num_elements)1321 int test_pipe_workgroup_readwrite_short( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements )
1322 {
1323     useWorkgroupReserve = 1;
1324     useSubgroupReserve = 0;
1325     useConvenienceBuiltIn = 0;
1326     return test_pipe_readwrite_short(deviceID, context, queue, num_elements);
1327 }
1328 
test_pipe_workgroup_readwrite_ushort(cl_device_id deviceID,cl_context context,cl_command_queue queue,int num_elements)1329 int test_pipe_workgroup_readwrite_ushort( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements )
1330 {
1331     useWorkgroupReserve = 1;
1332     useSubgroupReserve = 0;
1333     useConvenienceBuiltIn = 0;
1334     return test_pipe_readwrite_ushort(deviceID, context, queue, num_elements);
1335 }
1336 
test_pipe_workgroup_readwrite_char(cl_device_id deviceID,cl_context context,cl_command_queue queue,int num_elements)1337 int test_pipe_workgroup_readwrite_char( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements )
1338 {
1339     useWorkgroupReserve = 1;
1340     useSubgroupReserve = 0;
1341     useConvenienceBuiltIn = 0;
1342     return test_pipe_readwrite_char(deviceID, context, queue, num_elements);
1343 }
1344 
test_pipe_workgroup_readwrite_uchar(cl_device_id deviceID,cl_context context,cl_command_queue queue,int num_elements)1345 int test_pipe_workgroup_readwrite_uchar( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements )
1346 {
1347     useWorkgroupReserve = 1;
1348     useSubgroupReserve = 0;
1349     useConvenienceBuiltIn = 0;
1350     return test_pipe_readwrite_uchar(deviceID, context, queue, num_elements);
1351 }
1352 
test_pipe_workgroup_readwrite_float(cl_device_id deviceID,cl_context context,cl_command_queue queue,int num_elements)1353 int test_pipe_workgroup_readwrite_float( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements )
1354 {
1355     useWorkgroupReserve = 1;
1356     useSubgroupReserve = 0;
1357     useConvenienceBuiltIn = 0;
1358     return test_pipe_readwrite_float(deviceID, context, queue, num_elements);
1359 }
1360 
test_pipe_workgroup_readwrite_half(cl_device_id deviceID,cl_context context,cl_command_queue queue,int num_elements)1361 int test_pipe_workgroup_readwrite_half( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements )
1362 {
1363     useWorkgroupReserve = 1;
1364     useSubgroupReserve = 0;
1365     useConvenienceBuiltIn = 0;
1366     return test_pipe_readwrite_half(deviceID, context, queue, num_elements);
1367 }
1368 
test_pipe_workgroup_readwrite_long(cl_device_id deviceID,cl_context context,cl_command_queue queue,int num_elements)1369 int test_pipe_workgroup_readwrite_long( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements )
1370 {
1371     useWorkgroupReserve = 1;
1372     useSubgroupReserve = 0;
1373     useConvenienceBuiltIn = 0;
1374     return test_pipe_readwrite_long(deviceID, context, queue, num_elements);
1375 }
1376 
test_pipe_workgroup_readwrite_ulong(cl_device_id deviceID,cl_context context,cl_command_queue queue,int num_elements)1377 int test_pipe_workgroup_readwrite_ulong( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements )
1378 {
1379     useWorkgroupReserve = 1;
1380     useSubgroupReserve = 0;
1381     useConvenienceBuiltIn = 0;
1382     return test_pipe_readwrite_ulong(deviceID, context, queue, num_elements);
1383 }
1384 
test_pipe_workgroup_readwrite_double(cl_device_id deviceID,cl_context context,cl_command_queue queue,int num_elements)1385 int test_pipe_workgroup_readwrite_double( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements )
1386 {
1387     useWorkgroupReserve = 1;
1388     useSubgroupReserve = 0;
1389     useConvenienceBuiltIn = 0;
1390     return test_pipe_readwrite_double(deviceID, context, queue, num_elements);
1391 }
1392 
test_pipe_workgroup_readwrite_struct(cl_device_id deviceID,cl_context context,cl_command_queue queue,int num_elements)1393 int test_pipe_workgroup_readwrite_struct( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements )
1394 {
1395     const char *kernelNames[] = {"test_pipe_workgroup_write_struct","test_pipe_workgroup_read_struct"};
1396     return test_pipe_readwrite_struct_generic(deviceID, context, queue, num_elements, pipe_workgroup_readwrite_struct_kernel_code, kernelNames);
1397 }
1398 
1399 // Sub-group functions for pipe reserve/commits
test_pipe_subgroup_readwrite_int(cl_device_id deviceID,cl_context context,cl_command_queue queue,int num_elements)1400 int test_pipe_subgroup_readwrite_int( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements )
1401 {
1402     useSubgroupReserve = 1;
1403     useWorkgroupReserve = 0;
1404     useConvenienceBuiltIn = 0;
1405 
1406     if(!is_extension_available(deviceID, "cl_khr_subgroups"))
1407     {
1408         log_info("cl_khr_subgroups is not supported on this platform. Skipping "
1409                  "test.\n");
1410         return CL_SUCCESS;
1411     }
1412     return test_pipe_readwrite_int(deviceID, context, queue, num_elements);
1413 }
1414 
test_pipe_subgroup_readwrite_uint(cl_device_id deviceID,cl_context context,cl_command_queue queue,int num_elements)1415 int test_pipe_subgroup_readwrite_uint( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements )
1416 {
1417     useSubgroupReserve = 1;
1418     useWorkgroupReserve = 0;
1419     useConvenienceBuiltIn = 0;
1420 
1421     if(!is_extension_available(deviceID, "cl_khr_subgroups"))
1422     {
1423         log_info("cl_khr_subgroups is not supported on this platform. Skipping "
1424                  "test.\n");
1425         return CL_SUCCESS;
1426     }
1427     return test_pipe_readwrite_uint(deviceID, context, queue, num_elements);
1428 }
1429 
test_pipe_subgroup_readwrite_short(cl_device_id deviceID,cl_context context,cl_command_queue queue,int num_elements)1430 int test_pipe_subgroup_readwrite_short( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements )
1431 {
1432     useSubgroupReserve = 1;
1433     useWorkgroupReserve = 0;
1434     useConvenienceBuiltIn = 0;
1435 
1436     if(!is_extension_available(deviceID, "cl_khr_subgroups"))
1437     {
1438         log_info("cl_khr_subgroups is not supported on this platform. Skipping "
1439                  "test.\n");
1440         return CL_SUCCESS;
1441     }
1442     return test_pipe_readwrite_short(deviceID, context, queue, num_elements);
1443 }
1444 
test_pipe_subgroup_readwrite_ushort(cl_device_id deviceID,cl_context context,cl_command_queue queue,int num_elements)1445 int test_pipe_subgroup_readwrite_ushort( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements )
1446 {
1447     useSubgroupReserve = 1;
1448     useWorkgroupReserve = 0;
1449     useConvenienceBuiltIn = 0;
1450 
1451     if(!is_extension_available(deviceID, "cl_khr_subgroups"))
1452     {
1453         log_info("cl_khr_subgroups is not supported on this platform. Skipping "
1454                  "test.\n");
1455         return CL_SUCCESS;
1456     }
1457     return test_pipe_readwrite_ushort(deviceID, context, queue, num_elements);
1458 }
1459 
test_pipe_subgroup_readwrite_char(cl_device_id deviceID,cl_context context,cl_command_queue queue,int num_elements)1460 int test_pipe_subgroup_readwrite_char( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements )
1461 {
1462     useSubgroupReserve = 1;
1463     useWorkgroupReserve = 0;
1464     useConvenienceBuiltIn = 0;
1465 
1466     if(!is_extension_available(deviceID, "cl_khr_subgroups"))
1467     {
1468         log_info("cl_khr_subgroups is not supported on this platform. Skipping "
1469                  "test.\n");
1470         return CL_SUCCESS;
1471     }
1472     return test_pipe_readwrite_char(deviceID, context, queue, num_elements);
1473 }
1474 
test_pipe_subgroup_readwrite_uchar(cl_device_id deviceID,cl_context context,cl_command_queue queue,int num_elements)1475 int test_pipe_subgroup_readwrite_uchar( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements )
1476 {
1477     useSubgroupReserve = 1;
1478     useWorkgroupReserve = 0;
1479     useConvenienceBuiltIn = 0;
1480 
1481     if(!is_extension_available(deviceID, "cl_khr_subgroups"))
1482     {
1483         log_info("cl_khr_subgroups is not supported on this platform. Skipping "
1484                  "test.\n");
1485         return CL_SUCCESS;
1486     }
1487     return test_pipe_readwrite_uchar(deviceID, context, queue, num_elements);
1488 
1489 }
1490 
test_pipe_subgroup_readwrite_float(cl_device_id deviceID,cl_context context,cl_command_queue queue,int num_elements)1491 int test_pipe_subgroup_readwrite_float( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements )
1492 {
1493     useSubgroupReserve = 1;
1494     useWorkgroupReserve = 0;
1495     useConvenienceBuiltIn = 0;
1496 
1497     if(!is_extension_available(deviceID, "cl_khr_subgroups"))
1498     {
1499         log_info("cl_khr_subgroups is not supported on this platform. Skipping "
1500                  "test.\n");
1501         return CL_SUCCESS;
1502     }
1503     return test_pipe_readwrite_float(deviceID, context, queue, num_elements);
1504 }
1505 
test_pipe_subgroup_readwrite_half(cl_device_id deviceID,cl_context context,cl_command_queue queue,int num_elements)1506 int test_pipe_subgroup_readwrite_half( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements )
1507 {
1508     useSubgroupReserve = 1;
1509     useWorkgroupReserve = 0;
1510     useConvenienceBuiltIn = 0;
1511 
1512     if(!is_extension_available(deviceID, "cl_khr_subgroups"))
1513     {
1514         log_info("cl_khr_subgroups is not supported on this platform. Skipping "
1515                  "test.\n");
1516         return CL_SUCCESS;
1517     }
1518     return test_pipe_readwrite_half(deviceID, context, queue, num_elements);
1519 }
1520 
test_pipe_subgroup_readwrite_long(cl_device_id deviceID,cl_context context,cl_command_queue queue,int num_elements)1521 int test_pipe_subgroup_readwrite_long( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements )
1522 {
1523     useSubgroupReserve = 1;
1524     useWorkgroupReserve = 0;
1525     useConvenienceBuiltIn = 0;
1526 
1527     if(!is_extension_available(deviceID, "cl_khr_subgroups"))
1528     {
1529         log_info("cl_khr_subgroups is not supported on this platform. Skipping "
1530                  "test.\n");
1531         return CL_SUCCESS;
1532     }
1533     return test_pipe_readwrite_long(deviceID, context, queue, num_elements);
1534 }
1535 
test_pipe_subgroup_readwrite_ulong(cl_device_id deviceID,cl_context context,cl_command_queue queue,int num_elements)1536 int test_pipe_subgroup_readwrite_ulong( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements )
1537 {
1538     useSubgroupReserve = 1;
1539     useWorkgroupReserve = 0;
1540     useConvenienceBuiltIn = 0;
1541 
1542     if(!is_extension_available(deviceID, "cl_khr_subgroups"))
1543     {
1544         log_info("cl_khr_subgroups is not supported on this platform. Skipping "
1545                  "test.\n");
1546         return CL_SUCCESS;
1547     }
1548     return test_pipe_readwrite_ulong(deviceID, context, queue, num_elements);
1549 }
1550 
test_pipe_subgroup_readwrite_double(cl_device_id deviceID,cl_context context,cl_command_queue queue,int num_elements)1551 int test_pipe_subgroup_readwrite_double( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements )
1552 {
1553     useSubgroupReserve = 1;
1554     useWorkgroupReserve = 0;
1555     useConvenienceBuiltIn = 0;
1556 
1557     if(!is_extension_available(deviceID, "cl_khr_subgroups"))
1558     {
1559         log_info("cl_khr_subgroups is not supported on this platform. Skipping "
1560                  "test.\n");
1561         return CL_SUCCESS;
1562     }
1563     return test_pipe_readwrite_double(deviceID, context, queue, num_elements);
1564 }
1565 
test_pipe_subgroup_readwrite_struct(cl_device_id deviceID,cl_context context,cl_command_queue queue,int num_elements)1566 int test_pipe_subgroup_readwrite_struct( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements )
1567 {
1568     if(!is_extension_available(deviceID, "cl_khr_subgroups"))
1569     {
1570         log_info("cl_khr_subgroups is not supported on this platform. Skipping "
1571                  "test.\n");
1572         return CL_SUCCESS;
1573     }
1574     const char *kernelNames[] = {"test_pipe_subgroup_write_struct","test_pipe_subgroup_read_struct"};
1575     return test_pipe_readwrite_struct_generic(deviceID, context, queue, num_elements, pipe_subgroup_readwrite_struct_kernel_code, kernelNames);
1576 }
1577 
1578 // Convenience functions for pipe reserve/commits
test_pipe_convenience_readwrite_int(cl_device_id deviceID,cl_context context,cl_command_queue queue,int num_elements)1579 int test_pipe_convenience_readwrite_int( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements )
1580 {
1581     useConvenienceBuiltIn = 1;
1582     useSubgroupReserve = 0;
1583     useWorkgroupReserve = 0;
1584 
1585     return test_pipe_readwrite_int(deviceID, context, queue, num_elements);
1586 }
1587 
test_pipe_convenience_readwrite_uint(cl_device_id deviceID,cl_context context,cl_command_queue queue,int num_elements)1588 int test_pipe_convenience_readwrite_uint( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements )
1589 {
1590     useConvenienceBuiltIn = 1;
1591     useSubgroupReserve = 0;
1592     useWorkgroupReserve = 0;
1593 
1594     return test_pipe_readwrite_uint(deviceID, context, queue, num_elements);
1595 }
1596 
test_pipe_convenience_readwrite_short(cl_device_id deviceID,cl_context context,cl_command_queue queue,int num_elements)1597 int test_pipe_convenience_readwrite_short( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements )
1598 {
1599     useConvenienceBuiltIn = 1;
1600     useSubgroupReserve = 0;
1601     useWorkgroupReserve = 0;
1602 
1603     return test_pipe_readwrite_short(deviceID, context, queue, num_elements);
1604 }
1605 
test_pipe_convenience_readwrite_ushort(cl_device_id deviceID,cl_context context,cl_command_queue queue,int num_elements)1606 int test_pipe_convenience_readwrite_ushort( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements )
1607 {
1608     useConvenienceBuiltIn = 1;
1609     useSubgroupReserve = 0;
1610     useWorkgroupReserve = 0;
1611 
1612     return test_pipe_readwrite_ushort(deviceID, context, queue, num_elements);
1613 }
1614 
test_pipe_convenience_readwrite_char(cl_device_id deviceID,cl_context context,cl_command_queue queue,int num_elements)1615 int test_pipe_convenience_readwrite_char( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements )
1616 {
1617     useConvenienceBuiltIn = 1;
1618     useSubgroupReserve = 0;
1619     useWorkgroupReserve = 0;
1620 
1621     return test_pipe_readwrite_char(deviceID, context, queue, num_elements);
1622 }
1623 
test_pipe_convenience_readwrite_uchar(cl_device_id deviceID,cl_context context,cl_command_queue queue,int num_elements)1624 int test_pipe_convenience_readwrite_uchar( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements )
1625 {
1626     useConvenienceBuiltIn = 1;
1627     useSubgroupReserve = 0;
1628     useWorkgroupReserve = 0;
1629 
1630     return test_pipe_readwrite_uchar(deviceID, context, queue, num_elements);
1631 }
1632 
1633 
test_pipe_convenience_readwrite_float(cl_device_id deviceID,cl_context context,cl_command_queue queue,int num_elements)1634 int test_pipe_convenience_readwrite_float( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements )
1635 {
1636     useConvenienceBuiltIn = 1;
1637     useSubgroupReserve = 0;
1638     useWorkgroupReserve = 0;
1639 
1640     return test_pipe_readwrite_float(deviceID, context, queue, num_elements);
1641 }
1642 
test_pipe_convenience_readwrite_half(cl_device_id deviceID,cl_context context,cl_command_queue queue,int num_elements)1643 int test_pipe_convenience_readwrite_half( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements )
1644 {
1645     useConvenienceBuiltIn = 1;
1646     useSubgroupReserve = 0;
1647     useWorkgroupReserve = 0;
1648 
1649     return test_pipe_readwrite_half(deviceID, context, queue, num_elements);
1650 }
1651 
test_pipe_convenience_readwrite_long(cl_device_id deviceID,cl_context context,cl_command_queue queue,int num_elements)1652 int test_pipe_convenience_readwrite_long( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements )
1653 {
1654     useConvenienceBuiltIn = 1;
1655     useSubgroupReserve = 0;
1656     useWorkgroupReserve = 0;
1657 
1658     return test_pipe_readwrite_long(deviceID, context, queue, num_elements);
1659 }
1660 
test_pipe_convenience_readwrite_ulong(cl_device_id deviceID,cl_context context,cl_command_queue queue,int num_elements)1661 int test_pipe_convenience_readwrite_ulong( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements )
1662 {
1663     useConvenienceBuiltIn = 1;
1664     useSubgroupReserve = 0;
1665     useWorkgroupReserve = 0;
1666 
1667     return test_pipe_readwrite_ulong(deviceID, context, queue, num_elements);
1668 }
1669 
test_pipe_convenience_readwrite_double(cl_device_id deviceID,cl_context context,cl_command_queue queue,int num_elements)1670 int test_pipe_convenience_readwrite_double( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements )
1671 {
1672     useConvenienceBuiltIn = 1;
1673     useSubgroupReserve = 0;
1674     useWorkgroupReserve = 0;
1675 
1676     return test_pipe_readwrite_double(deviceID, context, queue, num_elements);
1677 }
1678 
test_pipe_convenience_readwrite_struct(cl_device_id deviceID,cl_context context,cl_command_queue queue,int num_elements)1679 int test_pipe_convenience_readwrite_struct( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements )
1680 {
1681     const char *kernelNames[] = {"test_pipe_convenience_write_struct","test_pipe_convenience_read_struct"};
1682     return test_pipe_readwrite_struct_generic(deviceID, context, queue, num_elements, pipe_convenience_readwrite_struct_kernel_code, kernelNames);
1683 }
1684