提交 60030e86 编写于 作者: Q Qiao Longfei

change the use of FLAGS_reader_queue_speed_test_mode

test=develop
上级 2178ae56
...@@ -14,4 +14,4 @@ if(WITH_INFERENCE) ...@@ -14,4 +14,4 @@ if(WITH_INFERENCE)
add_subdirectory(inference) add_subdirectory(inference)
endif() endif()
add_subdirectory(train) #add_subdirectory(train)
...@@ -14,14 +14,11 @@ ...@@ -14,14 +14,11 @@
#pragma once #pragma once
#include <gflags/gflags.h>
#include <condition_variable> // NOLINT #include <condition_variable> // NOLINT
#include <deque> #include <deque>
#include "paddle/fluid/platform/enforce.h" #include "paddle/fluid/platform/enforce.h"
DECLARE_bool(reader_queue_speed_test_mode);
namespace paddle { namespace paddle {
namespace operators { namespace operators {
namespace reader { namespace reader {
...@@ -34,8 +31,8 @@ class BlockingQueue { ...@@ -34,8 +31,8 @@ class BlockingQueue {
// is a workaround and a simplified version of framework::Channel as it // is a workaround and a simplified version of framework::Channel as it
// doesn't support GPU and it implements on buffered blocking queue. // doesn't support GPU and it implements on buffered blocking queue.
public: public:
explicit BlockingQueue(size_t capacity) explicit BlockingQueue(size_t capacity, bool speed_test_mode = false)
: capacity_(capacity), closed_(false) { : capacity_(capacity), speed_test_mode_(speed_test_mode), closed_(false) {
PADDLE_ENFORCE_GT( PADDLE_ENFORCE_GT(
capacity_, 0, capacity_, 0,
"The capacity of a reader::BlockingQueue must be greater than 0."); "The capacity of a reader::BlockingQueue must be greater than 0.");
...@@ -75,7 +72,7 @@ class BlockingQueue { ...@@ -75,7 +72,7 @@ class BlockingQueue {
if (!queue_.empty()) { if (!queue_.empty()) {
PADDLE_ENFORCE_NOT_NULL(elem); PADDLE_ENFORCE_NOT_NULL(elem);
*elem = queue_.front(); *elem = queue_.front();
if (LIKELY(!FLAGS_reader_queue_speed_test_mode)) { if (LIKELY(!speed_test_mode_)) {
queue_.pop_front(); queue_.pop_front();
} }
send_cv_.notify_one(); send_cv_.notify_one();
...@@ -119,6 +116,7 @@ class BlockingQueue { ...@@ -119,6 +116,7 @@ class BlockingQueue {
private: private:
size_t capacity_; size_t capacity_;
bool speed_test_mode_;
bool closed_; bool closed_;
std::deque<T> queue_; std::deque<T> queue_;
......
...@@ -33,8 +33,9 @@ class LoDTensorBlockingQueue { ...@@ -33,8 +33,9 @@ class LoDTensorBlockingQueue {
private: private:
LoDTensorBlockingQueue(size_t capacity, LoDTensorBlockingQueue(size_t capacity,
const std::vector<framework::DDim>& dims) const std::vector<framework::DDim>& dims,
: queue_(capacity), dims_(dims) {} bool speed_test_mode = false)
: queue_(capacity, speed_test_mode), dims_(dims) {}
public: public:
bool Push(const std::vector<framework::LoDTensor>& lod_tensor_vec) { bool Push(const std::vector<framework::LoDTensor>& lod_tensor_vec) {
...@@ -69,11 +70,12 @@ class LoDTensorBlockingQueue { ...@@ -69,11 +70,12 @@ class LoDTensorBlockingQueue {
class LoDTensorBlockingQueueHolder { class LoDTensorBlockingQueueHolder {
public: public:
void InitOnce(size_t capacity, const std::vector<framework::DDim>& dims) { void InitOnce(size_t capacity, const std::vector<framework::DDim>& dims,
bool speed_test_mode = false) {
PADDLE_ENFORCE( PADDLE_ENFORCE(
queue_ == nullptr, queue_ == nullptr,
"LoDTensorBlockingQueueHolder::InitOnce() can only be called once"); "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<LoDTensorBlockingQueue>& GetQueue() const { inline const std::shared_ptr<LoDTensorBlockingQueue>& GetQueue() const {
......
...@@ -20,10 +20,6 @@ ...@@ -20,10 +20,6 @@
#include "paddle/fluid/operators/reader/blocking_queue.h" #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; using paddle::operators::reader::BlockingQueue;
TEST(BlockingQueue, CapacityTest) { TEST(BlockingQueue, CapacityTest) {
...@@ -222,27 +218,26 @@ TEST(BlockingQueue, MyClassTest) { ...@@ -222,27 +218,26 @@ TEST(BlockingQueue, MyClassTest) {
EXPECT_EQ(a.val_, b.val_); EXPECT_EQ(a.val_, b.val_);
} }
TEST(BlockingQueue, reader_queue_speed_test_mode_flag) { TEST(BlockingQueue, speed_test_mode) {
FLAGS_reader_queue_speed_test_mode = false;
size_t queue_size = 10; size_t queue_size = 10;
BlockingQueue<size_t> q(queue_size); BlockingQueue<size_t> q1(queue_size, false);
for (size_t i = 0; i < queue_size; ++i) { for (size_t i = 0; i < queue_size; ++i) {
q.Send(i); q1.Send(i);
} }
size_t b; size_t b;
for (size_t i = 0; i < queue_size; ++i) { for (size_t i = 0; i < queue_size; ++i) {
q.Receive(&b); q1.Receive(&b);
EXPECT_EQ(b, i); EXPECT_EQ(b, i);
} }
EXPECT_EQ(q.Size(), 0); EXPECT_EQ(q1.Size(), 0);
FLAGS_reader_queue_speed_test_mode = true; BlockingQueue<size_t> q2(queue_size, true);
for (size_t i = 0; i < queue_size; ++i) { for (size_t i = 0; i < queue_size; ++i) {
q.Send(i); q2.Send(i);
} }
for (size_t i = 0; i < queue_size; ++i) { for (size_t i = 0; i < queue_size; ++i) {
q.Receive(&b); q2.Receive(&b);
EXPECT_EQ(b, 0); EXPECT_EQ(b, 0);
} }
EXPECT_EQ(q.Size(), queue_size); EXPECT_EQ(q2.Size(), queue_size);
} }
...@@ -341,7 +341,8 @@ All parameter, weight, gradient are variables in Paddle. ...@@ -341,7 +341,8 @@ All parameter, weight, gradient are variables in Paddle.
return make_ddim(shape); return make_ddim(shape);
}); });
auto *holder = var.GetMutable<LoDTensorBlockingQueueHolder>(); auto *holder = var.GetMutable<LoDTensorBlockingQueueHolder>();
holder->InitOnce(capacity, dims); holder->InitOnce(capacity, dims,
FLAGS_reader_queue_speed_test_mode);
return holder->GetQueue(); return holder->GetQueue();
}, },
py::return_value_policy::copy); py::return_value_policy::copy);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册