HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ortdevice.h
Go to the documentation of this file.
1 // Copyright (c) Microsoft Corporation. All rights reserved.
2 // Licensed under the MIT License.
3 
4 #pragma once
5 
6 #include <sstream>
7 
8 // Struct to represent a physical device.
9 struct OrtDevice {
10  using DeviceType = int8_t;
11  using MemoryType = int8_t;
12  using DeviceId = int16_t;
13 
14  // Pre-defined device types.
15  static const DeviceType CPU = 0;
16  static const DeviceType GPU = 1; // Nvidia or AMD
17  static const DeviceType FPGA = 2;
18  static const DeviceType NPU = 3; // Ascend
19 
20  struct MemType {
21  // Pre-defined memory types.
22  static const MemoryType DEFAULT = 0;
23  static const MemoryType CUDA_PINNED = 1;
24  static const MemoryType HIP_PINNED = 2;
25  static const MemoryType CANN_PINNED = 3;
26  };
27 
28  constexpr OrtDevice(DeviceType device_type_, MemoryType memory_type_, DeviceId device_id_)
29  : device_type(device_type_),
30  memory_type(memory_type_),
31  device_id(device_id_) {}
32 
33  constexpr OrtDevice() : OrtDevice(CPU, MemType::DEFAULT, 0) {}
34 
35  DeviceType Type() const {
36  return device_type;
37  }
38 
39  MemoryType MemType() const {
40  return memory_type;
41  }
42 
43  DeviceId Id() const {
44  return device_id;
45  }
46 
48  std::ostringstream ostr;
49  ostr << "Device:["
50  << "DeviceType:" << static_cast<int>(device_type)
51  << " MemoryType:" << static_cast<int>(memory_type)
52  << " DeviceId:" << device_id
53  << "]";
54  return ostr.str();
55  }
56 
57  private:
58  // Device type.
59  DeviceType device_type;
60 
61  // Memory type.
62  MemoryType memory_type;
63 
64  // Device index.
65  DeviceId device_id;
66 };
67 
68 inline bool operator==(const OrtDevice& left, const OrtDevice& other) {
69  return left.Id() == other.Id() && left.MemType() == other.MemType() && left.Type() == other.Type();
70 }
71 
72 inline bool operator!=(const OrtDevice& left, const OrtDevice& other) {
73  return !(left == other);
74 }
GLint left
Definition: glcorearb.h:2005
GLsizei const GLchar *const * string
Definition: glcorearb.h:814
static const DeviceType FPGA
Definition: ortdevice.h:17
int8_t DeviceType
Definition: ortdevice.h:10
static const MemoryType DEFAULT
Definition: ortdevice.h:22
simple inheritance: W = L * pW
int16_t DeviceId
Definition: ortdevice.h:12
bool operator!=(const Mat3< T0 > &m0, const Mat3< T1 > &m1)
Inequality operator, does exact floating point comparisons.
Definition: Mat3.h:556
constexpr OrtDevice(DeviceType device_type_, MemoryType memory_type_, DeviceId device_id_)
Definition: ortdevice.h:28
MemoryType MemType() const
Definition: ortdevice.h:39
static const DeviceType GPU
Definition: ortdevice.h:16
int8_t MemoryType
Definition: ortdevice.h:11
static const DeviceType CPU
Definition: ortdevice.h:15
DeviceId Id() const
Definition: ortdevice.h:43
DeviceType
Definition: oidn.hpp:311
static const MemoryType CUDA_PINNED
Definition: ortdevice.h:23
constexpr OrtDevice()
Definition: ortdevice.h:33
static const MemoryType HIP_PINNED
Definition: ortdevice.h:24
static const MemoryType CANN_PINNED
Definition: ortdevice.h:25
static const DeviceType NPU
Definition: ortdevice.h:18
bool operator==(const Mat3< T0 > &m0, const Mat3< T1 > &m1)
Equality operator, does exact floating point comparisons.
Definition: Mat3.h:542
std::string ToString() const
Definition: ortdevice.h:47
DeviceType Type() const
Definition: ortdevice.h:35