// // Copyright (c) 2017 The Khronos Group Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // #include "harness/compat.h" #include #include #include #include #include #include "procs.h" static int verify_abs_char( const void *p, const void *q, size_t n, const char *sizeName, size_t vecSize ) { const cl_char *inA = (const cl_char*) p; const cl_uchar *outptr = (const cl_uchar*) q; size_t i; for( i = 0; i < n; i++ ) { cl_uchar r = inA[i]; if( inA[i] < 0 ) r = -inA[i]; if( r != outptr[i] ) { log_info( "%ld) Failure for abs( (char%s) 0x%2.2x) = *0x%2.2x vs 0x%2.2x\n", i, sizeName, inA[i],r, outptr[i] ); return -1; } } return 0; } static int verify_abs_short( const void *p, const void *q, size_t n, const char *sizeName, size_t vecSize ) { const cl_short *inA = (const cl_short*) p; const cl_ushort *outptr = (const cl_ushort*) q; size_t i; for( i = 0; i < n; i++ ) { cl_ushort r = inA[i]; if( inA[i] < 0 ) r = -inA[i]; if( r != outptr[i] ) { log_info( "%ld) Failure for abs( (short%s) 0x%4.4x) = *0x%4.4x vs 0x%4.4x\n", i, sizeName, inA[i],r, outptr[i] ); return -1; } } return 0; } static int verify_abs_int( const void *p, const void *q, size_t n, const char *sizeName , size_t vecSize) { const cl_int *inA = (const cl_int*) p; const cl_uint *outptr = (const cl_uint*) q; size_t i; for( i = 0; i < n; i++ ) { cl_uint r = inA[i]; if( inA[i] < 0 ) r = -inA[i]; if( r != outptr[i] ) { log_info( "%ld) Failure for abs( (int%s) 0x%2.2x) = *0x%8.8x vs 0x%8.8x\n", i, sizeName, inA[i],r, outptr[i] ); return -1; } } return 0; } static int verify_abs_long( const void *p, const void *q, size_t n, const char *sizeName, size_t vecSize ) { const cl_long *inA = (const cl_long*) p; const cl_ulong *outptr = (const cl_ulong*) q; size_t i; for( i = 0; i < n; i++ ) { cl_ulong r = inA[i]; if( inA[i] < 0 ) r = -inA[i]; if( r != outptr[i] ) { log_info( "%ld) Failure for abs( (long%s) 0x%16.16llx) = *0x%16.16llx vs 0x%16.16llx\n", i, sizeName, inA[i],r, outptr[i] ); return -1; } } return 0; } static int verify_abs_uchar( const void *p, const void *q, size_t n, const char *sizeName, size_t vecSize ) { const cl_uchar *inA = (const cl_uchar*) p; const cl_uchar *outptr = (const cl_uchar*) q; size_t i; for( i = 0; i < n; i++ ) { cl_uchar r = inA[i]; if( r != outptr[i] ) { log_info( "%ld) Failure for abs( (uchar%s) 0x%2.2x) = *0x%2.2x vs 0x%2.2x\n", i, sizeName, inA[i],r, outptr[i] ); return -1; } } return 0; } static int verify_abs_ushort( const void *p, const void *q, size_t n, const char *sizeName, size_t vecSize ) { const cl_ushort *inA = (const cl_ushort*) p; const cl_ushort *outptr = (const cl_ushort*) q; size_t i; for( i = 0; i < n; i++ ) { cl_ushort r = inA[i]; if( r != outptr[i] ) { log_info( "%ld) Failure for abs( (short%s) 0x%4.4x) = *0x%4.4x vs 0x%4.4x\n", i, sizeName, inA[i],r, outptr[i] ); return -1; } } return 0; } static int verify_abs_uint( const void *p, const void *q, size_t n, const char *sizeName , size_t vecSize) { const cl_uint *inA = (const cl_uint*) p; const cl_uint *outptr = (const cl_uint*) q; size_t i; for( i = 0; i < n; i++ ) { cl_uint r = inA[i]; if( r != outptr[i] ) { log_info( "%ld) Failure for abs( (int%s) 0x%2.2x) = *0x%8.8x vs 0x%8.8x\n", i, sizeName, inA[i],r, outptr[i] ); return -1; } } return 0; } static int verify_abs_ulong( const void *p, const void *q, size_t n, const char *sizeName, size_t vecSize ) { const cl_ulong *inA = (const cl_ulong*) p; const cl_ulong *outptr = (const cl_ulong*) q; size_t i; for( i = 0; i < n; i++ ) { cl_ulong r = inA[i]; if( r != outptr[i] ) { log_info( "%ld) Failure for abs( (long%s) 0x%16.16llx) = *0x%16.16llx vs 0x%16.16llx\n", i, sizeName, inA[i],r, outptr[i] ); return -1; } } return 0; } typedef int (*verifyFunc)( const void *, const void *, size_t n, const char *sizeName, size_t vecSize ); static const verifyFunc verify[] = { verify_abs_char, verify_abs_short, verify_abs_int, verify_abs_long, verify_abs_uchar, verify_abs_ushort, verify_abs_uint, verify_abs_ulong }; static const char *test_str_names[] = { "char", "short", "int", "long" , "uchar", "ushort", "uint", "ulong"}; static const char *test_ustr_names[] = { "uchar", "ushort", "uint", "ulong" , "uchar", "ushort", "uint", "ulong"}; static const int vector_sizes[] = {1, 2, 3, 4, 8, 16}; static const char *vector_size_names[] = { "", "2", "3", "4", "8", "16" }; static const char *vector_size_names_io_types[] = { "", "2", "", "4", "8", "16" }; static const size_t kSizes[9] = { 1, 2, 4, 8, 1, 2, 4, 8 }; static const char * source_loads[] = { "srcA[tid]", "vload3(tid, srcA)" }; static const char * dest_stores[] = { " dst[tid] = tmp;\n", " vstore3(tmp, tid, dst);\n" }; int test_integer_abs(cl_device_id device, cl_context context, cl_command_queue queue, int n_elems) { cl_int *input_ptr, *output_ptr, *p; int err; int i; cl_uint vectorSizeIdx; cl_uint type; MTdata d; int fail_count = 0; size_t length = sizeof(cl_int) * 4 * n_elems; input_ptr = (cl_int*)malloc(length); output_ptr = (cl_int*)malloc(length); p = input_ptr; d = init_genrand( gRandomSeed ); for (i=0; i