CMS 3D CMS Logo

triton_utils.h
Go to the documentation of this file.
1 #ifndef HeterogeneousCore_SonicTriton_triton_utils
2 #define HeterogeneousCore_SonicTriton_triton_utils
3 
7 
8 #include <string>
9 #include <string_view>
10 #include <vector>
11 #include <unordered_set>
12 
13 #include "grpc_client.h"
14 
15 namespace triton_utils {
16  template <typename C>
17  std::string printColl(const C& coll, const std::string& delim = ", ");
18  //implemented as a standalone function to avoid repeated specializations for different TritonData types
19  template <typename DT>
21  return false;
22  }
23  //turn CMS exceptions into warnings
24  void convertToWarning(const cms::Exception& e);
25 } // namespace triton_utils
26 
27 //explicit specializations (inlined)
28 //special cases:
29 //bool: vector<bool> doesn't have data() accessor, so use char (same byte size)
30 //FP16 (half precision): no C++ primitive exists, so use uint16_t (e.g. with libminifloat)
31 template <>
32 inline bool triton_utils::checkType<char>(inference::DataType dtype) {
33  return dtype == inference::DataType::TYPE_BOOL or dtype == inference::DataType::TYPE_STRING;
34 }
35 template <>
36 inline bool triton_utils::checkType<uint8_t>(inference::DataType dtype) {
37  return dtype == inference::DataType::TYPE_UINT8;
38 }
39 template <>
40 inline bool triton_utils::checkType<uint16_t>(inference::DataType dtype) {
41  return dtype == inference::DataType::TYPE_UINT16 or dtype == inference::DataType::TYPE_FP16;
42 }
43 template <>
44 inline bool triton_utils::checkType<uint32_t>(inference::DataType dtype) {
45  return dtype == inference::DataType::TYPE_UINT32;
46 }
47 template <>
48 inline bool triton_utils::checkType<uint64_t>(inference::DataType dtype) {
49  return dtype == inference::DataType::TYPE_UINT64;
50 }
51 template <>
52 inline bool triton_utils::checkType<int8_t>(inference::DataType dtype) {
53  return dtype == inference::DataType::TYPE_INT8;
54 }
55 template <>
56 inline bool triton_utils::checkType<int16_t>(inference::DataType dtype) {
57  return dtype == inference::DataType::TYPE_INT16;
58 }
59 template <>
60 inline bool triton_utils::checkType<int32_t>(inference::DataType dtype) {
61  return dtype == inference::DataType::TYPE_INT32;
62 }
63 template <>
64 inline bool triton_utils::checkType<int64_t>(inference::DataType dtype) {
65  return dtype == inference::DataType::TYPE_INT64;
66 }
67 template <>
68 inline bool triton_utils::checkType<float>(inference::DataType dtype) {
69  return dtype == inference::DataType::TYPE_FP32;
70 }
71 template <>
72 inline bool triton_utils::checkType<double>(inference::DataType dtype) {
73  return dtype == inference::DataType::TYPE_FP64;
74 }
75 
76 //helper to turn triton error into exception
77 //implemented as a macro to avoid constructing the MSG string for successful function calls
78 #define TRITON_THROW_IF_ERROR(X, MSG, NOTIFY) \
79  { \
80  triton::client::Error err = (X); \
81  if (!err.IsOk()) \
82  throw TritonException("TritonFailure", NOTIFY) << (MSG) << (err.Message().empty() ? "" : ": " + err.Message()); \
83  }
84 
85 extern template std::string triton_utils::printColl(const edm::Span<std::vector<int64_t>::const_iterator>& coll,
86  const std::string& delim);
87 extern template std::string triton_utils::printColl(const std::vector<uint8_t>& coll, const std::string& delim);
88 extern template std::string triton_utils::printColl(const std::vector<float>& coll, const std::string& delim);
89 extern template std::string triton_utils::printColl(const std::vector<std::string>& coll, const std::string& delim);
90 extern template std::string triton_utils::printColl(const std::unordered_set<std::string>& coll,
91  const std::string& delim);
92 
93 #endif
bool checkType(inference::DataType dtype)
Definition: triton_utils.h:20
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e< void, edm::EventID const &, edm::Timestamp const & > We also list in braces which AR_WATCH_USING_METHOD_ is used for those or
Definition: Activities.doc:12
void convertToWarning(const cms::Exception &e)
Definition: triton_utils.cc:19
Definition: Span.h:16
std::string printColl(const C &coll, const std::string &delim=", ")
Definition: triton_utils.cc:10