18#include <eigen3/unsupported/Eigen/CXX11/Tensor>
20#include <model_config.pb.h>
31using VectorType =
typename std::conditional_t<std::is_const_v<T>,
32 Eigen::Map<const Eigen::VectorX<typename std::remove_const_t<T>>>,
33 Eigen::Map<Eigen::VectorX<T>>>;
43 Eigen::Map<const Eigen::Matrix<typename std::remove_const_t<T>, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor>>,
44 Eigen::Map<Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor>>>;
54template <
typename T,
int rank>
57 Eigen::TensorMap<const Eigen::Tensor<typename std::remove_const_t<T>, rank, Eigen::RowMajor, Eigen::Index>>,
58 Eigen::TensorMap<Eigen::Tensor<T, rank, Eigen::RowMajor, Eigen::Index>>>;
70 std::variant<bool, uint8_t, uint16_t, uint32_t, uint64_t, int8_t, int16_t, int32_t, int64_t, float, double, Eigen::half>;
81 case inference::DataType::TYPE_BOOL:
83 case inference::DataType::TYPE_UINT8:
84 return static_cast<uint8_t
>(0);
85 case inference::DataType::TYPE_UINT16:
86 return static_cast<uint16_t
>(0);
87 case inference::DataType::TYPE_UINT32:
88 return static_cast<uint32_t
>(0);
89 case inference::DataType::TYPE_UINT64:
90 return static_cast<uint64_t
>(0);
91 case inference::DataType::TYPE_INT8:
92 return static_cast<int8_t
>(0);
93 case inference::DataType::TYPE_INT16:
94 return static_cast<int16_t
>(0);
95 case inference::DataType::TYPE_INT32:
96 return static_cast<int32_t
>(0);
97 case inference::DataType::TYPE_INT64:
98 return static_cast<int64_t
>(0);
99 case inference::DataType::TYPE_FP16:
100 return Eigen::half{0.0f};
101 case inference::DataType::TYPE_FP32:
102 return static_cast<float>(0);
103 case inference::DataType::TYPE_FP64:
104 return static_cast<double>(0);
106 throw std::invalid_argument(
"Unsupported data type");
117 return std::visit([](
auto&& arg) {
return alignof(std::decay_t<
decltype(arg)>); },
getZero(type));
127 constexpr std::size_t kMinSharedMemoryAlignment = 8;
128 return std::max(
getAlignment(type), kMinSharedMemoryAlignment);
137inline std::size_t
alignUp(std::size_t offset, std::size_t alignment) {
138 if (alignment <= 1) {
141 const std::size_t remainder = offset % alignment;
142 return remainder == 0 ? offset : offset + (alignment - remainder);
148using ModelOutput = std::map<std::string, std::shared_ptr<triton::client::InferRequestedOutput>>;
159 std::shared_ptr<triton::client::InferInput>
input;
188 const bool owns_host_buffer = other.ownsHostBuffer();
189 input = std::move(other.input);
190 data = std::move(other.data);
191 data_raw = owns_host_buffer ?
data.data() : other.data_raw;
194 other.data_raw =
nullptr;
195 other.device_data_raw =
nullptr;
196 other.data_raw_size = 0;
201 if (
this != &other) {
202 const bool owns_host_buffer = other.ownsHostBuffer();
214 if (
this != &other) {
215 const bool owns_host_buffer = other.ownsHostBuffer();
216 input = std::move(other.input);
217 data = std::move(other.data);
218 data_raw = owns_host_buffer ?
data.data() : other.data_raw;
221 other.data_raw =
nullptr;
222 other.device_data_raw =
nullptr;
223 other.data_raw_size = 0;
268 bool ownsHostBuffer() const noexcept {
return data_raw ==
data.data(); }
291 std::visit([](auto&& arg) {
return static_cast<std::int64_t
>(
sizeof(arg)); },
getZero(
datatype))} {}
std::size_t getAlignment(inference::DataType type)
Return the natural C++ alignment for a Triton datatype.
std::variant< bool, uint8_t, uint16_t, uint32_t, uint64_t, int8_t, int16_t, int32_t, int64_t, float, double, Eigen::half > TritonDataType
Type alias for all possible C++ scalar types that the triton server supports.
std::size_t getSharedMemoryAlignment(inference::DataType type)
Return the alignment used when packing tensors into shared memory.
typename std::conditional_t< std::is_const_v< T >, Eigen::Map< const Eigen::Matrix< typename std::remove_const_t< T >, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor > >, Eigen::Map< Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor > > > MatrixType
Helper type template for Eigen::Matrix compatible with Triton.
typename std::conditional_t< std::is_const_v< T >, Eigen::Map< const Eigen::VectorX< typename std::remove_const_t< T > > >, Eigen::Map< Eigen::VectorX< T > > > VectorType
Helper type template for Eigen::Vector compatible with Triton.
typename std::conditional_t< std::is_const_v< T >, Eigen::TensorMap< const Eigen::Tensor< typename std::remove_const_t< T >, rank, Eigen::RowMajor, Eigen::Index > >, Eigen::TensorMap< Eigen::Tensor< T, rank, Eigen::RowMajor, Eigen::Index > > > TensorType
Helper type template for Eigen::Tensor compatible with Triton.
TritonDataType getZero(inference::DataType type)
Get a zero value in the correct C++ type, given a Triton datatype.
std::size_t alignUp(std::size_t offset, std::size_t alignment)
Round an offset up to an alignment boundary.
std::int64_t accumulate_shape(It begin, It end)
Compute the element count represented by a tensor shape.
std::map< std::string, std::shared_ptr< triton::client::InferRequestedOutput > > ModelOutput
Map model output names to Triton requested-output objects.