forked from CoinCheung/BiSeNet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtrt_dep.hpp
57 lines (43 loc) · 1.29 KB
/
trt_dep.hpp
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
52
53
54
55
56
57
#ifndef _TRT_DEP_HPP_
#define _TRT_DEP_HPP_
#include "NvInfer.h"
#include "NvOnnxParser.h"
#include "NvInferPlugin.h"
#include <cuda_runtime_api.h>
#include "NvInferRuntimeCommon.h"
#include <iostream>
#include <string>
#include <vector>
#include <memory>
using std::string;
using std::vector;
using std::cout;
using std::endl;
using nvinfer1::ICudaEngine;
using nvinfer1::ILogger;
using Severity = nvinfer1::ILogger::Severity;
class Logger: public ILogger {
public:
void log(Severity severity, const char* msg) override {
if (severity != Severity::kINFO) {
std::cout << msg << std::endl;
}
}
};
struct TrtDeleter {
template <typename T>
void operator()(T* obj) const {
if (obj) {obj->destroy();}
}
};
template <typename T>
using TrtUniquePtr = std::unique_ptr<T, TrtDeleter>;
using TrtSharedEnginePtr = std::shared_ptr<ICudaEngine>;
extern Logger gLogger;
TrtSharedEnginePtr shared_engine_ptr(ICudaEngine* ptr);
TrtSharedEnginePtr parse_to_engine(string onnx_path, bool use_fp16);
void serialize(TrtSharedEnginePtr engine, string save_path);
TrtSharedEnginePtr deserialize(string serpth);
vector<int> infer_with_engine(TrtSharedEnginePtr engine, vector<float>& data);
void test_fps_with_engine(TrtSharedEnginePtr engine);
#endif