From 8686f7c68e2e524a3d0cdd2f0c555851eafeb59a Mon Sep 17 00:00:00 2001 From: Qiao Longfei Date: Sat, 13 Oct 2018 18:31:41 +0800 Subject: [PATCH] add reader_queue_speed_test_mode flag for speed test --- paddle/fluid/operators/reader/blocking_queue.h | 7 ++++++- .../fluid/operators/reader/reader_blocking_queue_test.cc | 4 ++++ paddle/fluid/platform/enforce.h | 7 +++++++ paddle/fluid/pybind/pybind.cc | 4 ++++ 4 files changed, 21 insertions(+), 1 deletion(-) diff --git a/paddle/fluid/operators/reader/blocking_queue.h b/paddle/fluid/operators/reader/blocking_queue.h index 28cc91a5ed5..3eefb2db51c 100644 --- a/paddle/fluid/operators/reader/blocking_queue.h +++ b/paddle/fluid/operators/reader/blocking_queue.h @@ -14,11 +14,14 @@ #pragma once +#include #include // NOLINT #include #include "paddle/fluid/platform/enforce.h" +DECLARE_bool(reader_queue_speed_test_mode); + namespace paddle { namespace operators { namespace reader { @@ -72,7 +75,9 @@ class BlockingQueue { if (!queue_.empty()) { PADDLE_ENFORCE_NOT_NULL(elem); *elem = queue_.front(); - queue_.pop_front(); + if (LIKELY(!FLAGS_reader_queue_speed_test_mode)) { + queue_.pop_front(); + } send_cv_.notify_one(); return true; } else { diff --git a/paddle/fluid/operators/reader/reader_blocking_queue_test.cc b/paddle/fluid/operators/reader/reader_blocking_queue_test.cc index 7d1b381d56c..9b016469cf6 100644 --- a/paddle/fluid/operators/reader/reader_blocking_queue_test.cc +++ b/paddle/fluid/operators/reader/reader_blocking_queue_test.cc @@ -20,6 +20,10 @@ #include "paddle/fluid/operators/reader/blocking_queue.h" +DEFINE_bool(reader_queue_speed_test_mode, false, + "If set true, the queue.pop will only get data from queue but not " + "remove the data from queue for speed testing"); + using paddle::operators::reader::BlockingQueue; TEST(BlockingQueue, CapacityTest) { diff --git a/paddle/fluid/platform/enforce.h b/paddle/fluid/platform/enforce.h index f04395a8ac0..a251bfcd991 100644 --- a/paddle/fluid/platform/enforce.h +++ b/paddle/fluid/platform/enforce.h @@ -130,6 +130,13 @@ struct EOFException : public std::exception { #define UNLIKELY(condition) (condition == 0) #endif +#if !defined(_WIN32) +#define LIKELY(condition) __builtin_expect(static_cast(condition), 1) +#else +// there is no equivalent intrinsics in msvc. +#define LIKELY(condition) (condition != 0) +#endif + template inline typename std::enable_if::type throw_on_error( bool stat, const Args&... args) { diff --git a/paddle/fluid/pybind/pybind.cc b/paddle/fluid/pybind/pybind.cc index 311cd944603..2b730f2bdc9 100644 --- a/paddle/fluid/pybind/pybind.cc +++ b/paddle/fluid/pybind/pybind.cc @@ -57,6 +57,10 @@ limitations under the License. */ #include "pybind11/stl.h" +DEFINE_bool(reader_queue_speed_test_mode, false, + "If set true, the queue.pop will only get data from queue but not " + "remove the data from queue for speed testing"); + // disable auto conversion to list in Python PYBIND11_MAKE_OPAQUE(paddle::framework::LoDTensorArray); -- GitLab