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