mirror of
https://github.com/NVIDIA/cuda-samples.git
synced 2026-10-25 22:28:17 +08:00
Apply consistent code formatting across the repo. Add clang-format and pre-commit hooks.
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -37,8 +37,8 @@
|
||||
|
||||
#define SWITCH_CHAR '-'
|
||||
|
||||
#define REFFUNC(funcname) ref_##funcname
|
||||
#define TESTGEN(funcname) get_##funcname##_params
|
||||
#define REFFUNC(funcname) ref_##funcname
|
||||
#define TESTGEN(funcname) get_##funcname##_params
|
||||
#define TESTPARAMS(funcname) funcname##TestParams
|
||||
|
||||
#define DEV_VER_DBL_SUPPORT (130)
|
||||
@@ -54,10 +54,11 @@
|
||||
//==============================================================================
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
extern "C"
|
||||
{
|
||||
#endif /* __cplusplus */
|
||||
int getDeviceVersion(void);
|
||||
size_t getDeviceMemory(void);
|
||||
int getDeviceVersion(void);
|
||||
size_t getDeviceMemory(void);
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
@@ -68,71 +69,58 @@ size_t getDeviceMemory(void);
|
||||
|
||||
static __inline__ int imax(int x, int y) { return (x > y) ? x : y; }
|
||||
|
||||
static __inline__ unsigned floatAsUInt(float x) {
|
||||
volatile union {
|
||||
float f;
|
||||
unsigned i;
|
||||
} xx;
|
||||
xx.f = x;
|
||||
return xx.i;
|
||||
static __inline__ unsigned floatAsUInt(float x)
|
||||
{
|
||||
volatile union
|
||||
{
|
||||
float f;
|
||||
unsigned i;
|
||||
} xx;
|
||||
xx.f = x;
|
||||
return xx.i;
|
||||
}
|
||||
|
||||
static __inline__ unsigned long long doubleAsULL(double x) {
|
||||
volatile union {
|
||||
double f;
|
||||
unsigned long long i;
|
||||
} xx;
|
||||
xx.f = x;
|
||||
return xx.i;
|
||||
static __inline__ unsigned long long doubleAsULL(double x)
|
||||
{
|
||||
volatile union
|
||||
{
|
||||
double f;
|
||||
unsigned long long i;
|
||||
} xx;
|
||||
xx.f = x;
|
||||
return xx.i;
|
||||
}
|
||||
|
||||
static __inline__ unsigned cuRand(void) {
|
||||
/* George Marsaglia's fast inline random number generator */
|
||||
static __inline__ unsigned cuRand(void)
|
||||
{
|
||||
/* George Marsaglia's fast inline random number generator */
|
||||
#define CUDA_ZNEW (cuda_z = 36969 * (cuda_z & 65535) + (cuda_z >> 16))
|
||||
#define CUDA_WNEW (cuda_w = 18000 * (cuda_w & 65535) + (cuda_w >> 16))
|
||||
#define CUDA_MWC ((CUDA_ZNEW << 16) + CUDA_WNEW)
|
||||
#define CUDA_SHR3 \
|
||||
(cuda_jsr = cuda_jsr ^ (cuda_jsr << 17), \
|
||||
cuda_jsr = cuda_jsr ^ (cuda_jsr >> 13), \
|
||||
cuda_jsr = cuda_jsr ^ (cuda_jsr << 5))
|
||||
#define CUDA_MWC ((CUDA_ZNEW << 16) + CUDA_WNEW)
|
||||
#define CUDA_SHR3 \
|
||||
(cuda_jsr = cuda_jsr ^ (cuda_jsr << 17), \
|
||||
cuda_jsr = cuda_jsr ^ (cuda_jsr >> 13), \
|
||||
cuda_jsr = cuda_jsr ^ (cuda_jsr << 5))
|
||||
#define CUDA_CONG (cuda_jcong = 69069 * cuda_jcong + 1234567)
|
||||
#define KISS ((CUDA_MWC ^ CUDA_CONG) + CUDA_SHR3)
|
||||
static unsigned int cuda_z = 362436069, cuda_w = 521288629;
|
||||
static unsigned int cuda_jsr = 123456789, cuda_jcong = 380116160;
|
||||
return KISS;
|
||||
#define KISS ((CUDA_MWC ^ CUDA_CONG) + CUDA_SHR3)
|
||||
static unsigned int cuda_z = 362436069, cuda_w = 521288629;
|
||||
static unsigned int cuda_jsr = 123456789, cuda_jcong = 380116160;
|
||||
return KISS;
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
// cuGet and cuEqual versions
|
||||
//==============================================================================
|
||||
|
||||
template <typename T_ELEM>
|
||||
__inline__ __device__ __host__ T_ELEM cuGet(double);
|
||||
template <>
|
||||
__inline__ __device__ __host__ float cuGet<float>(double x) {
|
||||
return float(x);
|
||||
}
|
||||
template <>
|
||||
__inline__ __device__ __host__ double cuGet<double>(double x) {
|
||||
return double(x);
|
||||
}
|
||||
template <typename T_ELEM> __inline__ __device__ __host__ T_ELEM cuGet(double);
|
||||
template <> __inline__ __device__ __host__ float cuGet<float>(double x) { return float(x); }
|
||||
template <> __inline__ __device__ __host__ double cuGet<double>(double x) { return double(x); }
|
||||
|
||||
template <typename T_ELEM>
|
||||
__inline__ __device__ __host__ T_ELEM cuGet(double, double);
|
||||
template <>
|
||||
__inline__ __device__ __host__ float cuGet<float>(double x, double y) {
|
||||
return float(x);
|
||||
}
|
||||
template <>
|
||||
__inline__ __device__ __host__ double cuGet<double>(double x, double y) {
|
||||
return double(x);
|
||||
}
|
||||
static __inline__ __device__ __host__ bool cuEqual(float x, float y) {
|
||||
return (x == y);
|
||||
}
|
||||
static __inline__ __device__ __host__ bool cuEqual(double x, double y) {
|
||||
return (x == y);
|
||||
}
|
||||
template <typename T_ELEM> __inline__ __device__ __host__ T_ELEM cuGet(double, double);
|
||||
template <> __inline__ __device__ __host__ float cuGet<float>(double x, double y) { return float(x); }
|
||||
template <> __inline__ __device__ __host__ double cuGet<double>(double x, double y) { return double(x); }
|
||||
static __inline__ __device__ __host__ bool cuEqual(float x, float y) { return (x == y); }
|
||||
static __inline__ __device__ __host__ bool cuEqual(double x, double y) { return (x == y); }
|
||||
|
||||
//==============================================================================
|
||||
// Platform dependent timing utility
|
||||
@@ -143,33 +131,36 @@ static __inline__ __device__ __host__ bool cuEqual(double x, double y) {
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#endif
|
||||
#include <windows.h>
|
||||
static __inline__ double second(void) {
|
||||
LARGE_INTEGER t;
|
||||
static double oofreq;
|
||||
static int checkedForHighResTimer;
|
||||
static BOOL hasHighResTimer;
|
||||
static __inline__ double second(void)
|
||||
{
|
||||
LARGE_INTEGER t;
|
||||
static double oofreq;
|
||||
static int checkedForHighResTimer;
|
||||
static BOOL hasHighResTimer;
|
||||
|
||||
if (!checkedForHighResTimer) {
|
||||
hasHighResTimer = QueryPerformanceFrequency(&t);
|
||||
oofreq = 1.0 / (double)t.QuadPart;
|
||||
checkedForHighResTimer = 1;
|
||||
}
|
||||
if (!checkedForHighResTimer) {
|
||||
hasHighResTimer = QueryPerformanceFrequency(&t);
|
||||
oofreq = 1.0 / (double)t.QuadPart;
|
||||
checkedForHighResTimer = 1;
|
||||
}
|
||||
|
||||
if (hasHighResTimer) {
|
||||
QueryPerformanceCounter(&t);
|
||||
return (double)t.QuadPart * oofreq;
|
||||
} else {
|
||||
return (double)GetTickCount() / 1000.0;
|
||||
}
|
||||
if (hasHighResTimer) {
|
||||
QueryPerformanceCounter(&t);
|
||||
return (double)t.QuadPart * oofreq;
|
||||
}
|
||||
else {
|
||||
return (double)GetTickCount() / 1000.0;
|
||||
}
|
||||
}
|
||||
#elif defined(__linux__) || defined(__QNX__)
|
||||
#include <stddef.h>
|
||||
#include <sys/resource.h>
|
||||
#include <sys/time.h>
|
||||
static double second(void) {
|
||||
struct timeval tv;
|
||||
gettimeofday(&tv, NULL);
|
||||
return (double)tv.tv_sec + (double)tv.tv_usec / 1000000.0;
|
||||
static double second(void)
|
||||
{
|
||||
struct timeval tv;
|
||||
gettimeofday(&tv, NULL);
|
||||
return (double)tv.tv_sec + (double)tv.tv_usec / 1000000.0;
|
||||
}
|
||||
#elif defined(__APPLE__)
|
||||
#include <stddef.h>
|
||||
@@ -177,10 +168,11 @@ static double second(void) {
|
||||
#include <sys/sysctl.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/types.h>
|
||||
static double second(void) {
|
||||
struct timeval tv;
|
||||
gettimeofday(&tv, NULL);
|
||||
return (double)tv.tv_sec + (double)tv.tv_usec / 1000000.0;
|
||||
static double second(void)
|
||||
{
|
||||
struct timeval tv;
|
||||
gettimeofday(&tv, NULL);
|
||||
return (double)tv.tv_sec + (double)tv.tv_usec / 1000000.0;
|
||||
}
|
||||
#else
|
||||
#error unsupported platform
|
||||
|
||||
Reference in New Issue
Block a user