Skip to content

Commit 3ff004e

Browse files
Add ability to select data types, vector size and stride for basic tests
This commit introduces command-line options to the basic tests that allow users to specify data types, vector sizes, and strides for the tests. This enhancement provides flexibility and easier debugability in testing various configurations. * added `v1|v2|v3|v4|v8|v16` options to select vector size * added `s1|s3|s4|s5` options to select stride value * added `char|uchar|short|ushort|int|uint|long|ulong|float|half|double` options to specify data type used in test. Above options available for following tests: - async_copy_global_to_local - async_copy_local_to_global - prefetch - async_strided_copy_global_to_local - async_strided_copy_local_to_global
1 parent 02e99f4 commit 3ff004e

File tree

4 files changed

+249
-33
lines changed

4 files changed

+249
-33
lines changed

test_conformance/basic/main.cpp

Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,16 @@
1717
#include "harness/deviceInfo.h"
1818
#include "harness/kernelHelpers.h"
1919
#include "harness/testHarness.h"
20+
#include "harness/parseParameters.h"
2021

2122
#include <CL/cl_half.h>
23+
#include "testBase.h"
2224

2325
cl_half_rounding_mode halfRoundingMode = CL_HALF_RTE;
26+
int gUseDataType = 0;
27+
unsigned int gUseVectorSize = 0;
28+
unsigned int gUseStride = 0;
29+
std::vector<ExplicitType> gVecType = {};
2430

2531
test_status InitCL(cl_device_id device)
2632
{
@@ -46,8 +52,170 @@ test_status InitCL(cl_device_id device)
4652
return TEST_PASS;
4753
}
4854

