• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 * vecSize; i++ )
28     {
29         float v = ( x[ i ] < y[ i ] ) ? y[ i ] : x[ i ];
30         if( v != out[ i ] )
31         {
32             log_error("x[%d]=%g y[%d]=%g out[%d]=%g, expected %g. (index %d is vector %d, element %d, for vector size %d)\n",
33                 i, x[i], i, y[i], i, out[i], v, i, i/vecSize, i%vecSize, vecSize);
34             return -1;
35         }
36     }
37     return 0;
38 }
39 
max_verify_double(double * x,double * y,double * out,int numElements,int vecSize)40 static int max_verify_double( double *x, double *y, double *out, int numElements, int vecSize )
41 {
42     for( int i = 0; i < numElements * vecSize; i++ )
43     {
44         double v = ( x[ i ] < y[ i ] ) ? y[ i ] : x[ i ];
45         if( v != out[ i ] )
46         {
47             log_error("x[%d]=%g y[%d]=%g out[%d]=%g, expected %g. (index %d is vector %d, element %d, for vector size %d)\n",
48                 i, x[i], i, y[i], i, out[i], v, i, i/vecSize, i%vecSize, vecSize);
49             return -1;
50         }
51     }
52     return 0;
53 }
54 
test_max(cl_device_id device,cl_context context,cl_command_queue queue,int n_elems)55 int test_max(cl_device_id device, cl_context context, cl_command_queue queue, int n_elems)
56 {
57     return test_binary_fn( device, context, queue, n_elems, "max", true, max_verify_float, max_verify_double );
58 }
59 
60 
61