• 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     long long int    sum_input = 0, sum_output = 0;
418     long long int    *inptr = (long long int *)ptr1;
419     long long int    *outptr = (long long int *)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 total_errors = 0;
630     int i;
631     MTdataHolder d(gRandomSeed);
632     clEventWrapper producer_sync_event = NULL;
633     clEventWrapper consumer_sync_event = NULL;
634 
635     size_t min_alignment = get_min_alignment(context);
636 
637     global_work_size[0] = (size_t)num_elements;
638 
639     inptr = (TestStruct *)align_malloc(size * num_elements, min_alignment);
640 
641     for (i = 0; i < num_elements; i++)
642     {
643         inptr[i].a = (char)genrand_int32(d);
644         inptr[i].b = genrand_int32(d);
645     }
646     BufferInPtr.reset(inptr, nullptr, 0, size, true);
647 
648     buffers[0] = clCreateBuffer(context, CL_MEM_COPY_HOST_PTR, size * num_elements, inptr, &err);
649     test_error_ret(err, " clCreateBuffer failed", -1);
650 
651     outptr = align_malloc( size * num_elements, min_alignment);
652     BufferOutPtr.reset(outptr, nullptr, 0, size, true);
653 
654     buffers[1] = clCreateBuffer(context, CL_MEM_USE_HOST_PTR,  size * num_elements, outptr, &err);
655     test_error_ret(err, " clCreateBuffer failed", -1);
656 
657     pipe = clCreatePipe(context, CL_MEM_HOST_NO_ACCESS, size, num_elements, NULL, &err);
658     test_error_ret(err, " clCreatePipe failed", -1);
659 
660     // Create producer kernel
661     err = create_single_kernel_helper(context, &program, &kernel[0], 1,
662                                       &kernelCode, kernelName[0]);
663     test_error_ret(err, " Error creating program", -1);
664 
665     //Create consumer kernel
666     kernel[1] = clCreateKernel(program, kernelName[1], &err);
667     test_error_ret(err, " Error creating kernel", -1);
668 
669     err = clSetKernelArg(kernel[0], 0, sizeof(cl_mem), (void*)&buffers[0]);
670     err |= clSetKernelArg(kernel[0], 1, sizeof(cl_mem), (void*)&pipe);
671     err |= clSetKernelArg(kernel[1], 0, sizeof(cl_mem), (void*)&pipe);
672     err |= clSetKernelArg(kernel[1], 1, sizeof(cl_mem), (void*)&buffers[1]);
673     test_error_ret(err, " clSetKernelArg failed", -1);
674 
675     // Launch Producer kernel
676     err = clEnqueueNDRangeKernel( queue, kernel[0], 1, NULL, global_work_size, NULL, 0, NULL, &producer_sync_event );
677     test_error_ret(err, " clEnqueueNDRangeKernel failed", -1);
678 
679     // Launch Consumer kernel
680     err = clEnqueueNDRangeKernel( queue, kernel[1], 1, NULL, global_work_size, NULL, 1, &producer_sync_event, &consumer_sync_event );
681     test_error_ret(err, " clEnqueueNDRangeKernel failed", -1);
682 
683     err = clEnqueueReadBuffer(queue, buffers[1], true, 0, size*num_elements, outptr, 1, &consumer_sync_event, NULL);
684     test_error_ret(err, " clEnqueueReadBuffer failed", -1);
685 
686     if( verify_readwrite_struct( inptr, outptr, num_elements)){
687         log_error("struct_readwrite test failed\n");
688         return -1;
689     }
690     else {
691         log_info("struct_readwrite test passed\n");
692     }
693 
694     return 0;
695 }
696 
697 
test_pipe_readwrite_int(cl_device_id deviceID,cl_context context,cl_command_queue queue,int num_elements)698 int test_pipe_readwrite_int( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements )
699 {
700     cl_int  *inptr[5];
701     size_t  ptrSizes[5];
702     int     i, err;
703     cl_uint j;
704     int     (*foo)(void *,void *,int);
705     MTdata  d = init_genrand( gRandomSeed );
706 
707     size_t  min_alignment = get_min_alignment(context);
708 
709     foo = verify_readwrite_int;
710 
711     ptrSizes[0] = sizeof(cl_int);
712     ptrSizes[1] = ptrSizes[0] << 1;
713     ptrSizes[2] = ptrSizes[1] << 1;
714     ptrSizes[3] = ptrSizes[2] << 1;
715     ptrSizes[4] = ptrSizes[3] << 1;
716 
717     for ( i = 0; i < 5; i++ ){
718         inptr[i] = (cl_int *)align_malloc(ptrSizes[i] * num_elements, min_alignment);
719 
720         for ( j = 0; j < ptrSizes[i] * num_elements / ptrSizes[0]; j++ )
721             inptr[i][j] = (int)genrand_int32(d);
722     }
723 
724     if(useWorkgroupReserve == 1){
725         err = test_pipe_readwrite( deviceID, context, queue, num_elements, sizeof( cl_int ), (char*)"int", 5, (void**)inptr,
726                                    workgroup_int_kernel_name, foo);
727     }
728     else if(useSubgroupReserve == 1){
729         err = test_pipe_readwrite( deviceID, context, queue, num_elements, sizeof( cl_int ), (char*)"int", 5, (void**)inptr,
730                                    subgroup_int_kernel_name, foo);
731     }
732     else if(useConvenienceBuiltIn == 1) {
733         err = test_pipe_readwrite( deviceID, context, queue, num_elements, sizeof( cl_int ), (char*)"int", 5, (void**)inptr,
734                                    convenience_int_kernel_name, foo);
735     }
736     else {
737         err = test_pipe_readwrite( deviceID, context, queue, num_elements, sizeof( cl_int ), (char*)"int", 5, (void**)inptr,
738                                    int_kernel_name, foo);
739     }
740 
741 
742     for ( i = 0; i < 5; i++ ){
743         align_free( (void *)inptr[i] );
744     }
745     free_mtdata(d);
746 
747     return err;
748 
749 }
750 
test_pipe_readwrite_uint(cl_device_id deviceID,cl_context context,cl_command_queue queue,int num_elements)751 int test_pipe_readwrite_uint( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements )
752 {
753     cl_uint     *inptr[5];
754     size_t  ptrSizes[5];
755     int     i, err;
756     cl_uint j;
757     int     (*foo)(void *,void *,int);
758     MTdata  d = init_genrand( gRandomSeed );
759 
760     size_t  min_alignment = get_min_alignment(context);
761 
762     foo = verify_readwrite_uint;
763 
764     ptrSizes[0] = sizeof(cl_uint);
765     ptrSizes[1] = ptrSizes[0] << 1;
766     ptrSizes[2] = ptrSizes[1] << 1;
767     ptrSizes[3] = ptrSizes[2] << 1;
768     ptrSizes[4] = ptrSizes[3] << 1;
769 
770     for ( i = 0; i < 5; i++ ){
771         inptr[i] = (cl_uint *)align_malloc(ptrSizes[i] * num_elements, min_alignment);
772 
773         for ( j = 0; j < ptrSizes[i] * num_elements / ptrSizes[0]; j++ )
774             inptr[i][j] = (cl_uint)genrand_int32(d);
775     }
776 
777     if(useWorkgroupReserve == 1){
778         err = test_pipe_readwrite( deviceID, context, queue, num_elements, sizeof( cl_uint ), (char*)"uint", 5, (void**)inptr,
779                                    workgroup_uint_kernel_name, foo);
780     }
781     else if(useSubgroupReserve == 1){
782         err = test_pipe_readwrite( deviceID, context, queue, num_elements, sizeof( cl_uint ), (char*)"uint", 5, (void**)inptr,
783                                    subgroup_uint_kernel_name, foo);
784     }
785     else if(useConvenienceBuiltIn == 1) {
786         err = test_pipe_readwrite( deviceID, context, queue, num_elements, sizeof( cl_uint ), (char*)"uint", 5, (void**)inptr,
787                                    convenience_uint_kernel_name, foo);
788     }
789     else {
790         err = test_pipe_readwrite( deviceID, context, queue, num_elements, sizeof( cl_uint ), (char*)"uint", 5, (void**)inptr,
791                                    uint_kernel_name, foo);
792     }
793 
794     for ( i = 0; i < 5; i++ ){
795         align_free( (void *)inptr[i] );
796     }
797     free_mtdata(d);
798 
799     return err;
800 
801 }
802 
test_pipe_readwrite_short(cl_device_id deviceID,cl_context context,cl_command_queue queue,int num_elements)803 int test_pipe_readwrite_short( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements )
804 {
805     cl_short     *inptr[5];
806     size_t  ptrSizes[5];
807     int     i, err;
808     cl_uint j;
809     int     (*foo)(void *,void *,int);
810     MTdata  d = init_genrand( gRandomSeed );
811 
812     size_t  min_alignment = get_min_alignment(context);
813 
814     foo = verify_readwrite_short;
815 
816     ptrSizes[0] = sizeof(cl_short);
817     ptrSizes[1] = ptrSizes[0] << 1;
818     ptrSizes[2] = ptrSizes[1] << 1;
819     ptrSizes[3] = ptrSizes[2] << 1;
820     ptrSizes[4] = ptrSizes[3] << 1;
821 
822     for ( i = 0; i < 5; i++ ){
823         inptr[i] = (cl_short *)align_malloc(ptrSizes[i] * num_elements, min_alignment);
824 
825         for ( j = 0; j < ptrSizes[i] * num_elements / ptrSizes[0]; j++ )
826             inptr[i][j] = (cl_short)genrand_int32(d);
827     }
828 
829     if(useWorkgroupReserve == 1){
830         err = test_pipe_readwrite( deviceID, context, queue, num_elements, sizeof( cl_short ), (char*)"short", 5, (void**)inptr,
831                                    workgroup_short_kernel_name, foo);
832     }
833     else if(useSubgroupReserve == 1){
834         err = test_pipe_readwrite( deviceID, context, queue, num_elements, sizeof( cl_short ), (char*)"short", 5, (void**)inptr,
835                                    subgroup_short_kernel_name, foo);
836     }
837     else if(useConvenienceBuiltIn == 1){
838         err = test_pipe_readwrite( deviceID, context, queue, num_elements, sizeof( cl_short ), (char*)"short", 5, (void**)inptr,
839                                    convenience_short_kernel_name, foo);
840     }
841     else{
842         err = test_pipe_readwrite( deviceID, context, queue, num_elements, sizeof( cl_short ), (char*)"short", 5, (void**)inptr,
843                                    short_kernel_name, foo);
844     }
845 
846     for ( i = 0; i < 5; i++ ){
847         align_free( (void *)inptr[i] );
848     }
849     free_mtdata(d);
850 
851     return err;
852 
853 }
854 
test_pipe_readwrite_ushort(cl_device_id deviceID,cl_context context,cl_command_queue queue,int num_elements)855 int test_pipe_readwrite_ushort( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements )
856 {
857     cl_ushort     *inptr[5];
858     size_t  ptrSizes[5];
859     int     i, err;
860     cl_uint j;
861     int     (*foo)(void *,void *,int);
862     MTdata  d = init_genrand( gRandomSeed );
863 
864     size_t  min_alignment = get_min_alignment(context);
865 
866     foo = verify_readwrite_ushort;
867 
868     ptrSizes[0] = sizeof(cl_ushort);
869     ptrSizes[1] = ptrSizes[0] << 1;
870     ptrSizes[2] = ptrSizes[1] << 1;
871     ptrSizes[3] = ptrSizes[2] << 1;
872     ptrSizes[4] = ptrSizes[3] << 1;
873 
874     for ( i = 0; i < 5; i++ ){
875         inptr[i] = (cl_ushort *)align_malloc(ptrSizes[i] * num_elements, min_alignment);
876 
877         for ( j = 0; j < ptrSizes[i] * num_elements / ptrSizes[0]; j++ )
878             inptr[i][j] = (cl_ushort)genrand_int32(d);
879     }
880 
881     if(useWorkgroupReserve == 1){
882         err = test_pipe_readwrite( deviceID, context, queue, num_elements, sizeof( cl_ushort ), (char*)"ushort", 5, (void**)inptr,
883                                    workgroup_ushort_kernel_name, foo);
884     }
885     else if(useSubgroupReserve == 1){
886         err = test_pipe_readwrite( deviceID, context, queue, num_elements, sizeof( cl_ushort ), (char*)"ushort", 5, (void**)inptr,
887                                    subgroup_ushort_kernel_name, foo);
888     }
889     else if(useConvenienceBuiltIn == 1){
890         err = test_pipe_readwrite( deviceID, context, queue, num_elements, sizeof( cl_ushort ), (char*)"ushort", 5, (void**)inptr,
891                                    convenience_ushort_kernel_name, foo);
892     }
893     else{
894         err = test_pipe_readwrite( deviceID, context, queue, num_elements, sizeof( cl_ushort ), (char*)"ushort", 5, (void**)inptr,
895                                    ushort_kernel_name, foo);
896     }
897 
898 
899     for ( i = 0; i < 5; i++ ){
900         align_free( (void *)inptr[i] );
901     }
902     free_mtdata(d);
903 
904     return err;
905 
906 }
907 
test_pipe_readwrite_char(cl_device_id deviceID,cl_context context,cl_command_queue queue,int num_elements)908 int test_pipe_readwrite_char( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements )
909 {
910     cl_char *inptr[5];
911     size_t  ptrSizes[5];
912     int     i, err;
913     cl_uint j;
914     int     (*foo)(void *,void *,int);
915     MTdata  d = init_genrand( gRandomSeed );
916 
917     size_t  min_alignment = get_min_alignment(context);
918 
919     foo = verify_readwrite_char;
920 
921     ptrSizes[0] = sizeof(cl_char);
922     ptrSizes[1] = ptrSizes[0] << 1;
923     ptrSizes[2] = ptrSizes[1] << 1;
924     ptrSizes[3] = ptrSizes[2] << 1;
925     ptrSizes[4] = ptrSizes[3] << 1;
926 
927     for ( i = 0; i < 5; i++ ){
928         inptr[i] = (cl_char *)align_malloc(ptrSizes[i] * num_elements, min_alignment);
929 
930         for ( j = 0; j < ptrSizes[i] * num_elements / ptrSizes[0]; j++ )
931             inptr[i][j] = (char)genrand_int32(d);
932     }
933 
934     if(useWorkgroupReserve == 1){
935         err = test_pipe_readwrite( deviceID, context, queue, num_elements, sizeof( cl_char ), (char*)"char", 5, (void**)inptr,
936                                    workgroup_char_kernel_name, foo);
937     }
938     else if(useSubgroupReserve == 1){
939         err = test_pipe_readwrite( deviceID, context, queue, num_elements, sizeof( cl_char ), (char*)"char", 5, (void**)inptr,
940                                    subgroup_char_kernel_name, foo);
941     }
942     else if(useConvenienceBuiltIn == 1){
943         err = test_pipe_readwrite( deviceID, context, queue, num_elements, sizeof( cl_char ), (char*)"char", 5, (void**)inptr,
944                                    convenience_char_kernel_name, foo);
945     }
946     else{
947         err = test_pipe_readwrite( deviceID, context, queue, num_elements, sizeof( cl_char ), (char*)"char", 5, (void**)inptr,
948                                    char_kernel_name, foo);
949     }
950 
951 
952     for ( i = 0; i < 5; i++ ){
953         align_free( (void *)inptr[i] );
954     }
955     free_mtdata(d);
956 
957     return err;
958 
959 }
960 
test_pipe_readwrite_uchar(cl_device_id deviceID,cl_context context,cl_command_queue queue,int num_elements)961 int test_pipe_readwrite_uchar( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements )
962 {
963     cl_uchar    *inptr[5];
964     size_t        ptrSizes[5];
965     int            i, err;
966     cl_uint        j;
967     int            (*foo)(void *,void *,int);
968     MTdata        d = init_genrand( gRandomSeed );
969 
970     size_t  min_alignment = get_min_alignment(context);
971 
972     foo = verify_readwrite_uchar;
973 
974     ptrSizes[0] = sizeof(cl_uchar);
975     ptrSizes[1] = ptrSizes[0] << 1;
976     ptrSizes[2] = ptrSizes[1] << 1;
977     ptrSizes[3] = ptrSizes[2] << 1;
978     ptrSizes[4] = ptrSizes[3] << 1;
979 
980     for ( i = 0; i < 5; i++ ){
981         inptr[i] = (cl_uchar *)align_malloc(ptrSizes[i] * num_elements, min_alignment);
982 
983         for ( j = 0; j < ptrSizes[i] * num_elements / ptrSizes[0]; j++ )
984             inptr[i][j] = (uchar)genrand_int32(d);
985     }
986 
987     if(useWorkgroupReserve == 1){
988         err = test_pipe_readwrite( deviceID, context, queue, num_elements, sizeof( cl_uchar ), (char*)"uchar", 5, (void**)inptr,
989                                    workgroup_uchar_kernel_name, foo);
990     }
991     else if(useSubgroupReserve == 1){
992         err = test_pipe_readwrite( deviceID, context, queue, num_elements, sizeof( cl_uchar ), (char*)"uchar", 5, (void**)inptr,
993                                    subgroup_uchar_kernel_name, foo);
994     }
995     else if(useConvenienceBuiltIn == 1){
996         err = test_pipe_readwrite( deviceID, context, queue, num_elements, sizeof( cl_uchar ), (char*)"uchar", 5, (void**)inptr,
997                                    convenience_uchar_kernel_name, foo);
998     }
999     else{
1000         err = test_pipe_readwrite( deviceID, context, queue, num_elements, sizeof( cl_uchar ), (char*)"uchar", 5, (void**)inptr,
1001                                    uchar_kernel_name, foo);
1002     }
1003     for ( i = 0; i < 5; i++ ){
1004         align_free( (void *)inptr[i] );
1005     }
1006     free_mtdata(d);
1007 
1008     return err;
1009 
1010 }
1011 
test_pipe_readwrite_float(cl_device_id deviceID,cl_context context,cl_command_queue queue,int num_elements)1012 int test_pipe_readwrite_float( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements )
1013 {
1014     float     *inptr[5];
1015     size_t  ptrSizes[5];
1016     int     i, err;
1017     cl_uint j;
1018     int     (*foo)(void *,void *,int);
1019     MTdata  d = init_genrand( gRandomSeed );
1020 
1021     size_t  min_alignment = get_min_alignment(context);
1022 
1023     foo = verify_readwrite_float;
1024 
1025     ptrSizes[0] = sizeof(cl_float);
1026     ptrSizes[1] = ptrSizes[0] << 1;
1027     ptrSizes[2] = ptrSizes[1] << 1;
1028     ptrSizes[3] = ptrSizes[2] << 1;
1029     ptrSizes[4] = ptrSizes[3] << 1;
1030 
1031     for ( i = 0; i < 5; i++ ){
1032         inptr[i] = (float *)align_malloc(ptrSizes[i] * num_elements, min_alignment);
1033 
1034         for ( j = 0; j < ptrSizes[i] * num_elements / ptrSizes[0]; j++ )
1035             inptr[i][j] = get_random_float( -32, 32, d );
1036     }
1037 
1038     if(useWorkgroupReserve == 1){
1039         err = test_pipe_readwrite( deviceID, context, queue, num_elements, sizeof( cl_float ), (char*)"float", 5, (void**)inptr,
1040                                    workgroup_float_kernel_name, foo);
1041     }
1042     else if(useSubgroupReserve == 1){
1043         err = test_pipe_readwrite( deviceID, context, queue, num_elements, sizeof( cl_float ), (char*)"float", 5, (void**)inptr,
1044                                    subgroup_float_kernel_name, foo);
1045     }
1046     else if(useConvenienceBuiltIn == 1){
1047         err = test_pipe_readwrite( deviceID, context, queue, num_elements, sizeof( cl_float ), (char*)"float", 5, (void**)inptr,
1048                                    convenience_float_kernel_name, foo);
1049     }
1050     else{
1051         err = test_pipe_readwrite( deviceID, context, queue, num_elements, sizeof( cl_float ), (char*)"float", 5, (void**)inptr,
1052                                    float_kernel_name, foo);
1053     }
1054 
1055     for ( i = 0; i < 5; i++ ){
1056         align_free( (void *)inptr[i] );
1057     }
1058     free_mtdata(d);
1059 
1060     return err;
1061 
1062 }
1063 
test_pipe_readwrite_half(cl_device_id deviceID,cl_context context,cl_command_queue queue,int num_elements)1064 int test_pipe_readwrite_half( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements )
1065 {
1066     float   *inptr[5];
1067     size_t  ptrSizes[5];
1068     int     i, err;
1069     cl_uint j;
1070     int     (*foo)(void *,void *,int);
1071     MTdata  d = init_genrand( gRandomSeed );
1072 
1073     size_t  min_alignment = get_min_alignment(context);
1074 
1075     foo = verify_readwrite_half;
1076 
1077     if(!is_extension_available(deviceID, "cl_khr_fp16"))
1078     {
1079         log_info("cl_khr_fp16 is not supported on this platoform. 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_long;
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("cl_khr_fp64 is not supported on this platoform. Skipping test.\n");
1261         return CL_SUCCESS;
1262     }
1263 
1264     for ( i = 0; i < 5; i++ ){
1265         inptr[i] = (cl_double *)align_malloc(ptrSizes[i] * num_elements, min_alignment);
1266 
1267         for ( j = 0; j < ptrSizes[i] * num_elements / ptrSizes[0]; j++ )
1268             inptr[i][j] = get_random_double( -32, 32, d );
1269     }
1270 
1271     if(useWorkgroupReserve == 1){
1272         err = test_pipe_readwrite( deviceID, context, queue, num_elements, sizeof( cl_double ), (char*)"double", 5, (void**)inptr,
1273                                    workgroup_double_kernel_name, foo);
1274     }
1275     else if(useSubgroupReserve == 1){
1276         err = test_pipe_readwrite( deviceID, context, queue, num_elements, sizeof( cl_double ), (char*)"double", 5, (void**)inptr,
1277                                    subgroup_double_kernel_name, foo);
1278     }
1279     else if(useConvenienceBuiltIn == 1){
1280         err = test_pipe_readwrite( deviceID, context, queue, num_elements, sizeof( cl_double ), (char*)"double", 5, (void**)inptr,
1281                                    convenience_double_kernel_name, foo);
1282     }
1283     else{
1284         err = test_pipe_readwrite( deviceID, context, queue, num_elements, sizeof( cl_double ), (char*)"double", 5, (void**)inptr,
1285                                    double_kernel_name, foo);
1286     }
1287 
1288     for ( i = 0; i < 5; i++ ){
1289         align_free( (void *)inptr[i] );
1290     }
1291     free_mtdata(d);
1292 
1293     return err;
1294 
1295 }
1296 
test_pipe_readwrite_struct(cl_device_id deviceID,cl_context context,cl_command_queue queue,int num_elements)1297 int test_pipe_readwrite_struct( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements )
1298 {
1299     const char *kernelNames[] = {"test_pipe_write_struct","test_pipe_read_struct"};
1300     return test_pipe_readwrite_struct_generic(deviceID, context, queue, num_elements, pipe_readwrite_struct_kernel_code, kernelNames);
1301 }
1302 
1303 // 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)1304 int test_pipe_workgroup_readwrite_int( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements )
1305 {
1306     useWorkgroupReserve = 1;
1307     useSubgroupReserve = 0;
1308     useConvenienceBuiltIn = 0;
1309     return test_pipe_readwrite_int(deviceID, context, queue, num_elements);
1310 }
1311 
test_pipe_workgroup_readwrite_uint(cl_device_id deviceID,cl_context context,cl_command_queue queue,int num_elements)1312 int test_pipe_workgroup_readwrite_uint( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements )
1313 {
1314     useWorkgroupReserve = 1;
1315     useSubgroupReserve = 0;
1316     useConvenienceBuiltIn = 0;
1317     return test_pipe_readwrite_uint(deviceID, context, queue, num_elements);
1318 }
1319 
test_pipe_workgroup_readwrite_short(cl_device_id deviceID,cl_context context,cl_command_queue queue,int num_elements)1320 int test_pipe_workgroup_readwrite_short( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements )
1321 {
1322     useWorkgroupReserve = 1;
1323     useSubgroupReserve = 0;
1324     useConvenienceBuiltIn = 0;
1325     return test_pipe_readwrite_short(deviceID, context, queue, num_elements);
1326 }
1327 
test_pipe_workgroup_readwrite_ushort(cl_device_id deviceID,cl_context context,cl_command_queue queue,int num_elements)1328 int test_pipe_workgroup_readwrite_ushort( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements )
1329 {
1330     useWorkgroupReserve = 1;
1331     useSubgroupReserve = 0;
1332     useConvenienceBuiltIn = 0;
1333     return test_pipe_readwrite_ushort(deviceID, context, queue, num_elements);
1334 }
1335 
test_pipe_workgroup_readwrite_char(cl_device_id deviceID,cl_context context,cl_command_queue queue,int num_elements)1336 int test_pipe_workgroup_readwrite_char( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements )
1337 {
1338     useWorkgroupReserve = 1;
1339     useSubgroupReserve = 0;
1340     useConvenienceBuiltIn = 0;
1341     return test_pipe_readwrite_char(deviceID, context, queue, num_elements);
1342 }
1343 
test_pipe_workgroup_readwrite_uchar(cl_device_id deviceID,cl_context context,cl_command_queue queue,int num_elements)1344 int test_pipe_workgroup_readwrite_uchar( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements )
1345 {
1346     useWorkgroupReserve = 1;
1347     useSubgroupReserve = 0;
1348     useConvenienceBuiltIn = 0;
1349     return test_pipe_readwrite_uchar(deviceID, context, queue, num_elements);
1350 }
1351 
test_pipe_workgroup_readwrite_float(cl_device_id deviceID,cl_context context,cl_command_queue queue,int num_elements)1352 int test_pipe_workgroup_readwrite_float( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements )
1353 {
1354     useWorkgroupReserve = 1;
1355     useSubgroupReserve = 0;
1356     useConvenienceBuiltIn = 0;
1357     return test_pipe_readwrite_float(deviceID, context, queue, num_elements);
1358 }
1359 
test_pipe_workgroup_readwrite_half(cl_device_id deviceID,cl_context context,cl_command_queue queue,int num_elements)1360 int test_pipe_workgroup_readwrite_half( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements )
1361 {
1362     useWorkgroupReserve = 1;
1363     useSubgroupReserve = 0;
1364     useConvenienceBuiltIn = 0;
1365     return test_pipe_readwrite_half(deviceID, context, queue, num_elements);
1366 }
1367 
test_pipe_workgroup_readwrite_long(cl_device_id deviceID,cl_context context,cl_command_queue queue,int num_elements)1368 int test_pipe_workgroup_readwrite_long( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements )
1369 {
1370     useWorkgroupReserve = 1;
1371     useSubgroupReserve = 0;
1372     useConvenienceBuiltIn = 0;
1373     return test_pipe_readwrite_long(deviceID, context, queue, num_elements);
1374 }
1375 
test_pipe_workgroup_readwrite_ulong(cl_device_id deviceID,cl_context context,cl_command_queue queue,int num_elements)1376 int test_pipe_workgroup_readwrite_ulong( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements )
1377 {
1378     useWorkgroupReserve = 1;
1379     useSubgroupReserve = 0;
1380     useConvenienceBuiltIn = 0;
1381     return test_pipe_readwrite_ulong(deviceID, context, queue, num_elements);
1382 }
1383 
test_pipe_workgroup_readwrite_double(cl_device_id deviceID,cl_context context,cl_command_queue queue,int num_elements)1384 int test_pipe_workgroup_readwrite_double( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements )
1385 {
1386     useWorkgroupReserve = 1;
1387     useSubgroupReserve = 0;
1388     useConvenienceBuiltIn = 0;
1389     return test_pipe_readwrite_double(deviceID, context, queue, num_elements);
1390 }
1391 
test_pipe_workgroup_readwrite_struct(cl_device_id deviceID,cl_context context,cl_command_queue queue,int num_elements)1392 int test_pipe_workgroup_readwrite_struct( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements )
1393 {
1394     const char *kernelNames[] = {"test_pipe_workgroup_write_struct","test_pipe_workgroup_read_struct"};
1395     return test_pipe_readwrite_struct_generic(deviceID, context, queue, num_elements, pipe_workgroup_readwrite_struct_kernel_code, kernelNames);
1396 }
1397 
1398 // 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)1399 int test_pipe_subgroup_readwrite_int( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements )
1400 {
1401     useSubgroupReserve = 1;
1402     useWorkgroupReserve = 0;
1403     useConvenienceBuiltIn = 0;
1404 
1405     if(!is_extension_available(deviceID, "cl_khr_subgroups"))
1406     {
1407         log_info("cl_khr_subgroups is not supported on this platoform. Skipping test.\n");
1408         return CL_SUCCESS;
1409     }
1410     return test_pipe_readwrite_int(deviceID, context, queue, num_elements);
1411 }
1412 
test_pipe_subgroup_readwrite_uint(cl_device_id deviceID,cl_context context,cl_command_queue queue,int num_elements)1413 int test_pipe_subgroup_readwrite_uint( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements )
1414 {
1415     useSubgroupReserve = 1;
1416     useWorkgroupReserve = 0;
1417     useConvenienceBuiltIn = 0;
1418 
1419     if(!is_extension_available(deviceID, "cl_khr_subgroups"))
1420     {
1421         log_info("cl_khr_subgroups is not supported on this platoform. Skipping test.\n");
1422         return CL_SUCCESS;
1423     }
1424     return test_pipe_readwrite_uint(deviceID, context, queue, num_elements);
1425 }
1426 
test_pipe_subgroup_readwrite_short(cl_device_id deviceID,cl_context context,cl_command_queue queue,int num_elements)1427 int test_pipe_subgroup_readwrite_short( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements )
1428 {
1429     useSubgroupReserve = 1;
1430     useWorkgroupReserve = 0;
1431     useConvenienceBuiltIn = 0;
1432 
1433     if(!is_extension_available(deviceID, "cl_khr_subgroups"))
1434     {
1435         log_info("cl_khr_subgroups is not supported on this platoform. Skipping test.\n");
1436         return CL_SUCCESS;
1437     }
1438     return test_pipe_readwrite_short(deviceID, context, queue, num_elements);
1439 }
1440 
test_pipe_subgroup_readwrite_ushort(cl_device_id deviceID,cl_context context,cl_command_queue queue,int num_elements)1441 int test_pipe_subgroup_readwrite_ushort( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements )
1442 {
1443     useSubgroupReserve = 1;
1444     useWorkgroupReserve = 0;
1445     useConvenienceBuiltIn = 0;
1446 
1447     if(!is_extension_available(deviceID, "cl_khr_subgroups"))
1448     {
1449         log_info("cl_khr_subgroups is not supported on this platoform. Skipping test.\n");
1450         return CL_SUCCESS;
1451     }
1452     return test_pipe_readwrite_ushort(deviceID, context, queue, num_elements);
1453 }
1454 
test_pipe_subgroup_readwrite_char(cl_device_id deviceID,cl_context context,cl_command_queue queue,int num_elements)1455 int test_pipe_subgroup_readwrite_char( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements )
1456 {
1457     useSubgroupReserve = 1;
1458     useWorkgroupReserve = 0;
1459     useConvenienceBuiltIn = 0;
1460 
1461     if(!is_extension_available(deviceID, "cl_khr_subgroups"))
1462     {
1463         log_info("cl_khr_subgroups is not supported on this platoform. Skipping test.\n");
1464         return CL_SUCCESS;
1465     }
1466     return test_pipe_readwrite_char(deviceID, context, queue, num_elements);
1467 }
1468 
test_pipe_subgroup_readwrite_uchar(cl_device_id deviceID,cl_context context,cl_command_queue queue,int num_elements)1469 int test_pipe_subgroup_readwrite_uchar( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements )
1470 {
1471     useSubgroupReserve = 1;
1472     useWorkgroupReserve = 0;
1473     useConvenienceBuiltIn = 0;
1474 
1475     if(!is_extension_available(deviceID, "cl_khr_subgroups"))
1476     {
1477         log_info("cl_khr_subgroups is not supported on this platoform. Skipping test.\n");
1478         return CL_SUCCESS;
1479     }
1480     return test_pipe_readwrite_uchar(deviceID, context, queue, num_elements);
1481 
1482 }
1483 
test_pipe_subgroup_readwrite_float(cl_device_id deviceID,cl_context context,cl_command_queue queue,int num_elements)1484 int test_pipe_subgroup_readwrite_float( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements )
1485 {
1486     useSubgroupReserve = 1;
1487     useWorkgroupReserve = 0;
1488     useConvenienceBuiltIn = 0;
1489 
1490     if(!is_extension_available(deviceID, "cl_khr_subgroups"))
1491     {
1492         log_info("cl_khr_subgroups is not supported on this platoform. Skipping test.\n");
1493         return CL_SUCCESS;
1494     }
1495     return test_pipe_readwrite_float(deviceID, context, queue, num_elements);
1496 }
1497 
test_pipe_subgroup_readwrite_half(cl_device_id deviceID,cl_context context,cl_command_queue queue,int num_elements)1498 int test_pipe_subgroup_readwrite_half( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements )
1499 {
1500     useSubgroupReserve = 1;
1501     useWorkgroupReserve = 0;
1502     useConvenienceBuiltIn = 0;
1503 
1504     if(!is_extension_available(deviceID, "cl_khr_subgroups"))
1505     {
1506         log_info("cl_khr_subgroups is not supported on this platoform. Skipping test.\n");
1507         return CL_SUCCESS;
1508     }
1509     return test_pipe_readwrite_half(deviceID, context, queue, num_elements);
1510 }
1511 
test_pipe_subgroup_readwrite_long(cl_device_id deviceID,cl_context context,cl_command_queue queue,int num_elements)1512 int test_pipe_subgroup_readwrite_long( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements )
1513 {
1514     useSubgroupReserve = 1;
1515     useWorkgroupReserve = 0;
1516     useConvenienceBuiltIn = 0;
1517 
1518     if(!is_extension_available(deviceID, "cl_khr_subgroups"))
1519     {
1520         log_info("cl_khr_subgroups is not supported on this platoform. Skipping test.\n");
1521         return CL_SUCCESS;
1522     }
1523     return test_pipe_readwrite_long(deviceID, context, queue, num_elements);
1524 }
1525 
test_pipe_subgroup_readwrite_ulong(cl_device_id deviceID,cl_context context,cl_command_queue queue,int num_elements)1526 int test_pipe_subgroup_readwrite_ulong( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements )
1527 {
1528     useSubgroupReserve = 1;
1529     useWorkgroupReserve = 0;
1530     useConvenienceBuiltIn = 0;
1531 
1532     if(!is_extension_available(deviceID, "cl_khr_subgroups"))
1533     {
1534         log_info("cl_khr_subgroups is not supported on this platoform. Skipping test.\n");
1535         return CL_SUCCESS;
1536     }
1537     return test_pipe_readwrite_ulong(deviceID, context, queue, num_elements);
1538 }
1539 
test_pipe_subgroup_readwrite_double(cl_device_id deviceID,cl_context context,cl_command_queue queue,int num_elements)1540 int test_pipe_subgroup_readwrite_double( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements )
1541 {
1542     useSubgroupReserve = 1;
1543     useWorkgroupReserve = 0;
1544     useConvenienceBuiltIn = 0;
1545 
1546     if(!is_extension_available(deviceID, "cl_khr_subgroups"))
1547     {
1548         log_info("cl_khr_subgroups is not supported on this platoform. Skipping test.\n");
1549         return CL_SUCCESS;
1550     }
1551     return test_pipe_readwrite_double(deviceID, context, queue, num_elements);
1552 }
1553 
test_pipe_subgroup_readwrite_struct(cl_device_id deviceID,cl_context context,cl_command_queue queue,int num_elements)1554 int test_pipe_subgroup_readwrite_struct( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements )
1555 {
1556     if(!is_extension_available(deviceID, "cl_khr_subgroups"))
1557     {
1558         log_info("cl_khr_subgroups is not supported on this platoform. Skipping test.\n");
1559         return CL_SUCCESS;
1560     }
1561     const char *kernelNames[] = {"test_pipe_subgroup_write_struct","test_pipe_subgroup_read_struct"};
1562     return test_pipe_readwrite_struct_generic(deviceID, context, queue, num_elements, pipe_subgroup_readwrite_struct_kernel_code, kernelNames);
1563 }
1564 
1565 // 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)1566 int test_pipe_convenience_readwrite_int( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements )
1567 {
1568     useConvenienceBuiltIn = 1;
1569     useSubgroupReserve = 0;
1570     useWorkgroupReserve = 0;
1571 
1572     return test_pipe_readwrite_int(deviceID, context, queue, num_elements);
1573 }
1574 
test_pipe_convenience_readwrite_uint(cl_device_id deviceID,cl_context context,cl_command_queue queue,int num_elements)1575 int test_pipe_convenience_readwrite_uint( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements )
1576 {
1577     useConvenienceBuiltIn = 1;
1578     useSubgroupReserve = 0;
1579     useWorkgroupReserve = 0;
1580 
1581     return test_pipe_readwrite_uint(deviceID, context, queue, num_elements);
1582 }
1583 
test_pipe_convenience_readwrite_short(cl_device_id deviceID,cl_context context,cl_command_queue queue,int num_elements)1584 int test_pipe_convenience_readwrite_short( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements )
1585 {
1586     useConvenienceBuiltIn = 1;
1587     useSubgroupReserve = 0;
1588     useWorkgroupReserve = 0;
1589 
1590     return test_pipe_readwrite_short(deviceID, context, queue, num_elements);
1591 }
1592 
test_pipe_convenience_readwrite_ushort(cl_device_id deviceID,cl_context context,cl_command_queue queue,int num_elements)1593 int test_pipe_convenience_readwrite_ushort( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements )
1594 {
1595     useConvenienceBuiltIn = 1;
1596     useSubgroupReserve = 0;
1597     useWorkgroupReserve = 0;
1598 
1599     return test_pipe_readwrite_ushort(deviceID, context, queue, num_elements);
1600 }
1601 
test_pipe_convenience_readwrite_char(cl_device_id deviceID,cl_context context,cl_command_queue queue,int num_elements)1602 int test_pipe_convenience_readwrite_char( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements )
1603 {
1604     useConvenienceBuiltIn = 1;
1605     useSubgroupReserve = 0;
1606     useWorkgroupReserve = 0;
1607 
1608     return test_pipe_readwrite_char(deviceID, context, queue, num_elements);
1609 }
1610 
test_pipe_convenience_readwrite_uchar(cl_device_id deviceID,cl_context context,cl_command_queue queue,int num_elements)1611 int test_pipe_convenience_readwrite_uchar( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements )
1612 {
1613     useConvenienceBuiltIn = 1;
1614     useSubgroupReserve = 0;
1615     useWorkgroupReserve = 0;
1616 
1617     return test_pipe_readwrite_uchar(deviceID, context, queue, num_elements);
1618 }
1619 
1620 
test_pipe_convenience_readwrite_float(cl_device_id deviceID,cl_context context,cl_command_queue queue,int num_elements)1621 int test_pipe_convenience_readwrite_float( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements )
1622 {
1623     useConvenienceBuiltIn = 1;
1624     useSubgroupReserve = 0;
1625     useWorkgroupReserve = 0;
1626 
1627     return test_pipe_readwrite_float(deviceID, context, queue, num_elements);
1628 }
1629 
test_pipe_convenience_readwrite_half(cl_device_id deviceID,cl_context context,cl_command_queue queue,int num_elements)1630 int test_pipe_convenience_readwrite_half( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements )
1631 {
1632     useConvenienceBuiltIn = 1;
1633     useSubgroupReserve = 0;
1634     useWorkgroupReserve = 0;
1635 
1636     return test_pipe_readwrite_half(deviceID, context, queue, num_elements);
1637 }
1638 
test_pipe_convenience_readwrite_long(cl_device_id deviceID,cl_context context,cl_command_queue queue,int num_elements)1639 int test_pipe_convenience_readwrite_long( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements )
1640 {
1641     useConvenienceBuiltIn = 1;
1642     useSubgroupReserve = 0;
1643     useWorkgroupReserve = 0;
1644 
1645     return test_pipe_readwrite_long(deviceID, context, queue, num_elements);
1646 }
1647 
test_pipe_convenience_readwrite_ulong(cl_device_id deviceID,cl_context context,cl_command_queue queue,int num_elements)1648 int test_pipe_convenience_readwrite_ulong( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements )
1649 {
1650     useConvenienceBuiltIn = 1;
1651     useSubgroupReserve = 0;
1652     useWorkgroupReserve = 0;
1653 
1654     return test_pipe_readwrite_ulong(deviceID, context, queue, num_elements);
1655 }
1656 
test_pipe_convenience_readwrite_double(cl_device_id deviceID,cl_context context,cl_command_queue queue,int num_elements)1657 int test_pipe_convenience_readwrite_double( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements )
1658 {
1659     useConvenienceBuiltIn = 1;
1660     useSubgroupReserve = 0;
1661     useWorkgroupReserve = 0;
1662 
1663     return test_pipe_readwrite_double(deviceID, context, queue, num_elements);
1664 }
1665 
test_pipe_convenience_readwrite_struct(cl_device_id deviceID,cl_context context,cl_command_queue queue,int num_elements)1666 int test_pipe_convenience_readwrite_struct( cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements )
1667 {
1668     const char *kernelNames[] = {"test_pipe_convenience_write_struct","test_pipe_convenience_read_struct"};
1669     return test_pipe_readwrite_struct_generic(deviceID, context, queue, num_elements, pipe_convenience_readwrite_struct_kernel_code, kernelNames);
1670 }
1671