Skip to content

Commit 8686f7c

Browse files
committed
add reader_queue_speed_test_mode flag for speed test
1 parent 9c77b65 commit 8686f7c

File tree

4 files changed

+21
-1
lines changed

4 files changed

+21
-1
lines changed

paddle/fluid/operators/reader/blocking_queue.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,14 @@
1414

1515
#pragma once
1616

17+
#include <gflags/gflags.h>
1718
#include <condition_variable> // NOLINT
1819
#include <deque>
1920

2021
#include "paddle/fluid/platform/enforce.h"
2122

23+
DECLARE_bool(reader_queue_speed_test_mode);
24+
2225
namespace paddle {
2326
namespace operators {
2427
namespace reader {
@@ -72,7 +75,9 @@ class BlockingQueue {
7275
if (!queue_.empty()) {
7376
PADDLE_ENFORCE_NOT_NULL(elem);
7477
*elem = queue_.front();
75-
queue_.pop_front();
78+
if (LIKELY(!FLAGS_reader_queue_speed_test_mode)) {
79+
queue_.pop_front();
80+
}
7681
send_cv_.notify_one();
7782
return true;
7883
} else {

paddle/fluid/operators/reader/reader_blocking_queue_test.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@
2020

2121
#include "paddle/fluid/operators/reader/blocking_queue.h"
2222

23+
DEFINE_bool(reader_queue_speed_test_mode, false,
24+
"If set true, the queue.pop will only get data from queue but not "
25+
"remove the data from queue for speed testing");
26+
2327
using paddle::operators::reader::BlockingQueue;
2428

2529
TEST(BlockingQueue, CapacityTest) {

paddle/fluid/platform/enforce.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,13 @@ struct EOFException : public std::exception {
130130
#define UNLIKELY(condition) (condition == 0)
131131
#endif
132132

133+
#if !defined(_WIN32)
134+
#define LIKELY(condition) __builtin_expect(static_cast<bool>(condition), 1)
135+
#else
136+
// there is no equivalent intrinsics in msvc.
137+
#define LIKELY(condition) (condition != 0)
138+
#endif
139+
133140
template <typename... Args>
134141
inline typename std::enable_if<sizeof...(Args) != 0, void>::type throw_on_error(
135142
bool stat, const Args&... args) {

paddle/fluid/pybind/pybind.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ limitations under the License. */
5757

5858
#include "pybind11/stl.h"
5959

60+
DEFINE_bool(reader_queue_speed_test_mode, false,
61+
"If set true, the queue.pop will only get data from queue but not "
62+
"remove the data from queue for speed testing");
63+
6064
// disable auto conversion to list in Python
6165
PYBIND11_MAKE_OPAQUE(paddle::framework::LoDTensorArray);
6266

0 commit comments

Comments
 (0)