Skip to content

Commit 38aed92

Browse files
gcuendet-cognexgcuendet
authored andcommitted
Add cmake support for the examples
The examples are considered as completely separated cmake project, in order to demonstrate how torchtrt would typically be consumed in a different CMake project and test the torchtrtConfig.cmake. Signed-off-by: Gabriel Cuendet <[email protected]> Signed-off-by: Gabriel Cuendet <[email protected]>
1 parent df47461 commit 38aed92

File tree

6 files changed

+63
-5
lines changed

6 files changed

+63
-5
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ if (DEFINED CMAKE_MODULE_PATH)
1313
endif()
1414

1515
include(cmake/build_options.cmake)
16-
include(cmake/dependencies.cmake)
1716
include(cmake/paths.cmake)
17+
include(cmake/dependencies.cmake)
1818
if(MSVC)
1919
add_compile_options(/wd4624 /wd4067 /permissive-)
2020
# When using Ninja generator, suppress the warning D9025

Config.cmake.in

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@
22

33
include(CMakeFindDependencyMacro)
44

5-
find_dependency(Torch REQUIRED CONFIG)
6-
find_dependency(TensorRT REQUIRED)
7-
5+
find_dependency(Torch)
6+
find_package(TensorRT QUIET)
7+
if (NOT TensorRT_FOUND)
8+
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/Modules")
9+
find_dependency(TensorRT)
10+
endif()
811
include("${CMAKE_CURRENT_LIST_DIR}/torchtrtTargets.cmake")
912

1013
check_required_components(MathFunctions)

cmake/dependencies.cmake

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# TensorRT
2-
find_package(TensorRT REQUIRED)
2+
find_package(TensorRT QUIET)
3+
if (NOT TensorRT_FOUND)
4+
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/Modules")
5+
find_package(TensorRT REQUIRED)
6+
endif()
7+
8+
# If the custom finders are needed at this point, there are good chances that they will be needed when consuming the library as well
9+
install(FILES "${CMAKE_SOURCE_DIR}/cmake/Modules/FindTensorRT.cmake" DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/torchtrt/Modules")
10+
install(FILES "${CMAKE_SOURCE_DIR}/cmake/Modules/FindcuDNN.cmake" DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/torchtrt/Modules")
311

412
# CUDA
513
find_package(CUDAToolkit REQUIRED)

examples/int8/ptq/CMakeLists.txt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
cmake_minimum_required(VERSION 3.17)
2+
project(ptq LANGUAGES CXX)
3+
4+
# Find dependencies
5+
find_package(Torch REQUIRED)
6+
find_package(torchtrt REQUIRED)
7+
8+
set(SRCS
9+
${CMAKE_SOURCE_DIR}/main.cpp
10+
${CMAKE_SOURCE_DIR}/../benchmark/benchmark.cpp
11+
${CMAKE_SOURCE_DIR}/../datasets/cifar10.cpp
12+
13+
)
14+
15+
add_executable(${CMAKE_PROJECT_NAME} ${SRCS})
16+
target_include_directories(${CMAKE_PROJECT_NAME} PRIVATE "${CMAKE_SOURCE_DIR}/../../..")
17+
target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE torch "-Wl,--no-as-needed" torchtrt "-Wl,--as-needed")

examples/int8/qat/CMakeLists.txt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
cmake_minimum_required(VERSION 3.17)
2+
project(qat LANGUAGES CXX)
3+
4+
# Find dependencies
5+
find_package(Torch REQUIRED)
6+
find_package(torchtrt REQUIRED)
7+
8+
set(SRCS
9+
${CMAKE_SOURCE_DIR}/main.cpp
10+
${CMAKE_SOURCE_DIR}/../benchmark/benchmark.cpp
11+
${CMAKE_SOURCE_DIR}/../datasets/cifar10.cpp
12+
13+
)
14+
15+
add_executable(${CMAKE_PROJECT_NAME} ${SRCS})
16+
target_include_directories(${CMAKE_PROJECT_NAME} PRIVATE "${CMAKE_SOURCE_DIR}/../../..")
17+
target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE torch "-Wl,--no-as-needed" torchtrt "-Wl,--as-needed")
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
cmake_minimum_required(VERSION 3.17)
2+
project(torchtrt_runtime_example LANGUAGES CXX)
3+
4+
# Find dependencies
5+
find_package(Torch REQUIRED)
6+
find_package(torchtrt REQUIRED)
7+
8+
set(SRCS
9+
main.cpp
10+
)
11+
12+
add_executable(${CMAKE_PROJECT_NAME} ${SRCS})
13+
target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE torch "-Wl,--no-as-needed" torchtrt_runtime "-Wl,--as-needed")

0 commit comments

Comments
 (0)