55+
static void PrintUsage(void)
56+
{
57+
vlog("additional options for test cases:\n");
58+
vlog("\t async_copy_global_to_local\n\t async_copy_local_to_global\n\t "
59+
"prefetch\n\t async_strided_copy_global_to_local\n\t "
60+
"async_strided_copy_local_to_global\n\n");
61+
vlog("\t [v1|v2|v3|v4|v8|v16] - specify vector size used in test.\n");
62+
vlog("\t [char|uchar|short|ushort|int|uint|long|ulong|float|half|double] "
63+
"- specify data type used in test.\n");
64+
vlog("\n\t In addition for async_strided_copy_global_to_local and "
65+
"async_strided_copy_local_to_global:\n");
66+
vlog("\t [s1|s3|s4|s5] - specify stride size used in test.\n");
67+
vlog("\n\t Examples of usage:\n");
68+
vlog("\t test_basic async_copy_local_to_global float v4\n");
69+
vlog("\t test_basic prefetch int uint v2\n");
70+
vlog("\t test_basic async_strided_copy_global_to_local uchar s4 v1\n");
71+
vlog("\t test_basic async_strided_copy_local_to_global char s3 v4\n\n");
72+
vlog("\t Notes:\n");
73+
vlog("\t Choose exactly one vector size: v1|v2|v3|v4|v8|v16.\n");
74+
vlog("\t You can include multiple data types (e.g., char int).\n");
75+
vlog("\t For strided variants, include exactly one stride: "
76+
"s1|s3|s4|s5.\n\n");
77+
vlog("\n");
78+
}
79+
4980
int main(int argc, const char *argv[])
5081
{
82+
argc = parseCustomParam(argc, argv);
83+
84+
// Parse arguments
85+
int argsRemoveNum = 0;
86+
for (int i = 1; i < argc; i++)
87+
{
88+
if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0)
89+
{
90+
PrintUsage();
91+
return -1;
92+
}
93+
if (strcmp(argv[i], "char") == 0)
94+
{
95+
gUseDataType = 1;
96+
gVecType.push_back(kChar);
97+
argsRemoveNum += 1;
98+
}
99+
else if (strcmp(argv[i], "uchar") == 0)
100+
{
101+
gUseDataType = 1;
102+
gVecType.push_back(kUChar);
103+
argsRemoveNum += 1;
104+
}
105+
else if (strcmp(argv[i], "short") == 0)
106+
{
107+
gUseDataType = 1;
108+
gVecType.push_back(kShort);
109+
argsRemoveNum += 1;
110+
}
111+
else if (strcmp(argv[i], "ushort") == 0)
112+
{
113+
gUseDataType = 1;
114+
gVecType.push_back(kUShort);
115+
argsRemoveNum += 1;
116+
}
117+
else if (strcmp(argv[i], "int") == 0)
118+
{
119+
gUseDataType = 1;
120+
gVecType.push_back(kInt);
121+
argsRemoveNum += 1;
122+
}
123+
else if (strcmp(argv[i], "uint") == 0)
124+
{
125+
gUseDataType = 1;
126+
gVecType.push_back(kUInt);
127+
argsRemoveNum += 1;
128+
}
129+
else if (strcmp(argv[i], "long") == 0)
130+
{
131+
gUseDataType = 1;
132+
gVecType.push_back(kLong);
133+
argsRemoveNum += 1;
134+
}
135+
else if (strcmp(argv[i], "ulong") == 0)
136+
{
137+
gUseDataType = 1;
138+
gVecType.push_back(kULong);
139+
argsRemoveNum += 1;
140+
}
141+
else if (strcmp(argv[i], "float") == 0)
142+
{
143+
gUseDataType = 1;
144+
gVecType.push_back(kFloat);
145+
argsRemoveNum += 1;
146+
}
147+
else if (strcmp(argv[i], "half") == 0)
148+
{
149+
gUseDataType = 1;
150+
gVecType.push_back(kHalf);
151+
argsRemoveNum += 1;
152+
}
153+
else if (strcmp(argv[i], "double") == 0)
154+
{
155+
gUseDataType = 1;
156+
gVecType.push_back(kDouble);
157+
argsRemoveNum += 1;
158+
}
159+
else if (strcmp(argv[i], "v1") == 0)
160+
{
161+
gUseVectorSize = 1;
162+
argsRemoveNum += 1;
163+
}
164+
else if (strcmp(argv[i], "v2") == 0)
165+
{
166+
gUseVectorSize = 2;
167+
argsRemoveNum += 1;
168+
}
169+
else if (strcmp(argv[i], "v3") == 0)
170+
{
171+
gUseVectorSize = 3;
172+
argsRemoveNum += 1;
173+
}
174+
else if (strcmp(argv[i], "v4") == 0)
175+
{
176+
gUseVectorSize = 4;
177+
argsRemoveNum += 1;
178+
}
179+
else if (strcmp(argv[i], "v8") == 0)
180+
{
181+
gUseVectorSize = 8;
182+
argsRemoveNum += 1;
183+
}
184+
else if (strcmp(argv[i], "v16") == 0)
185+
{
186+
gUseVectorSize = 16;
187+
argsRemoveNum += 1;
188+
}
189+
else if (strcmp(argv[i], "s1") == 0)
190+
{
191+
gUseStride = 1;
192+
argsRemoveNum += 1;
193+
}
194+
else if (strcmp(argv[i], "s3") == 0)
195+
{
196+
gUseStride = 3;
197+
argsRemoveNum += 1;
198+
}
199+
else if (strcmp(argv[i], "s4") == 0)
200+
{
201+
gUseStride = 4;
202+
argsRemoveNum += 1;
203+
}
204+
else if (strcmp(argv[i], "s5") == 0)
205+
{
206+
gUseStride = 5;
207+
argsRemoveNum += 1;
208+
}
209+
}
210+
// remove additionally parsed args from argv
211+
if (argsRemoveNum > 0)
212+
{
213+
for (int j = argc; j < argc - argsRemoveNum; j++)
214+
{
215+
argv[j] = argv[j + argsRemoveNum];
216+
}
217+
argc -= argsRemoveNum;
218+
}
51219
return runTestHarnessWithCheck(
52220
argc, argv, test_registry::getInstance().num_tests(),
53221
test_registry::getInstance().definitions(), false, 0, InitCL);

test_conformance/basic/testBase.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,9 @@
2222
#include "harness/testHarness.h"
2323
#include "harness/typeWrappers.h"
2424
#include "harness/rounding_mode.h"
25+
extern int gUseDataType;
26+
extern unsigned int gUseVectorSize;
27+
extern unsigned int gUseStride;
28+
extern std::vector<ExplicitType> gVecType;
2529

2630
#endif // _testBase_h

test_conformance/basic/test_async_copy.cpp

