From 03748b446bc456308bcdadca9f86fa35e028bb11 Mon Sep 17 00:00:00 2001 From: "balhau@balhau.net" Date: Sat, 25 Dec 2021 19:27:44 +0000 Subject: [PATCH] Fixed timer implementation and call --- app/sse.cpp | 17 +++++++++-------- src/cpu/x86/sse.cpp | 1 + src/platform/timer.hpp | 21 ++++++--------------- 3 files changed, 16 insertions(+), 23 deletions(-) diff --git a/app/sse.cpp b/app/sse.cpp index 226dec7..214f1d7 100644 --- a/app/sse.cpp +++ b/app/sse.cpp @@ -1,4 +1,5 @@ #include +#include #include "../src/cpu/utils.hpp" #include "../src/cpu/x86/sse.hpp" #include "../src/cpu/naive.hpp" @@ -12,7 +13,7 @@ using namespace std; void naive128(UInt *v1_128, UInt *v2_128) { - Timer("Naive 128: "); + Timer t=Timer("Naive 128: "); for (int i = 0; i < MAX_ITER; i++) { Naive::add_128(v1_128, v2_128); @@ -21,7 +22,7 @@ void naive128(UInt *v1_128, UInt *v2_128) void int128(SSE *sse, UInt *v1_128, UInt *v2_128) { - Timer("SIMD(Int) 128: "); + Timer t=Timer("SIMD(Byte) 256: "); for (int i = 0; i < MAX_ITER; i++) { sse->add_128(v1_128, v2_128); @@ -30,7 +31,7 @@ void int128(SSE *sse, UInt *v1_128, UInt *v2_128) void long128(SSE *sse, ULong *v1_128_l, ULong *v2_128_l) { - Timer("SIMD(Long) 128: "); + Timer t=Timer("SIMD(Byte) 256: "); for (int i = 0; i < MAX_ITER; i++) { sse->add_128(v1_128_l, v2_128_l); @@ -39,7 +40,7 @@ void long128(SSE *sse, ULong *v1_128_l, ULong *v2_128_l) void byte128(SSE *sse, UChar *c1_128, UChar *c2_128) { - Timer("SIMD(Byte) 128: "); + Timer t=Timer("SIMD(Byte) 256: "); for (int i = 0; i < MAX_ITER; i++) { sse->add_128(c1_128, c2_128); @@ -48,7 +49,7 @@ void byte128(SSE *sse, UChar *c1_128, UChar *c2_128) void naive256(UInt *v1_256, UInt *v2_256) { - Timer("Naive 256: "); + Timer t=Timer("Naive 256: "); for (int i = 0; i < MAX_ITER; i++) { Naive::add_256(v1_256, v2_256); @@ -57,7 +58,7 @@ void naive256(UInt *v1_256, UInt *v2_256) void int256(SSE *sse, UInt *v1_256, UInt *v2_256) { - Timer("SIMD(Int) 256: "); + Timer t=Timer("SIMD(Byte) 256: "); for (int i = 0; i < MAX_ITER; i++) { sse->add_256(v1_256, v2_256); @@ -66,7 +67,7 @@ void int256(SSE *sse, UInt *v1_256, UInt *v2_256) void long256(SSE *sse, ULong *v1_256, ULong *v2_256) { - Timer("SIMD(Long) 256: "); + Timer t=Timer("SIMD(Byte) 256: "); for (int i = 0; i < MAX_ITER; i++) { sse->add_256(v1_256, v2_256); @@ -75,7 +76,7 @@ void long256(SSE *sse, ULong *v1_256, ULong *v2_256) void byte256(SSE *sse, UChar *v1_256, UChar *v2_256) { - Timer("SIMD(Byte) 256: "); + Timer t=Timer("SIMD(Byte) 256: "); for (int i = 0; i < MAX_ITER; i++) { sse->add_256(v1_256, v2_256); diff --git a/src/cpu/x86/sse.cpp b/src/cpu/x86/sse.cpp index 62c25ad..303c6ca 100644 --- a/src/cpu/x86/sse.cpp +++ b/src/cpu/x86/sse.cpp @@ -62,6 +62,7 @@ }; //X86 Assembly to add two 256 bit numbers in the form of packed long 64bit + //Here we are using vmovdqu instead of vmovdqa because memory is not aligned. void cpu::SSE::add_256(ULong *a,ULong *b) { asm volatile( "vmovdqu %0, %%ymm1\n" diff --git a/src/platform/timer.hpp b/src/platform/timer.hpp index b2b1543..d2383ad 100644 --- a/src/platform/timer.hpp +++ b/src/platform/timer.hpp @@ -1,8 +1,7 @@ #pragma once #include -#include -#include +#include namespace platform { @@ -10,28 +9,20 @@ namespace platform { private: std::string label; - long int start; - long int end; - - long int gettime() - { - struct timeval tp; - gettimeofday(&tp, NULL); - return (double)(tp.tv_sec * 1000 + (double)tp.tv_usec / 1000); - }; + std::chrono::high_resolution_clock::time_point start; + std::chrono::high_resolution_clock::time_point end; public: Timer(const char *lbl) { this->label = std::string(lbl); - this->start = this->gettime(); + this->start = std::chrono::high_resolution_clock::now(); } ~Timer() { - this->end = this->gettime(); - unsigned long diff = this->end - this->start; - std::cout << this->label << diff << std::endl; + this->end = std::chrono::high_resolution_clock::now(); + std::cout << this->label << std::chrono::duration_cast(end-start).count() << std::endl; } }; }; \ No newline at end of file