-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcheck.hpp
41 lines (34 loc) · 1.25 KB
/
check.hpp
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
#ifndef __CHECK_HPP__
#define __CHECK_HPP__
#include <cstdio>
#include <cstdlib>
#include <cuda_runtime.h>
#include <cupti.h>
#include "cbits/fmt/format.h"
extern void log_debug(const char *msg);
extern void log_info(const char *msg);
extern void log_error(const char *msg);
static inline void gpuAssert(cudaError_t code, const char *file,
const char *func, int line) {
if (code != cudaSuccess) {
fmt::MemoryWriter msg;
msg.write("CUDA_CHECK: {} in {} {} {}\n", cudaGetErrorString(code), func,
file, line);
log_error(msg.c_str());
}
}
static inline void cuptiAssert(CUptiResult code, const char *file,
const char *func, int line, bool abort = false) {
if (code != CUPTI_SUCCESS) {
const char *errstr;
cuptiGetResultString(code, &errstr);
fmt::MemoryWriter msg;
msg.write("CUPI_CHECK: {} in {} {} {}\n", errstr, func, file, line);
log_error(msg.c_str());
}
}
#define CUDA_CHECK(ans) \
{ gpuAssert((ans), __FILE__, __func__, __LINE__); }
#define CUPTI_CHECK(ans) \
{ cuptiAssert((ans), __FILE__, __func__, __LINE__); }
#endif // __CHECK_HPP__