Skip to content

Commit

Permalink
vstrt/vs_tensorrt.cpp: cosmetics
Browse files Browse the repository at this point in the history
  • Loading branch information
WolframRhodium committed May 26, 2024
1 parent b13fb45 commit e7f5a34
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/windows-trt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ jobs:
- name: Configure
run: cmake -S . -B build -G Ninja -LA
-D CMAKE_BUILD_TYPE=Release
-D CMAKE_CXX_FLAGS="/EHsc /W4 /wd4100 /wd4996"
-D CMAKE_CXX_FLAGS="/EHsc /Wall /wd4100 /wd4625 /wd4626 /wd4996"
-D CMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded
-D CUDAToolkit_ROOT="C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.4"
-D VAPOURSYNTH_INCLUDE_DIRECTORY="%cd%\vapoursynth\include"
Expand Down
18 changes: 14 additions & 4 deletions vstrt/vs_tensorrt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <cstdint>
#include <cstdlib>
#include <fstream>
#include <ios>
#include <memory>
#include <mutex>
#include <string>
Expand Down Expand Up @@ -420,15 +421,24 @@ static void VS_CC vsTrtCreate(
return set_error("open engine failed");
}

size_t engine_nbytes = engine_stream.tellg();
auto engine_nbytes = engine_stream.tellg();
if (engine_nbytes == -1) {
return set_error("open engine failed");
}

std::unique_ptr<char [], decltype(&free)> engine_data {
(char *) malloc(engine_nbytes), free
(char *) malloc(static_cast<size_t>(engine_nbytes)), free
};
engine_stream.seekg(0, std::ios::beg);
engine_stream.read(engine_data.get(), engine_nbytes);
engine_stream.read(engine_data.get(), static_cast<std::streamsize>(engine_nbytes));

d->runtime.reset(nvinfer1::createInferRuntime(d->logger));
auto maybe_engine = initEngine(engine_data.get(), engine_nbytes, d->runtime, !d->flexible_output_prop.empty());
auto maybe_engine = initEngine(
engine_data.get(),
static_cast<size_t>(engine_nbytes),
d->runtime,
!d->flexible_output_prop.empty()
);
if (std::holds_alternative<std::unique_ptr<nvinfer1::ICudaEngine>>(maybe_engine)) {
d->engines.push_back(std::move(std::get<std::unique_ptr<nvinfer1::ICudaEngine>>(maybe_engine)));
} else {
Expand Down

0 comments on commit e7f5a34

Please sign in to comment.