Skip to content

Commit

Permalink
Moved cudaGetLastError() call to NVBENCH_CUDA_CALL macro
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergey Pavlov committed May 30, 2024
1 parent b333e5c commit 9f8818b
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 21 deletions.
17 changes: 2 additions & 15 deletions nvbench/cuda_call.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,14 @@
#include <string>

/// Throws a std::runtime_error if `call` doesn't return `cudaSuccess`.
/// Resets the error with cudaGetLastError().
#define NVBENCH_CUDA_CALL(call) \
do \
{ \
const cudaError_t nvbench_cuda_call_error = call; \
if (nvbench_cuda_call_error != cudaSuccess) \
{ \
cudaGetLastError(); \
nvbench::cuda_call::throw_error(__FILE__, __LINE__, #call, nvbench_cuda_call_error); \
} \
} while (false)
Expand Down Expand Up @@ -57,21 +59,6 @@
} \
} while (false)

/// Throws a std::runtime_error if `call` doesn't return `cudaSuccess`.
/// Resets the error with cudaGetLastError().
#define NVBENCH_CUDA_CALL_RESET_ERROR(call) \
do \
{ \
const cudaError_t nvbench_cuda_call_error = call; \
if (nvbench_cuda_call_error != cudaSuccess) \
{ \
cudaGetLastError(); \
nvbench::cuda_call::throw_error(__FILE__, __LINE__, #call, nvbench_cuda_call_error); \
} \
} \
while (false)


namespace nvbench::cuda_call
{

Expand Down
2 changes: 1 addition & 1 deletion nvbench/detail/measure_cold.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ protected:

__forceinline__ void sync_stream() const
{
NVBENCH_CUDA_CALL_RESET_ERROR(cudaStreamSynchronize(m_launch.get_stream()));
NVBENCH_CUDA_CALL(cudaStreamSynchronize(m_launch.get_stream()));
}

void block_stream();
Expand Down
2 changes: 1 addition & 1 deletion nvbench/detail/measure_cupti.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ protected:

__forceinline__ void sync_stream() const
{
NVBENCH_CUDA_CALL_RESET_ERROR(cudaStreamSynchronize(m_launch.get_stream()));
NVBENCH_CUDA_CALL(cudaStreamSynchronize(m_launch.get_stream()));
}

nvbench::state &m_state;
Expand Down
2 changes: 1 addition & 1 deletion nvbench/detail/measure_hot.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ private:

__forceinline__ void sync_stream() const
{
NVBENCH_CUDA_CALL_RESET_ERROR(cudaStreamSynchronize(m_launch.get_stream()));
NVBENCH_CUDA_CALL(cudaStreamSynchronize(m_launch.get_stream()));
}

KernelLauncher &m_kernel_launcher;
Expand Down
7 changes: 4 additions & 3 deletions testing/reset_error.cu
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "test_asserts.cuh"


namespace
{
__global__ void multiply5(const int32_t* __restrict__ a, int32_t* __restrict__ b)
Expand All @@ -17,13 +18,13 @@ int main()

try
{
NVBENCH_CUDA_CALL_RESET_ERROR(cudaStreamSynchronize(0));
return 1;
NVBENCH_CUDA_CALL(cudaStreamSynchronize(0));
ASSERT(false);
}
catch (const std::runtime_error &)
{
ASSERT(cudaGetLastError() == cudaError_t::cudaSuccess);
}

return 0;
}
}

0 comments on commit 9f8818b

Please sign in to comment.