Skip to content

Commit a171514

Browse files
psvvspSergey Pavlov
andauthored
Added cudaGetLastError() calls to reset benchmarking kernel errors (issue 88). (#173)
* Create and use NVBENCH_CUDA_CALL_RESET_ERROR. * Moved cudaGetLastError() call to NVBENCH_CUDA_CALL macro --------- Co-authored-by: Sergey Pavlov <[email protected]>
1 parent 088c9ee commit a171514

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

nvbench/cuda_call.cuh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,14 @@
2424
#include <string>
2525

2626
/// Throws a std::runtime_error if `call` doesn't return `cudaSuccess`.
27+
/// Resets the error with cudaGetLastError().
2728
#define NVBENCH_CUDA_CALL(call) \
2829
do \
2930
{ \
3031
const cudaError_t nvbench_cuda_call_error = call; \
3132
if (nvbench_cuda_call_error != cudaSuccess) \
3233
{ \
34+
cudaGetLastError(); \
3335
nvbench::cuda_call::throw_error(__FILE__, __LINE__, #call, nvbench_cuda_call_error); \
3436
} \
3537
} while (false)

testing/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ set(test_srcs
1616
named_values.cu
1717
option_parser.cu
1818
range.cu
19+
reset_error.cu
1920
ring_buffer.cu
2021
runner.cu
2122
state.cu

testing/reset_error.cu

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#include <nvbench/cuda_call.cuh>
2+
3+
#include "test_asserts.cuh"
4+
5+
6+
namespace
7+
{
8+
__global__ void multiply5(const int32_t* __restrict__ a, int32_t* __restrict__ b)
9+
{
10+
const auto id = blockIdx.x * blockDim.x + threadIdx.x;
11+
b[id] = 5 * a[id];
12+
}
13+
}
14+
15+
int main()
16+
{
17+
multiply5<<<256, 256>>>(nullptr, nullptr);
18+
19+
try
20+
{
21+
NVBENCH_CUDA_CALL(cudaStreamSynchronize(0));
22+
ASSERT(false);
23+
}
24+
catch (const std::runtime_error &)
25+
{
26+
ASSERT(cudaGetLastError() == cudaError_t::cudaSuccess);
27+
}
28+
29+
return 0;
30+
}

0 commit comments

Comments
 (0)