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
max_verify_float(float * x,float * y,float * out,int numElements,int vecSize)25 static int max_verify_float( float *x, float *y, float *out, int numElements, int vecSize )
26 {
27 for( int i = 0; i < numElements; i++ )
28 {
29 for( int j = 0; j < vecSize; j++ )
30 {
31 float v = ( x[ i * vecSize + j ] < y[ i ] ) ? y[ i ] : x[ i * vecSize + j ];
32 if( v != out[ i * vecSize + j ] )
33 {
34 log_error( "Failure for vector size %d at position %d, element %d:\n\t max(%a, %a) = *%a vs %a\n", vecSize, i, j, x[ i * vecSize + j ], y[i], v, out[ i * vecSize + j ] );
35 return -1;
36 }
37 }
38 }
39 return 0;
40 }
41
max_verify_double(double * x,double * y,double * out,int numElements,int vecSize)42 static int max_verify_double( double *x, double *y, double *out, int numElements, int vecSize )
43 {
44 for( int i = 0; i < numElements; i++ )
45 {
46 for( int j = 0; j < vecSize; j++ )
47 {
48 double v = ( x[ i * vecSize + j ] < y[ i ] ) ? y[ i ] : x[ i * vecSize + j ];
49 if( v != out[ i * vecSize + j ] )
50 {
51 log_error( "Failure for vector size %d at position %d, element %d:\n\t max(%a, %a) = *%a vs %a\n", vecSize, i, j, x[ i * vecSize + j ], y[i], v, out[ i * vecSize + j ] );
52 return -1;
53 }
54 }
55 }
56 return 0;
57 }
58
test_maxf(cl_device_id device,cl_context context,cl_command_queue queue,int n_elems)59 int test_maxf(cl_device_id device, cl_context context, cl_command_queue queue, int n_elems)
60 {
61 return test_binary_fn( device, context, queue, n_elems, "max", false, max_verify_float, max_verify_double );
62 }
63
64
65