-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpublic.h
128 lines (114 loc) · 2.83 KB
/
public.h
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#ifndef PUBLIC_H
#define PUBLIC_H
#include <iostream>
#include <fstream>
#include <unistd.h>
#include <string.h>
#include <cmath>
#include <iomanip>
#include <chrono>
#include <string>
#include <vector>
#include <map>
#include <NvInfer.h>
#include <cuda_fp16.h>
#include <cuda_runtime_api.h>
#include <opencv2/opencv.hpp>
#define CHECK(call) check(call, __LINE__, __FILE__)
inline bool check(cudaError_t e, int iLine, const char *szFile)
{
if (e != cudaSuccess)
{
std::cout << "CUDA runtime API error " << cudaGetErrorName(e) << " at line " << iLine << " in file " << szFile << std::endl;
return false;
}
return true;
}
using namespace nvinfer1;
class Logger : public ILogger
{
public:
Severity reportableSeverity;
Logger(Severity severity = Severity::kINFO):
reportableSeverity(severity) {}
void log(Severity severity, const char *msg) noexcept override
{
if (severity > reportableSeverity)
{
return;
}
switch (severity)
{
case Severity::kINTERNAL_ERROR:
std::cerr << "INTERNAL_ERROR: ";
break;
case Severity::kERROR:
std::cerr << "ERROR: ";
break;
case Severity::kWARNING:
std::cerr << "WARNING: ";
break;
case Severity::kINFO:
std::cerr << "INFO: ";
break;
default:
std::cerr << "VERBOSE: ";
break;
}
std::cerr << msg << std::endl;
}
};
// get the size in byte of a TensorRT data type
__inline__ size_t dataTypeToSize(DataType dataType)
{
switch ((int)dataType)
{
case int(DataType::kFLOAT):
return 4;
case int(DataType::kHALF):
return 2;
case int(DataType::kINT8):
return 1;
case int(DataType::kINT32):
return 4;
case int(DataType::kBOOL):
return 1;
default:
return 4;
}
}
// get the string of a TensorRT shape
__inline__ std::string shapeToString(Dims32 dim)
{
std::string output("(");
if (dim.nbDims == 0)
{
return output + std::string(")");
}
for (int i = 0; i < dim.nbDims - 1; i++)
{
output += std::to_string(dim.d[i]) + std::string(", ");
}
output += std::to_string(dim.d[dim.nbDims - 1]) + std::string(")");
return output;
}
// get the string of a TensorRT data type
__inline__ std::string dataTypeToString(DataType dataType)
{
switch (dataType)
{
case DataType::kFLOAT:
return std::string("FP32 ");
case DataType::kHALF:
return std::string("FP16 ");
case DataType::kINT8:
return std::string("INT8 ");
case DataType::kINT32:
return std::string("INT32");
case DataType::kBOOL:
return std::string("BOOL ");
default:
return std::string("Unknown");
}
}
#endif // PUBLIC_H