-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcuda_utils.h
More file actions
27 lines (24 loc) · 1.15 KB
/
Copy pathcuda_utils.h
File metadata and controls
27 lines (24 loc) · 1.15 KB
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
#pragma once
#include <cstdlib>
#include <cuda_runtime.h>
#include <iostream>
// Macro kiểm tra lỗi CUDA chuẩn
#define CUDA_CHECK(call) \
do { \
cudaError_t err = call; \
if (err != cudaSuccess) { \
std::cerr << "CUDA Error: " << cudaGetErrorString(err) \
<< " (err_num=" << err << ") at " << __FILE__ << ":" \
<< __LINE__ << std::endl; \
exit(1); \
} \
} while (0)
// Hàm kiểm tra kernel launch (gọi sau mỗi kernel <<<...>>>)
inline void checkKernelError(const char *msg) {
cudaError_t err = cudaGetLastError();
if (err != cudaSuccess) {
std::cerr << "Kernel Launch Error (" << msg
<< "): " << cudaGetErrorString(err) << std::endl;
exit(1);
}
}