From 5a0a4617536aa4c79a30f195f88653794fe98678 Mon Sep 17 00:00:00 2001 From: Yibing Liu Date: Fri, 5 Jan 2018 09:57:28 +0000 Subject: [PATCH] Make time calc funcs return ms instead of us --- paddle/platform/profiler.cc | 13 ++++++------- paddle/platform/profiler.h | 4 ++-- paddle/platform/profiler_test.cc | 8 ++++---- 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/paddle/platform/profiler.cc b/paddle/platform/profiler.cc index a35d6e94f07..ea16e560767 100644 --- a/paddle/platform/profiler.cc +++ b/paddle/platform/profiler.cc @@ -74,11 +74,11 @@ std::string Event::kind() const { PADDLE_THROW("Unknown EventKind."); } -double Event::CpuElapsedUs(const Event& e) const { - return (e.cpu_ns_ - cpu_ns_) / (1000.0); +double Event::CpuElapsedMs(const Event& e) const { + return (e.cpu_ns_ - cpu_ns_) / (1000000.0); } -double Event::CudaElapsedUs(const Event& e) const { +double Event::CudaElapsedMs(const Event& e) const { #ifdef PADDLE_WITH_CUDA PADDLE_ENFORCE(e.has_cuda() && has_cuda()); PADDLE_ENFORCE(e.device() == device()); @@ -86,7 +86,7 @@ double Event::CudaElapsedUs(const Event& e) const { PADDLE_ENFORCE(cudaEventSynchronize(e.event())); float ms; PADDLE_ENFORCE(cudaEventElapsedTime(&ms, event_, e.event())); - return ms * 1000.0; + return ms; #else PADDLE_THROW("CUDA is not enabled"); #endif @@ -239,11 +239,10 @@ void ParseEvents(std::vector>& events, ++rit; } if (rit != pushed_events.rend()) { -// get event time in ms #ifdef PADDLE_WITH_CUDA - double event_time = rit->CudaElapsedUs(events[i][j]) / 1000.0; + double event_time = rit->CudaElapsedMs(events[i][j]); #else - double event_time = rit->CpuElapsedUs(events[i][j]) / 1000.0; + double event_time = rit->CpuElapsedMs(events[i][j]); #endif std::string event_name = "thread" + std::to_string(rit->thread_id()) + "::" + rit->name(); diff --git a/paddle/platform/profiler.h b/paddle/platform/profiler.h index 7504aff5cd9..d51ec644321 100644 --- a/paddle/platform/profiler.h +++ b/paddle/platform/profiler.h @@ -41,8 +41,8 @@ class Event { int device() const { return device_; } #endif - double CpuElapsedUs(const Event& e) const; - double CudaElapsedUs(const Event& e) const; + double CpuElapsedMs(const Event& e) const; + double CudaElapsedMs(const Event& e) const; private: EventKind kind_; diff --git a/paddle/platform/profiler_test.cc b/paddle/platform/profiler_test.cc index d4fd4c88503..3800f3914f1 100644 --- a/paddle/platform/profiler_test.cc +++ b/paddle/platform/profiler_test.cc @@ -26,7 +26,7 @@ TEST(Event, CpuElapsedTime) { counter++; } Event stop_event(EventKind::kPopRange, "test", 0, nullptr); - EXPECT_GT(start_event.CpuElapsedUs(stop_event), 0); + EXPECT_GT(start_event.CpuElapsedMs(stop_event), 0); } #ifdef PADDLE_WITH_CUDA @@ -45,7 +45,7 @@ TEST(Event, CudaElapsedTime) { counter++; } Event stop_event(EventKind::kPopRange, "test", 0, dev_ctx); - EXPECT_GT(start_event.CudaElapsedUs(stop_event), 0); + EXPECT_GT(start_event.CudaElapsedMs(stop_event), 0); } #endif @@ -114,9 +114,9 @@ TEST(RecordEvent, RecordEvent) { if (events[i][j].name() == "push") { EXPECT_EQ(events[i][j + 1].name(), "pop"); #ifdef PADDLE_WITH_CUDA - EXPECT_GT(events[i][j].CudaElapsedUs(events[i][j + 1]), 0); + EXPECT_GT(events[i][j].CudaElapsedMs(events[i][j + 1]), 0); #else - EXPECT_GT(events[i][j].CpuElapsedUs(events[i][j + 1]), 0); + EXPECT_GT(events[i][j].CpuElapsedMs(events[i][j + 1]), 0); #endif } } -- GitLab