Lines changed: 48 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -23,51 +23,51 @@
2323
#include "testBase.h"
2424

2525
static const char *async_global_to_local_kernel =
26-
"%s\n" // optional pragma string
26+
"%s\n" // optional pragma string
2727
"__kernel void test_fn( const __global %s *src, __global %s *dst, __local %s *localBuffer, int copiesPerWorkgroup, int copiesPerWorkItem )\n"
28-
"{\n"
29-
" int i;\n"
30-
// Zero the local storage first
31-
" for(i=0; i<copiesPerWorkItem; i++)\n"
32-
" localBuffer[ get_local_id( 0 )*copiesPerWorkItem+i ] = (%s)(%s)0;\n"
28+
"{\n"
29+
" int i;\n"
30+
// Zero the local storage first
31+
" for(i=0; i<copiesPerWorkItem; i++)\n"
32+
" localBuffer[ get_local_id( 0 )*copiesPerWorkItem+i ] = (%s)(%s)0;\n"
3333
// Do this to verify all kernels are done zeroing the local buffer before we try the copy
34-
" barrier( CLK_LOCAL_MEM_FENCE );\n"
35-
" event_t event;\n"
34+
" barrier( CLK_LOCAL_MEM_FENCE );\n"
35+
" event_t event;\n"
3636
" event = async_work_group_copy( (__local %s*)localBuffer, (__global const %s*)(src+copiesPerWorkgroup*get_group_id(0)), (size_t)copiesPerWorkgroup, 0 );\n"
3737
// Wait for the copy to complete, then verify by manually copying to the dest
38-
" wait_group_events( 1, &event );\n"
39-
" for(i=0; i<copiesPerWorkItem; i++)\n"
38+
" wait_group_events( 1, &event );\n"
39+
" for(i=0; i<copiesPerWorkItem; i++)\n"
4040
" dst[ get_global_id( 0 )*copiesPerWorkItem+i ] = localBuffer[ get_local_id( 0 )*copiesPerWorkItem+i ];\n"
4141
"}\n" ;
4242

4343
static const char *async_local_to_global_kernel =
44-
"%s\n" // optional pragma string
44+
"%s\n" // optional pragma string
4545
"__kernel void test_fn( const __global %s *src, __global %s *dst, __local %s *localBuffer, int copiesPerWorkgroup, int copiesPerWorkItem )\n"
46-
"{\n"
47-
" int i;\n"
48-
// Zero the local storage first
49-
" for(i=0; i<copiesPerWorkItem; i++)\n"
50-
" localBuffer[ get_local_id( 0 )*copiesPerWorkItem+i ] = (%s)(%s)0;\n"
46+
"{\n"
47+
" int i;\n"
48+
// Zero the local storage first
49+
" for(i=0; i<copiesPerWorkItem; i++)\n"
50+
" localBuffer[ get_local_id( 0 )*copiesPerWorkItem+i ] = (%s)(%s)0;\n"
5151
// Do this to verify all kernels are done zeroing the local buffer before we try the copy
52-
" barrier( CLK_LOCAL_MEM_FENCE );\n"
53-
" for(i=0; i<copiesPerWorkItem; i++)\n"
52+
" barrier( CLK_LOCAL_MEM_FENCE );\n"
53+
" for(i=0; i<copiesPerWorkItem; i++)\n"
5454
" localBuffer[ get_local_id( 0 )*copiesPerWorkItem+i ] = src[ get_global_id( 0 )*copiesPerWorkItem+i ];\n"
5555
// Do this to verify all kernels are done copying to the local buffer before we try the copy
56-
" barrier( CLK_LOCAL_MEM_FENCE );\n"
57-
" event_t event;\n"
56+
" barrier( CLK_LOCAL_MEM_FENCE );\n"
57+
" event_t event;\n"
5858
" event = async_work_group_copy((__global %s*)(dst+copiesPerWorkgroup*get_group_id(0)), (__local const %s*)localBuffer, (size_t)copiesPerWorkgroup, 0 );\n"
59-
" wait_group_events( 1, &event );\n"
59+
" wait_group_events( 1, &event );\n"
6060
"}\n" ;
6161

6262

6363
static const char *prefetch_kernel =
64-
"%s\n" // optional pragma string
64+
"%s\n" // optional pragma string
6565
"__kernel void test_fn( const __global %s *src, __global %s *dst, __local %s *localBuffer, int copiesPerWorkgroup, int copiesPerWorkItem )\n"
66-
"{\n"
67-
" // Ignore this: %s%s%s\n"
68-
" int i;\n"
66+
"{\n"
67+
" // Ignore this: %s%s%s\n"
68+
" int i;\n"
6969
" prefetch( (const __global %s*)(src+copiesPerWorkItem*get_global_id(0)), copiesPerWorkItem);\n"
70-
" for(i=0; i<copiesPerWorkItem; i++)\n"
70+
" for(i=0; i<copiesPerWorkItem; i++)\n"
7171
" dst[ get_global_id( 0 )*copiesPerWorkItem+i ] = src[ get_global_id( 0 )*copiesPerWorkItem+i ];\n"
7272
"}\n" ;
7373

@@ -237,12 +237,30 @@ static int test_copy(cl_device_id deviceID, cl_context context,
237237
static int test_copy_all_types(cl_device_id deviceID, cl_context context,
238238
cl_command_queue queue, const char *kernelCode)
239239
{
240-
const std::vector<ExplicitType> vecType = { kChar, kUChar, kShort, kUShort,
241-
kInt, kUInt, kLong, kULong,
242-
kFloat, kHalf, kDouble };
243-
unsigned int vecSizes[] = { 1, 2, 3, 4, 8, 16, 0 };
240+
std::vector<ExplicitType> vecType = { kChar, kUChar, kShort, kUShort,
241+
kInt, kUInt, kLong, kULong,
242+
kFloat, kHalf, kDouble };
244243
unsigned int size, typeIndex;
245244

245+
std::vector<unsigned int> vecSizes;
246+
247+
if (gUseDataType)
248+
{
249+
log_info("WARNING: Running subset of data types !\n");
250+
vecType = gVecType;
251+
}
252+
253+
if (gUseVectorSize)
254+
{
255+
log_info("WARNING: Running for subset of vector size: %d only !\n",
256+
gUseVectorSize);
257+
vecSizes.assign({ gUseVectorSize, 0 });
258+
}
259+
else
260+
{
261+
vecSizes.assign({ 1, 2, 3, 4, 8, 16, 0 });
262+
}
263+
246264
int errors = 0;
247265

248266
bool fp16Support = is_extension_available(deviceID, "cl_khr_fp16");

test_conformance/basic/test_async_strided_copy.cpp

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -237,12 +237,38 @@ static int test_strided_copy_all_types(cl_device_id deviceID,
237237
cl_command_queue queue,
238238
const char *kernelCode)
239239
{
240-
const std::vector<ExplicitType> vecType = { kChar, kUChar, kShort, kUShort,
240+
std::vector<ExplicitType> vecType = { kChar, kUChar, kShort, kUShort,
241241
kInt, kUInt, kLong, kULong,
242242
kFloat, kHalf, kDouble };
243-
const unsigned int vecSizes[] = { 1, 2, 3, 4, 8, 16, 0 };
244-
const unsigned int strideSizes[] = { 1, 3, 4, 5, 0 };
245243
unsigned int size, typeIndex, stride;
244+
std::vector<unsigned int> vecSizes;
245+
std::vector<unsigned int> strideSizes;
246+
247+
if (gUseDataType)
248+
{
249+
log_info("WARNING: Running subset of data types !\n");
250+
vecType = gVecType;
251+
}
252+
253+
if (gUseVectorSize)
254+
{
255+
log_info("WARNING: Running for vector size: %d only !\n",
256+
gUseVectorSize);
257+
vecSizes.assign({ gUseVectorSize, 0 });
258+
}
259+
else
260+
{
261+
vecSizes.assign({ 1, 2, 3, 4, 8, 16, 0 });
262+
}
263+
if (gUseStride)
264+
{
265+
log_info("WARNING: Running for stride: %d only !\n", gUseStride);
266+
strideSizes.assign({ gUseStride, 0 });
267+
}
268+
else
269+
{
270+
strideSizes.assign({ 1, 3, 4, 5, 0 });
271+
}
246272

247273
int errors = 0;
248274

0 commit comments

Comments
 (0)