diff options
author | Guangda Lai <laigd@google.com> | 2017-12-18 20:16:08 -0800 |
---|---|---|
committer | TensorFlower Gardener <gardener@tensorflow.org> | 2017-12-18 20:20:09 -0800 |
commit | 14cb8e14a8fb1e78e2ce623e4198972762e6e253 (patch) | |
tree | 9104a9c3e2b7a9a1c5c05ad62433aed106c24b2c /tensorflow/core/common_runtime/gpu/gpu_device.h | |
parent | 1203dc0832133250de970ce10833ba43b71daf7b (diff) |
Added virtual gpu support.
PiperOrigin-RevId: 179504116
Diffstat (limited to 'tensorflow/core/common_runtime/gpu/gpu_device.h')
-rw-r--r-- | tensorflow/core/common_runtime/gpu/gpu_device.h | 42 |
1 files changed, 24 insertions, 18 deletions
diff --git a/tensorflow/core/common_runtime/gpu/gpu_device.h b/tensorflow/core/common_runtime/gpu/gpu_device.h index 74176cd448..41e60b4884 100644 --- a/tensorflow/core/common_runtime/gpu/gpu_device.h +++ b/tensorflow/core/common_runtime/gpu/gpu_device.h @@ -28,6 +28,8 @@ limitations under the License. #include "third_party/eigen3/unsupported/Eigen/CXX11/Tensor" #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_utils.h" #include "tensorflow/core/common_runtime/gpu_device_context.h" #include "tensorflow/core/common_runtime/local_device.h" #include "tensorflow/core/framework/allocator.h" @@ -45,10 +47,10 @@ namespace tensorflow { class BaseGPUDevice : public LocalDevice { public: BaseGPUDevice(const SessionOptions& options, const string& name, - Bytes memory_limit, const DeviceLocality& locality, int gpu_id, - const string& physical_device_desc, Allocator* gpu_allocator, - Allocator* cpu_allocator, bool sync_every_op, - int32 max_streams); + Bytes memory_limit, const DeviceLocality& locality, + TfGpuId tf_gpu_id, const string& physical_device_desc, + Allocator* gpu_allocator, Allocator* cpu_allocator, + bool sync_every_op, int32 max_streams); ~BaseGPUDevice() override; @@ -84,9 +86,9 @@ class BaseGPUDevice : public LocalDevice { void ReinitializeGpuDevice(OpKernelContext* context, PerOpGpuDevice* device, DeviceContext* dc, Allocator* allocator) override; - // Returns the 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 gpu_id_; } + // 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(); } // The executor that provides control for the device; e.g., for CUDA this // corresponds to the cuda context. @@ -112,7 +114,7 @@ class BaseGPUDevice : public LocalDevice { std::vector<GPUDeviceContext*> device_contexts_; GpuDeviceInfo* gpu_device_info_ = nullptr; mutex trace_mu_; - int gpu_id_ = -1; + TfGpuId tf_gpu_id_; const bool sync_every_op_ = false; const int32 max_streams_; std::unique_ptr<EventMgr> em_; @@ -139,26 +141,30 @@ class BaseGPUDeviceFactory : public DeviceFactory { std::vector<Device*>* devices) override; private: - Status CreateGPUDevice(const SessionOptions& options, const string& name, - int gpu_id, BaseGPUDevice** out_device); + // Creates a BaseGPUDevice associated with 'tf_gpu_id', allocates (strictly) + // 'memory_limit' bytes of GPU memory to it, and adds it to the 'devices' + // vector. + Status CreateGPUDevice(const SessionOptions& options, + const string& name_prefix, TfGpuId tf_gpu_id, + int64 memory_limit, std::vector<Device*>* devices); virtual BaseGPUDevice* CreateGPUDevice(const SessionOptions& options, const string& name, Bytes memory_limit, const DeviceLocality& locality, - int gpu_id, + TfGpuId tf_gpu_id, const string& physical_device_desc, Allocator* gpu_allocator, Allocator* cpu_allocator) = 0; - // Returns into 'ids' the list of valid GPU ids, in the order that - // they should map to logical gpu ids "/device:GPU:0", "/device:GPU:1", etc, + // Returns into 'ids' the list of valid CUDA GPU ids, in the order that + // they should map to TF GPU ids "/device:GPU:0", "/device:GPU:1", etc, // based upon 'visible_gpu_order' which was generated by parsing - // GPUOptions::visible_device_list which is a comma-separated list of - // 'visible gpu ids'. - Status GetValidDeviceIds(const std::vector<int>& visible_gpu_order, - std::vector<int>* ids); + // GPUOptions::visible_device_list which is a comma-separated list of CUDA GPU + // ids. + Status GetValidDeviceIds(const std::vector<CudaGpuId>& visible_gpu_order, + std::vector<CudaGpuId>* ids); - // visible_gpu_initialized_[gpu_id] is true if visible GPU gpu_id + // visible_gpu_initialized_[cuda_gpu_id] is true if visible GPU cuda_gpu_id // has been initialized by the process. std::unordered_map<int, bool> visible_gpu_initialized_; }; |