feat(ANSODEngine): run a sealed model on TensorRT without unsealing it
A .ansmodel reaching the GPU path went to ModelOptimizer, which knows one way to open a model — unzip it — and failed on the first byte. Even past that, the TensorRT engine only ever parsed an ONNX file, so the one thing the format exists to prevent, a decrypted model on disk, was the only way it could have run. The builder now takes its bytes from memory when it has them. The path it is given still names the plan that gets cached beside it, because a plan is a built artefact and carries no model: the second run loads it and never needs the ONNX at all. For a package the plan lands in the folder the zip flow used, so a model converted from a zip reuses the plan that zip already built. OptimizeModelStr recognises a package and skips the unzip-and-optimise leg entirely: the handle below it opens the package in memory and builds the plan from the decrypted bytes, which is the same work by a shorter road. Still on the file path: the other TensorRT handlers (segmentation, pose, classification). Only the YOLO detector reads a package today. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -4,6 +4,48 @@
|
||||
#include <NvInferVersion.h> // also defines TRT version macros
|
||||
#include <cudnn_version.h> // CUDNN_MAJOR/MINOR/PATCHLEVEL
|
||||
#include <cuda_runtime.h> // cudaRuntimeGetVersion
|
||||
#include <cstring> // memset for wiping decrypted model bytes
|
||||
#include <fstream>
|
||||
|
||||
// ============================================================================
|
||||
// ONNX bytes in memory
|
||||
//
|
||||
// A sealed .ansmodel is decrypted into RAM and stays there: handing the
|
||||
// parser a buffer is what keeps the plaintext model off the disk. The build
|
||||
// path still takes a path, because the path names the TensorRT plan that is
|
||||
// cached beside it — a plan is a built artefact and carries no model.
|
||||
// ============================================================================
|
||||
template <typename T>
|
||||
void Engine<T>::setOnnxBytes(const void* data, size_t size) {
|
||||
clearOnnxBytes();
|
||||
if (data == nullptr || size == 0) return;
|
||||
const char* p = static_cast<const char*>(data);
|
||||
m_onnxBytes.assign(p, p + size);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void Engine<T>::clearOnnxBytes() {
|
||||
if (m_onnxBytes.empty()) return;
|
||||
std::memset(m_onnxBytes.data(), 0, m_onnxBytes.size());
|
||||
m_onnxBytes.clear();
|
||||
m_onnxBytes.shrink_to_fit();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
bool Engine<T>::readOnnxBytes(const std::string& onnxModelPath,
|
||||
std::vector<char>& buffer) const {
|
||||
if (!m_onnxBytes.empty()) {
|
||||
buffer = m_onnxBytes;
|
||||
return true;
|
||||
}
|
||||
std::ifstream file(onnxModelPath, std::ios::binary | std::ios::ate);
|
||||
if (!file.good()) return false;
|
||||
const std::streamsize size = file.tellg();
|
||||
if (size <= 0) return false;
|
||||
file.seekg(0, std::ios::beg);
|
||||
buffer.resize(static_cast<size_t>(size));
|
||||
return static_cast<bool>(file.read(buffer.data(), size));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void Engine<T>::transformOutput(std::vector<std::vector<std::vector<T>>> &input, std::vector<std::vector<T>> &output) {
|
||||
|
||||
Reference in New Issue
Block a user