ie_device.hpp
Go to the documentation of this file.
1 // Copyright (C) 2018 Intel Corporation
2 // SPDX-License-Identifier: Apache-2.0
3 //
4 
5 /**
6  * @brief This header file contains aspects of working on different devices like CPU, GEN, FPGA, etc.
7  * @file ie_device.hpp
8  */
9 #pragma once
10 
11 #include <string>
12 #include <vector>
13 #include <map>
14 #include <ie_api.h>
15 #include <ie_common.h>
16 
17 namespace InferenceEngine {
18 
19 /**
20  * @enum TargetDevice
21  * @brief Describes known device types
22  */
23 enum class TargetDevice : uint8_t {
24  eDefault = 0,
25  eBalanced = 1,
26  eCPU = 2,
27  eGPU = 3,
28  eFPGA = 4,
29  eMYRIAD = 5,
30  eHDDL = 6,
31  eGNA = 7,
32  eHETERO = 8
33 };
34 
35 /**
36  * @brief Describes the relationship between the enumerator type and the actual device's name
37  */
39  struct Info {
40  TargetDevice device;
41  std::string name;
42  Info(TargetDevice device, std::string name) : device(device), name(name){}
43  };
44  static const std::vector<Info> & getAll() {
45 #define DECL_DEVICE(device_type) {TargetDevice::e##device_type, #device_type}
46 
47  static std::vector<Info> g_allDeviceInfos = {
48  DECL_DEVICE(Default),
49  DECL_DEVICE(Balanced),
50  DECL_DEVICE(CPU),
51  DECL_DEVICE(GPU),
52  DECL_DEVICE(FPGA),
53  DECL_DEVICE(MYRIAD),
54  DECL_DEVICE(HDDL),
55  DECL_DEVICE(GNA),
56  DECL_DEVICE(HETERO)
57  };
58 #undef DECLARE
59  return g_allDeviceInfos;
60  }
61 
62  public:
63  static TargetDevice fromStr(const std::string &deviceName) {
64  static std::map<std::string, InferenceEngine::TargetDevice> deviceFromNameMap = {
65  { "CPU", InferenceEngine::TargetDevice::eCPU },
66  { "GPU", InferenceEngine::TargetDevice::eGPU },
67  { "FPGA", InferenceEngine::TargetDevice::eFPGA },
68  { "MYRIAD", InferenceEngine::TargetDevice::eMYRIAD },
69  { "HDDL", InferenceEngine::TargetDevice::eHDDL },
70  { "GNA", InferenceEngine::TargetDevice::eGNA },
71  { "BALANCED", InferenceEngine::TargetDevice::eBalanced },
72  { "HETERO", InferenceEngine::TargetDevice::eHETERO }
73  };
74  auto val = deviceFromNameMap.find(deviceName);
75  return val != deviceFromNameMap.end() ? val->second : InferenceEngine::TargetDevice::eDefault;
76  }
77 
78  static const char * name(TargetDevice device) {
79  auto res = std::find_if(getAll().cbegin(), getAll().cend(), [&](const Info & info){
80  return device == info.device;
81  });
82  if (res == getAll().cend()) {
83  return "Unknown device";
84  }
85  return res->name.c_str();
86  }
87 };
88 
89 /**
90  * @brief Returns the device name
91  * @param device Instance of TargetDevice
92  * @return A c-string with the name
93  */
94 inline const char *getDeviceName(TargetDevice device) {
95  return TargetDeviceInfo::name(device);
96 }
97 
98 /**
99  * @struct FindPluginRequest
100  * @brief Defines a message that contains the TargetDevice object to find a plugin for
101  */
103  /**
104  * @brief object of TargetDevice to find a plugin for
105  */
107 };
108 
109 /**
110  * @struct FindPluginResponse
111  * @brief Defines a message that contains a list of appropriate plugin names
112  */
114  /**
115  * @brief A list of appropriate plugin names
116  */
117  std::vector<std::string> names;
118 };
119 
120 /**
121  * @brief Finds an appropriate plugin for requested target device
122  * @param req A requested target device
123  * @param result The results of the request
124  * @param resp The response message description
125  * @return A response message
126  */
128 
129 INFERENCE_ENGINE_API(StatusCode) findPlugin(const FindPluginRequest &req, FindPluginResponse &result,
130  ResponseDesc *resp) noexcept;
131 } // namespace InferenceEngine
TargetDevice
Describes known device types.
Definition: ie_device.hpp:23
Defines a message that contains a list of appropriate plugin names.
Definition: ie_device.hpp:113
Definition: ie_argmax_layer.hpp:11
StatusCode
This enum contains codes for all possible return values of the interface functions.
Definition: ie_common.h:172
Defines a message that contains the TargetDevice object to find a plugin for.
Definition: ie_device.hpp:102
TargetDevice device
object of TargetDevice to find a plugin for
Definition: ie_device.hpp:106
Represents detailed information for an error.
Definition: ie_common.h:195
FindPluginResponse findPlugin(const FindPluginRequest &req)
Finds an appropriate plugin for requested target device.
The macro defines a symbol import/export mechanism essential for Microsoft Windows(R) OS...
const char * getDeviceName(TargetDevice device)
Returns the device name.
Definition: ie_device.hpp:94
Describes the relationship between the enumerator type and the actual device&#39;s name.
Definition: ie_device.hpp:38
std::vector< std::string > names
A list of appropriate plugin names.
Definition: ie_device.hpp:117
This is a header file with common inference engine definitions.