Skip to content

Commit eb5e56e

Browse files
author
Vijay Vasudevan
committed
TensorFlow: Upstream changes to git.
Change 109344341 Teach ./configure about Python 3 (and other minor Python 3 issues) ./configure now writes bazel.rc based on a bazel.rc.template, which gives us a place to tell bazel which version of Python we were using. Also fix a few tests whose Python 3 support had degraded. The only thing left before we have Python 3 support is protocolbuffers/protobuf#1023 Change 109343002 Update ops.pbtxt to reflect 109321497. Change 109342838 Do memory deallocation outside the critical section in gpu_event_mgr.cc. Change 109334210 PTB LSTM example: use slicing instead of splitting the inputs. Change 109332238 Cleanup TensorBoard local development environment Change 109331051 Use __all__ in __init__.py to restrict exported modules Specifically, __all__ is now anything that (1) doesn't begin with an underscore and (2) isn't a non-whitelisted module. This fixes one tiny piece of b/25561952. Specifically, the following no longer exist: tf.np, tf.math_ops, and tf.variables. tf.ops and tf.tensor_util still exist but shouldn't; that will have to wait for a later CL. Change 109327154 tf.tuple allow Tensors to be passed in as control_inputs like tf.control_dependencies. Change 109324239 Make tf.control_dependencies(None) clear the control dependencies. Use that to prevent ops created for Variables to inherit the current control dependencies. This fixes issues when using ExponentialMovingAverages with control dependencies. Change 109323719 Added support for boolean tf.scatter_update. Base CL: 109348398
1 parent a4806a3 commit eb5e56e

31 files changed

Lines changed: 346 additions & 184 deletions

