Skip to content

Commit

Permalink
TensorRT 6.0 ONNX Parser Release
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinch-nv committed Sep 16, 2019
1 parent 8c3fa1f commit 400df73
Show file tree
Hide file tree
Showing 10 changed files with 797 additions and 623 deletions.
10 changes: 6 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ set(CMAKE_CXX_STANDARD 11)

# Enable compiler warnings
if ( CMAKE_COMPILER_IS_GNUCC )
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wno-deprecated-declarations -Wno-unused-function -Wno-unused-but-set-variable")
endif()
if ( MSVC )
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4")
Expand All @@ -59,9 +59,9 @@ set(RUNTIME_LINKER_SCRIPT ${ONNX2TRT_ROOT}/libnvonnxparser_runtime.version)
#--------------------------------------------------
# Version information
#--------------------------------------------------
set(ONNX2TRT_MAJOR 0)
set(ONNX2TRT_MINOR 1)
set(ONNX2TRT_PATCH 0)
set(ONNX2TRT_MAJOR 6)
set(ONNX2TRT_MINOR 0)
set(ONNX2TRT_PATCH 1)

#--------------------------------------------------
# Build configurations, global to all projects
Expand Down Expand Up @@ -159,6 +159,7 @@ if(${CMAKE_VERSION} VERSION_LESS ${CMAKE_VERSION_THRESHOLD})
-lineinfo \
-g \
--expt-extended-lambda \
-Xcompiler -Wno-deprecated-declarations \
${GENCODES} \
")

Expand All @@ -174,6 +175,7 @@ else()
-lineinfo \
-g \
--expt-extended-lambda \
-Xcompiler -Wno-deprecated-declarations \
${GENCODES} \
")

Expand Down
15 changes: 15 additions & 0 deletions ModelImporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,21 @@ Status importInputs(ImporterContext* importer_ctx,
ASSERT_INPUT(!tensors->count(input.name()), ErrorCode::kINVALID_GRAPH,input.name());
tensors->insert({input.name(), tensor});
}

// According to the ONNX spec: initializers do not have to be specified as agraph input.
// In order for these initializers to be populated down to TRT, we need to add them to the tensors list.
for (auto initializer : initializer_map)
{
const std::string initializer_name = initializer.first;
if (!tensors->count(initializer_name))
{
const auto& initializer_weight = *initializer.second;
ShapedWeights weights;
ASSERT(convert_onnx_weights(initializer_weight, &weights), ErrorCode::kUNSUPPORTED_NODE);
tensors->insert({initializer_name, weights});
}
}

return Status::success();
}

Expand Down
6 changes: 3 additions & 3 deletions NvOnnxParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@
#include "NvInfer.h"
#include "NvOnnxParserTypedefs.h"

#define NV_ONNX_PARSER_MAJOR 0
#define NV_ONNX_PARSER_MINOR 1
#define NV_ONNX_PARSER_PATCH 0
#define NV_ONNX_PARSER_MAJOR 6
#define NV_ONNX_PARSER_MINOR 0
#define NV_ONNX_PARSER_PATCH 1

