Skip to content

Commit

Permalink
TensorRT 8.5 GA Release (#879)
Browse files Browse the repository at this point in the history
Signed-off-by: Kevin Chen <[email protected]>

Signed-off-by: Kevin Chen <[email protected]>
  • Loading branch information
kevinch-nv authored Nov 2, 2022
1 parent 12eb0d6 commit 3b008c4
Show file tree
Hide file tree
Showing 19 changed files with 1,478 additions and 1,223 deletions.
41 changes: 9 additions & 32 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ add_definitions("-DSOURCE_LENGTH=${SOURCE_LENGTH}")
# Version information
#--------------------------------------------------
set(ONNX2TRT_MAJOR 8)
set(ONNX2TRT_MINOR 4)
set(ONNX2TRT_PATCH 3)
set(ONNX2TRT_MINOR 5)
set(ONNX2TRT_PATCH 1)
set(ONNX2TRT_VERSION "${ONNX2TRT_MAJOR}.${ONNX2TRT_MINOR}.${ONNX2TRT_PATCH}" CACHE STRING "ONNX2TRT version")

#--------------------------------------------------
Expand All @@ -55,16 +55,10 @@ if (BUILD_ONNXIFI)
set(ONNXIFI_SOURCES onnx_trt_backend.cpp)
endif()

# Build executables if BUILD_EXES flag is set
if (DEFINED BUILD_EXES)
set(EXECUTABLE_SOURCES
main.cpp
)
set(API_TESTS_SOURCES
getSupportedAPITest.cpp
ModelImporter.cpp
)
endif()
set(API_TESTS_SOURCES
getSupportedAPITest.cpp
ModelImporter.cpp
)

if (NOT TARGET protobuf::libprotobuf)
FIND_PACKAGE(Protobuf REQUIRED)
Expand Down Expand Up @@ -135,23 +129,12 @@ if(BUILD_ONNXIFI)
target_link_libraries(trt_onnxify PUBLIC nvonnxparser_static ${CMAKE_THREAD_LIBS_INIT} ${CMAKE_DL_LIBS})
endif()

# --------------------------------
# Converter executable
# --------------------------------
if (DEFINED BUILD_EXES)
add_executable(onnx2trt ${EXECUTABLE_SOURCES})
target_include_directories(onnx2trt PUBLIC ${ONNX_INCLUDE_DIRS})
target_link_libraries(onnx2trt PUBLIC ${PROTOBUF_LIB} onnx nvonnxparser_static ${CMAKE_THREAD_LIBS_INIT} ${CMAKE_DL_LIBS}) #${CUDA_LIBRARIES}
endif()

# --------------------------------
# API Tests
# --------------------------------
if (DEFINED BUILD_EXES)
add_executable(getSupportedAPITest ${API_TESTS_SOURCES})
target_include_directories(getSupportedAPITest PUBLIC ${ONNX_INCLUDE_DIRS} ${CUDNN_INCLUDE_DIR})
target_link_libraries(getSupportedAPITest PUBLIC ${PROTOBUF_LIB} nvonnxparser_static ${CMAKE_THREAD_LIBS_INIT} ${CMAKE_DL_LIBS}) #${CUDA_LIBRARIES}
endif()
add_executable(getSupportedAPITest ${API_TESTS_SOURCES})
target_include_directories(getSupportedAPITest PUBLIC ${ONNX_INCLUDE_DIRS} ${CUDNN_INCLUDE_DIR})
target_link_libraries(getSupportedAPITest PUBLIC ${PROTOBUF_LIB} nvonnxparser_static ${CMAKE_THREAD_LIBS_INIT} ${CMAKE_DL_LIBS})

# --------------------------------
# Installation
Expand All @@ -166,12 +149,6 @@ install(TARGETS
install(FILES ${HEADERS}
DESTINATION include
)
if (DEFINED BUILD_EXES)
install(TARGETS
onnx2trt
RUNTIME DESTINATION bin
)
endif()

SET(CPACK_GENERATOR "DEB")
SET(CPACK_DEBIAN_PACKAGE_MAINTAINER "NVIDIA") #required
Expand Down
9 changes: 6 additions & 3 deletions ConditionalHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,10 @@ Status addConditionalInputLayer(IImporterContext* ctx, nvinfer1::IIfConditional*
inputsMap[name] = inputLayer;
const std::string inputLayerName(name);
ctx->registerLayer(inputLayer, inputLayerName + "_InputLayer");
ctx->registerTensor(TensorOrWeights{inputLayer->getOutput(0)}, inputLayerName + "_InputLayer_output");
// Note: Since multiple conditionals may use the same external tensor, check unique names for output tensors of
// IfConditionalInputLayers to avoid tensor name duplication.
ctx->registerTensor(
TensorOrWeights{inputLayer->getOutput(0)}, inputLayerName + "_InputLayer_output", /*checkUniqueName*/ true);
}
else
{
Expand Down Expand Up @@ -259,11 +262,11 @@ Status getSubgraphTensors(const std::vector<nvinfer1::ILayer*>& newLayers,
}

using TensorsVec = std::vector<nvinfer1::ITensor*>;
auto getOutputs = [&](nvinfer1::ILayer const* l, TensorsVec res) {
auto getOutputs = [&](nvinfer1::ILayer const* l, TensorsVec& res) {
getTensors(l, false, [&](nvinfer1::ITensor* t) { res.emplace_back(t); });
};

auto getInputs = [&](nvinfer1::ILayer const* l, TensorsVec res) {
auto getInputs = [&](nvinfer1::ILayer const* l, TensorsVec& res) {
getTensors(l, true, [&](nvinfer1::ITensor* t) { res.emplace_back(t); });
};

Expand Down
18 changes: 12 additions & 6 deletions ImporterContext.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/*
* SPDX-License-Identifier: Apache-2.0
*/

#include "ImporterContext.hpp"

namespace onnx2trt
Expand Down Expand Up @@ -25,7 +29,7 @@ void ImporterContext::popBaseNameScope()
mBaseNameScopeStack.pop_back();
}

void ImporterContext::registerTensor(TensorOrWeights tensor, std::string const& basename)
void ImporterContext::registerTensor(TensorOrWeights tensor, std::string const& basename, bool const checkUniqueName)
{
// TRT requires unique tensor names.
std::string const& uniqueName = generateUniqueName(mTensorNames, basename);
Expand All @@ -48,7 +52,7 @@ void ImporterContext::registerTensor(TensorOrWeights tensor, std::string const&
convertINT64(reinterpret_cast<int64_t*>(weights.values), weights.shape, this), weights.shape};
}
// It may be possible for nested subgraphs to have different values for the same initializer.
// For multiple name scopes - use unique name to keep track of weights.
// For multiple name scopes - use unique name to keep track of weights.
if (!mBaseNameScopeStack.empty())
{
tensor.weights().setName(uniqueName.c_str());
Expand All @@ -60,13 +64,15 @@ void ImporterContext::registerTensor(TensorOrWeights tensor, std::string const&
}
}

auto const p = this->tensors().emplace(basename, TensorOrWeights{});
std::string const& nameToCheck = checkUniqueName ? uniqueName : basename;

auto const p = this->tensors().emplace(nameToCheck, TensorOrWeights{});
bool nameIsDuplicate = false;
if (!mBaseNameScopeStack.empty())
{
// Remember original binding so it can be restored when scope is popped.
auto const q
= mBaseNameScopeStack.back().emplace(basename, std::make_pair(p.second, std::move(p.first->second)));
= mBaseNameScopeStack.back().emplace(nameToCheck, std::make_pair(p.second, std::move(p.first->second)));
// Check that scope did not already have a binding for basename.
nameIsDuplicate = !q.second;
}
Expand All @@ -78,7 +84,7 @@ void ImporterContext::registerTensor(TensorOrWeights tensor, std::string const&
}
if (nameIsDuplicate)
{
throw std::runtime_error("ONNX graph has duplicate tensor name: " + basename);
throw std::runtime_error("ONNX graph has duplicate tensor name: " + nameToCheck);
}
p.first->second = std::move(tensor);
}
Expand All @@ -97,7 +103,7 @@ void ImporterContext::registerLayer(nvinfer1::ILayer* layer, std::string const&
layer->setName(uniqueName.c_str());
if (layer->getType() == nvinfer1::LayerType::kCONSTANT)
{
if (basename != uniqueName)
if (basename != uniqueName && mConstantLayers.find(uniqueName) != mConstantLayers.end())
{
LOG_ERROR("Constant layer: " << uniqueName << " can be a duplicate of: " << basename);
assert(!"Internal error: duplicate constant layers for the same weights");
Expand Down
3 changes: 2 additions & 1 deletion ImporterContext.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,8 @@ class ImporterContext final : public IImporterContext
void popBaseNameScope() override;

// This actually handles weights as well, but is named this way to be consistent with the tensors()
void registerTensor(TensorOrWeights tensor, std::string const& basename) override;
void registerTensor(
TensorOrWeights tensor, std::string const& basename, bool const checkUniqueName = false) override;

void registerLayer(nvinfer1::ILayer* layer, std::string const& basename) override;

Expand Down
Loading

0 comments on commit 3b008c4

Please sign in to comment.