Public Types | Public Member Functions | Private Member Functions | Private Attributes | Friends | List of all members
lartriton::TritonData< IO > Class Template Reference

#include <TritonData.h>

Public Types

using Result = nvidia::inferenceserver::client::InferResult
 
using TensorMetadata = inference::ModelMetadataResponse_TensorMetadata
 
using ShapeType = std::vector< int64_t >
 
using ShapeView = triton_span::Span< ShapeType::const_iterator >
 

Public Member Functions

 TritonData (const std::string &name, const TensorMetadata &model_info, bool noBatch)
 
bool setShape (const ShapeType &newShape)
 
bool setShape (unsigned loc, int64_t val)
 
template<typename DT >
void toServer (std::shared_ptr< TritonInput< DT >> ptr)
 
template<typename DT >
TritonOutput< DT > fromServer () const
 
const ShapeViewshape () const
 
int64_t byteSize () const
 
const std::stringdname () const
 
unsigned batchSize () const
 
bool variableDims () const
 
int64_t sizeDims () const
 
int64_t sizeShape () const
 

Private Member Functions

bool setShape (const ShapeType &newShape, bool canThrow)
 
bool setShape (unsigned loc, int64_t val, bool canThrow)
 
void setBatchSize (unsigned bsize)
 
void reset ()
 
void setResult (std::shared_ptr< Result > result)
 
IO * data ()
 
bool anyNeg (const ShapeView &vec) const
 
int64_t dimProduct (const ShapeView &vec) const
 
void createObject (IO **ioptr) const
 

Private Attributes

std::string name_
 
std::shared_ptr< IO > data_
 
const ShapeType dims_
 
bool noBatch_
 
unsigned batchSize_
 
ShapeType fullShape_
 
ShapeView shape_
 
bool variableDims_
 
int64_t productDims_
 
std::string dname_
 
inference::DataType dtype_
 
int64_t byteSize_
 
std::any holder_
 
std::shared_ptr< Resultresult_
 

Friends

class TritonClient
 

Detailed Description

template<typename IO>
class lartriton::TritonData< IO >

Definition at line 31 of file TritonData.h.

Member Typedef Documentation

template<typename IO>
using lartriton::TritonData< IO >::Result = nvidia::inferenceserver::client::InferResult

Definition at line 33 of file TritonData.h.

template<typename IO>
using lartriton::TritonData< IO >::ShapeType = std::vector<int64_t>

Definition at line 35 of file TritonData.h.

Definition at line 36 of file TritonData.h.

template<typename IO>
using lartriton::TritonData< IO >::TensorMetadata = inference::ModelMetadataResponse_TensorMetadata

Definition at line 34 of file TritonData.h.

Constructor & Destructor Documentation

template<typename IO>
lartriton::TritonData< IO >::TritonData ( const std::string name,
const TensorMetadata model_info,
bool  noBatch 
)

Definition at line 27 of file TritonData.cc.

28  : name_(name),
29  dims_(model_info.shape().begin(), model_info.shape().end()),
30  noBatch_(noBatch),
31  batchSize_(0),
33  shape_(fullShape_.begin() + (noBatch_ ? 0 : 1), fullShape_.end()),
36  dname_(model_info.datatype()),
39  //create input or output object
40  IO* iotmp;
41  createObject(&iotmp);
42  data_.reset(iotmp);
43 }
static QCString name
Definition: declinfo.cpp:673
std::string name_
Definition: TritonData.h:84
const ShapeType dims_
Definition: TritonData.h:86
bool anyNeg(const ShapeView &vec) const
Definition: TritonData.h:75
ShapeType fullShape_
Definition: TritonData.h:89
inference::DataType dtype_
Definition: TritonData.h:94
void createObject(IO **ioptr) const
std::shared_ptr< IO > data_
Definition: TritonData.h:85
int64_t dimProduct(const ShapeView &vec) const
Definition: TritonData.h:78
std::string dname_
Definition: TritonData.h:93
inference::DataType ProtocolStringToDataType(const std::string &dtype)
size_t GetDataTypeByteSize(const inference::DataType dtype)

Member Function Documentation

template<typename IO>
bool lartriton::TritonData< IO >::anyNeg ( const ShapeView vec) const
inlineprivate

Definition at line 75 of file TritonData.h.

75  {
76  return std::any_of(vec.begin(), vec.end(), [](int64_t i) { return i < 0; });
77  }
template<typename IO>
unsigned lartriton::TritonData< IO >::batchSize ( ) const
inline

Definition at line 55 of file TritonData.h.

55 { return batchSize_; }
template<typename IO>
int64_t lartriton::TritonData< IO >::byteSize ( ) const
inline

Definition at line 53 of file TritonData.h.

53 { return byteSize_; }
template<typename IO>
void lartriton::TritonData< IO >::createObject ( IO **  ioptr) const
private
template<typename IO>
IO* lartriton::TritonData< IO >::data ( )
inlineprivate

Definition at line 72 of file TritonData.h.

