diff options
author | 2018-04-10 13:32:38 -0700 | |
---|---|---|
committer | 2018-04-10 13:34:57 -0700 | |
commit | 6b593d329005ffb1a10b1c9cd1374d2cdb620b21 (patch) | |
tree | dc31cffc5657725e1ea07ce8810626de5656d896 /tensorflow/core/kernels/stage_op.cc | |
parent | 4bf8270ed534c4cd37160e757d7b8a3dc765d1f0 (diff) |
Update declaration order in staging ops Buffer class according to C++ style guide
PiperOrigin-RevId: 192336966
Diffstat (limited to 'tensorflow/core/kernels/stage_op.cc')
-rw-r--r-- | tensorflow/core/kernels/stage_op.cc | 83 |
1 files changed, 38 insertions, 45 deletions
diff --git a/tensorflow/core/kernels/stage_op.cc b/tensorflow/core/kernels/stage_op.cc index 03fc4467a1..73a02a34cf 100644 --- a/tensorflow/core/kernels/stage_op.cc +++ b/tensorflow/core/kernels/stage_op.cc @@ -32,53 +32,8 @@ namespace { class Buffer : public ResourceBase { public: - // public types using Tuple = std::vector<Tensor>; - private: - // private variables - std::size_t capacity_; - std::size_t memory_limit_; - std::size_t current_bytes_; - std::mutex mu_; - std::condition_variable non_empty_cond_var_; - std::condition_variable full_cond_var_; - std::deque<Tuple> buf_; - - private: - // private methods - - // If the buffer is configured for bounded capacity, notify - // waiting inserters that space is now available - void notify_inserters_if_bounded(std::unique_lock<std::mutex>* lock) { - if (IsBounded()) { - lock->unlock(); - // Notify all inserters. The removal of an element - // may make memory available for many inserters - // to insert new elements - full_cond_var_.notify_all(); - } - } - - // Are there a limit number of elements or a memory limit - // configued on this buffer? - bool IsBounded() const { return capacity_ > 0 || memory_limit_ > 0; } - - bool IsCapacityFull() const { return buf_.size() >= capacity_; } - - bool WouldExceedMemoryLimit(std::size_t bytes) const { - return bytes + current_bytes_ > memory_limit_; - } - - std::size_t GetTupleBytes(const Tuple& tuple) { - return std::accumulate(tuple.begin(), tuple.end(), 0, - [](const std::size_t& lhs, const Tensor& rhs) { - return lhs + rhs.TotalBytes(); - }); - } - - public: - // public methods explicit Buffer(std::size_t capacity, std::size_t memory_limit) : capacity_(capacity), memory_limit_(memory_limit), current_bytes_(0) {} @@ -181,6 +136,44 @@ class Buffer : public ResourceBase { std::unique_lock<std::mutex> lock(mu_); return strings::StrCat("Staging size: ", buf_.size()); } + + private: + // If the buffer is configured for bounded capacity, notify + // waiting inserters that space is now available + void notify_inserters_if_bounded(std::unique_lock<std::mutex>* lock) { + if (IsBounded()) { + lock->unlock(); + // Notify all inserters. The removal of an element + // may make memory available for many inserters + // to insert new elements + full_cond_var_.notify_all(); + } + } + + // Are there a limit number of elements or a memory limit + // configued on this buffer? + bool IsBounded() const { return capacity_ > 0 || memory_limit_ > 0; } + + bool IsCapacityFull() const { return buf_.size() >= capacity_; } + + bool WouldExceedMemoryLimit(std::size_t bytes) const { + return bytes + current_bytes_ > memory_limit_; + } + + std::size_t GetTupleBytes(const Tuple& tuple) { + return std::accumulate(tuple.begin(), tuple.end(), 0, + [](const std::size_t& lhs, const Tensor& rhs) { + return lhs + rhs.TotalBytes(); + }); + } + + std::size_t capacity_; + std::size_t memory_limit_; + std::size_t current_bytes_; + std::mutex mu_; + std::condition_variable non_empty_cond_var_; + std::condition_variable full_cond_var_; + std::deque<Tuple> buf_; }; Status GetBuffer(OpKernelContext* ctx, const NodeDef& ndef, Buffer** buf) { |