Publishing 2019 R1 content
[platform/upstream/dldt.git] / inference-engine / include / ie_device.hpp
1 // Copyright (C) 2018-2019 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     eKMB = 9,
34 };
35
36 /**
37  * @brief Describes the relationship between the enumerator type and the actual device's name
38  */
39 class TargetDeviceInfo {
40     struct Info {
41         TargetDevice device;
42         std::string name;
43         Info(TargetDevice device, std::string name) : device(device), name(name){}
44     };
45     static const std::vector<Info> & getAll() {
46 #define DECL_DEVICE(device_type) {TargetDevice::e##device_type, #device_type}
47
48         static std::vector<Info> g_allDeviceInfos = {
49             DECL_DEVICE(Default),
50             DECL_DEVICE(Balanced),
51             DECL_DEVICE(CPU),
52             DECL_DEVICE(GPU),
53             DECL_DEVICE(FPGA),
54             DECL_DEVICE(MYRIAD),
55             DECL_DEVICE(HDDL),
56             DECL_DEVICE(GNA),
57             DECL_DEVICE(HETERO),
58             DECL_DEVICE(KMB)
59         };
60 #undef DECLARE
61         return g_allDeviceInfos;
62     }
63
64  public:
65     static TargetDevice fromStr(const std::string &deviceName) {
66         static std::map<std::string, InferenceEngine::TargetDevice> deviceFromNameMap = {
67             { "CPU", InferenceEngine::TargetDevice::eCPU },
68             { "GPU", InferenceEngine::TargetDevice::eGPU },
69             { "FPGA", InferenceEngine::TargetDevice::eFPGA },
70             { "MYRIAD", InferenceEngine::TargetDevice::eMYRIAD },
71             { "HDDL", InferenceEngine::TargetDevice::eHDDL },
72             { "GNA", InferenceEngine::TargetDevice::eGNA },
73             { "BALANCED", InferenceEngine::TargetDevice::eBalanced },
74             { "HETERO", InferenceEngine::TargetDevice::eHETERO },
75             { "KMB", InferenceEngine::TargetDevice::eKMB }
76         };
77         auto val = deviceFromNameMap.find(deviceName);
78         return val != deviceFromNameMap.end() ? val->second : InferenceEngine::TargetDevice::eDefault;
79     }
80
81     static const char * name(TargetDevice device) {
82         auto res = std::find_if(getAll().cbegin(), getAll().cend(), [&](const Info & info){
83             return device == info.device;
84         });
85         if (res == getAll().cend()) {
86             return "Unknown device";
87         }
88         return res->name.c_str();
89     }
90 };
91
92 /**
93  * @brief Returns the device name
94  * @param device Instance of TargetDevice
95  * @return A c-string with the name
96  */
97 inline const char *getDeviceName(TargetDevice device) {
98     return TargetDeviceInfo::name(device);
99 }
100
101 /**
102  * @struct FindPluginRequest
103  * @brief Defines a message that contains the TargetDevice object to find a plugin for
104  */
105 struct FindPluginRequest {
106     /**
107      * @brief object of TargetDevice to find a plugin for
108      */
109     TargetDevice device;
110 };
111
112 /**
113  * @struct FindPluginResponse
114  * @brief Defines a message that contains a list of appropriate plugin names
115  */
116 struct FindPluginResponse {
117     /**
118      * @brief A list of appropriate plugin names
119      */
120     std::vector<std::string> names;
121 };
122
123 /**
124  * @brief Finds an appropriate plugin for requested target device
125  * @param req A requested target device
126  * @param result The results of the request
127  * @param resp The response message description
128  * @return A response message
129  */
130 FindPluginResponse findPlugin(const FindPluginRequest &req);
131
132 INFERENCE_ENGINE_API(StatusCode) findPlugin(const FindPluginRequest &req, FindPluginResponse &result,
133                                             ResponseDesc *resp) noexcept;
134 }  // namespace InferenceEngine