72 { return data_.get(); }
std::shared_ptr< IO > data_
Definition: TritonData.h:85
template<typename IO>
int64_t lartriton::TritonData< IO >::dimProduct ( const ShapeView vec) const
inlineprivate

Definition at line 78 of file TritonData.h.

78  {
79  return std::accumulate(vec.begin(), vec.end(), 1, std::multiplies<int64_t>());
80  }
template<typename IO>
const std::string& lartriton::TritonData< IO >::dname ( ) const
inline

Definition at line 54 of file TritonData.h.

54 { return dname_; }
std::string dname_
Definition: TritonData.h:93
template<typename DT >
TritonOutput< DT > lartriton::TritonOutputData::fromServer ( ) const

Definition at line 138 of file TritonData.cc.

138  {
139  if (!result_) {
140  throw cet::exception("TritonDataError") << name_ << " output(): missing result";
141  }
142 
143  if (byteSize_ != sizeof(DT)) {
144  throw cet::exception("TritonDataError") << name_ << " output(): inconsistent byte size " << sizeof(DT)
145  << " (should be " << byteSize_ << " for " << dname_ << ")";
146  }
147 
148  uint64_t nOutput = sizeShape();
149  TritonOutput<DT> dataOut;
150  const uint8_t* r0;
151  size_t contentByteSize;
152  size_t expectedContentByteSize = nOutput * byteSize_ * batchSize_;
153  triton_utils::throwIfError(result_->RawData(name_, &r0, &contentByteSize), "output(): unable to get raw");
154  if (contentByteSize != expectedContentByteSize) {
155  throw cet::exception("TritonDataError") << name_ << " output(): unexpected content byte size " << contentByteSize
156  << " (expected " << expectedContentByteSize << ")";
157  }
158 
159  const DT* r1 = reinterpret_cast<const DT*>(r0);
160  dataOut.reserve(batchSize_);
161  for (unsigned i0 = 0; i0 < batchSize_; ++i0) {
162  auto offset = i0 * nOutput;
163  dataOut.emplace_back(r1 + offset, r1 + offset + nOutput);
164  }
165 
166  return dataOut;
167 }
std::string name_
Definition: TritonData.h:84
void throwIfError(const Error &err, std::string_view msg)
Definition: triton_utils.cc:22
int64_t sizeShape() const
Definition: TritonData.h:61
std::shared_ptr< Result > result_
Definition: TritonData.h:97
std::string dname_
Definition: TritonData.h:93
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
void lartriton::TritonOutputData::reset ( )
private

Definition at line 170 of file TritonData.cc.

170  {
171  data_->Reset();
172  holder_.reset();
173 }
std::shared_ptr< IO > data_
Definition: TritonData.h:85
template<typename IO >
void lartriton::TritonData< IO >::setBatchSize ( unsigned  bsize)
private

Definition at line 100 of file TritonData.cc.

100  {
101  batchSize_ = bsize;
102  if (!noBatch_)
103  fullShape_[0] = batchSize_;
104 }
ShapeType fullShape_
Definition: TritonData.h:89
template<typename IO>
void lartriton::TritonData< IO >::setResult ( std::shared_ptr< Result result)
inlineprivate

Definition at line 71 of file TritonData.h.

71 { result_ = result; }
static QCString result
std::shared_ptr< Result > result_
Definition: TritonData.h:97
template<typename IO>
bool lartriton::TritonData< IO >::setShape ( const ShapeType newShape)
inline

Definition at line 42 of file TritonData.h.

42 { return setShape(newShape, true); }
bool setShape(const ShapeType &newShape)
Definition: TritonData.h:42
template<typename IO>
bool lartriton::TritonData< IO >::setShape ( unsigned  loc,
int64_t  val 
)
inline

Definition at line 43 of file TritonData.h.

43 { return setShape(loc, val, true); }
bool setShape(const ShapeType &newShape)
Definition: TritonData.h:42
template<typename IO>
bool lartriton::TritonData< IO >::setShape ( const ShapeType newShape,
bool  canThrow 
)
private
template<typename IO >
bool lartriton::TritonData< IO >::setShape ( unsigned  loc,
int64_t  val,
bool  canThrow 
)
private

Definition at line 66 of file TritonData.cc.

66  {
67  std::stringstream msg;
68  unsigned full_loc = loc + (noBatch_ ? 0 : 1);
69 
70  //check boundary
71  if (full_loc >= fullShape_.size()) {
72  msg << name_ << " setShape(): dimension " << full_loc << " out of bounds (" << fullShape_.size() << ")";
73  if (canThrow)
74  throw cet::exception("TritonDataError") << msg.str();
75  else {
76  MF_LOG_WARNING("TritonDataWarning") << msg.str();
77  return false;
78  }
79  }
80 
81  if (val != fullShape_[full_loc]) {
82  if (dims_[full_loc] == -1) {
83  fullShape_[full_loc] = val;
84  return true;
85  } else {
86  msg << name_ << " setShape(): attempt to change value of non-variable shape dimension " << loc;
87  if (canThrow)
88  throw cet::exception("TritonDataError") << msg.str();
89  else {
90  MF_LOG_WARNING("TritonDataError") << msg.str();
91  return false;
92  }
93  }
94  }
95 
96  return true;
97 }
std::string name_
Definition: TritonData.h:84
void msg(const char *fmt,...)
Definition: message.cpp:107
const ShapeType dims_
Definition: TritonData.h:86
ShapeType fullShape_
Definition: TritonData.h:89
#define MF_LOG_WARNING(category)
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
template<typename IO>
const ShapeView& lartriton::TritonData< IO >::shape ( ) const
inline