static const int NV_ONNX_PARSER_VERSION = ((NV_ONNX_PARSER_MAJOR * 10000) +
(NV_ONNX_PARSER_MINOR * 100) +
Expand Down
36 changes: 20 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ See also the [TensorRT documentation](https://docs.nvidia.com/deeplearning/sdk/#

## Supported TensorRT Versions

Development on the Master branch is for the latest version of [TensorRT (5.1)](https://developer.nvidia.com/nvidia-tensorrt-download)
Development on the Master branch is for the latest version of [TensorRT 6.0](https://developer.nvidia.com/nvidia-tensorrt-download)

For versions < 5.1, clone and build from the [5.0 branch](https://github.com/onnx/onnx-tensorrt/tree/v5.0)
For version 5.1, clone and build from the [5.1 branch](https://github.com/onnx/onnx-tensorrt/tree/5.1)

For version < 5.1, clone and build from the [5.0 branch](https://github.com/onnx/onnx-tensorrt/tree/v5.0)


## Supported Operators
Expand All @@ -19,8 +21,8 @@ Current supported ONNX operators are found in the [operator support matrix](oper

### Dependencies

- [Protobuf](https://github.com/google/protobuf/releases)
- [TensorRT](https://developer.nvidia.com/tensorrt)
- [Protobuf >= 3.8.x](https://github.com/google/protobuf/releases)
- [TensorRT 6.0](https://developer.nvidia.com/tensorrt)

### Download the code
Clone the code from GitHub.
Expand All @@ -31,7 +33,7 @@ Clone the code from GitHub.

The TensorRT-ONNX executables and libraries are built with CMAKE. Note by default CMAKE will tell the CUDA compiler generate code for the latest SM version. If you are using a GPU with a lower SM version you can specify which SMs to build for by using the optional `-DGPU_ARCHS` flag. For example, if you have a GTX 1080, you can specify `-DGPU_ARCHS="61"` to generate CUDA code specifically for that card.

See [here](https://developer.nvidia.com/cuda-gpus) for finding what maximum compute capability your specific GPU supports.
See [here](https://developer.nvidia.com/cuda-gpus) for the compute capability matrix for your specific GPU.

mkdir build
cd build
Expand All @@ -56,6 +58,15 @@ See more usage information by running:

onnx2trt -h

### Python modules
Python bindings for the ONNX-TensorRT parser are packaged in the shipped `.whl` files. Install them with

pip install <tensorrt_install_dir>/python/tensorrt-6.0.1.5-cp27-none-linux_x86_64.whl

TensorRT 6.0 supports ONNX release 1.5.0. Install it with:

pip install onnx==1.5.0

## ONNX Python backend usage

The TensorRT backend for ONNX can be used in Python as follows:
Expand Down Expand Up @@ -84,22 +95,15 @@ libnvonnxparser_runtime.so, which has its C++ API declared in this header:

NvOnnxParserRuntime.h

### Python modules
Python bindings for the ONNX-TensorRT parser in TensorRT versions >= 5.0 are packaged in the shipped `.whl` files. Install them with

pip install <tensorrt_install_dir>/python/tensorrt-5.1.6.0-cp27-none-linux_x86_64.whl

For earlier versions of TensorRT, the Python wrappers are built using SWIG.
Build the Python wrappers and modules by running:
Important typedefs required for parsing ONNX models are declared in this header:

python setup.py build
sudo python setup.py install
NvOnnxParserTypedefs.h

### Docker image

Build the onnx_tensorrt Docker image by running:

cp /path/to/TensorRT-5.1.*.tar.gz .
cp /path/to/TensorRT-6.0.*.tar.gz .
docker build -t onnx_tensorrt .

### Tests
Expand All @@ -118,4 +122,4 @@ You can use `-v` flag to make output more verbose.

## Pre-trained models

Pre-trained models in ONNX format can be found at the [ONNX Model Zoo](https://github.com/onnx/models)
Pre-trained models in ONNX format can be found at the [ONNX Model Zoo](https://github.com/onnx/models)
11 changes: 8 additions & 3 deletions ShapedWeights.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,16 @@ bool convertINT64(void* weightValues, const size_t nbWeights, std::vector<int32_
}

size_t ShapedWeights::count() const {
if( this->shape.nbDims == 0 ) {
if( this->values == nullptr && this->shape.nbDims == 0 )
{
return 0;
} else {
}
else
{
// TRT supports scalars, so 0D tensors should have a count of 1.
size_t c = 1;
for( int i=0; i<this->shape.nbDims; ++i ) {
for( int i=0; i<this->shape.nbDims; ++i )
{
c *= this->shape.d[i];
}
return c;
Expand Down
Loading

0 comments on commit 400df73

Please sign in to comment.