1 #ifndef COMMON_H 2 #define COMMON_H 3 4 #define CL_HPP_ENABLE_EXCEPTIONS 5 #define CL_HPP_MINIMUM_OPENCL_VERSION 120 6 #define CL_HPP_TARGET_OPENCL_VERSION 120 7 8 #include <CL/opencl.hpp> 9 10 #if defined(__APPLE__) || defined(__MACOSX) || defined(__FreeBSD__) 11 #include <sys/types.h> 12 #endif 13 14 #include <stdlib.h> 15 #include <chrono> 16 #include <string> 17 #include <cstdint> 18 #include <algorithm> 19 20 #define TAB " " 21 #define NEWLINE "\n" 22 #ifndef __FreeBSD__ 23 #define uint unsigned int 24 #endif 25 #define ulong unsigned long 26 27 #ifdef UNUSED 28 #undef UNUSED 29 #endif 30 #define UNUSED(expr) do { (void)(expr); } while (0) 31 32 #if defined(__APPLE__) || defined(__MACOSX) 33 #define OS_NAME "Macintosh" 34 #elif defined(__ANDROID__) 35 #define OS_NAME "Android" 36 #elif defined(_WIN32) 37 #if defined(_WIN64) 38 #define OS_NAME "Win64" 39 #else 40 #define OS_NAME "Win32" 41 #endif 42 #elif defined(__linux__) 43 #if defined(__x86_64__) 44 #define OS_NAME "Linux x64" 45 #elif defined(__i386__) 46 #define OS_NAME "Linux x86" 47 #elif defined(__arm__) 48 #define OS_NAME "Linux ARM" 49 #elif defined(__aarch64__) 50 #define OS_NAME "Linux ARM64" 51 #else 52 #define OS_NAME "Linux unknown" 53 #endif 54 #elif defined(__FreeBSD__) 55 #define OS_NAME "FreeBSD" 56 #else 57 #define OS_NAME "Unknown" 58 #endif 59 60 61 typedef struct { 62 std::string deviceName; 63 std::string driverVersion; 64 65 uint numCUs; 66 uint maxWGSize; 67 uint64_t maxAllocSize; 68 uint64_t maxGlobalSize; 69 uint maxClockFreq; 70 71 bool halfSupported; 72 bool doubleSupported; 73 cl_device_type deviceType; 74 75 // Test specific options 76 uint gloalBWIters; 77 uint64_t globalBWMaxSize; 78 uint computeWgsPerCU; 79 uint computeDPWgsPerCU; 80 uint computeIters; 81 uint transferBWIters; 82 uint kernelLatencyIters; 83 uint64_t transferBWMaxSize; 84 } device_info_t; 85 86 class Timer 87 { 88 public: 89 90 std::chrono::high_resolution_clock::time_point tick, tock; 91 92 void start(); 93 94 // Stop and return time in micro-seconds 95 float stopAndTime(); 96 }; 97 98 device_info_t getDeviceInfo(cl::Device &d); 99 100 // Return time in us for the given event 101 float timeInUS(cl::Event &timeEvent); 102 103 // Round down to next multiple of the given base with an optional maximum value 104 uint64_t roundToMultipleOf(uint64_t number, uint64_t base, uint64_t maxValue = UINT64_MAX); 105 106 void populate(float *ptr, uint64_t N); 107 void populate(double *ptr, uint64_t N); 108 109 void trimString(std::string &str); 110 111 #endif // COMMON_H 112 113