Commit 6a4ddb5e authored by Miklós Homolya's avatar Miklós Homolya

add precise Timer

parent 413830ae
#include "kernel.h"
#include "timer.h"
#include <algorithm>
#include <stdio.h>
template<typename T>
__device__ __host__ T min(T a, T b)
......@@ -118,6 +121,11 @@ void executeKernel(void *d_in, void *d_out, size_t w, size_t h)
float *d_U = reinterpret_cast<float *>(d_in);
uchar4 *pixel = reinterpret_cast<uchar4 *>(d_out);
static Timer timer;
timer.end();
printf("time: %.2fms (%.2f FPS)\n", timer.get() * 1E3F, 1.F / timer.get());
timer.start();
dim3 dimBlock(32, 16);
dim3 dimGrid = make_grid(dim3(w, h, 1), dimBlock);
......@@ -151,6 +159,4 @@ void executeKernel(void *d_in, void *d_out, size_t w, size_t h)
cudaFree(d_F);
cudaFree(d_Xi);
cudaFree(d_Xj);
// createVertices<<<dimGrid, dimBlock>>>(in, pixel, w, h);
}
#ifndef TIMER_H
#define TIMER_H
#include <time.h>
// measuring time
class Timer
{
public:
Timer() : running(false), sec(0)
{
}
void start()
{
clock_gettime(CLOCK_MONOTONIC, &tStart);
running = true;
}
void end()
{
if (!running) { sec = 0; return; }
struct timespec tEnd;
clock_gettime(CLOCK_MONOTONIC, &tEnd);
sec = (tEnd.tv_sec - tStart.tv_sec) + (tEnd.tv_nsec - tStart.tv_nsec) * 1E-9F;
running = false;
}
float get()
{
if (running) end();
return sec;
}
private:
struct timespec tStart;
bool running;
float sec;
};
#endif // TIMER_H
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment