-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommon.h
56 lines (46 loc) · 2.14 KB
/
common.h
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
#ifndef CUDA_CHECK_H
#define CUDA_CHECK_H
#include <iostream>
#include <cublas_v2.h>
#define CUDA_CHECK(expression) \
{ \
cudaError_t status = (expression); \
if (status != cudaSuccess) { \
std::cerr << __FILE__ << " Error on line " << __LINE__ << ": " \
<< cudaGetErrorString(status) << std::endl; \
std::exit(EXIT_FAILURE); \
} \
}
#define CUDNN_CHECK(expression) \
{ \
cudnnStatus_t status = (expression); \
if (status != CUDNN_STATUS_SUCCESS) { \
std::cerr << __FILE__ << " Error on line " << __LINE__ << ": " \
<< cudnnGetErrorString(status) << std::endl; \
std::exit(EXIT_FAILURE); \
} \
}
#define CUBLAS_CHECK(expression) \
{ \
cublasStatus_t status = (expression); \
if (status != CUBLAS_STATUS_SUCCESS) { \
std::cerr << __FILE__ << " Error on line " << __LINE__ << ": " \
<< cublasGetStatusString(status) << std::endl;\
std::exit(EXIT_FAILURE); \
} \
}
static void cublasPrintMat(double* mat, int m, int n, std::string tag){
std::cout << tag << std::endl;
double *h_tmp;
CUDA_CHECK(cudaMallocHost((void **)&h_tmp, m * n * sizeof(double)));
CUDA_CHECK(cudaMemcpy(h_tmp, mat, m * n * sizeof(double), cudaMemcpyDeviceToHost));
for(int i = 0; i < m; i ++){
for(int j = 0; j < n; j++){
std::cout << h_tmp[i * n + j] << " ";
}
std::cout << std::endl;
}
std::cout << std::endl;
CUDA_CHECK(cudaFreeHost(h_tmp));
}
#endif //CUDA_CHECK_H