19 #include <cuda_runtime_api.h> 25 #include "NvCaffeParser.h" 27 #include "NvInferPlugin.h" 35 virtual DimsHW
compute(DimsHW input_dims, DimsHW kernel_size, DimsHW stride,
36 DimsHW padding, DimsHW dilation,
37 const char *layerName)
const {
38 const int kernel_extent_h = dilation.d[0] * (kernel_size.d[0] - 1) + 1;
39 const int kernel_extent_w = dilation.d[1] * (kernel_size.d[1] - 1) + 1;
40 auto &&h_temp = (input_dims.d[0] + 2 * padding.d[0] - kernel_extent_h) *
42 auto &&w_temp = (input_dims.d[1] + 2 * padding.d[1] - kernel_extent_w) *
45 std::string str_name(layerName);
46 if (str_name.find(
"as_conv") == std::string::npos) {
47 return DimsHW(static_cast<int>(ceil(h_temp)) + 1,
48 static_cast<int>(ceil(w_temp)) + 1);
50 return DimsHW(static_cast<int>(h_temp) + 1, static_cast<int>(w_temp) + 1);
62 bool read_cache, std::string network)
63 : stream_(stream), read_cache_(read_cache), network_(network) {
64 DimsNCHW dims = stream_.getDims();
65 input_count_ = stream_.getBatchSize() * dims.c() * dims.h() * dims.w();
66 cudaMalloc(&device_input_, input_count_ *
sizeof(
float));
67 stream_.reset(first_batch);
72 (cudaFree(device_input_));
76 int getBatchSize()
const override {
return stream_.getBatchSize(); }
78 bool getBatch(
void *bindings[],
const char *names[],
79 int nbBindings)
override {
80 if (!stream_.next()) {
84 (cudaMemcpy(device_input_, stream_.getBatch(), input_count_ *
sizeof(float),
85 cudaMemcpyHostToDevice));
86 bindings[0] = device_input_;
91 calibration_cache_.clear();
95 input >> std::noskipws;
96 if (read_cache_ && input.good()) {
97 std::copy(std::istream_iterator<char>(input),
98 std::istream_iterator<char>(),
99 std::back_inserter(calibration_cache_));
102 length = calibration_cache_.size();
103 return length ? &calibration_cache_[0] :
nullptr;
107 std::ofstream output(
110 output.write(reinterpret_cast<const char *>(cache), length);
114 return CalibrationAlgoType::kENTROPY_CALIBRATION;
119 bool read_cache_ =
true;
120 std::string network_ =
"yolo";
122 void *device_input_ =
nullptr;
123 std::vector<char> calibration_cache_;
std::string locateFile(const std::string &path, const std::string &input)
const void * readCalibrationCache(size_t &length) override
Definition: entropy_calibrator.h:90
int getBatchSize() const override
Definition: entropy_calibrator.h:76
Definition: batch_stream.h:28
virtual CalibrationAlgoType getAlgorithm()
Definition: entropy_calibrator.h:113
Definition: entropy_calibrator.h:32
void writeCalibrationCache(const void *cache, size_t length) override
Definition: entropy_calibrator.h:106
Int8EntropyCalibrator(const apollo::perception::inference::BatchStream &stream, int first_batch, bool read_cache, std::string network)
Definition: entropy_calibrator.h:60
bool getBatch(void *bindings[], const char *names[], int nbBindings) override
Definition: entropy_calibrator.h:78
Definition: entropy_calibrator.h:58
virtual ~Int8EntropyCalibrator()
Definition: entropy_calibrator.h:70