19#include <NvInferVersion.h>
21#ifdef NV_TENSORRT_MAJOR
22#if NV_TENSORRT_MAJOR == 8
35 bool read_cache, std::string network)
36 : stream_(stream), read_cache_(read_cache), network_(network) {
39 cudaMalloc(&device_input_, input_count_ *
sizeof(
float));
40 stream_.
reset(first_batch);
45 (cudaFree(device_input_));
50 int nbBindings)
noexcept {
51 if (!stream_.next()) {
55 (cudaMemcpy(device_input_, stream_.getBatch(), input_count_ *
sizeof(
float),
56 cudaMemcpyHostToDevice));
57 bindings[0] = device_input_;
62 size_t &length)
noexcept {
63 calibration_cache_.clear();
67 input >> std::noskipws;
68 if (read_cache_ && input.good()) {
69 std::copy(std::istream_iterator<char>(input), std::istream_iterator<char>(),
70 std::back_inserter(calibration_cache_));
73 length = calibration_cache_.size();
74 return length ? &calibration_cache_[0] :
nullptr;
78 size_t length)
noexcept {
82 output.write(
reinterpret_cast<const char *
>(cache), length);
void reset(int firstBatch)
nvinfer1::DimsNCHW getDims() const
Int8EntropyCalibrator(const apollo::perception::inference::BatchStream &stream, int first_batch, bool read_cache, std::string network)
void writeCalibrationCache(const void *cache, size_t length) noexcept override
virtual ~Int8EntropyCalibrator()
const void * readCalibrationCache(size_t &length) noexcept override
bool getBatch(void *bindings[], const char *names[], int nbBindings) noexcept override
std::string locateFile(const std::string &network, const std::string &input)