From 60030e867892e657104a34436bf83bda93c4b8ca Mon Sep 17 00:00:00 2001 From: Qiao Longfei Date: Mon, 15 Oct 2018 17:33:12 +0800 Subject: [PATCH] change the use of FLAGS_reader_queue_speed_test_mode test=develop --- paddle/fluid/CMakeLists.txt | 2 +- .../fluid/operators/reader/blocking_queue.h | 10 ++++---- .../reader/lod_tensor_blocking_queue.h | 10 ++++---- .../reader/reader_blocking_queue_test.cc | 23 ++++++++----------- paddle/fluid/pybind/pybind.cc | 3 ++- 5 files changed, 22 insertions(+), 26 deletions(-) diff --git a/paddle/fluid/CMakeLists.txt b/paddle/fluid/CMakeLists.txt index 519a00fb0..6e3411f7a 100644 --- a/paddle/fluid/CMakeLists.txt +++ b/paddle/fluid/CMakeLists.txt @@ -14,4 +14,4 @@ if(WITH_INFERENCE) add_subdirectory(inference) endif() -add_subdirectory(train) +#add_subdirectory(train) diff --git a/paddle/fluid/operators/reader/blocking_queue.h b/paddle/fluid/operators/reader/blocking_queue.h index 3eefb2db5..51b980acb 100644 --- a/paddle/fluid/operators/reader/blocking_queue.h +++ b/paddle/fluid/operators/reader/blocking_queue.h @@ -14,14 +14,11 @@ #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 { @@ -34,8 +31,8 @@ class BlockingQueue { // is a workaround and a simplified version of framework::Channel as it // doesn't support GPU and it implements on buffered blocking queue. public: - explicit BlockingQueue(size_t capacity) - : capacity_(capacity), closed_(false) { + explicit BlockingQueue(size_t capacity, bool speed_test_mode = false) + : capacity_(capacity), speed_test_mode_(speed_test_mode), closed_(false) { PADDLE_ENFORCE_GT( capacity_, 0, "The capacity of a reader::BlockingQueue must be greater than 0."); @@ -75,7 +72,7 @@ class BlockingQueue { if (!queue_.empty()) { PADDLE_ENFORCE_NOT_NULL(elem); *elem = queue_.front(); - if (LIKELY(!FLAGS_reader_queue_speed_test_mode)) { + if (LIKELY(!speed_test_mode_)) { queue_.pop_front(); } send_cv_.notify_one(); @@ -119,6 +116,7 @@ class BlockingQueue { private: size_t capacity_; + bool speed_test_mode_; bool closed_; std::deque queue_; diff --git a/paddle/fluid/operators/reader/lod_tensor_blocking_queue.h b/paddle/fluid/operators/reader/lod_tensor_blocking_queue.h index 4f7cfc24e..3f041ff7e 100644 --- a/paddle/fluid/operators/reader/lod_tensor_blocking_queue.h +++ b/paddle/fluid/operators/reader/lod_tensor_blocking_queue.h @@ -33,8 +33,9 @@ class LoDTensorBlockingQueue { private: LoDTensorBlockingQueue(size_t capacity, - const std::vector& dims) - : queue_(capacity), dims_(dims) {} + const std::vector& dims, + bool speed_test_mode = false) + : queue_(capacity, speed_test_mode), dims_(dims) {} public: bool Push(const std::vector& lod_tensor_vec) { @@ -69,11 +70,12 @@ class LoDTensorBlockingQueue { class LoDTensorBlockingQueueHolder { public: - void InitOnce(size_t capacity, const std::vector& dims) { + void InitOnce(size_t capacity, const std::vector& dims, + bool speed_test_mode = false) { PADDLE_ENFORCE( queue_ == nullptr, "LoDTensorBlockingQueueHolder::InitOnce() can only be called once"); - queue_.reset(new LoDTensorBlockingQueue(capacity, dims)); + queue_.reset(new LoDTensorBlockingQueue(capacity, dims, speed_test_mode)); } inline const std::shared_ptr& GetQueue() const { diff --git a/paddle/fluid/operators/reader/reader_blocking_queue_test.cc b/paddle/fluid/operators/reader/reader_blocking_queue_test.cc index cfcac1122..bd7ac64b2 100644 --- a/paddle/fluid/operators/reader/reader_blocking_queue_test.cc +++ b/paddle/fluid/operators/reader/reader_blocking_queue_test.cc @@ -20,10 +20,6 @@ #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) { @@ -222,27 +218,26 @@ TEST(BlockingQueue, MyClassTest) { EXPECT_EQ(a.val_, b.val_); } -TEST(BlockingQueue, reader_queue_speed_test_mode_flag) { - FLAGS_reader_queue_speed_test_mode = false; +TEST(BlockingQueue, speed_test_mode) { size_t queue_size = 10; - BlockingQueue q(queue_size); + BlockingQueue q1(queue_size, false); for (size_t i = 0; i < queue_size; ++i) { - q.Send(i); + q1.Send(i); } size_t b; for (size_t i = 0; i < queue_size; ++i) { - q.Receive(&b); + q1.Receive(&b); EXPECT_EQ(b, i); } - EXPECT_EQ(q.Size(), 0); + EXPECT_EQ(q1.Size(), 0); - FLAGS_reader_queue_speed_test_mode = true; + BlockingQueue q2(queue_size, true); for (size_t i = 0; i < queue_size; ++i) { - q.Send(i); + q2.Send(i); } for (size_t i = 0; i < queue_size; ++i) { - q.Receive(&b); + q2.Receive(&b); EXPECT_EQ(b, 0); } - EXPECT_EQ(q.Size(), queue_size); + EXPECT_EQ(q2.Size(), queue_size); } diff --git a/paddle/fluid/pybind/pybind.cc b/paddle/fluid/pybind/pybind.cc index 2b730f2bd..7af5b7705 100644 --- a/paddle/fluid/pybind/pybind.cc +++ b/paddle/fluid/pybind/pybind.cc @@ -341,7 +341,8 @@ All parameter, weight, gradient are variables in Paddle. return make_ddim(shape); }); auto *holder = var.GetMutable(); - holder->InitOnce(capacity, dims); + holder->InitOnce(capacity, dims, + FLAGS_reader_queue_speed_test_mode); return holder->GetQueue(); }, py::return_value_policy::copy); -- GitLab