ThunderSVM
ThunderSVM: An Open-Source SVM Library on GPUs and CPUs
include
thundersvm
util
common.h
1
//
2
// Created by jiashuai on 17-9-21.
3
//
4
5
#ifndef THUNDERSVM_COMMON_H
6
#define THUNDERSVM_COMMON_H
7
#ifndef max
8
9
template
<
class
T>
10
static
inline
T max(T x, T y) {
return
(x > y) ? x : y; }
11
12
#endif
13
#ifndef min
14
15
template
<
class
T>
16
static
inline
T min(T x, T y) {
return
(x < y) ? x : y; }
17
18
#endif
19
20
inline
int
max2power(
int
n) {
21
return
int(pow(2, floor(log2f(
float
(n)))));
22
}
23
const
int
BLOCK_SIZE = 512;
24
25
const
int
NUM_BLOCKS = 32 * 56;
26
27
28
#ifdef USE_CUDA
29
30
#include "cuda_runtime_api.h"
31
32
#define CUDA_CHECK(condition) \
33
/* Code block avoids redefinition of cudaError_t error */
\
34
do { \
35
cudaError_t error = condition; \
36
CHECK_EQ(error, cudaSuccess) << " " << cudaGetErrorString(error); \
37
} while (0)
38
#define SAFE_KERNEL_LAUNCH(kernel_name, ...) \
39
kernel_name<<<NUM_BLOCKS,BLOCK_SIZE>>>(__VA_ARGS__);\
40
CUDA_CHECK(cudaPeekAtLastError())
41
#define KERNEL_LOOP(i, n) \
42
for (int i = blockIdx.x * blockDim.x + threadIdx.x; \
43
i < (n); \
44
i += blockDim.x * gridDim.x)
45
#else
46
#define __host__
47
#define __device__
48
#define KERNEL_LOOP(i, n) \
49
for (int i = 0; \
50
i < (n); \
51
i++)
52
#endif
53
54
#define NO_GPU \
55
LOG(FATAL)<<"Cannot use GPU when compiling without GPU"
56
#endif //THUNDERSVM_COMMON_H
Generated by
1.8.13