Open3D (C++ API)  0.18.0+252c867
Device.h
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - Open3D: www.open3d.org -
3 // ----------------------------------------------------------------------------
4 // Copyright (c) 2018-2023 www.open3d.org
5 // SPDX-License-Identifier: MIT
6 // ----------------------------------------------------------------------------
7 
8 #pragma once
9 
10 #include <string>
11 #include <vector>
12 
13 namespace open3d {
14 namespace core {
15 
18 class Device {
19 public:
21  enum class DeviceType {
22  CPU = 0,
23  CUDA = 1,
24  SYCL = 2, // SYCL gpu_selector().
25  };
26 
28  Device() = default;
29 
31  explicit Device(DeviceType device_type, int device_id);
32 
34  explicit Device(const std::string& device_type, int device_id);
35 
37  explicit Device(const std::string& type_colon_id);
38 
39  bool operator==(const Device& other) const;
40 
41  bool operator!=(const Device& other) const;
42 
43  bool operator<(const Device& other) const;
44 
46  inline bool IsCPU() const { return device_type_ == DeviceType::CPU; }
47 
49  inline bool IsCUDA() const { return device_type_ == DeviceType::CUDA; }
50 
52  inline bool IsSYCL() const { return device_type_ == DeviceType::SYCL; }
53 
55  std::string ToString() const;
56 
58  inline DeviceType GetType() const { return device_type_; }
59 
61  inline int GetID() const { return device_id_; }
62 
64  bool IsAvailable() const;
65 
67  static std::vector<Device> GetAvailableDevices();
68 
70  static std::vector<Device> GetAvailableCPUDevices();
71 
73  static std::vector<Device> GetAvailableCUDADevices();
74 
76  static std::vector<Device> GetAvailableSYCLDevices();
77 
79  static void PrintAvailableDevices();
80 
81 protected:
83  int device_id_ = 0;
84 };
85 
88 class IsDevice {
89 public:
90  IsDevice() = default;
91  virtual ~IsDevice() = default;
92 
93  virtual core::Device GetDevice() const = 0;
94 
95  inline bool IsCPU() const {
97  }
98 
99  inline bool IsCUDA() const {
101  }
102 };
103 
104 } // namespace core
105 } // namespace open3d
106 
107 namespace std {
108 template <>
109 struct hash<open3d::core::Device> {
111  return std::hash<std::string>{}(device.ToString());
112  }
113 };
114 } // namespace std
Definition: Device.h:18
bool IsSYCL() const
Returns true iff device type is SYCL GPU.
Definition: Device.h:52
bool IsAvailable() const
Returns true if the device is available.
Definition: Device.cpp:107
int GetID() const
Returns the device index (within the same device type).
Definition: Device.h:61
DeviceType
Type for device.
Definition: Device.h:21
static std::vector< Device > GetAvailableSYCLDevices()
Returns a vector of available SYCL device.
Definition: Device.cpp:139
bool operator!=(const Device &other) const
Definition: Device.cpp:80
DeviceType device_type_
Definition: Device.h:82
static void PrintAvailableDevices()
Print all available devices.
Definition: Device.cpp:143
bool operator==(const Device &other) const
Definition: Device.cpp:75
bool IsCPU() const
Returns true iff device type is CPU.
Definition: Device.h:46
Device()=default
Default constructor -> "CPU:0".
static std::vector< Device > GetAvailableCPUDevices()
Returns a vector of available CPU device.
Definition: Device.cpp:127
bool operator<(const Device &other) const
Definition: Device.cpp:84
bool IsCUDA() const
Returns true iff device type is CUDA.
Definition: Device.h:49
int device_id_
Definition: Device.h:83
static std::vector< Device > GetAvailableCUDADevices()
Returns a vector of available CUDA device.
Definition: Device.cpp:131
std::string ToString() const
Returns string representation of device, e.g. "CPU:0", "CUDA:0".
Definition: Device.cpp:88
static std::vector< Device > GetAvailableDevices()
Returns a vector of available devices.
Definition: Device.cpp:116
DeviceType GetType() const
Returns type of the device, e.g. DeviceType::CPU, DeviceType::CUDA.
Definition: Device.h:58
Definition: Device.h:88
bool IsCUDA() const
Definition: Device.h:99
virtual core::Device GetDevice() const =0
bool IsCPU() const
Definition: Device.h:95
virtual ~IsDevice()=default
const char const char value recording_handle imu_sample recording_handle uint8_t size_t data_size k4a_record_configuration_t config target_format k4a_capture_t capture_handle k4a_imu_sample_t imu_sample playback_handle k4a_logging_message_cb_t void min_level device_handle k4a_imu_sample_t timeout_in_ms capture_handle capture_handle capture_handle image_handle temperature_c k4a_image_t image_handle uint8_t image_handle image_handle image_handle image_handle image_handle timestamp_usec white_balance image_handle k4a_device_configuration_t config device_handle char size_t serial_number_size bool int32_t int32_t int32_t int32_t k4a_color_control_mode_t default_mode value const const k4a_calibration_t calibration char size_t
Definition: K4aPlugin.cpp:719
Definition: PinholeCameraIntrinsic.cpp:16
Definition: Device.h:107
std::size_t operator()(const open3d::core::Device &device) const
Definition: Device.h:110