tensorflow/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ filegroup(
4040
py_library(
4141
name = "tensorflow_py",
4242
srcs = ["__init__.py"],
43+
srcs_version = "PY2AND3",
4344
visibility = ["//visibility:public"],
4445
deps = ["//tensorflow/python"],
4546
)

tensorflow/core/common_runtime/gpu/gpu_event_mgr.cc

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,13 @@ EventMgr::~EventMgr() {
4040
delete e;
4141
}
4242
while (!used_events_.empty()) {
43-
delete used_events_[0].event;
44-
delete used_events_[0].mem;
45-
if (used_events_[0].bufrec.buf) {
46-
used_events_[0].bufrec.alloc->DeallocateRaw(used_events_[0].bufrec.buf);
43+
InUse* ue = &used_events_[0];
44+
delete ue->event;
45+
delete ue->mem;
46+
if (ue->bufrec.buf) {
47+
ue->bufrec.alloc->DeallocateRaw(ue->bufrec.buf);
4748
}
48-
if (used_events_[0].func != nullptr)
49-
threadpool_.Schedule(used_events_[0].func);
49+
if (ue->func != nullptr) threadpool_.Schedule(ue->func);
5050
used_events_.pop_front();
5151
}
5252
}
@@ -60,10 +60,12 @@ EventMgr::~EventMgr() {
6060
void EventMgr::PollLoop() {
6161
while (!stop_polling_.HasBeenNotified()) {
6262
Env::Default()->SleepForMicroseconds(1 * 1000);
63+
ToFreeVector to_free;
6364
{
6465
mutex_lock l(mu_);
65-
PollEvents(true);
66+
PollEvents(true, &to_free);
6667
}
68+
FreeMemory(to_free);
6769
}
6870
polling_stopped_.Notify();
6971
}
@@ -103,7 +105,8 @@ void EventMgr::QueueInUse(gpu::Stream* stream, InUse iu) {
103105
// GPU memory use to spike needlessly. An alternative strategy would
104106
// be to throttle new Op execution until the pending event queue
105107
// clears.
106-
void EventMgr::PollEvents(bool is_dedicated_poller) {
108+
void EventMgr::PollEvents(bool is_dedicated_poller,
109+
gtl::InlinedVector<InUse, 4>* to_free) {
107110
VLOG(2) << "PollEvents free_events_ " << free_events_.size()
108111
<< " used_events_ " << used_events_.size();
109112
// Sweep the remaining events in order. If this is the dedicated
@@ -123,11 +126,9 @@ void EventMgr::PollEvents(bool is_dedicated_poller) {
123126
if (!is_dedicated_poller) return; // quit processing queue
124127
break;
125128
case gpu::Event::Status::kComplete:
126-
delete iu.mem;
127-
if (iu.bufrec.buf) iu.bufrec.alloc->DeallocateRaw(iu.bufrec.buf);
128-
// The function must be called in another thread, outside of
129-
// the mutex held here.
130-
if (iu.func != nullptr) threadpool_.Schedule(iu.func);
129+
// Make a copy of the InUse record so we can free it after releasing
130+
// the lock
131+
to_free->push_back(iu);
131132
free_events_.push_back(iu.event);
132133
// Mark this InUse record as completed.
133134
iu.event = nullptr;

tensorflow/core/common_runtime/gpu/gpu_event_mgr.h

Lines changed: 40 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@ limitations under the License.
1818

1919
#include <deque>
2020
#include <vector>
21+
#include "tensorflow/stream_executor/stream.h"
2122
#include "tensorflow/core/lib/core/notification.h"
2223
#include "tensorflow/core/lib/core/threadpool.h"
24+
#include "tensorflow/core/lib/gtl/inlined_vector.h"
2325
#include "tensorflow/core/platform/port.h"
2426
#include "tensorflow/core/platform/thread_annotations.h"
2527
#include "tensorflow/core/public/tensor.h"
@@ -47,9 +49,13 @@ class EventMgr {
4749
// currently enqueued on *stream have completed.
4850
inline void ThenDeleteTensors(perftools::gputools::Stream* stream,
4951
std::vector<Tensor>* tensors) {
50-
mutex_lock l(mu_);
51-
QueueTensors(stream, tensors);
52-
PollEvents(false);
52+
ToFreeVector to_free;
53+
{
54+
mutex_lock l(mu_);
55+
QueueTensors(stream, tensors);
56+
PollEvents(false, &to_free);
57+
}
58+
FreeMemory(to_free);
5359
}
5460

5561
struct BufRec {
@@ -61,16 +67,24 @@ class EventMgr {
6167
// on it as soon as all events currently enqueued on *stream have completed.
6268
inline void ThenDeleteBuffer(perftools::gputools::Stream* stream,
6369
BufRec bufrec) {
64-
mutex_lock l(mu_);
65-
QueueBuffer(stream, bufrec);
66-
PollEvents(false);
70+
ToFreeVector to_free;
71+
{
72+
mutex_lock l(mu_);
73+
QueueBuffer(stream, bufrec);
74+
PollEvents(false, &to_free);
75+
}
76+
FreeMemory(to_free);
6777
}
6878

6979
inline void ThenExecute(perftools::gputools::Stream* stream,
7080
std::function<void()> func) {
71-
mutex_lock l(mu_);
72-
QueueFunc(stream, func);
73-
PollEvents(false);
81+
ToFreeVector to_free;
82+
{
83+
mutex_lock l(mu_);
84+
QueueFunc(stream, func);
85+
PollEvents(false, &to_free);
86+
}
87+
FreeMemory(to_free);
7488
}
7589

7690
private:
@@ -85,10 +99,22 @@ class EventMgr {
8599
std::function<void()> func;
86100
};
87101

102+
typedef gtl::InlinedVector<InUse, 4> ToFreeVector;
103+
104+
void FreeMemory(const ToFreeVector& to_free) {
105+
for (const auto& iu : to_free) {
106+
delete iu.mem;
107+
if (iu.bufrec.buf) iu.bufrec.alloc->DeallocateRaw(iu.bufrec.buf);
108+
// The function must be called in another thread.
109+
if (iu.func != nullptr) threadpool_.Schedule(iu.func);
110+
}
111+
}
112+
88113
// Stream-enqueue an unused Event and save with it a collection of
89114
// Tensors and/or a BufRec to be deleted only after the Event
90115
// records.
91116
void QueueInUse(perftools::gputools::Stream* stream, InUse in_use)
117+
92118
EXCLUSIVE_LOCKS_REQUIRED(mu_);
93119

94120
void QueueTensors(perftools::gputools::Stream* stream,
@@ -109,8 +135,11 @@ class EventMgr {
109135

110136
// This function should be called at roughly the same tempo as
111137
// QueueTensors() to check whether pending events have recorded,
112-
// and then retire them.
113-
void PollEvents(bool is_dedicated_poller) EXCLUSIVE_LOCKS_REQUIRED(mu_);
138+
// and then retire them. It appends InUse elements that need cleanup
139+
// to "*to_free". The caller should call FreeMemory(to_free)
140+
// when this returns.
141+
void PollEvents(bool is_dedicated_poller, ToFreeVector* to_free)
142+
EXCLUSIVE_LOCKS_REQUIRED(mu_);
114143

115144
// An internal polling loop that runs at a low frequency to clear
116145
// straggler Events.

tensorflow/core/common_runtime/gpu/gpu_event_mgr_test.cc

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,12 @@ class TEST_EventMgrHelper {
4747
}
4848

4949
void PollEvents(bool is_dedicated_poller) {
50-
mutex_lock l(em_->mu_);
51-
em_->PollEvents(is_dedicated_poller);
50+
EventMgr::ToFreeVector to_free;
51+
{
52+
mutex_lock l(em_->mu_);
53+
em_->PollEvents(is_dedicated_poller, &to_free);
54+
}
55+
em_->FreeMemory(to_free);
5256
}
5357

5458
private:

tensorflow/core/kernels/scatter_op.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,8 @@ class ScatterUpdateOp : public OpKernel {
140140

141141
TF_CALL_NUMBER_TYPES(REGISTER_SCATTER_UPDATE_INT32);
142142
TF_CALL_NUMBER_TYPES(REGISTER_SCATTER_UPDATE_INT64);
143+
REGISTER_SCATTER_UPDATE_INT32(bool)
144+
REGISTER_SCATTER_UPDATE_INT64(bool)
143145

144146
#undef REGISTER_SCATTER_UPDATE_INT64
145147
#undef REGISTER_SCATTER_UPDATE_INT32

0 commit comments

Comments
 (0)