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 #ifndef TESTSELECTS_INCLUDED_H 17 #define TESTSELECTS_INCLUDED_H 18 19 #include "harness/compat.h" 20 21 #include <stdio.h> 22 #include <string.h> 23 24 #ifdef __APPLE__ 25 #include <OpenCL/opencl.h> 26 #else 27 #include <CL/opencl.h> 28 #endif 29 30 // Defines the set of types we support (no support for double) 31 typedef enum { 32 kuchar = 0, 33 kchar = 1, 34 kushort = 2, 35 kshort = 3, 36 kuint = 4, 37 kint = 5, 38 kfloat = 6, 39 kulong = 7, 40 klong = 8, 41 kdouble = 9, 42 kTypeCount // always goes last 43 } Type; 44 45 46 // Support max vector size of 16 47 #define kVectorSizeCount 6 48 #define kMaxVectorSize 16 49 50 51 // Type names and their sizes in bytes 52 extern const char *type_name[kTypeCount]; 53 extern const size_t type_size[kTypeCount]; 54 55 // Associated comparison types 56 extern const Type ctype[kTypeCount][2]; 57 58 // Reference functions for the primitive (non vector) type 59 typedef void (*Select)(void *dest, void *src1, void *src2, void *cmp, size_t c); 60 extern Select refSelects[kTypeCount][2]; 61 62 // Reference functions for the primtive type but uses the vector 63 // definition of true and false 64 extern Select vrefSelects[kTypeCount][2]; 65 66 // Check functions for each output type 67 typedef size_t (*CheckResults)(void *out1, void *out2, size_t count, size_t vectorSize); 68 extern CheckResults checkResults[kTypeCount]; 69 70 // Helpful macros 71 72 // The next three functions check on different return values. Returns -1 73 // if the check failed 74 #define checkErr(err, msg) \ 75 if (err != CL_SUCCESS) { \ 76 log_error("%s failed errcode:%d\n", msg, err); \ 77 return -1; \ 78 } 79 80 #define checkZero(val, msg) \ 81 if (val == 0) { \ 82 log_error("%s failed errcode:%d\n", msg, err); \ 83 return -1; \ 84 } 85 86 #define checkNull(ptr, msg) \ 87 if (!ptr) { \ 88 log_error("%s failed\n", msg); \ 89 return -1; \ 90 } 91 92 // When a helper returns a negative one, we want to return from main 93 // with negative one. This helper prevents me from having to write 94 // this multiple time 95 #define checkHelperErr(err) \ 96 if (err == -1) { \ 97 return err; \ 98 } 99 100 101 #endif // TESTSELECTS_INCLUDED_H 102