提交 5a0a4617 编写于 作者: Y Yibing Liu

Make time calc funcs return ms instead of us

上级 d7e56847
...@@ -74,11 +74,11 @@ std::string Event::kind() const { ...@@ -74,11 +74,11 @@ std::string Event::kind() const {
PADDLE_THROW("Unknown EventKind."); PADDLE_THROW("Unknown EventKind.");
} }
double Event::CpuElapsedUs(const Event& e) const { double Event::CpuElapsedMs(const Event& e) const {
return (e.cpu_ns_ - cpu_ns_) / (1000.0); 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 #ifdef PADDLE_WITH_CUDA
PADDLE_ENFORCE(e.has_cuda() && has_cuda()); PADDLE_ENFORCE(e.has_cuda() && has_cuda());
PADDLE_ENFORCE(e.device() == device()); PADDLE_ENFORCE(e.device() == device());
...@@ -86,7 +86,7 @@ double Event::CudaElapsedUs(const Event& e) const { ...@@ -86,7 +86,7 @@ double Event::CudaElapsedUs(const Event& e) const {
PADDLE_ENFORCE(cudaEventSynchronize(e.event())); PADDLE_ENFORCE(cudaEventSynchronize(e.event()));
float ms; float ms;
PADDLE_ENFORCE(cudaEventElapsedTime(&ms, event_, e.event())); PADDLE_ENFORCE(cudaEventElapsedTime(&ms, event_, e.event()));
return ms * 1000.0; return ms;
#else #else
PADDLE_THROW("CUDA is not enabled"); PADDLE_THROW("CUDA is not enabled");
#endif #endif
...@@ -239,11 +239,10 @@ void ParseEvents(std::vector<std::vector<Event>>& events, ...@@ -239,11 +239,10 @@ void ParseEvents(std::vector<std::vector<Event>>& events,
++rit; ++rit;
} }
if (rit != pushed_events.rend()) { if (rit != pushed_events.rend()) {
// get event time in ms
#ifdef PADDLE_WITH_CUDA #ifdef PADDLE_WITH_CUDA
double event_time = rit->CudaElapsedUs(events[i][j]) / 1000.0; double event_time = rit->CudaElapsedMs(events[i][j]);
#else #else
double event_time = rit->CpuElapsedUs(events[i][j]) / 1000.0; double event_time = rit->CpuElapsedMs(events[i][j]);
#endif #endif
std::string event_name = std::string event_name =
"thread" + std::to_string(rit->thread_id()) + "::" + rit->name(); "thread" + std::to_string(rit->thread_id()) + "::" + rit->name();
......
...@@ -41,8 +41,8 @@ class Event { ...@@ -41,8 +41,8 @@ class Event {
int device() const { return device_; } int device() const { return device_; }
#endif #endif
double CpuElapsedUs(const Event& e) const; double CpuElapsedMs(const Event& e) const;
double CudaElapsedUs(const Event& e) const; double CudaElapsedMs(const Event& e) const;
private: private:
EventKind kind_; EventKind kind_;
......
...@@ -26,7 +26,7 @@ TEST(Event, CpuElapsedTime) { ...@@ -26,7 +26,7 @@ TEST(Event, CpuElapsedTime) {
counter++; counter++;
} }
Event stop_event(EventKind::kPopRange, "test", 0, nullptr); 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 #ifdef PADDLE_WITH_CUDA
...@@ -45,7 +45,7 @@ TEST(Event, CudaElapsedTime) { ...@@ -45,7 +45,7 @@ TEST(Event, CudaElapsedTime) {
counter++; counter++;
} }
Event stop_event(EventKind::kPopRange, "test", 0, dev_ctx); 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 #endif
...@@ -114,9 +114,9 @@ TEST(RecordEvent, RecordEvent) { ...@@ -114,9 +114,9 @@ TEST(RecordEvent, RecordEvent) {
if (events[i][j].name() == "push") { if (events[i][j].name() == "push") {
EXPECT_EQ(events[i][j + 1].name(), "pop"); EXPECT_EQ(events[i][j + 1].name(), "pop");
#ifdef PADDLE_WITH_CUDA #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 #else
EXPECT_GT(events[i][j].CpuElapsedUs(events[i][j + 1]), 0); EXPECT_GT(events[i][j].CpuElapsedMs(events[i][j + 1]), 0);
#endif #endif
} }
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册