1#include "/opt/MagAOX/vendor/TensorRT-10.0.0.6/include/NvInfer.h"
7#include <cuda_runtime_api.h>
25template <
typename Clock = std::chrono::high_resolution_clock>
class Stopwatch {
32 template <
typename Rep =
typename Clock::duration::rep,
typename Units =
typename Clock::duration> Rep
elapsedTime()
const {
33 std::atomic_thread_fence(std::memory_order_relaxed);
34 auto counted_time = std::chrono::duration_cast<Units>(Clock::now() -
start_point).count();
35 std::atomic_thread_fence(std::memory_order_relaxed);
36 return static_cast<Rep
>(counted_time);
42class Logger :
public nvinfer1::ILogger
49 std::cout << msg << std::endl;
55 std::ifstream f(filepath.c_str());
59inline void parseCSV(std::string filepath,
float * fileData)
62 std::ifstream file(filepath);
63 if (!file.is_open()) {
64 std::cout <<
"Error opening file!" << std::endl;
69 int arrayLength =
sizeof(&fileData) /
sizeof(
float);
73 std::stringstream ss(line);
75 while (getline(ss, cell,
',')) {
76 fileData[i] = std::stof(cell);
86 const std::string& filepathSuffix,
const std::vector<std::string>& directories,
bool reportError =
true)
88 const int MAX_DEPTH{10};
92 for (
auto& dir : directories)
94 if (!dir.empty() && dir.back() !=
'/')
97 filepath = dir +
"\\" + filepathSuffix;
99 filepath = dir +
"/" + filepathSuffix;
104 filepath = dir + filepathSuffix;
107 for (
int i = 0; i < MAX_DEPTH && !found; i++)
109 const std::ifstream checkFile(filepath);
110 found = checkFile.is_open();
116 filepath =
"../" + filepath;
128 if (filepath.empty())
130 const std::string dirList = std::accumulate(directories.begin() + 1, directories.end(), directories.front(),
131 [](
const std::string& a,
const std::string& b) { return a +
"\n\t" + b; });
132 std::cout <<
"Could not find " << filepathSuffix <<
" in data directories:\n\t" << dirList << std::endl;
136 std::cout <<
"&&&& FAILED" << std::endl;
146 nvinfer1::IBuilder* builder, nvinfer1::IBuilderConfig* config,
int useDLACore,
bool allowGPUFallback =
true)
150 if (builder->getNbDLACores() == 0)
152 std::cerr <<
"Trying to use DLA core " << useDLACore <<
" on a platform that doesn't have any DLA cores"
154 assert(
"Error: use DLA core on a platfrom that doesn't have any DLA cores" &&
false);
156 if (allowGPUFallback)
158 config->setFlag(nvinfer1::BuilderFlag::kGPU_FALLBACK);
160 if (!config->getFlag(nvinfer1::BuilderFlag::kINT8))
164 config->setFlag(nvinfer1::BuilderFlag::kFP16);
166 config->setDefaultDeviceType(nvinfer1::DeviceType::kDLA);
167 config->setDLACore(useDLACore);
173 template <
typename T>
183 static_cast<void>(cudaStreamDestroy(*pStream));
191 if (cudaStreamCreateWithFlags(pStream.get(), cudaStreamNonBlocking) != cudaSuccess)
193 pStream.reset(
nullptr);
void log(Severity severity, const char *msg) noexcept override
Clock::time_point start_point
void operator()(T *obj) const
std::string locateFile(const std::string &filepathSuffix, const std::vector< std::string > &directories, bool reportError=true)
bool doesFileExist(const std::string &filepath)
static auto StreamDeleter
void parseCSV(std::string filepath, float *fileData)
void enableDLA(nvinfer1::IBuilder *builder, nvinfer1::IBuilderConfig *config, int useDLACore, bool allowGPUFallback=true)
std::unique_ptr< cudaStream_t, decltype(StreamDeleter)> makeCudaStream()