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 
6 
7 #include <string>
8 #include <string_view>
9 #include <vector>
10 #include <unordered_set>
11 
12 #include "grpc_client.h"
13 
14 namespace triton_utils {
15  template <typename C>
16  std::string printColl(const C& coll, const std::string& delim = ", ");
17  //implemented as a standalone function to avoid repeated specializations for different TritonData types
18  template <typename DT>
20  return false;
21  }
22 } // namespace triton_utils
23 
24 //explicit specializations (inlined)
25 //special cases:
26 //bool: vector<bool> doesn't have data() accessor, so use char (same byte size)
27 //FP16 (half precision): no C++ primitive exists, so use uint16_t (e.g. with libminifloat)
28 template <>
29 inline bool triton_utils::checkType<char>(inference::DataType dtype) {
30  return dtype == inference::DataType::TYPE_BOOL or dtype == inference::DataType::TYPE_STRING;
31 }
32 template <>
33 inline bool triton_utils::checkType<uint8_t>(inference::DataType dtype) {
34  return dtype == inference::DataType::TYPE_UINT8;
35 }
36 template <>
37 inline bool triton_utils::checkType<uint16_t>(inference::DataType dtype) {
38  return dtype == inference::DataType::TYPE_UINT16 or dtype == inference::DataType::TYPE_FP16;
39 }
40 template <>
41 inline bool triton_utils::checkType<uint32_t>(inference::DataType dtype) {
42  return dtype == inference::DataType::TYPE_UINT32;
43 }
44 template <>
45 inline bool triton_utils::checkType<uint64_t>(inference::DataType dtype) {
46  return dtype == inference::DataType::TYPE_UINT64;
47 }
48 template <>
49 inline bool triton_utils::checkType<int8_t>(inference::DataType dtype) {
50  return dtype == inference::DataType::TYPE_INT8;
51 }
52 template <>
53 inline bool triton_utils::checkType<int16_t>(inference::DataType dtype) {
54  return dtype == inference::DataType::TYPE_INT16;
55 }
56 template <>
57 inline bool triton_utils::checkType<int32_t>(inference::DataType dtype) {
58  return dtype == inference::DataType::TYPE_INT32;
59 }
60 template <>
61 inline bool triton_utils::checkType<int64_t>(inference::DataType dtype) {
62  return dtype == inference::DataType::TYPE_INT64;
63 }
64 template <>
65 inline bool triton_utils::checkType<float>(inference::DataType dtype) {
66  return dtype == inference::DataType::TYPE_FP32;
67 }
68 template <>
69 inline bool triton_utils::checkType<double>(inference::DataType dtype) {
70  return dtype == inference::DataType::TYPE_FP64;
71 }
72 
73 //helper to turn triton error into exception
74 //implemented as a macro to avoid constructing the MSG string for successful function calls
75 #define TRITON_THROW_IF_ERROR(X, MSG) \
76  { \
77  triton::client::Error err = (X); \
78  if (!err.IsOk()) \
79  throw TritonException("TritonFailure") << (MSG) << (err.Message().empty() ? "" : ": " + err.Message()); \
80  }
81 
82 extern template std::string triton_utils::printColl(const edm::Span<std::vector<int64_t>::const_iterator>& coll,
83  const std::string& delim);
84 extern template std::string triton_utils::printColl(const std::vector<uint8_t>& coll, const std::string& delim);
85 extern template std::string triton_utils::printColl(const std::vector<float>& coll, const std::string& delim);
86 extern template std::string triton_utils::printColl(const std::vector<std::string>& coll, const std::string& delim);
87 extern template std::string triton_utils::printColl(const std::unordered_set<std::string>& coll,
88  const std::string& delim);
89 
90 #endif
bool checkType(inference::DataType dtype)
Definition: triton_utils.h:19
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
Definition: Span.h:16
std::string printColl(const C &coll, const std::string &delim=", ")
Definition: triton_utils.cc:9