Definition at line 52 of file TritonData.h.

52 { return shape_; }
template<typename IO>
int64_t lartriton::TritonData< IO >::sizeDims ( ) const
inline

Definition at line 59 of file TritonData.h.

59 { return productDims_; }
template<typename IO>
int64_t lartriton::TritonData< IO >::sizeShape ( ) const
inline

Definition at line 61 of file TritonData.h.

61 { return variableDims_ ? dimProduct(shape_) : sizeDims(); }
int64_t sizeDims() const
Definition: TritonData.h:59
int64_t dimProduct(const ShapeView &vec) const
Definition: TritonData.h:78
template<typename DT >
void lartriton::TritonInputData::toServer ( std::shared_ptr< TritonInput< DT >>  ptr)

Definition at line 109 of file TritonData.cc.

109  {
110  const auto& data_in = *ptr;
111 
112  //check batch size
113  if (data_in.size() != batchSize_) {
114  throw cet::exception("TritonDataError") << name_ << " input(): input vector has size " << data_in.size()
115  << " but specified batch size is " << batchSize_;
116  }
117 
118  //shape must be specified for variable dims or if batch size changes
119  data_->SetShape(fullShape_);
120 
121  if (byteSize_ != sizeof(DT))
122  throw cet::exception("TritonDataError") << name_ << " input(): inconsistent byte size " << sizeof(DT)
123  << " (should be " << byteSize_ << " for " << dname_ << ")";
124 
125  int64_t nInput = sizeShape();
126  for (unsigned i0 = 0; i0 < batchSize_; ++i0) {
127  const DT* arr = data_in[i0].data();
128  triton_utils::throwIfError(data_->AppendRaw(reinterpret_cast<const uint8_t*>(arr), nInput * byteSize_),
129  name_ + " input(): unable to set data for batch entry " + std::to_string(i0));
130  }
131 
132  //keep input data in scope
133  holder_ = std::move(ptr);
134 }
std::string name_
Definition: TritonData.h:84
ShapeType fullShape_
Definition: TritonData.h:89
void throwIfError(const Error &err, std::string_view msg)
Definition: triton_utils.cc:22
def move(depos, offset)
Definition: depos.py:107
int64_t sizeShape() const
Definition: TritonData.h:61
std::shared_ptr< IO > data_
Definition: TritonData.h:85
std::string dname_
Definition: TritonData.h:93
std::string to_string(ModuleType const mt)
Definition: ModuleType.h:34
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
template<typename IO>
bool lartriton::TritonData< IO >::variableDims ( ) const
inline

Definition at line 58 of file TritonData.h.

58 { return variableDims_; }

Friends And Related Function Documentation

template<typename IO>
friend class TritonClient
friend

Definition at line 64 of file TritonData.h.

Member Data Documentation

template<typename IO>
unsigned lartriton::TritonData< IO >::batchSize_
private

Definition at line 88 of file TritonData.h.

template<typename IO>
int64_t lartriton::TritonData< IO >::byteSize_
private

Definition at line 95 of file TritonData.h.

template<typename IO>
std::shared_ptr<IO> lartriton::TritonData< IO >::data_
private

Definition at line 85 of file TritonData.h.

template<typename IO>
const ShapeType lartriton::TritonData< IO >::dims_
private

Definition at line 86 of file TritonData.h.

template<typename IO>
std::string lartriton::TritonData< IO >::dname_
private

Definition at line 93 of file TritonData.h.

template<typename IO>
inference::DataType lartriton::TritonData< IO >::dtype_
private

Definition at line 94 of file TritonData.h.

template<typename IO>
ShapeType lartriton::TritonData< IO >::fullShape_
private

Definition at line 89 of file TritonData.h.

template<typename IO>
std::any lartriton::TritonData< IO >::holder_
private

Definition at line 96 of file TritonData.h.

template<typename IO>
std::string lartriton::TritonData< IO >::name_
private

Definition at line 84 of file TritonData.h.

template<typename IO>
bool lartriton::TritonData< IO >::noBatch_
private

Definition at line 87 of file TritonData.h.

template<typename IO>
int64_t lartriton::TritonData< IO >::productDims_
private

Definition at line 92 of file TritonData.h.

template<typename IO>
std::shared_ptr<Result> lartriton::TritonData< IO >::result_
private

Definition at line 97 of file TritonData.h.

template<typename IO>
ShapeView lartriton::TritonData< IO >::shape_
private

Definition at line 90 of file TritonData.h.

template<typename IO>
bool lartriton::TritonData< IO >::variableDims_
private

Definition at line 91 of file TritonData.h.


The documentation for this class was generated from the following files: