From 956af616d37538dd0ca8f1a260f6b3ae70d1e052 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 25 Nov 2021 22:23:02 +0800 Subject: [PATCH] add clock macro --- common/clock.cuh | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 common/clock.cuh diff --git a/common/clock.cuh b/common/clock.cuh new file mode 100644 index 0000000..8b3b4eb --- /dev/null +++ b/common/clock.cuh @@ -0,0 +1,33 @@ +#include + +using namespace std::chrono; + + +#define cudaClockStart \ + float elapsed_time = 0; \ + float curr_time = 0; \ + cudaEvent_t start, stop; \ + CHECK(cudaEventCreate(&start)); \ + CHECK(cudaEventCreate(&stop)); \ + CHECK(cudaEventRecord(start)); \ + cudaEventQuery(start); \ + + +#define cudaClockCurr \ + CHECK(cudaEventRecord(stop)); \ + CHECK(cudaEventSynchronize(stop)); \ + CHECK(cudaEventElapsedTime(&curr_time, start, stop)); \ + printf("cuda time cost: %f ms.\n", curr_time - elapsed_time); \ + elapsed_time = curr_time; \ + + +#define cppClockStart \ + double t = 0; \ + auto tStart = system_clock::now(); \ + auto tStop = system_clock::now(); \ + + +#define cppClockCurr \ + tStop = system_clock::now(); \ + t = duration(tStart - tStop).count(); \ + printf("cpp time cost: %f ms.\n", t); \