Skip to content

Commit

Permalink
TensorFlow: upstream changes from the afternoon.
Browse files Browse the repository at this point in the history
Changes:

- futurize --stage2 changes for Python 3 compatibility by @girving.

- Small updates to documentation by @vrv, schuster and others

- Account for failure of std::thread::hardware_concurrency by @ebrevdo.

- More changes for backwards-compatibility tests by Josh

- Updates to python op doc generation by Josh

- Added support for using the best-fit allocator via ConfigProto by @vrv.

- Rename LocalSession to DirectSession, since local was a bad name for
  it.

- Enable tf.nn.moments() to work with tensors of unknown shape by @mrry.
  GITHUB_ISSUE: 139

- Changes for Android build by Andrew.

Base CL: 107645181
  • Loading branch information
Vijay Vasudevan committed Nov 12, 2015
1 parent 3961abe commit f2102f4
Show file tree
Hide file tree
Showing 322 changed files with 2,609 additions and 710 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ installing from source, GPU-enabled support, etc., see

The TensorFlow Python API currently requires Python 2.7: we are
[working](https://github.com/tensorflow/tensorflow/issues/1) on adding support
for Python 3.0.
for Python 3.

The simplest way to install TensorFlow is using
[pip](https://pypi.python.org/pypi/pip) for both Linux and Mac.
Expand Down
4 changes: 4 additions & 0 deletions tensorflow/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# Bring in all of the public TensorFlow interface into this
# module.
# pylint: disable=wildcard-import
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

from tensorflow.python import *
1 change: 0 additions & 1 deletion tensorflow/cc/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ cc_binary(
deps = [
":cc_ops",
"//tensorflow/core:kernels",
"//tensorflow/core:local",
"//tensorflow/core:tensorflow",
],
)
Expand Down
18 changes: 9 additions & 9 deletions tensorflow/core/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ tf_cuda_library(
"common_runtime/gpu/*.cc",
"common_runtime/copy_tensor.cc",
"common_runtime/gpu_device_factory.cc",
"common_runtime/local_session.cc",
"common_runtime/local_session.h",
"common_runtime/direct_session.cc",
"common_runtime/direct_session.h",
],
),
hdrs = glob(["public/**/*.h"]),
Expand Down Expand Up @@ -113,10 +113,10 @@ tf_cuda_library(
)

tf_cuda_library(
name = "local",
name = "direct_session",
srcs = [
"common_runtime/local_session.cc",
"common_runtime/local_session.h",
"common_runtime/direct_session.cc",
"common_runtime/direct_session.h",
],
copts = tf_copts(),
cuda_deps = [
Expand Down Expand Up @@ -200,10 +200,10 @@ tf_cuda_library(
visibility = ["//visibility:public"],
deps = [
":core",
":direct_session",
":gpu_runtime",
":kernels",
":lib",
":local",
],
)

Expand Down Expand Up @@ -300,7 +300,7 @@ tf_proto_library(
cc_api_version = 2,
go_api_version = 2,
java_api_version = 2,
py_api_version = 2,
py_api_version = 2, # TODO(irving): Handle 3
visibility = ["//tensorflow:internal"],
)

Expand Down Expand Up @@ -402,9 +402,9 @@ tf_cc_tests(
),
deps = [
":core",
":direct_session",
":kernels",
":lib",
":local",
":test_main",
":testlib",
"//tensorflow/cc:cc_ops",
Expand All @@ -423,8 +423,8 @@ tf_cc_tests(
],
),
deps = [
":direct_session",
":kernels",
":local",
":test_main",
":testlib",
"//tensorflow/cc:cc_ops",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "tensorflow/core/common_runtime/local_session.h"
#include "tensorflow/core/common_runtime/direct_session.h"

#include <string>
#include <vector>
Expand Down Expand Up @@ -42,7 +42,7 @@ static bool InitModule(const SessionOptions& options) {
// Default to using the number of cores available in the process.
inter_op_parallelism_threads = port::NumSchedulableCPUs();
}
LOG(INFO) << "Local session inter op parallelism threads: "
LOG(INFO) << "Direct session inter op parallelism threads: "
<< inter_op_parallelism_threads;
kernel_thread_pool_ = new thread::ThreadPool(options.env, "Compute",
inter_op_parallelism_threads);
Expand Down Expand Up @@ -92,7 +92,7 @@ void SchedClosure(std::function<void()> c) {

} // namespace

LocalSession::LocalSession(const SessionOptions& options,
DirectSession::DirectSession(const SessionOptions& options,
const DeviceMgr* device_mgr)
: options_(options),
device_mgr_(device_mgr),
Expand Down Expand Up @@ -124,7 +124,7 @@ LocalSession::LocalSession(const SessionOptions& options,
}
}

LocalSession::~LocalSession() {
DirectSession::~DirectSession() {
for (auto d : device_mgr_->ListDevices()) {
d->op_segment()->RemoveHold(session_handle_);
}
Expand All @@ -134,7 +134,7 @@ LocalSession::~LocalSession() {
delete cancellation_manager_;
}

Status LocalSession::Create(const GraphDef& graph) {
Status DirectSession::Create(const GraphDef& graph) {
mutex_lock l(graph_def_lock_);
if (graph_created_) {
return errors::AlreadyExists(
Expand All @@ -143,18 +143,18 @@ Status LocalSession::Create(const GraphDef& graph) {
return ExtendLocked(graph);
}

Status LocalSession::Extend(const GraphDef& graph) {
Status DirectSession::Extend(const GraphDef& graph) {
mutex_lock l(graph_def_lock_);
return ExtendLocked(graph);
}

Status LocalSession::ExtendLocked(const GraphDef& graph) {
Status DirectSession::ExtendLocked(const GraphDef& graph) {
graph_created_ = true; // In case this is first call
graph_def_.MergeFrom(graph);
return Status::OK();
}

Status LocalSession::Run(const std::vector<std::pair<string, Tensor>>& inputs,
Status DirectSession::Run(const std::vector<std::pair<string, Tensor>>& inputs,
const std::vector<string>& output_names,
const std::vector<string>& target_nodes,
std::vector<Tensor>* outputs) {
Expand Down Expand Up @@ -250,7 +250,7 @@ Status LocalSession::Run(const std::vector<std::pair<string, Tensor>>& inputs,
return s;
}

Status LocalSession::GetOrCreateExecutors(
Status DirectSession::GetOrCreateExecutors(
gtl::ArraySlice<string> inputs, gtl::ArraySlice<string> outputs,
gtl::ArraySlice<string> target_nodes,
ExecutorsAndKeys** executors_and_keys) {
Expand Down Expand Up @@ -358,7 +358,7 @@ Status LocalSession::GetOrCreateExecutors(
return Status::OK();
}

void LocalSession::SaveStatefulNodes(Graph* graph) {
void DirectSession::SaveStatefulNodes(Graph* graph) {
for (Node* n : graph->nodes()) {
if (n->op_def().is_stateful()) {
VLOG(2) << "Saving " << n->DebugString();
Expand All @@ -367,7 +367,7 @@ void LocalSession::SaveStatefulNodes(Graph* graph) {
}
}

void LocalSession::RestoreStatefulNodes(Graph* graph) {
void DirectSession::RestoreStatefulNodes(Graph* graph) {
for (Node* n : graph->nodes()) {
if (n->op_def().is_stateful()) {
auto iter = stateful_placements_.find(n->name());
Expand All @@ -379,7 +379,7 @@ void LocalSession::RestoreStatefulNodes(Graph* graph) {
}
}

Status LocalSession::CreateGraphs(gtl::ArraySlice<string> feeds,
Status DirectSession::CreateGraphs(gtl::ArraySlice<string> feeds,
gtl::ArraySlice<string> fetches,
gtl::ArraySlice<string> target_nodes,
std::unordered_map<string, Graph*>* outputs) {
Expand Down Expand Up @@ -422,7 +422,7 @@ Status LocalSession::CreateGraphs(gtl::ArraySlice<string> feeds,
return strings::StrCat(prefix, "/_", name_counter_++);
};
popts.get_incarnation = [](const string& name) {
// The local session does not have changing incarnation numbers.
// The direct session does not have changing incarnation numbers.
// Just return '1'.
return 1;
};
Expand Down Expand Up @@ -476,29 +476,29 @@ Status LocalSession::CreateGraphs(gtl::ArraySlice<string> feeds,
return Status::OK();
}

::tensorflow::Status LocalSession::Close() {
::tensorflow::Status DirectSession::Close() {
cancellation_manager_->StartCancel();
return ::tensorflow::Status::OK();
}

class LocalSessionFactory : public SessionFactory {
class DirectSessionFactory : public SessionFactory {
public:
LocalSessionFactory() {}
DirectSessionFactory() {}

Session* NewSession(const SessionOptions& options) override {
std::vector<Device*> devices;
DeviceFactory::AddDevices(options, "/job:localhost/replica:0/task:0",
&devices);
return new LocalSession(options, new DeviceMgr(devices));
return new DirectSession(options, new DeviceMgr(devices));
}
};

class LocalSessionRegistrar {
class DirectSessionRegistrar {
public:
LocalSessionRegistrar() {
SessionFactory::Register("LOCAL_SESSION", new LocalSessionFactory());
DirectSessionRegistrar() {
SessionFactory::Register("DIRECT_SESSION", new DirectSessionFactory());
}
};
static LocalSessionRegistrar registrar;
static DirectSessionRegistrar registrar;

} // namespace tensorflow
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef TENSORFLOW_COMMON_RUNTIME_LOCAL_SESSION_H_
#define TENSORFLOW_COMMON_RUNTIME_LOCAL_SESSION_H_
#ifndef TENSORFLOW_COMMON_RUNTIME_DIRECT_SESSION_H_
#define TENSORFLOW_COMMON_RUNTIME_DIRECT_SESSION_H_

#include <memory>
#include <string>
Expand All @@ -22,11 +22,11 @@ namespace tensorflow {

class Device;

class LocalSession : public Session {
class DirectSession : public Session {
public:
// Takes ownership of 'device_mgr'.
LocalSession(const SessionOptions& options, const DeviceMgr* device_mgr);
~LocalSession() override;
DirectSession(const SessionOptions& options, const DeviceMgr* device_mgr);
~DirectSession() override;

::tensorflow::Status Create(const GraphDef& graph) override;
::tensorflow::Status Extend(const GraphDef& graph) override;
Expand Down Expand Up @@ -101,9 +101,9 @@ class LocalSession : public Session {
// For generating unique names.
int64 name_counter_ GUARDED_BY(mu_) = 0;

TF_DISALLOW_COPY_AND_ASSIGN(LocalSession);
TF_DISALLOW_COPY_AND_ASSIGN(DirectSession);
};

} // end namespace tensorflow

#endif // TENSORFLOW_COMMON_RUNTIME_LOCAL_SESSION_H_
#endif // TENSORFLOW_COMMON_RUNTIME_DIRECT_SESSION_H_
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "tensorflow/core/common_runtime/local_session.h"
#include "tensorflow/core/common_runtime/direct_session.h"

#include <map>
#include <string>
Expand Down Expand Up @@ -29,7 +29,7 @@ Session* CreateSession() {
return NewSession(options);
}

class LocalSessionMinusAXTest : public ::testing::Test {
class DirectSessionMinusAXTest : public ::testing::Test {
public:
void Initialize(std::initializer_list<float> a_values) {
RequireDefaultOps();
Expand Down Expand Up @@ -64,7 +64,7 @@ class LocalSessionMinusAXTest : public ::testing::Test {
GraphDef def_;
};

TEST_F(LocalSessionMinusAXTest, RunSimpleNetwork) {
TEST_F(DirectSessionMinusAXTest, RunSimpleNetwork) {
Initialize({3, 2, -1, 0});
std::unique_ptr<Session> session(CreateSession());
ASSERT_TRUE(session != nullptr);
Expand All @@ -86,7 +86,7 @@ TEST_F(LocalSessionMinusAXTest, RunSimpleNetwork) {
EXPECT_FLOAT_EQ(5.0, mat(0, 0));
}

TEST_F(LocalSessionMinusAXTest, TestFeed) {
TEST_F(DirectSessionMinusAXTest, TestFeed) {
Initialize({1, 2, 3, 4});
std::unique_ptr<Session> session(CreateSession());
ASSERT_TRUE(session != nullptr);
Expand Down Expand Up @@ -115,7 +115,7 @@ TEST_F(LocalSessionMinusAXTest, TestFeed) {
EXPECT_FLOAT_EQ(39.0, mat(1, 0));
}

TEST_F(LocalSessionMinusAXTest, TestConcurrency) {
TEST_F(DirectSessionMinusAXTest, TestConcurrency) {
Initialize({1, 2, 3, 4});
std::unique_ptr<Session> session(CreateSession());
ASSERT_TRUE(session != nullptr);
Expand Down Expand Up @@ -147,7 +147,7 @@ TEST_F(LocalSessionMinusAXTest, TestConcurrency) {
delete tp;
}

TEST_F(LocalSessionMinusAXTest, TwoCreateCallsFails) {
TEST_F(DirectSessionMinusAXTest, TwoCreateCallsFails) {
Initialize({1, 2, 3, 4});
std::unique_ptr<Session> session(CreateSession());
ASSERT_TRUE(session != nullptr);
Expand All @@ -157,7 +157,7 @@ TEST_F(LocalSessionMinusAXTest, TwoCreateCallsFails) {
ASSERT_FALSE(session->Create(def_).ok());
}

TEST_F(LocalSessionMinusAXTest, ForgetToCreate) {
TEST_F(DirectSessionMinusAXTest, ForgetToCreate) {
Initialize({1, 2, 3, 4});
std::unique_ptr<Session> session(CreateSession());
ASSERT_TRUE(session != nullptr);
Expand All @@ -166,7 +166,7 @@ TEST_F(LocalSessionMinusAXTest, ForgetToCreate) {
ASSERT_FALSE(session->Run(inputs, {y_ + ":0"}, {y_neg_}, &outputs).ok());
}

TEST_F(LocalSessionMinusAXTest, InvalidDevice) {
TEST_F(DirectSessionMinusAXTest, InvalidDevice) {
GraphDef def;
Graph graph(OpRegistry::Global());

Expand Down Expand Up @@ -203,7 +203,7 @@ TEST_F(LocalSessionMinusAXTest, InvalidDevice) {
ASSERT_OK(session->Run(inputs, output_names, {}, &outputs));
}

TEST(LocalSessionTest, KeepsStateAcrossRunsOfSession) {
TEST(DirectSessionTest, KeepsStateAcrossRunsOfSession) {
GraphDef def;
Graph g(OpRegistry::Global());
Node* var = test::graph::Var(&g, DT_FLOAT, TensorShape({10}));
Expand Down Expand Up @@ -242,7 +242,7 @@ TEST(LocalSessionTest, KeepsStateAcrossRunsOfSession) {
EXPECT_EQ(20.0, outputs[0].flat<float>()(0));
}

TEST(LocalSessionTest, MultipleFeedTest) {
TEST(DirectSessionTest, MultipleFeedTest) {
GraphDef def;
Graph g(OpRegistry::Global());
Node* var = test::graph::Var(&g, DT_FLOAT, TensorShape({10}));
Expand Down
11 changes: 6 additions & 5 deletions tensorflow/core/common_runtime/gpu/gpu_device.cc
Original file line number Diff line number Diff line change
Expand Up @@ -558,11 +558,12 @@ LocalDevice* BaseGPUDeviceFactory::CreateGPUDevice(
<< " numa: " << desc.numa_node() << " pci: " << desc.pci_bus_id();

ProcessState* process_state = ProcessState::singleton();
return CreateGPUDevice(
options, name, allocated_bytes, bus_adjacency, gpu_id,
GetShortDeviceDescription(gpu_id, desc),
process_state->GetGPUAllocator(gpu_id, allocated_memory),
process_state->GetCPUAllocator(desc.numa_node()));
return CreateGPUDevice(options, name, allocated_bytes, bus_adjacency, gpu_id,
GetShortDeviceDescription(gpu_id, desc),
process_state->GetGPUAllocator(
gpu_id, allocated_memory,
options.config.gpu_options().allocator_type()),
process_state->GetCPUAllocator(desc.numa_node()));
}

static int GetMinGPUMultiprocessorCount() {
Expand Down
Loading

0 comments on commit f2102f4

Please sign in to comment.