-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #21 from mstallmo/tensorrt-version
Expand build script to be more flexible with respect to TensorRT version
- Loading branch information
Showing
11 changed files
with
157 additions
and
117 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
tensorrt-sys/3rdParty/TensorRT-5.1.5/libnvinfer_plugin_static.a filter=lfs diff=lfs merge=lfs -text | ||
tensorrt-sys/3rdParty/TensorRT-5.1.5/libnvinfer_static.a filter=lfs diff=lfs merge=lfs -text | ||
tensorrt-sys/3rdParty/TensorRT-5.1.5/libnvparsers_static.a filter=lfs diff=lfs merge=lfs -text |
3 changes: 3 additions & 0 deletions
3
tensorrt-sys/3rdParty/TensorRT-5.1.5/libnvinfer_plugin_static.a
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,115 @@ | ||
use cmake::Config; | ||
use std::process::Command; | ||
use std::string::String; | ||
use std::process::Stdio; | ||
use std::path::PathBuf; | ||
|
||
fn main() { | ||
let dst = Config::new("trt-sys").build(); | ||
fn get_shared_lib_link_path(library_name: &str) -> Option<PathBuf> { | ||
match get_all_possible_link_paths(library_name) { | ||
Some(all_link_paths) => { | ||
for line in all_link_paths.lines() { | ||
if line.ends_with(&format!("{}.so", library_name)) { | ||
let link_path = line.split("=>").collect::<Vec<&str>>().last().unwrap().to_owned(); | ||
println!("link path: {}", link_path); | ||
return Some(PathBuf::from(link_path.trim().to_owned())); | ||
} | ||
} | ||
None | ||
} | ||
None => { | ||
None | ||
} | ||
} | ||
} | ||
|
||
fn get_all_possible_link_paths(library_name: &str) -> Option<String> { | ||
let mut ld_config = Command::new("ldconfig").arg("-p").stdout(Stdio::piped()).spawn().expect("Failed to run ldconfig"); | ||
|
||
println!("cargo:rustc-link-search=native={}", dst.display()); | ||
if let Some(ld_config_output) = ld_config.stdout.take() { | ||
let grep_config = Command::new("grep").arg(library_name).stdin(ld_config_output).stdout(Stdio::piped()).spawn().unwrap(); | ||
let grep_stdout = grep_config.wait_with_output().unwrap(); | ||
ld_config.wait().unwrap(); | ||
Some(String::from_utf8(grep_stdout.stdout).unwrap()) | ||
} else { | ||
None | ||
} | ||
} | ||
|
||
#[cfg(feature = "trt-515")] | ||
fn configuration(full_library_path: &PathBuf) { | ||
if full_library_path.to_str().unwrap().ends_with("5.1.5") { | ||
let mut config = Config::new("trt-sys"); | ||
let dst = config.define("TRT_VERSION", "5.1.5").build(); | ||
println!("cargo:rustc-link-search=native={}", dst.display()); | ||
println!("cargo:rustc-flags=-l dylib=nvinfer"); | ||
println!("cargo:rustc-flags=-l dylib=nvparsers"); | ||
println!("cargo:rustc-flags=-L {}/3rdParty/TensorRT-5.1.5", env!("CARGO_MANIFEST_DIR")); | ||
println!("cargo:rustc-flags=-l static=nvinfer_plugin_static"); | ||
cuda_configuration(); | ||
} else { | ||
panic!("Invalid nvinfer version found. Expected: libnvinfer.so.5.1.5, Found: {}", full_library_path.to_str().unwrap()); | ||
} | ||
} | ||
|
||
#[cfg(feature = "trt-713")] | ||
fn configuration(full_library_path: &PathBuf) { | ||
if full_library_path.to_str().unwrap().ends_with("7.1.3") { | ||
let mut config = Config::new("trt-sys"); | ||
let dst = config.define("TRT_VERSION", "7.1.3").build(); | ||
println!("cargo:rustc-link-search=native={}", dst.display()); | ||
println!("cargo:rustc-flags=-l dylib=nvinfer"); | ||
println!("cargo:rustc-flags=-l dylib=nvparsers"); | ||
cuda_configuration(); | ||
} else { | ||
panic!("Invalid nvinfer version found. Expected: libnvinfer.so.7.1.3, Found: {}", full_library_path.to_str().unwrap()); | ||
} | ||
} | ||
|
||
#[cfg(feature = "cuda-101")] | ||
fn cuda_configuration() { | ||
println!("cargo:rustc-flags=-L /usr/local/cuda-10.1/lib64"); | ||
println!("cargo:rustc-flags=-l dylib=cudart"); | ||
println!("cargo:rustc-flags=-l dylib=cublas"); | ||
println!("cargo:rustc-flags=-l dylib=cublasLt"); | ||
println!("cargo:rustc-flags=-l dylib=cudnn"); | ||
} | ||
|
||
#[cfg(feature = "cuda-102")] | ||
fn cuda_configuration() { | ||
println!("cargo:rustc-flags=-L /usr/local/cuda-10.2/lib64"); | ||
println!("cargo:rustc-flags=-l dylib=cudart"); | ||
} | ||
|
||
#[cfg(feature = "cuda-110")] | ||
fn cuda_configuration() { | ||
println!("cargo:rustc-flags=-L /usr/local/cuda-11.0/lib64"); | ||
println!("cargo:rustc-flags=-l dylib=cudart"); | ||
} | ||
|
||
// Not sure if I love this solution but I think it's relatively robust enough for now on Unix systems. | ||
// Still have to thoroughly test what happens with a TRT library installed that's not done by the | ||
// dpkg. It's possible that we'll just have to fall back to only supporting one system library and assuming that | ||
// the user has the correct library installed and is viewable via ldconfig. | ||
// | ||
// Hopefully something like this will work for Windows installs as well, not having a default library | ||
// install location will make that significantly harder. | ||
fn main() { | ||
println!("cargo:rustc-link-lib=static=trt-sys"); | ||
println!("cargo:rustc-flags=-l dylib=stdc++"); | ||
println!("cargo:rustc-flags=-l dylib=nvinfer"); | ||
println!("cargo:rustc-flags=-l dylib=nvparsers"); | ||
println!("cargo:rustc-flags=-L /usr/local/cuda/lib64"); | ||
println!("cargo:rustc-flags=-l dylib=cudart"); | ||
|
||
match get_shared_lib_link_path("libnvinfer") { | ||
Some(link_path) => { | ||
match std::fs::read_link(link_path) { | ||
Ok(full_library_path) => { | ||
configuration(&full_library_path); | ||
}, | ||
Err(_) => { | ||
panic!("libnvinfer.so not found! See https://docs.nvidia.com/deeplearning/tensorrt/archives/tensorrt-515/tensorrt-install-guide/index.html for install instructions"); | ||
} | ||
} | ||
}, | ||
None => { | ||
panic!("libnvinfer.so not found! See https://docs.nvidia.com/deeplearning/tensorrt/archives/tensorrt-515/tensorrt-install-guide/index.html for install instructions"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,28 @@ | ||
cmake_minimum_required(VERSION 3.10) | ||
project(LibTRT LANGUAGES CXX CUDA) | ||
|
||
if(${TRT_VERSION} MATCHES "5.1.5") | ||
message(STATUS "TRT version is ${TRT_VERSION}") | ||
add_definitions(-DTRT_VERSION="${TRT_VERSION}") | ||
endif() | ||
|
||
set(CMAKE_CXX_STANDARD 17) | ||
|
||
set(CMAKE_CXX_FLAGS "-O3 -Wall -Wextra -Werror -Wno-unknown-pragmas") | ||
|
||
file(GLOB source_files | ||
"TRTLogger/*.h" | ||
"TRTLogger/*.cpp" | ||
"TRTRuntime/*.h" | ||
"TRTRuntime/*cpp" | ||
"TRTCudaEngine/*.h" | ||
"TRTCudaEngine/*.cpp" | ||
"TRTContext/*.h" | ||
"TRTContext/*.cpp" | ||
"TRTUffParser/*.h" | ||
"TRTUffParser/*.cpp" | ||
"TRTDims/*.h" | ||
"TRTDims/*.cpp" | ||
"TRTBuilder/*.h" | ||
"TRTBuilder/*.cpp" | ||
"TRTNetworkDefinition/*.h" | ||
"TRTNetworkDefinition/*.cpp" | ||
"TRTHostMemory/*.h" | ||
"TRTHostMemory/*.cpp" | ||
"*.h" | ||
) | ||
|
||
find_library(CUDART_LIBRARY cudart ${CMAKE_CUDA_IMPLICIT_LINK_DIRECTORIES}) | ||
|
||
add_library(trt-sys STATIC ${source_files}) | ||
target_link_libraries(trt-sys PRIVATE nvinfer ${CUDART_LIBRARY}) | ||
include_directories(${CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES}) | ||
|
||
install(TARGETS trt-sys DESTINATION .) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters