] + tf_additional_device_tracer_deps(),
)
+cc_library(
+ name = "gpu_id",
+ srcs = ["common_runtime/gpu/gpu_id_manager.cc"],
+ hdrs = [
+ "common_runtime/gpu/gpu_id.h",
+ "common_runtime/gpu/gpu_id_manager.h",
+ ],
+ deps = [
+ ":lib",
+ ],
+)
+
GPU_RUNTIME_HEADERS = [
"common_runtime/gpu/gpu_bfc_allocator.h",
"common_runtime/gpu/gpu_cudamalloc_allocator.h",
"common_runtime/gpu/gpu_debug_allocator.h",
"common_runtime/gpu/gpu_device.h",
- "common_runtime/gpu/gpu_id.h",
"common_runtime/gpu/gpu_id_utils.h",
"common_runtime/gpu/gpu_init.h",
"common_runtime/gpu/gpu_managed_allocator.h",
"common_runtime/gpu/gpu_debug_allocator.cc",
"common_runtime/gpu/gpu_device.cc",
"common_runtime/gpu/gpu_device_factory.cc",
- "common_runtime/gpu/gpu_id_utils.cc",
"common_runtime/gpu/gpu_managed_allocator.cc",
"common_runtime/gpu/gpu_stream_util.cc",
"common_runtime/gpu/gpu_util.cc",
":core_cpu_lib",
":framework",
":framework_internal",
+ ":gpu_id",
":gpu_init_impl",
":gpu_lib",
":graph",
linkstatic = tf_kernel_tests_linkstatic(),
deps = [
":gpu_headers_lib",
+ ":gpu_id",
":gpu_runtime",
":test",
],
srcs = glob(["user_ops/**/*_test.cc"]) + [
"common_runtime/gpu/gpu_bfc_allocator_test.cc",
"common_runtime/gpu/gpu_device_test.cc",
- "common_runtime/gpu/gpu_id_utils_test.cc",
+ "common_runtime/gpu/gpu_id_manager_test.cc",
"common_runtime/gpu/gpu_event_mgr_test.cc",
"common_runtime/gpu/pool_allocator_test.cc",
],
":direct_session",
":framework",
":framework_internal",
+ ":gpu_id",
":gpu_runtime",
":lib",
":lib_internal",
":direct_session",
":framework",
":framework_internal",
+ ":gpu_id",
":gpu_runtime",
":lib",
":lib_internal",
#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"
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];
}
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.
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;
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);
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.
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();
// 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());
#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"
// 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.
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>
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;
}
};
} // 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
--- /dev/null
+/* 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_
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"
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");
}
#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"
// 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(
}
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."
#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"
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"));