aboutsummaryrefslogtreecommitdiffhomepage
path: root/tensorflow/core/common_runtime/gpu
diff options
context:
space:
mode:
authorGravatar Guangda Lai <laigd@google.com>2018-02-09 12:20:38 -0800
committerGravatar TensorFlower Gardener <gardener@tensorflow.org>2018-02-09 12:27:57 -0800
commitdf982b8dea49eba273e33e4283c3b14eab171b04 (patch)
tree2ab961d8b3e52672e6492040bc887c3564731bc9 /tensorflow/core/common_runtime/gpu
parentc967fed58227e919be4c844bae241874f8717933 (diff)
Split gpu_id.h and GpuIdManager out from build target //tensorflow/core:gpu_runtime, to reduce the size of dependencies, so when other lightweight libraries like grappler utils needs the TfToCudaGpuId translation function it doesn't need to depend on things like stream executor and cuda libraries.
PiperOrigin-RevId: 185175757
Diffstat (limited to 'tensorflow/core/common_runtime/gpu')
-rw-r--r--tensorflow/core/common_runtime/gpu/gpu_device.cc15
-rw-r--r--tensorflow/core/common_runtime/gpu/gpu_device.h3
-rw-r--r--tensorflow/core/common_runtime/gpu/gpu_id_manager.cc (renamed from tensorflow/core/common_runtime/gpu/gpu_id_utils.cc)18
-rw-r--r--tensorflow/core/common_runtime/gpu/gpu_id_manager.h33
-rw-r--r--tensorflow/core/common_runtime/gpu/gpu_id_manager_test.cc (renamed from tensorflow/core/common_runtime/gpu/gpu_id_utils_test.cc)24
-rw-r--r--tensorflow/core/common_runtime/gpu/gpu_id_utils.h8
-rw-r--r--tensorflow/core/common_runtime/gpu/process_state.cc3
7 files changed, 69 insertions, 35 deletions
diff --git a/tensorflow/core/common_runtime/gpu/gpu_device.cc b/tensorflow/core/common_runtime/gpu/gpu_device.cc
index a9485a835e..0fb908b080 100644
--- a/tensorflow/core/common_runtime/gpu/gpu_device.cc
+++ b/tensorflow/core/common_runtime/gpu/gpu_device.cc
@@ -33,6 +33,7 @@ limitations under the License.
#include "tensorflow/core/common_runtime/device_factory.h"
#include "tensorflow/core/common_runtime/gpu/gpu_event_mgr.h"
#include "tensorflow/core/common_runtime/gpu/gpu_id.h"
+#include "tensorflow/core/common_runtime/gpu/gpu_id_manager.h"
#include "tensorflow/core/common_runtime/gpu/gpu_id_utils.h"
#include "tensorflow/core/common_runtime/gpu/gpu_init.h"
#include "tensorflow/core/common_runtime/gpu/gpu_stream_util.h"
@@ -99,7 +100,7 @@ class EigenCudaStreamDevice : public ::Eigen::StreamInterface {
reinterpret_cast<unsigned int*>(scratch + Eigen::kCudaScratchSize);
stream_ = cuda_stream;
allocator_ = alloc;
- const int cuda_gpu_id = GpuIdUtil::TfToCudaGpuId(tf_gpu_id).value();
+ const int cuda_gpu_id = GpuIdManager::TfToCudaGpuId(tf_gpu_id).value();
device_prop_ = &Eigen::m_deviceProperties[cuda_gpu_id];
}
@@ -311,7 +312,7 @@ Status BaseGPUDevice::Init(const SessionOptions& options) {
gpu_device_info_->stream = streams_[0]->compute;
gpu_device_info_->default_context = device_contexts_[0];
gpu_device_info_->event_mgr = em_.get();
- gpu_device_info_->gpu_id = GpuIdUtil::TfToCudaGpuId(tf_gpu_id_).value();
+ gpu_device_info_->gpu_id = GpuIdManager::TfToCudaGpuId(tf_gpu_id_).value();
set_tensorflow_gpu_device_info(gpu_device_info_);
// Whether and how the GPU device uses its own threadpool.
@@ -955,7 +956,7 @@ Status BaseGPUDeviceFactory::CreateDevices(const SessionOptions& options,
while (next_tf_gpu_id < memory_limit_bytes.size()) {
TfGpuId tf_gpu_id(next_tf_gpu_id);
++next_tf_gpu_id;
- GpuIdUtil::InsertTfCudaGpuIdPair(tf_gpu_id, cuda_gpu_id);
+ GpuIdManager::InsertTfCudaGpuIdPair(tf_gpu_id, cuda_gpu_id);
}
}
const int num_tf_gpus = next_tf_gpu_id;
@@ -1006,7 +1007,7 @@ Status BaseGPUDeviceFactory::CreateGPUDevice(const SessionOptions& options,
const string device_name =
strings::StrCat(name_prefix, "/device:GPU:", tf_gpu_id.value());
GpuIdUtil::CheckValidTfGpuId(tf_gpu_id);
- CudaGpuId cuda_gpu_id = GpuIdUtil::TfToCudaGpuId(tf_gpu_id);
+ CudaGpuId cuda_gpu_id = GpuIdManager::TfToCudaGpuId(tf_gpu_id);
int numa_node = dev_locality.numa_node();
Bytes allocated_bytes = static_cast<Bytes>(memory_limit);
@@ -1078,7 +1079,7 @@ Status BaseGPUDeviceFactory::GetDeviceLocalities(
all_tf_gpu_ids.push_back(TfGpuId(i));
}
for (TfGpuId tf_gpu_id : all_tf_gpu_ids) {
- CudaGpuId cuda_gpu_id = GpuIdUtil::TfToCudaGpuId(tf_gpu_id);
+ CudaGpuId cuda_gpu_id = GpuIdManager::TfToCudaGpuId(tf_gpu_id);
// Get GPU bus_id from its reported NUMA affinity. Because GPUs are
// virtualized in some environments, we can't just use the GPU id.
// NUMA locales are indexed from 0, buses are indexed from 1.
@@ -1106,7 +1107,7 @@ Status BaseGPUDeviceFactory::GetDeviceLocalities(
LocalLinks* links = dev_locality.mutable_links();
for (const InterconnectMap& imap : interconnects) {
for (TfGpuId tf_gpu_dst : all_tf_gpu_ids) {
- CudaGpuId cuda_gpu_dst = GpuIdUtil::TfToCudaGpuId(tf_gpu_dst);
+ CudaGpuId cuda_gpu_dst = GpuIdManager::TfToCudaGpuId(tf_gpu_dst);
if (imap.directed_links.find({cuda_gpu_id, cuda_gpu_dst}) !=
imap.directed_links.end()) {
InterconnectLink* ilink = links->add_link();
@@ -1121,7 +1122,7 @@ Status BaseGPUDeviceFactory::GetDeviceLocalities(
// add high strength links to the others.
for (TfGpuId tf_gpu_dst : all_tf_gpu_ids) {
if (tf_gpu_id == tf_gpu_dst) continue;
- CudaGpuId cuda_gpu_dst = GpuIdUtil::TfToCudaGpuId(tf_gpu_dst);
+ CudaGpuId cuda_gpu_dst = GpuIdManager::TfToCudaGpuId(tf_gpu_dst);
if (cuda_gpu_id == cuda_gpu_dst) {
InterconnectLink* ilink = links->add_link();
ilink->set_device_id(tf_gpu_dst.value());
diff --git a/tensorflow/core/common_runtime/gpu/gpu_device.h b/tensorflow/core/common_runtime/gpu/gpu_device.h
index 82ce3a2e9d..c88daa8ff8 100644
--- a/tensorflow/core/common_runtime/gpu/gpu_device.h
+++ b/tensorflow/core/common_runtime/gpu/gpu_device.h
@@ -29,6 +29,7 @@ limitations under the License.
#include "tensorflow/core/common_runtime/device_factory.h"
#include "tensorflow/core/common_runtime/gpu/gpu_event_mgr.h"
#include "tensorflow/core/common_runtime/gpu/gpu_id.h"
+#include "tensorflow/core/common_runtime/gpu/gpu_id_manager.h"
#include "tensorflow/core/common_runtime/gpu/gpu_id_utils.h"
#include "tensorflow/core/common_runtime/gpu_device_context.h"
#include "tensorflow/core/common_runtime/local_device.h"
@@ -88,7 +89,7 @@ class BaseGPUDevice : public LocalDevice {
// Returns the CUDA GPU id of this device within the native driver system;
// e.g., for CUDA this is the ordinal of the GPU within the system.
- int gpu_id() const { return GpuIdUtil::TfToCudaGpuId(tf_gpu_id_).value(); }
+ int gpu_id() const { return GpuIdManager::TfToCudaGpuId(tf_gpu_id_).value(); }
// The executor that provides control for the device; e.g., for CUDA this
// corresponds to the cuda context.
diff --git a/tensorflow/core/common_runtime/gpu/gpu_id_utils.cc b/tensorflow/core/common_runtime/gpu/gpu_id_manager.cc
index 92cd19453f..207afdca75 100644
--- a/tensorflow/core/common_runtime/gpu/gpu_id_utils.cc
+++ b/tensorflow/core/common_runtime/gpu/gpu_id_manager.cc
@@ -13,7 +13,7 @@ See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/
-#include "tensorflow/core/common_runtime/gpu/gpu_id_utils.h"
+#include "tensorflow/core/common_runtime/gpu/gpu_id_manager.h"
#include <unordered_map>
@@ -24,10 +24,10 @@ limitations under the License.
namespace tensorflow {
namespace {
// Manages the map between TfGpuId and CUDA GPU id.
-class GpuIdManager {
+class TfToCudaGpuIdMap {
public:
- static GpuIdManager* singleton() {
- static auto* manager = new GpuIdManager;
+ static TfToCudaGpuIdMap* singleton() {
+ static auto* manager = new TfToCudaGpuIdMap;
return manager;
}
@@ -62,13 +62,13 @@ class GpuIdManager {
};
} // namespace
-void GpuIdUtil::InsertTfCudaGpuIdPair(TfGpuId tf_gpu_id,
- CudaGpuId cuda_gpu_id) {
- GpuIdManager::singleton()->InsertOrDie(tf_gpu_id, cuda_gpu_id);
+void GpuIdManager::InsertTfCudaGpuIdPair(TfGpuId tf_gpu_id,
+ CudaGpuId cuda_gpu_id) {
+ TfToCudaGpuIdMap::singleton()->InsertOrDie(tf_gpu_id, cuda_gpu_id);
}
-CudaGpuId GpuIdUtil::TfToCudaGpuId(TfGpuId tf_gpu_id) {
- return CudaGpuId(GpuIdManager::singleton()->FindOrDie(tf_gpu_id));
+CudaGpuId GpuIdManager::TfToCudaGpuId(TfGpuId tf_gpu_id) {
+ return CudaGpuId(TfToCudaGpuIdMap::singleton()->FindOrDie(tf_gpu_id));
}
} // namespace tensorflow
diff --git a/tensorflow/core/common_runtime/gpu/gpu_id_manager.h b/tensorflow/core/common_runtime/gpu/gpu_id_manager.h
new file mode 100644
index 0000000000..33925d8c36
--- /dev/null
+++ b/tensorflow/core/common_runtime/gpu/gpu_id_manager.h
@@ -0,0 +1,33 @@
+/* Copyright 2015 The TensorFlow Authors. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+==============================================================================*/
+
+#ifndef TENSORFLOW_CORE_COMMON_RUNTIME_GPU_GPU_ID_MANAGER_H_
+#define TENSORFLOW_CORE_COMMON_RUNTIME_GPU_GPU_ID_MANAGER_H_
+
+#include "tensorflow/core/common_runtime/gpu/gpu_id.h"
+
+namespace tensorflow {
+
+// Class that manages the translation between Tensorflow GPU ids and CUDA GPU
+// ids.
+class GpuIdManager {
+ public:
+ static void InsertTfCudaGpuIdPair(TfGpuId tf_gpu_id, CudaGpuId cuda_gpu_id);
+ static CudaGpuId TfToCudaGpuId(TfGpuId tf_gpu_id);
+};
+
+} // namespace tensorflow
+
+#endif // TENSORFLOW_CORE_COMMON_RUNTIME_GPU_GPU_ID_MANAGER_H_
diff --git a/tensorflow/core/common_runtime/gpu/gpu_id_utils_test.cc b/tensorflow/core/common_runtime/gpu/gpu_id_manager_test.cc
index bebe00a431..bdbd8d065b 100644
--- a/tensorflow/core/common_runtime/gpu/gpu_id_utils_test.cc
+++ b/tensorflow/core/common_runtime/gpu/gpu_id_manager_test.cc
@@ -13,7 +13,7 @@ See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/
-#include "tensorflow/core/common_runtime/gpu/gpu_id_utils.h"
+#include "tensorflow/core/common_runtime/gpu/gpu_id_manager.h"
#include "tensorflow/core/common_runtime/gpu/gpu_id.h"
#include "tensorflow/core/platform/test.h"
@@ -21,33 +21,33 @@ limitations under the License.
namespace tensorflow {
namespace test {
-TEST(GpuIdTest, Basics) {
+TEST(GpuIdManagerTest, Basics) {
TfGpuId key_0(0);
CudaGpuId value_0(0);
- GpuIdUtil::InsertTfCudaGpuIdPair(key_0, value_0);
- EXPECT_EQ(value_0, GpuIdUtil::TfToCudaGpuId(key_0));
+ GpuIdManager::InsertTfCudaGpuIdPair(key_0, value_0);
+ EXPECT_EQ(value_0, GpuIdManager::TfToCudaGpuId(key_0));
// Multiple calls to map the same value is ok.
- GpuIdUtil::InsertTfCudaGpuIdPair(key_0, value_0);
- EXPECT_EQ(value_0, GpuIdUtil::TfToCudaGpuId(key_0));
+ GpuIdManager::InsertTfCudaGpuIdPair(key_0, value_0);
+ EXPECT_EQ(value_0, GpuIdManager::TfToCudaGpuId(key_0));
// Map a different TfGpuId to a different value.
TfGpuId key_1(3);
CudaGpuId value_1(2);
- GpuIdUtil::InsertTfCudaGpuIdPair(key_1, value_1);
- EXPECT_EQ(value_1, GpuIdUtil::TfToCudaGpuId(key_1));
+ GpuIdManager::InsertTfCudaGpuIdPair(key_1, value_1);
+ EXPECT_EQ(value_1, GpuIdManager::TfToCudaGpuId(key_1));
// Mapping a different TfGpuId to the same value is ok.
TfGpuId key_2(10);
- GpuIdUtil::InsertTfCudaGpuIdPair(key_2, value_1);
- EXPECT_EQ(value_1, GpuIdUtil::TfToCudaGpuId(key_2));
+ GpuIdManager::InsertTfCudaGpuIdPair(key_2, value_1);
+ EXPECT_EQ(value_1, GpuIdManager::TfToCudaGpuId(key_2));
// Mapping the same TfGpuId to a different value will crash the program.
- ASSERT_DEATH(GpuIdUtil::InsertTfCudaGpuIdPair(key_2, value_0),
+ ASSERT_DEATH(GpuIdManager::InsertTfCudaGpuIdPair(key_2, value_0),
"Mapping the same TfGpuId to a different CUDA GPU id");
// Getting an nonexistent mapping will crash the program.
- ASSERT_DEATH(GpuIdUtil::TfToCudaGpuId(TfGpuId(100)),
+ ASSERT_DEATH(GpuIdManager::TfToCudaGpuId(TfGpuId(100)),
"Could not find the mapping for TfGpuId");
}
diff --git a/tensorflow/core/common_runtime/gpu/gpu_id_utils.h b/tensorflow/core/common_runtime/gpu/gpu_id_utils.h
index 6d196b16ed..2e90687fe8 100644
--- a/tensorflow/core/common_runtime/gpu/gpu_id_utils.h
+++ b/tensorflow/core/common_runtime/gpu/gpu_id_utils.h
@@ -17,6 +17,7 @@ limitations under the License.
#define TENSORFLOW_CORE_COMMON_RUNTIME_GPU_GPU_ID_UTILS_H_
#include "tensorflow/core/common_runtime/gpu/gpu_id.h"
+#include "tensorflow/core/common_runtime/gpu/gpu_id_manager.h"
#include "tensorflow/core/common_runtime/gpu/gpu_init.h"
#include "tensorflow/core/lib/gtl/int_type.h"
#include "tensorflow/core/platform/stream_executor.h"
@@ -27,9 +28,6 @@ namespace gpu = ::perftools::gputools;
// Utility methods for translation between Tensorflow GPU ids and CUDA GPU ids.
class GpuIdUtil {
public:
- static void InsertTfCudaGpuIdPair(TfGpuId tf_gpu_id, CudaGpuId cuda_gpu_id);
- static CudaGpuId TfToCudaGpuId(TfGpuId tf_gpu_id);
-
// Convenient methods for getting the associated executor given a TfGpuId or
// CudaGpuId.
static gpu::port::StatusOr<gpu::StreamExecutor*> ExecutorForCudaGpuId(
@@ -42,12 +40,12 @@ class GpuIdUtil {
}
static gpu::port::StatusOr<gpu::StreamExecutor*> ExecutorForTfGpuId(
TfGpuId tf_gpu_id) {
- return ExecutorForCudaGpuId(GpuIdUtil::TfToCudaGpuId(tf_gpu_id));
+ return ExecutorForCudaGpuId(GpuIdManager::TfToCudaGpuId(tf_gpu_id));
}
// Verify that the cuda_gpu_id associated with a TfGpuId is legitimate.
static void CheckValidTfGpuId(TfGpuId tf_gpu_id) {
- const CudaGpuId cuda_gpu_id = GpuIdUtil::TfToCudaGpuId(tf_gpu_id);
+ const CudaGpuId cuda_gpu_id = GpuIdManager::TfToCudaGpuId(tf_gpu_id);
const int visible_device_count = GPUMachineManager()->VisibleDeviceCount();
CHECK_LT(cuda_gpu_id.value(), visible_device_count)
<< "cuda_gpu_id is outside discovered device range."
diff --git a/tensorflow/core/common_runtime/gpu/process_state.cc b/tensorflow/core/common_runtime/gpu/process_state.cc
index b195de7cba..61013bd1ac 100644
--- a/tensorflow/core/common_runtime/gpu/process_state.cc
+++ b/tensorflow/core/common_runtime/gpu/process_state.cc
@@ -22,6 +22,7 @@ limitations under the License.
#include "tensorflow/core/common_runtime/gpu/gpu_cudamalloc_allocator.h"
#include "tensorflow/core/common_runtime/gpu/gpu_debug_allocator.h"
#include "tensorflow/core/common_runtime/gpu/gpu_id.h"
+#include "tensorflow/core/common_runtime/gpu/gpu_id_manager.h"
#include "tensorflow/core/common_runtime/gpu/gpu_id_utils.h"
#include "tensorflow/core/common_runtime/gpu/gpu_init.h"
#include "tensorflow/core/common_runtime/gpu/pool_allocator.h"
@@ -124,7 +125,7 @@ Allocator* ProcessState::GetGPUAllocator(const GPUOptions& options,
return nullptr;
}
- const CudaGpuId cuda_gpu_id = GpuIdUtil::TfToCudaGpuId(tf_gpu_id);
+ const CudaGpuId cuda_gpu_id = GpuIdManager::TfToCudaGpuId(tf_gpu_id);
gpu_allocator =
new GPUBFCAllocator(cuda_gpu_id, total_bytes, options,
strings::StrCat("GPU_", tf_gpu_id.value(), "_bfc"));