forked from zerollzeng/tiny-tensorrt
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInt8EntropyCalibrator.h
More file actions
51 lines (37 loc) · 1.2 KB
/
Int8EntropyCalibrator.h
File metadata and controls
51 lines (37 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/*
* @Description: In User Settings Edit
* @Author: your name
* @Date: 2019-08-21 16:48:34
* @LastEditTime: 2019-08-22 17:06:20
* @LastEditors: Please set LastEditors
*/
#ifndef _ENTROY_CALIBRATOR_H
#define _ENTROY_CALIBRATOR_H
#include <cudnn.h>
#include <string>
#include <vector>
#include "NvInfer.h"
#include "utils.h"
class Int8EntropyCalibrator : public nvinfer1::IInt8EntropyCalibrator2 {
public:
Int8EntropyCalibrator(int BatchSize,const std::vector<std::vector<float>>& data,const std::string& CalibDataName = "",bool readCache = true);
virtual ~Int8EntropyCalibrator();
int getBatchSize() const override {
std::cout << "getbatchSize: " << mBatchSize << std::endl;
return mBatchSize;
}
bool getBatch(void* bindings[], const char* names[], int nbBindings) override;
const void* readCalibrationCache(size_t& length) override;
void writeCalibrationCache(const void* cache, size_t length) override;
private:
std::string mCalibDataName;
std::vector<std::vector<float>> mDatas;
int mBatchSize;
int mCurBatchIdx;
float* mCurBatchData{ nullptr };
size_t mInputCount;
bool mReadCache;
void* mDeviceInput{ nullptr };
std::vector<char> mCalibrationCache;
};
#endif //_ENTROY_CALIBRATOR_H