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

change the use of FLAGS_reader_queue_speed_test_mode

test=develop
上级 2178ae56
......@@ -14,4 +14,4 @@ if(WITH_INFERENCE)
add_subdirectory(inference)
endif()
add_subdirectory(train)
#add_subdirectory(train)
......@@ -14,14 +14,11 @@
#pragma once
#include <gflags/gflags.h>
#include <condition_variable> // NOLINT
#include <deque>
#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<T> queue_;
......
......@@ -33,8 +33,9 @@ class LoDTensorBlockingQueue {
private:
LoDTensorBlockingQueue(size_t capacity,
const std::vector<framework::DDim>& dims)
: queue_(capacity), dims_(dims) {}
const std::vector<framework::DDim>& dims,
bool speed_test_mode = false)
: queue_(capacity, speed_test_mode), dims_(dims) {}
public:
bool Push(const std::vector<framework::LoDTensor>& lod_tensor_vec) {
......@@ -69,11 +70,12 @@ class LoDTensorBlockingQueue {
class LoDTensorBlockingQueueHolder {
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(
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<LoDTensorBlockingQueue>& GetQueue() const {
......
......@@ -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<size_t> q(queue_size);
BlockingQueue<size_t> 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<size_t> 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);
}
......@@ -341,7 +341,8 @@ All parameter, weight, gradient are variables in Paddle.
return make_ddim(shape);
});
auto *holder = var.GetMutable<LoDTensorBlockingQueueHolder>();
holder->InitOnce(capacity, dims);
holder->InitOnce(capacity, dims,
FLAGS_reader_queue_speed_test_mode);
return holder->GetQueue();
},
py::return_value_policy::copy);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册