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 <stdio.h>
19 #include <string.h>
20 #include <sys/types.h>
21 #include <sys/stat.h>
22
23 #include "procs.h"
24 #include "harness/errorHelpers.h"
25
min_verify_float(float * x,float * y,float * out,int numElements,int vecSize)26 static int min_verify_float( float *x, float *y, float *out, int numElements, int vecSize )
27 {
28 for( int i = 0; i < numElements; i++ )
29 {
30 for( int j = 0; j < vecSize; j++ )
31 {
32 float v = ( y[ i ] < x[ i * vecSize + j ] ) ? y[ i ] : x[ i * vecSize + j ];
33 if( v != out[ i * vecSize + j ] )
34 {
35 log_error( "Failure for vector size %d at position %d, element %d:\n\t min(%a, %a) = *%a vs %a\n", vecSize, i, j, x[ i * vecSize + j ], y[i], v, out[ i * vecSize + j ] );
36 return -1;
37 }
38 }
39 }
40 return 0;
41 }
42
min_verify_double(double * x,double * y,double * out,int numElements,int vecSize)43 static int min_verify_double( double *x, double *y, double *out, int numElements, int vecSize )
44 {
45 int maxFail = 1;
46 int numFails = 0;
47 for( int i = 0; i < numElements; i++ )
48 {
49 for( int j = 0; j < vecSize; j++ )
50 {
51 double v = ( y[ i ] < x[ i * vecSize + j ] ) ? y[ i ] : x[ i * vecSize + j ];
52 if( v != out[ i * vecSize + j ] )
53 {
54 log_error( "Failure for vector size %d at position %d, element %d:\n\t min(%a, %a) = *%a vs %a\n", vecSize, i, j, x[ i * vecSize + j ], y[i], v, out[ i * vecSize + j ] );
55 ++numFails;
56 if(numFails >= maxFail) {
57 return -1;
58 }
59 }
60 }
61 }
62 return 0;
63 }
64
test_minf(cl_device_id device,cl_context context,cl_command_queue queue,int n_elems)65 int test_minf(cl_device_id device, cl_context context, cl_command_queue queue, int n_elems)
66 {
67 return test_binary_fn( device, context, queue, n_elems, "min", false, min_verify_float, min_verify_double );
68 }
69
70
71