gpu_context_helpers.hpp
Go to the documentation of this file.
1 // Copyright (C) 2018-2020 Intel Corporation
2 // SPDX-License-Identifier: Apache-2.0
3 //
4 
5 /**
6  * @brief a header that defines helpers for GPU plugin-specific wrappers
7  *
8  * @file gpu_context_helpers.hpp
9  */
10 #pragma once
11 
12 #include <string>
13 
14 namespace InferenceEngine {
15 
16 namespace gpu {
17 
18 namespace details {
19 /**
20 * @brief This wrapper class is used to obtain low-level handles
21 * from remote blob or context object parameters.
22 */
24 protected:
25  /**
26  * @brief Template function that returns specified
27  * object parameter typecasted to desired user type
28  */
29  template <typename Result, typename Tmp>
31  const std::string& handle_Key,
32  const std::string& type_Key,
33  const std::string& obj_T1,
34  const std::string& obj_T2 = "__") const {
35  auto itrType = params.find(type_Key);
36  if (itrType == params.end())
37  THROW_IE_EXCEPTION << "Parameter of type " << type_Key << " not found";
38 
39  std::string param_val = itrType->second.as<std::string>();
40  if (obj_T1 != param_val && obj_T2 != param_val)
41  THROW_IE_EXCEPTION << "Unexpected object type " << param_val;
42 
43  auto itrHandle = params.find(handle_Key);
44  if (itrHandle == params.end()) {
45  THROW_IE_EXCEPTION << "No parameter " << handle_Key << " found";
46  }
47 
48  Tmp handle = itrHandle->second;
49  return static_cast<Result>(handle);
50  }
51 
52  /**
53  * @brief Same as _ObjFromParams(), but should be used if check
54  * for object type is not required
55  */
56  template <typename Result>
57  Result _ObjFromParamSimple(const ParamMap& params, const std::string& handle_Key) const {
58  auto itrHandle = params.find(handle_Key);
59  if (itrHandle == params.end()) {
60  THROW_IE_EXCEPTION << "No parameter " << handle_Key << " found";
61  }
62 
63  Result handle = itrHandle->second;
64  return handle;
65  }
66 
67  /**
68  * @brief Template function that extracts string value
69  * from map entry under specified key
70  */
71  std::string _StrFromParams(const ParamMap& params,
72  std::string Key) const {
73  auto itrType = params.find(Key);
74  if (itrType == params.end())
75  THROW_IE_EXCEPTION << "Parameter key " << Key << " not found";
76  return itrType->second.as<std::string>();
77  }
78 };
79 
80 } // namespace details
81 
82 } // namespace gpu
83 
84 } // namespace InferenceEngine
#define THROW_IE_EXCEPTION
A macro used to throw the exception with a notable description.
Definition: ie_exception.hpp:25
std::string _StrFromParams(const ParamMap &params, std::string Key) const
Template function that extracts string value from map entry under specified key.
Definition: gpu_context_helpers.hpp:71
Inference Engine API.
Definition: ie_argmax_layer.hpp:15
Result _ObjFromParamSimple(const ParamMap &params, const std::string &handle_Key) const
Same as _ObjFromParams(), but should be used if check for object type is not required.
Definition: gpu_context_helpers.hpp:57
This wrapper class is used to obtain low-level handles from remote blob or context object parameters...
Definition: gpu_context_helpers.hpp:23
std::map< std::string, Parameter > ParamMap
An std::map object containing low-level object parameters of classes that are derived from RemoteBlob...
Definition: ie_remote_context.hpp:26
std::map< std::string, std::string > params
Map of pairs: (parameter name, parameter value)
Definition: ie_layers.h:607
Result _ObjFromParams(const ParamMap &params, const std::string &handle_Key, const std::string &type_Key, const std::string &obj_T1, const std::string &obj_T2="__") const
Template function that returns specified object parameter typecasted to desired user type...
Definition: gpu_context_helpers.hpp:30