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