forked from CIS565-Fall-2020/Project4-CUDA-Denoiser
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/millersy/Project3-CUDA-Pa…
…th-Tracer into master
- Loading branch information
Showing
9 changed files
with
135 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -73,6 +73,7 @@ set(headers | |
src/sceneStructs.h | ||
src/preview.h | ||
src/utilities.h | ||
src/timer.h | ||
) | ||
|
||
set(sources | ||
|
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
#pragma once | ||
|
||
#include <cuda.h> | ||
#include <cuda_runtime.h> | ||
|
||
#include <cstdio> | ||
#include <cstring> | ||
#include <cmath> | ||
#include <algorithm> | ||
#include <chrono> | ||
#include <stdexcept> | ||
|
||
/** | ||
* This class is used for timing the performance | ||
* Uncopyable and unmovable | ||
* | ||
* Adapted from WindyDarian(https://github.com/WindyDarian) | ||
*/ | ||
class PerformanceTimer | ||
{ | ||
public: | ||
PerformanceTimer() | ||
{ | ||
cudaEventCreate(&event_start); | ||
cudaEventCreate(&event_end); | ||
} | ||
|
||
~PerformanceTimer() | ||
{ | ||
cudaEventDestroy(event_start); | ||
cudaEventDestroy(event_end); | ||
} | ||
|
||
void startCpuTimer() | ||
{ | ||
if (cpu_timer_started) { throw std::runtime_error("CPU timer already started"); } | ||
cpu_timer_started = true; | ||
|
||
time_start_cpu = std::chrono::high_resolution_clock::now(); | ||
} | ||
|
||
void endCpuTimer() | ||
{ | ||
time_end_cpu = std::chrono::high_resolution_clock::now(); | ||
|
||
if (!cpu_timer_started) { throw std::runtime_error("CPU timer not started"); } | ||
|
||
std::chrono::duration<double, std::milli> duro = time_end_cpu - time_start_cpu; | ||
prev_elapsed_time_cpu_milliseconds = | ||
static_cast<decltype(prev_elapsed_time_cpu_milliseconds)>(duro.count()); | ||
|
||
cpu_timer_started = false; | ||
} | ||
|
||
void startGpuTimer() | ||
{ | ||
if (gpu_timer_started) { throw std::runtime_error("GPU timer already started"); } | ||
gpu_timer_started = true; | ||
|
||
cudaEventRecord(event_start); | ||
} | ||
|
||
void endGpuTimer() | ||
{ | ||
cudaEventRecord(event_end); | ||
cudaEventSynchronize(event_end); | ||
|
||
if (!gpu_timer_started) { throw std::runtime_error("GPU timer not started"); } | ||
|
||
cudaEventElapsedTime(&prev_elapsed_time_gpu_milliseconds, event_start, event_end); | ||
gpu_timer_started = false; | ||
} | ||
|
||
float getCpuElapsedTimeForPreviousOperation() //noexcept //(damn I need VS 2015 | ||
{ | ||
return prev_elapsed_time_cpu_milliseconds; | ||
} | ||
|
||
float getGpuElapsedTimeForPreviousOperation() //noexcept | ||
{ | ||
return prev_elapsed_time_gpu_milliseconds; | ||
} | ||
|
||
// remove copy and move functions | ||
PerformanceTimer(const PerformanceTimer&) = delete; | ||
PerformanceTimer(PerformanceTimer&&) = delete; | ||
PerformanceTimer& operator=(const PerformanceTimer&) = delete; | ||
PerformanceTimer& operator=(PerformanceTimer&&) = delete; | ||
|
||
private: | ||
cudaEvent_t event_start = nullptr; | ||
cudaEvent_t event_end = nullptr; | ||
|
||
using time_point_t = std::chrono::high_resolution_clock::time_point; | ||
time_point_t time_start_cpu; | ||
time_point_t time_end_cpu; | ||
|
||
bool cpu_timer_started = false; | ||
bool gpu_timer_started = false; | ||
|
||
float prev_elapsed_time_cpu_milliseconds = 0.f; | ||
float prev_elapsed_time_gpu_milliseconds = 0.f; | ||
}; |