From 4082dc372341e466c4516d4f8acfdfa43da75358 Mon Sep 17 00:00:00 2001 From: djairoh Date: Mon, 20 Jan 2025 13:19:07 +0100 Subject: [PATCH] / --- src/consts.h | 4 ++-- src/gui/MainWindow.cpp | 26 +++++++++++++++++++++++++- src/gui/MainWindow.h | 5 +++++ 3 files changed, 32 insertions(+), 3 deletions(-) diff --git a/src/consts.h b/src/consts.h index cb339c2..3480c4a 100644 --- a/src/consts.h +++ b/src/consts.h @@ -5,8 +5,8 @@ #include // --------------------------- Basic Constants --------------------------- -const int INITIAL_WINDOW_WIDTH = 1200; -const int INITIAL_WINDOW_HEIGHT = 900; +const int INITIAL_WINDOW_WIDTH = 200; +const int INITIAL_WINDOW_HEIGHT = 150; const double epsilon = 1e-10f; const double infty = 1e15f; // This value is used to represent missing values in data diff --git a/src/gui/MainWindow.cpp b/src/gui/MainWindow.cpp index f0cfe3a..be75dea 100644 --- a/src/gui/MainWindow.cpp +++ b/src/gui/MainWindow.cpp @@ -1,6 +1,7 @@ #include "MainWindow.h" #include "cuda_runtime.h" +#include #include #include @@ -11,6 +12,9 @@ Window::Window(unsigned int w, unsigned int h) { this->w = w; this->h = h; + + this->gpuPerf.open("gpuPerformance"); + this->cpuPerf.open("cpuPerformance"); } void framebuffer_size_callback(GLFWwindow* window, int w, int h) { @@ -87,6 +91,9 @@ void Window::free(float* data) { glfwDestroyWindow(window); glfwTerminate(); + + this->gpuPerf.close(); + this->cpuPerf.close(); } @@ -95,6 +102,7 @@ void Window::tick() { std::chrono::steady_clock::time_point now = std::chrono::steady_clock::now(); float diff = (float) std::chrono::duration_cast(now - this->last_frame).count(); this->last_frame = now; + this->cpuPerf << diff << "\n"; // input this->widget->tick(1000.0/diff); @@ -107,7 +115,23 @@ void Window::tick() { glBindFramebuffer(GL_FRAMEBUFFER, 0); glDisable(GL_DEPTH_TEST); - if (!this->widget->paused) this->quad->render(); + if (!this->widget->paused){ + cudaEvent_t start, stop; + cudaEventCreate(&start); + cudaEventCreate(&stop); + cudaEventRecord(start, 0); + this->quad->render(); + + cudaEventRecord(stop, 0); + cudaEventSynchronize(stop); + float t; + cudaEventElapsedTime(&t, start, stop); + this->gpuPerf << t << "\n"; + + cudaEventDestroy(start); + cudaEventDestroy(stop); + } + this->shader->use(); glBindVertexArray(this->quad->VAO); glBindTexture(GL_TEXTURE_2D, this->quad->tex); diff --git a/src/gui/MainWindow.h b/src/gui/MainWindow.h index f4ed0f1..8aca638 100644 --- a/src/gui/MainWindow.h +++ b/src/gui/MainWindow.h @@ -7,6 +7,8 @@ #include #include #include "input/Widget.h" +#include +#include class Window { @@ -26,6 +28,9 @@ private: std::unique_ptr quad; Widget* widget; + std::ofstream gpuPerf; + std::ofstream cpuPerf; + std::chrono::steady_clock::time_point last_frame; void tick();