aboutsummaryrefslogtreecommitdiffhomepage
path: root/tensorflow/core/common_runtime/gpu/gpu_device_factory.cc
blob: 240ac474994bd281d7a509a9f6b8ee49bf3335a0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#if GOOGLE_CUDA

#define EIGEN_USE_GPU

#include "tensorflow/core/common_runtime/gpu/gpu_device.h"
#include "tensorflow/core/common_runtime/gpu/process_state.h"

namespace tensorflow {

void RequireGPUDevice() {}

class GPUDevice : public BaseGPUDevice {
 public:
  GPUDevice(const SessionOptions& options, const string& name,
            Bytes memory_limit, BusAdjacency bus_adjacency, int gpu_id,
            const string& physical_device_desc, Allocator* gpu_allocator,
            Allocator* cpu_allocator)
      : BaseGPUDevice(options, name, memory_limit, bus_adjacency, gpu_id,
                      physical_device_desc, gpu_allocator, cpu_allocator) {}

  Allocator* GetAllocator(AllocatorAttributes attr) override {
    if (attr.on_host()) {
      ProcessState* ps = ProcessState::singleton();
      if (attr.gpu_compatible()) {
        return ps->GetCUDAHostAllocator(0);
      } else {
        return cpu_allocator_;
      }
    } else {
      return gpu_allocator_;
    }
  }
};

class GPUDeviceFactory : public BaseGPUDeviceFactory {
 private:
  LocalDevice* CreateGPUDevice(const SessionOptions& options,
                               const string& name, Bytes memory_limit,
                               BusAdjacency bus_adjacency, int gpu_id,
                               const string& physical_device_desc,
                               Allocator* gpu_allocator,
                               Allocator* cpu_allocator) override {
    return new GPUDevice(options, name, memory_limit, bus_adjacency, gpu_id,
                         physical_device_desc, gpu_allocator, cpu_allocator);
  }
};

REGISTER_LOCAL_DEVICE_FACTORY("GPU", GPUDeviceFactory);

}  // namespace tensorflow

#endif  // GOOGLE_CUDA