2 #include "cetlib_except/exception.h" 9 namespace ni = triton::common;
10 namespace nic = triton::client;
17 template <
typename IO>
22 , dims_(model_info.shape().
begin(), model_info.shape().
end())
26 , shape_(fullShape_.
begin() + (noBatch_ ? 0 : 1), fullShape_.
end())
27 , variableDims_(anyNeg(shape_))
28 , productDims_(variableDims_ ? -1 : dimProduct(shape_))
29 , dname_(model_info.datatype())
30 , dtype_(ni::ProtocolStringToDataType(dname_))
31 , byteSize_(ni::GetDataTypeByteSize(dtype_))
48 nic::InferRequestedOutput::Create(ioptr,
name_);
52 template <
typename IO>
56 for (
unsigned i = 0; i < newShape.size(); ++i) {
57 result &=
setShape(i, newShape[i], canThrow);
62 template <
typename IO>
65 std::stringstream msg;
66 unsigned full_loc = loc + (
noBatch_ ? 0 : 1);
70 msg <<
name_ <<
" setShape(): dimension " << full_loc <<
" out of bounds (" 81 if (
dims_[full_loc] == -1) {
86 msg <<
name_ <<
" setShape(): attempt to change value of non-variable shape dimension " 100 template <
typename IO>
109 template <
typename DT>
112 const auto& data_in = *ptr;
117 <<
name_ <<
" input(): input vector has size " << data_in.size()
118 <<
" but specified batch size is " <<
batchSize_;
126 <<
name_ <<
" input(): inconsistent byte size " <<
sizeof(DT) <<
" (should be " <<
byteSize_ 127 <<
" for " <<
dname_ <<
")";
130 for (
unsigned i0 = 0; i0 <
batchSize_; ++i0) {
131 const DT* arr = data_in[i0].data();
133 data_->AppendRaw(reinterpret_cast<const uint8_t*>(arr), nInput *
byteSize_),
142 template <
typename DT>
151 <<
name_ <<
" output(): inconsistent byte size " <<
sizeof(DT) <<
" (should be " 158 size_t contentByteSize;
161 "output(): unable to get raw");
162 if (contentByteSize != expectedContentByteSize) {
164 <<
name_ <<
" output(): unexpected content byte size " << contentByteSize <<
" (expected " 165 << expectedContentByteSize <<
")";
168 const DT* r1 =
reinterpret_cast<const DT*
>(r0);
169 dataOut.reserve(batchSize_);
170 for (
unsigned i0 = 0; i0 <
batchSize_; ++i0) {
171 auto offset = i0 * nOutput;
172 dataOut.emplace_back(r1 + offset, r1 + offset + nOutput);
void setBatchSize(unsigned bsize)
bool setShape(const ShapeType &newShape)
TritonData(const std::string &name, const TensorMetadata &model_info, bool noBatch)
std::vector< int64_t > ShapeType
void throwIfError(const Error &err, std::string_view msg)
void toServer(std::shared_ptr< TritonInput< DT >> ptr)
decltype(auto) constexpr end(T &&obj)
ADL-aware version of std::end.
decltype(auto) constexpr to_string(T &&obj)
ADL-aware version of std::to_string.
std::vector< std::vector< DT >> TritonInput
int64_t sizeShape() const
void createObject(IO **ioptr) const
std::shared_ptr< Result > result_
std::vector< triton_span::Span< const DT * >> TritonOutput
decltype(auto) constexpr begin(T &&obj)
ADL-aware version of std::begin.
std::shared_ptr< IO > data_
inference::ModelMetadataResponse_TensorMetadata TensorMetadata
#define MF_LOG_WARNING(category)
TritonOutput< DT > fromServer() const
cet::coded_exception< error, detail::translate > exception