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 "testBase.h"
17 #include "harness/conversions.h"
18 #include "harness/typeWrappers.h"
19 #include "harness/testHarness.h"
20
21 const char *anyAllTestKernelPattern =
22 "%s\n" // optional pragma
23 "__kernel void sample_test(__global %s%s *sourceA, __global int *destValues)\n"
24 "{\n"
25 " int tid = get_global_id(0);\n"
26 " destValues[tid] = %s( sourceA[tid] );\n"
27 "\n"
28 "}\n";
29
30 const char *anyAllTestKernelPatternVload =
31 "%s\n" // optional pragma
32 "__kernel void sample_test(__global %s%s *sourceA, __global int *destValues)\n"
33 "{\n"
34 " int tid = get_global_id(0);\n"
35 " destValues[tid] = %s(vload3(tid, (__global %s *)sourceA));\n" // ugh, almost
36 "\n"
37 "}\n";
38
39 #define TEST_SIZE 512
40
41 typedef int (*anyAllVerifyFn)( ExplicitType vecType, unsigned int vecSize, void *inData );
42
test_any_all_kernel(cl_context context,cl_command_queue queue,const char * fnName,ExplicitType vecType,unsigned int vecSize,anyAllVerifyFn verifyFn,MTdata d)43 int test_any_all_kernel(cl_context context, cl_command_queue queue,
44 const char *fnName, ExplicitType vecType,
45 unsigned int vecSize, anyAllVerifyFn verifyFn,
46 MTdata d )
47 {
48 clProgramWrapper program;
49 clKernelWrapper kernel;
50 clMemWrapper streams[2];
51 cl_long inDataA[TEST_SIZE * 16], clearData[TEST_SIZE * 16];
52 int outData[TEST_SIZE];
53 int error, i;
54 size_t threads[1], localThreads[1];
55 char kernelSource[10240];
56 char *programPtr;
57 char sizeName[4];
58
59
60 /* Create the source */
61 if( g_vector_aligns[vecSize] == 1 ) {
62 sizeName[ 0 ] = 0;
63 } else {
64 sprintf( sizeName, "%d", vecSize );
65 }
66 log_info("Testing any/all on %s%s\n",
67 get_explicit_type_name( vecType ), sizeName);
68 if(DENSE_PACK_VECS && vecSize == 3) {
69 // anyAllTestKernelPatternVload
70 sprintf( kernelSource, anyAllTestKernelPatternVload,
71 vecType == kDouble ? "#pragma OPENCL EXTENSION cl_khr_fp64 : enable" : "",
72 get_explicit_type_name( vecType ), sizeName, fnName,
73 get_explicit_type_name(vecType));
74 } else {
75 sprintf( kernelSource, anyAllTestKernelPattern,
76 vecType == kDouble ? "#pragma OPENCL EXTENSION cl_khr_fp64 : enable" : "",
77 get_explicit_type_name( vecType ), sizeName, fnName );
78 }
79 /* Create kernels */
80 programPtr = kernelSource;
81 if( create_single_kernel_helper( context, &program, &kernel, 1,
82 (const char **)&programPtr,
83 "sample_test" ) )
84 {
85 return -1;
86 }
87
88 /* Generate some streams */
89 generate_random_data( vecType, TEST_SIZE * g_vector_aligns[vecSize], d, inDataA );
90 memset( clearData, 0, sizeof( clearData ) );
91
92 streams[0] = clCreateBuffer(context, CL_MEM_COPY_HOST_PTR,
93 get_explicit_type_size(vecType)
94 * g_vector_aligns[vecSize] * TEST_SIZE,
95 &inDataA, &error);
96 if( streams[0] == NULL )
97 {
98 print_error( error, "Creating input array A failed!\n");
99 return -1;
100 }
101 streams[1] =
102 clCreateBuffer(context, CL_MEM_COPY_HOST_PTR,
103 sizeof(cl_int) * g_vector_aligns[vecSize] * TEST_SIZE,
104 clearData, &error);
105 if( streams[1] == NULL )
106 {
107 print_error( error, "Creating output array failed!\n");
108 return -1;
109 }
110
111 /* Assign streams and execute */
112 error = clSetKernelArg( kernel, 0, sizeof( streams[0] ), &streams[0] );
113 test_error( error, "Unable to set indexed kernel arguments" );
114 error = clSetKernelArg( kernel, 1, sizeof( streams[1] ), &streams[1] );
115 test_error( error, "Unable to set indexed kernel arguments" );
116
117 /* Run the kernel */
118 threads[0] = TEST_SIZE;
119
120 error = get_max_common_work_group_size( context, kernel, threads[0], &localThreads[0] );
121 test_error( error, "Unable to get work group size to use" );
122
123 error = clEnqueueNDRangeKernel( queue, kernel, 1, NULL, threads, localThreads, 0, NULL, NULL );
124 test_error( error, "Unable to execute test kernel" );
125
126 /* Now get the results */
127 error = clEnqueueReadBuffer( queue, streams[1], true, 0, sizeof( int ) * TEST_SIZE, outData, 0, NULL, NULL );
128 test_error( error, "Unable to read output array!" );
129
130 /* And verify! */
131 for( i = 0; i < TEST_SIZE; i++ )
132 {
133 int expected = verifyFn( vecType, vecSize, (char *)inDataA + i * get_explicit_type_size( vecType ) * g_vector_aligns[vecSize] );
134 if( expected != outData[ i ] )
135 {
136 unsigned int *ptr = (unsigned int *)( (char *)inDataA + i * get_explicit_type_size( vecType ) * g_vector_aligns[vecSize] );
137 log_error( "ERROR: Data sample %d does not validate! Expected (%d), got (%d), source 0x%08x\n",
138 i, expected, outData[i], *ptr );
139 return -1;
140 }
141 }
142
143 return 0;
144 }
145
anyVerifyFn(ExplicitType vecType,unsigned int vecSize,void * inData)146 int anyVerifyFn( ExplicitType vecType, unsigned int vecSize, void *inData )
147 {
148 unsigned int i;
149 switch( vecType )
150 {
151 case kChar:
152 {
153 char sum = 0;
154 char *tData = (char *)inData;
155 for( i = 0; i < vecSize; i++ )
156 sum |= tData[ i ] & 0x80;
157 return (sum != 0) ? 1 : 0;
158 }
159 case kShort:
160 {
161 short sum = 0;
162 short *tData = (short *)inData;
163 for( i = 0; i < vecSize; i++ )
164 sum |= tData[ i ] & 0x8000;
165 return (sum != 0);
166 }
167 case kInt:
168 {
169 cl_int sum = 0;
170 cl_int *tData = (cl_int *)inData;
171 for( i = 0; i < vecSize; i++ )
172 sum |= tData[ i ] & (cl_int)0x80000000L;
173 return (sum != 0);
174 }
175 case kLong:
176 {
177 cl_long sum = 0;
178 cl_long *tData = (cl_long *)inData;
179 for( i = 0; i < vecSize; i++ )
180 sum |= tData[ i ] & 0x8000000000000000LL;
181 return (sum != 0);
182 }
183 default:
184 return 0;
185 }
186 }
187
test_relational_any(cl_device_id device,cl_context context,cl_command_queue queue,int numElements)188 int test_relational_any(cl_device_id device, cl_context context, cl_command_queue queue, int numElements )
189 {
190 ExplicitType vecType[] = { kChar, kShort, kInt, kLong };
191 unsigned int vecSizes[] = { 1, 2, 3, 4, 8, 16, 0 };
192 unsigned int index, typeIndex;
193 int retVal = 0;
194 RandomSeed seed(gRandomSeed );
195
196 for( typeIndex = 0; typeIndex < 4; typeIndex++ )
197 {
198 if (vecType[typeIndex] == kLong && !gHasLong)
199 continue;
200
201 for( index = 0; vecSizes[ index ] != 0; index++ )
202 {
203 // Test!
204 if( test_any_all_kernel(context, queue, "any", vecType[ typeIndex ], vecSizes[ index ], anyVerifyFn, seed ) != 0 )
205 {
206 log_error( " Vector %s%d FAILED\n", get_explicit_type_name( vecType[ typeIndex ] ), vecSizes[ index ] );
207 retVal = -1;
208 }
209 }
210 }
211
212 return retVal;
213 }
214
allVerifyFn(ExplicitType vecType,unsigned int vecSize,void * inData)215 int allVerifyFn( ExplicitType vecType, unsigned int vecSize, void *inData )
216 {
217 unsigned int i;
218 switch( vecType )
219 {
220 case kChar:
221 {
222 char sum = 0x80;
223 char *tData = (char *)inData;
224 for( i = 0; i < vecSize; i++ )
225 sum &= tData[ i ] & 0x80;
226 return (sum != 0) ? 1 : 0;
227 }
228 case kShort:
229 {
230 short sum = 0x8000;
231 short *tData = (short *)inData;
232 for( i = 0; i < vecSize; i++ )
233 sum &= tData[ i ] & 0x8000;
234 return (sum != 0);
235 }
236 case kInt:
237 {
238 cl_int sum = 0x80000000L;
239 cl_int *tData = (cl_int *)inData;
240 for( i = 0; i < vecSize; i++ )
241 sum &= tData[ i ] & (cl_int)0x80000000L;
242 return (sum != 0);
243 }
244 case kLong:
245 {
246 cl_long sum = 0x8000000000000000LL;
247 cl_long *tData = (cl_long *)inData;
248 for( i = 0; i < vecSize; i++ )
249 sum &= tData[ i ] & 0x8000000000000000LL;
250 return (sum != 0);
251 }
252 default:
253 return 0;
254 }
255 }
256
test_relational_all(cl_device_id device,cl_context context,cl_command_queue queue,int numElements)257 int test_relational_all(cl_device_id device, cl_context context, cl_command_queue queue, int numElements )
258 {
259 ExplicitType vecType[] = { kChar, kShort, kInt, kLong };
260 unsigned int vecSizes[] = { 1, 2, 3, 4, 8, 16, 0 };
261 unsigned int index, typeIndex;
262 int retVal = 0;
263 RandomSeed seed(gRandomSeed );
264
265
266 for( typeIndex = 0; typeIndex < 4; typeIndex++ )
267 {
268 if (vecType[typeIndex] == kLong && !gHasLong)
269 continue;
270
271 for( index = 0; vecSizes[ index ] != 0; index++ )
272 {
273 // Test!
274 if( test_any_all_kernel(context, queue, "all", vecType[ typeIndex ], vecSizes[ index ], allVerifyFn, seed ) != 0 )
275 {
276 log_error( " Vector %s%d FAILED\n", get_explicit_type_name( vecType[ typeIndex ] ), vecSizes[ index ] );
277 retVal = -1;
278 }
279 }
280 }
281
282 return retVal;
283 }
284
285 const char *selectTestKernelPattern =
286 "%s\n" // optional pragma
287 "__kernel void sample_test(__global %s%s *sourceA, __global %s%s *sourceB, __global %s%s *sourceC, __global %s%s *destValues)\n"
288 "{\n"
289 " int tid = get_global_id(0);\n"
290 " destValues[tid] = %s( sourceA[tid], sourceB[tid], sourceC[tid] );\n"
291 "\n"
292 "}\n";
293
294
295 const char *selectTestKernelPatternVload =
296 "%s\n" // optional pragma
297 "__kernel void sample_test(__global %s%s *sourceA, __global %s%s *sourceB, __global %s%s *sourceC, __global %s%s *destValues)\n"
298 "{\n"
299 " int tid = get_global_id(0);\n"
300 " %s%s tmp = %s( vload3(tid, (__global %s *)sourceA), vload3(tid, (__global %s *)sourceB), vload3(tid, (__global %s *)sourceC) );\n"
301 " vstore3(tmp, tid, (__global %s *)destValues);\n"
302 "\n"
303 "}\n";
304
305 typedef void (*selectVerifyFn)( ExplicitType vecType, ExplicitType testVecType, unsigned int vecSize, void *inDataA, void *inDataB, void *inDataTest, void *outData );
306
test_select_kernel(cl_context context,cl_command_queue queue,const char * fnName,ExplicitType vecType,unsigned int vecSize,ExplicitType testVecType,selectVerifyFn verifyFn,MTdata d)307 int test_select_kernel(cl_context context, cl_command_queue queue, const char *fnName,
308 ExplicitType vecType, unsigned int vecSize, ExplicitType testVecType, selectVerifyFn verifyFn, MTdata d )
309 {
310 clProgramWrapper program;
311 clKernelWrapper kernel;
312 clMemWrapper streams[4];
313 cl_long inDataA[TEST_SIZE * 16], inDataB[ TEST_SIZE * 16 ], inDataC[ TEST_SIZE * 16 ];
314 cl_long outData[TEST_SIZE * 16], expected[16];
315 int error, i;
316 size_t threads[1], localThreads[1];
317 char kernelSource[10240];
318 char *programPtr;
319 char sizeName[4], outSizeName[4];
320 unsigned int outVecSize;
321
322
323 /* Create the source */
324 if( vecSize == 1 )
325 sizeName[ 0 ] = 0;
326 else
327 sprintf( sizeName, "%d", vecSize );
328
329 outVecSize = vecSize;
330
331 if( outVecSize == 1 )
332 outSizeName[ 0 ] = 0;
333 else
334 sprintf( outSizeName, "%d", outVecSize );
335
336 if(DENSE_PACK_VECS && vecSize == 3) {
337 // anyAllTestKernelPatternVload
338 sprintf( kernelSource, selectTestKernelPatternVload,
339 (vecType == kDouble || testVecType == kDouble) ? "#pragma OPENCL EXTENSION cl_khr_fp64 : enable" : "",
340 get_explicit_type_name( vecType ), sizeName,
341 get_explicit_type_name( vecType ), sizeName,
342 get_explicit_type_name( testVecType ), sizeName,
343 get_explicit_type_name( vecType ), outSizeName,
344 get_explicit_type_name( vecType ), sizeName,
345 fnName,
346 get_explicit_type_name( vecType ),
347 get_explicit_type_name( vecType ),
348 get_explicit_type_name( vecType ),
349 get_explicit_type_name( testVecType ) );
350 } else {
351 sprintf( kernelSource, selectTestKernelPattern,
352 (vecType == kDouble || testVecType == kDouble) ? "#pragma OPENCL EXTENSION cl_khr_fp64 : enable" : "",
353 get_explicit_type_name( vecType ), sizeName,
354 get_explicit_type_name( vecType ), sizeName,
355 get_explicit_type_name( testVecType ), sizeName,
356 get_explicit_type_name( vecType ), outSizeName,
357 fnName );
358 }
359
360 /* Create kernels */
361 programPtr = kernelSource;
362 if( create_single_kernel_helper( context, &program, &kernel, 1, (const char **)&programPtr, "sample_test" ) )
363 {
364 return -1;
365 }
366
367 /* Generate some streams */
368 generate_random_data( vecType, TEST_SIZE * g_vector_aligns[vecSize], d, inDataA );
369 generate_random_data( vecType, TEST_SIZE * g_vector_aligns[vecSize], d, inDataB );
370 generate_random_data( testVecType, TEST_SIZE * g_vector_aligns[vecSize], d, inDataC );
371
372 streams[0] = clCreateBuffer(context, CL_MEM_COPY_HOST_PTR,
373 get_explicit_type_size(vecType)
374 * g_vector_aligns[vecSize] * TEST_SIZE,
375 &inDataA, &error);
376 if( streams[0] == NULL )
377 {
378 print_error( error, "Creating input array A failed!\n");
379 return -1;
380 }
381 streams[1] = clCreateBuffer(context, CL_MEM_COPY_HOST_PTR,
382 get_explicit_type_size(vecType)
383 * g_vector_aligns[vecSize] * TEST_SIZE,
384 &inDataB, &error);
385 if( streams[1] == NULL )
386 {
387 print_error( error, "Creating input array A failed!\n");
388 return -1;
389 }
390 streams[2] = clCreateBuffer(context, CL_MEM_COPY_HOST_PTR,
391 get_explicit_type_size(testVecType)
392 * g_vector_aligns[vecSize] * TEST_SIZE,
393 &inDataC, &error);
394 if( streams[2] == NULL )
395 {
396 print_error( error, "Creating input array A failed!\n");
397 return -1;
398 }
399 streams[3] = clCreateBuffer( context, CL_MEM_READ_WRITE, get_explicit_type_size( vecType ) * g_vector_aligns[outVecSize] * TEST_SIZE, NULL, &error);
400 if( streams[3] == NULL )
401 {
402 print_error( error, "Creating output array failed!\n");
403 return -1;
404 }
405
406 /* Assign streams and execute */
407 error = clSetKernelArg( kernel, 0, sizeof( streams[0] ), &streams[0] );
408 test_error( error, "Unable to set indexed kernel arguments" );
409 error = clSetKernelArg( kernel, 1, sizeof( streams[1] ), &streams[1] );
410 test_error( error, "Unable to set indexed kernel arguments" );
411 error = clSetKernelArg( kernel, 2, sizeof( streams[2] ), &streams[2] );
412 test_error( error, "Unable to set indexed kernel arguments" );
413 error = clSetKernelArg( kernel, 3, sizeof( streams[3] ), &streams[3] );
414 test_error( error, "Unable to set indexed kernel arguments" );
415
416 /* Run the kernel */
417 threads[0] = TEST_SIZE;
418
419 error = get_max_common_work_group_size( context, kernel, threads[0], &localThreads[0] );
420 test_error( error, "Unable to get work group size to use" );
421
422 error = clEnqueueNDRangeKernel( queue, kernel, 1, NULL, threads, localThreads, 0, NULL, NULL );
423 test_error( error, "Unable to execute test kernel" );
424
425 /* Now get the results */
426 error = clEnqueueReadBuffer( queue, streams[3], true, 0, get_explicit_type_size( vecType ) * TEST_SIZE * g_vector_aligns[outVecSize], outData, 0, NULL, NULL );
427 test_error( error, "Unable to read output array!" );
428
429 /* And verify! */
430 for( i = 0; i < (int)(TEST_SIZE * g_vector_aligns[vecSize]); i++ )
431 {
432 if(i%g_vector_aligns[vecSize] >= (int) vecSize) {
433 continue;
434 }
435 verifyFn( vecType, testVecType, vecSize, (char *)inDataA + i * get_explicit_type_size( vecType ),
436 (char *)inDataB + i * get_explicit_type_size( vecType ),
437 (char *)inDataC + i * get_explicit_type_size( testVecType ),
438 expected);
439
440 char *outPtr = (char *)outData;
441 outPtr += ( i / g_vector_aligns[vecSize] ) * get_explicit_type_size( vecType ) * g_vector_aligns[outVecSize];
442 outPtr += ( i % g_vector_aligns[vecSize] ) * get_explicit_type_size( vecType );
443 if( memcmp( expected, outPtr, get_explicit_type_size( vecType ) ) != 0 )
444 {
445 log_error( "ERROR: Data sample %d:%d does not validate! Expected (0x%08x), got (0x%08x) from (0x%08x) and (0x%08x) with test (0x%08x)\n",
446 i / g_vector_aligns[vecSize],
447 i % g_vector_aligns[vecSize],
448 *( (int *)expected ),
449 *( (int *)( (char *)outData +
450 i * get_explicit_type_size( vecType
451 ) ) ),
452 *( (int *)( (char *)inDataA +
453 i * get_explicit_type_size( vecType
454 ) ) ),
455 *( (int *)( (char *)inDataB +
456 i * get_explicit_type_size( vecType
457 ) ) ),
458 *( (int *)( (char *)inDataC +
459 i*get_explicit_type_size( testVecType
460 ) ) ) );
461 int j;
462 log_error( "inA: " );
463 unsigned char *a = (unsigned char *)( (char *)inDataA + i * get_explicit_type_size( vecType ) );
464 unsigned char *b = (unsigned char *)( (char *)inDataB + i * get_explicit_type_size( vecType ) );
465 unsigned char *c = (unsigned char *)( (char *)inDataC + i * get_explicit_type_size( testVecType ) );
466 unsigned char *e = (unsigned char *)( expected );
467 unsigned char *g = (unsigned char *)( (char *)outData + i * get_explicit_type_size( vecType ) );
468 for( j = 0; j < 16; j++ )
469 log_error( "0x%02x ", a[ j ] );
470 log_error( "\ninB: " );
471 for( j = 0; j < 16; j++ )
472 log_error( "0x%02x ", b[ j ] );
473 log_error( "\ninC: " );
474 for( j = 0; j < 16; j++ )
475 log_error( "0x%02x ", c[ j ] );
476 log_error( "\nexp: " );
477 for( j = 0; j < 16; j++ )
478 log_error( "0x%02x ", e[ j ] );
479 log_error( "\ngot: " );
480 for( j = 0; j < 16; j++ )
481 log_error( "0x%02x ", g[ j ] );
482 return -1;
483 }
484 }
485
486 return 0;
487 }
488
bitselect_verify_fn(ExplicitType vecType,ExplicitType testVecType,unsigned int vecSize,void * inDataA,void * inDataB,void * inDataTest,void * outData)489 void bitselect_verify_fn( ExplicitType vecType, ExplicitType testVecType, unsigned int vecSize, void *inDataA, void *inDataB, void *inDataTest, void *outData )
490 {
491 char *inA = (char *)inDataA, *inB = (char *)inDataB, *inT = (char *)inDataTest, *out = (char *)outData;
492 size_t i, numBytes = get_explicit_type_size( vecType );
493
494 // Type is meaningless, this is all bitwise!
495 for( i = 0; i < numBytes; i++ )
496 {
497 out[ i ] = ( inA[ i ] & ~inT[ i ] ) | ( inB[ i ] & inT[ i ] );
498 }
499 }
500
test_relational_bitselect(cl_device_id device,cl_context context,cl_command_queue queue,int numElements)501 int test_relational_bitselect(cl_device_id device, cl_context context, cl_command_queue queue, int numElements )
502 {
503 ExplicitType vecType[] = { kChar, kUChar, kShort, kUShort, kInt, kUInt, kLong, kULong, kFloat, kDouble };
504 unsigned int vecSizes[] = { 1, 2, 3, 4, 8, 16, 0 };
505 unsigned int index, typeIndex;
506 int retVal = 0;
507 RandomSeed seed( gRandomSeed );
508
509
510 for( typeIndex = 0; typeIndex < 10; typeIndex++ )
511 {
512 if ((vecType[typeIndex] == kLong || vecType[typeIndex] == kULong) && !gHasLong)
513 continue;
514
515 if (vecType[typeIndex] == kDouble)
516 {
517 if(!is_extension_available(device, "cl_khr_fp64"))
518 {
519 log_info("Extension cl_khr_fp64 not supported; skipping double tests.\n");
520 continue;
521 }
522 else
523 log_info("Testing doubles.\n");
524 }
525 for( index = 0; vecSizes[ index ] != 0; index++ )
526 {
527 // Test!
528 if( test_select_kernel(context, queue, "bitselect", vecType[ typeIndex ], vecSizes[ index ], vecType[typeIndex], bitselect_verify_fn, seed ) != 0 )
529 {
530 log_error( " Vector %s%d FAILED\n", get_explicit_type_name( vecType[ typeIndex ] ), vecSizes[ index ] );
531 retVal = -1;
532 }
533 }
534 }
535
536 return retVal;
537 }
538
select_signed_verify_fn(ExplicitType vecType,ExplicitType testVecType,unsigned int vecSize,void * inDataA,void * inDataB,void * inDataTest,void * outData)539 void select_signed_verify_fn( ExplicitType vecType, ExplicitType testVecType, unsigned int vecSize, void *inDataA, void *inDataB, void *inDataTest, void *outData )
540 {
541 bool yep = false;
542 if (vecSize == 1) {
543 switch( testVecType )
544 {
545 case kChar:
546 yep = *( (char *)inDataTest ) ? true : false;
547 break;
548 case kShort:
549 yep = *( (short *)inDataTest ) ? true : false;
550 break;
551 case kInt:
552 yep = *( (int *)inDataTest ) ? true : false;
553 break;
554 case kLong:
555 yep = *( (cl_long *)inDataTest ) ? true : false;
556 break;
557 default:
558 // Should never get here
559 return;
560 }
561 }
562 else {
563 switch( testVecType )
564 {
565 case kChar:
566 yep = *( (char *)inDataTest ) & 0x80 ? true : false;
567 break;
568 case kShort:
569 yep = *( (short *)inDataTest ) & 0x8000 ? true : false;
570 break;
571 case kInt:
572 yep = *( (int *)inDataTest ) & 0x80000000L ? true : false;
573 break;
574 case kLong:
575 yep = *( (cl_long *)inDataTest ) & 0x8000000000000000LL ? true : false;
576 break;
577 default:
578 // Should never get here
579 return;
580 }
581 }
582 memcpy( outData, ( yep ) ? inDataB : inDataA, get_explicit_type_size( vecType ) );
583 }
584
test_relational_select_signed(cl_device_id device,cl_context context,cl_command_queue queue,int numElements)585 int test_relational_select_signed(cl_device_id device, cl_context context, cl_command_queue queue, int numElements )
586 {
587 ExplicitType vecType[] = { kChar, kUChar, kShort, kUShort, kInt, kUInt, kLong, kULong, kFloat, kDouble };
588 ExplicitType testVecType[] = { kChar, kShort, kInt, kLong, kNumExplicitTypes };
589 unsigned int vecSizes[] = { 1, 2, 4, 8, 16, 0 };
590 unsigned int index, typeIndex, testTypeIndex;
591 int retVal = 0;
592 RandomSeed seed( gRandomSeed );
593
594 for( typeIndex = 0; typeIndex < 10; typeIndex++ )
595 {
596 if ((vecType[typeIndex] == kLong || vecType[typeIndex] == kULong) && !gHasLong)
597 continue;
598
599 if (vecType[typeIndex] == kDouble) {
600 if(!is_extension_available(device, "cl_khr_fp64")) {
601 log_info("Extension cl_khr_fp64 not supported; skipping double tests.\n");
602 continue;
603 } else {
604 log_info("Testing doubles.\n");
605 }
606 }
607 for( testTypeIndex = 0; testVecType[ testTypeIndex ] != kNumExplicitTypes; testTypeIndex++ )
608 {
609 if( testVecType[ testTypeIndex ] != vecType[ typeIndex ] )
610 continue;
611
612 for( index = 0; vecSizes[ index ] != 0; index++ )
613 {
614 // Test!
615 if( test_select_kernel(context, queue, "select", vecType[ typeIndex ], vecSizes[ index ], testVecType[ testTypeIndex ], select_signed_verify_fn, seed ) != 0 )
616 {
617 log_error( " Vector %s%d, test vector %s%d FAILED\n", get_explicit_type_name( vecType[ typeIndex ] ), vecSizes[ index ],
618 get_explicit_type_name( testVecType[ testTypeIndex ] ), vecSizes[ index ] );
619 retVal = -1;
620 }
621 }
622 }
623 }
624
625 return retVal;
626 }
627
select_unsigned_verify_fn(ExplicitType vecType,ExplicitType testVecType,unsigned int vecSize,void * inDataA,void * inDataB,void * inDataTest,void * outData)628 void select_unsigned_verify_fn( ExplicitType vecType, ExplicitType testVecType, unsigned int vecSize, void *inDataA, void *inDataB, void *inDataTest, void *outData )
629 {
630 bool yep = false;
631 if (vecSize == 1) {
632 switch( testVecType )
633 {
634 case kUChar:
635 yep = *( (unsigned char *)inDataTest ) ? true : false;
636 break;
637 case kUShort:
638 yep = *( (unsigned short *)inDataTest ) ? true : false;
639 break;
640 case kUInt:
641 yep = *( (unsigned int *)inDataTest ) ? true : false;
642 break;
643 case kULong:
644 yep = *( (cl_ulong *)inDataTest ) ? true : false;
645 break;
646 default:
647 // Should never get here
648 return;
649 }
650 }
651 else {
652 switch( testVecType )
653 {
654 case kUChar:
655 yep = *( (unsigned char *)inDataTest ) & 0x80 ? true : false;
656 break;
657 case kUShort:
658 yep = *( (unsigned short *)inDataTest ) & 0x8000 ? true : false;
659 break;
660 case kUInt:
661 yep = *( (unsigned int *)inDataTest ) & 0x80000000L ? true : false;
662 break;
663 case kULong:
664 yep = *( (cl_ulong *)inDataTest ) & 0x8000000000000000LL ? true : false;
665 break;
666 default:
667 // Should never get here
668 return;
669 }
670 }
671 memcpy( outData, ( yep ) ? inDataB : inDataA, get_explicit_type_size( vecType ) );
672 }
673
test_relational_select_unsigned(cl_device_id device,cl_context context,cl_command_queue queue,int numElements)674 int test_relational_select_unsigned(cl_device_id device, cl_context context, cl_command_queue queue, int numElements )
675 {
676 ExplicitType vecType[] = { kChar, kUChar, kShort, kUShort, kInt, kUInt, kLong, kULong, kFloat, kDouble };
677 ExplicitType testVecType[] = { kUChar, kUShort, kUInt, kULong, kNumExplicitTypes };
678 unsigned int vecSizes[] = { 1, 2, 4, 8, 16, 0 };
679 unsigned int index, typeIndex, testTypeIndex;
680 int retVal = 0;
681 RandomSeed seed(gRandomSeed);
682
683
684 for( typeIndex = 0; typeIndex < 10; typeIndex++ )
685 {
686 if ((vecType[typeIndex] == kLong || vecType[typeIndex] == kULong) && !gHasLong)
687 continue;
688
689 if (vecType[typeIndex] == kDouble) {
690 if(!is_extension_available(device, "cl_khr_fp64")) {
691 log_info("Extension cl_khr_fp64 not supported; skipping double tests.\n");
692 continue;
693 } else {
694 log_info("Testing doubles.\n");
695 }
696 }
697 for( testTypeIndex = 0; testVecType[ testTypeIndex ] != kNumExplicitTypes; testTypeIndex++ )
698 {
699 if( testVecType[ testTypeIndex ] != vecType[ typeIndex ] )
700 continue;
701
702 for( index = 0; vecSizes[ index ] != 0; index++ )
703 {
704 // Test!
705 if( test_select_kernel(context, queue, "select", vecType[ typeIndex ], vecSizes[ index ], testVecType[ testTypeIndex ], select_unsigned_verify_fn, seed ) != 0 )
706 {
707 log_error( " Vector %s%d, test vector %s%d FAILED\n", get_explicit_type_name( vecType[ typeIndex ] ), vecSizes[ index ],
708 get_explicit_type_name( testVecType[ testTypeIndex ] ), vecSizes[ index ] );
709 retVal = -1;
710 }
711 }
712 }
713 }
714
715 return retVal;
716 }
717
718
719
720 extern int test_relational_isequal_float(cl_device_id device, cl_context context, cl_command_queue queue, int numElements );
721 extern int test_relational_isnotequal_float(cl_device_id device, cl_context context, cl_command_queue queue, int numElements );
722 extern int test_relational_isgreater_float(cl_device_id device, cl_context context, cl_command_queue queue, int numElements );
723 extern int test_relational_isgreaterequal_float(cl_device_id device, cl_context context, cl_command_queue queue, int numElements );
724 extern int test_relational_isless_float(cl_device_id device, cl_context context, cl_command_queue queue, int numElements );
725 extern int test_relational_islessequal_float(cl_device_id device, cl_context context, cl_command_queue queue, int numElements );
726 extern int test_relational_islessgreater_float(cl_device_id device, cl_context context, cl_command_queue queue, int numElements );
727 extern int test_relational_isequal_double(cl_device_id device, cl_context context, cl_command_queue queue, int numElements );
728 extern int test_relational_isnotequal_double(cl_device_id device, cl_context context, cl_command_queue queue, int numElements );
729 extern int test_relational_isgreater_double(cl_device_id device, cl_context context, cl_command_queue queue, int numElements );
730 extern int test_relational_isgreaterequal_double(cl_device_id device, cl_context context, cl_command_queue queue, int numElements );
731 extern int test_relational_isless_double(cl_device_id device, cl_context context, cl_command_queue queue, int numElements );
732 extern int test_relational_islessequal_double(cl_device_id device, cl_context context, cl_command_queue queue, int numElements );
733 extern int test_relational_islessgreater_double(cl_device_id device, cl_context context, cl_command_queue queue, int numElements );
734
735
test_relational_isequal(cl_device_id device,cl_context context,cl_command_queue queue,int numElements)736 int test_relational_isequal(cl_device_id device, cl_context context, cl_command_queue queue, int numElements )
737 {
738 int err = 0;
739 err |= test_relational_isequal_float( device, context, queue, numElements );
740 err |= test_relational_isequal_double( device, context, queue, numElements );
741 return err;
742 }
743
744
test_relational_isnotequal(cl_device_id device,cl_context context,cl_command_queue queue,int numElements)745 int test_relational_isnotequal(cl_device_id device, cl_context context, cl_command_queue queue, int numElements )
746 {
747 int err = 0;
748 err |= test_relational_isnotequal_float( device, context, queue, numElements );
749 err |= test_relational_isnotequal_double( device, context, queue, numElements );
750 return err;
751 }
752
753
test_relational_isgreater(cl_device_id device,cl_context context,cl_command_queue queue,int numElements)754 int test_relational_isgreater(cl_device_id device, cl_context context, cl_command_queue queue, int numElements )
755 {
756 int err = 0;
757 err |= test_relational_isgreater_float( device, context, queue, numElements );
758 err |= test_relational_isgreater_double( device, context, queue, numElements );
759 return err;
760 }
761
762
test_relational_isgreaterequal(cl_device_id device,cl_context context,cl_command_queue queue,int numElements)763 int test_relational_isgreaterequal(cl_device_id device, cl_context context, cl_command_queue queue, int numElements )
764 {
765 int err = 0;
766 err |= test_relational_isgreaterequal_float( device, context, queue, numElements );
767 err |= test_relational_isgreaterequal_double( device, context, queue, numElements );
768 return err;
769 }
770
771
test_relational_isless(cl_device_id device,cl_context context,cl_command_queue queue,int numElements)772 int test_relational_isless(cl_device_id device, cl_context context, cl_command_queue queue, int numElements )
773 {
774 int err = 0;
775 err |= test_relational_isless_float( device, context, queue, numElements );
776 err |= test_relational_isless_double( device, context, queue, numElements );
777 return err;
778 }
779
780
test_relational_islessequal(cl_device_id device,cl_context context,cl_command_queue queue,int numElements)781 int test_relational_islessequal(cl_device_id device, cl_context context, cl_command_queue queue, int numElements )
782 {
783 int err = 0;
784 err |= test_relational_islessequal_float( device, context, queue, numElements );
785 err |= test_relational_islessequal_double( device, context, queue, numElements );
786 return err;
787 }
788
789
test_relational_islessgreater(cl_device_id device,cl_context context,cl_command_queue queue,int numElements)790 int test_relational_islessgreater(cl_device_id device, cl_context context, cl_command_queue queue, int numElements )
791 {
792 int err = 0;
793 err |= test_relational_islessgreater_float( device, context, queue, numElements );
794 err |= test_relational_islessgreater_double( device, context, queue, numElements );
795 return err;
796 }
797
798
799