Back to home page

EIC code displayed by LXR

 
 

    


Warning, /acts/cmake/FindTensorRT.cmake is written in an unsupported language. File is not indexed.

0001 # ~~~
0002 # Copyright 2021 Olivier Le Doeuff
0003 # Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
0004 # The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
0005 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
0006 # This module defines the following variables:
0007 #
0008 # - TensorRT_FOUND: A boolean specifying whether or not TensorRT was found.
0009 # - TensorRT_VERSION: The exact version of TensorRT found
0010 # - TensorRT_VERSION_MAJOR: The major version of TensorRT.
0011 # - TensorRT_VERSION_MINOR: The minor version of TensorRT.
0012 # - TensorRT_VERSION_PATCH: The patch version of TensorRT.
0013 # - TensorRT_VERSION_TWEAK: The tweak version of TensorRT.
0014 # - TensorRT_INCLUDE_DIRS: The path to TensorRT ``include`` folder containing the header files    required to compile a project linking against TensorRT.
0015 # - TensorRT_LIBRARY_DIRS: The path to TensorRT library directory that contains libraries.
0016 #
0017 # This module create following targets:
0018 # - trt::nvinfer
0019 # - trt::nvinfer_plugin
0020 # - trt::nvonnxparser
0021 # - trt::nvparsers
0022 # This script was inspired from https://github.com/NicolasIRAGNE/CMakeScripts
0023 # This script was inspired from https://github.com/NVIDIA/tensorrt-laboratory/blob/master/cmake/FindTensorRT.cmake
0024 #
0025 # Hints
0026 # ^^^^^
0027 # A user may set ``TensorRT_ROOT`` to an installation root to tell this module where to look.
0028 # ~~~
0029 
0030 if(NOT TensorRT_FIND_COMPONENTS)
0031     set(TensorRT_FIND_COMPONENTS nvinfer nvinfer_plugin nvonnxparser nvparsers)
0032 endif()
0033 set(TensorRT_LIBRARIES)
0034 
0035 # find the include directory of TensorRT
0036 find_path(
0037     TensorRT_INCLUDE_DIR
0038     NAMES NvInfer.h
0039     PATHS ${TensorRT_ROOT}
0040     ENV TensorRT_ROOT
0041     PATH_SUFFIXES include
0042 )
0043 
0044 string(FIND ${TensorRT_INCLUDE_DIR} "NOTFOUND" _include_dir_notfound)
0045 if(NOT _include_dir_notfound EQUAL -1)
0046     if(TensorRT_FIND_REQUIRED)
0047         message(
0048             FATAL_ERROR
0049             "Fail to find TensorRT, please set TensorRT_ROOT. Include path not found."
0050         )
0051     endif()
0052     return()
0053 endif()
0054 set(TensorRT_INCLUDE_DIRS ${TensorRT_INCLUDE_DIR})
0055 
0056 # Extract version of tensorrt
0057 if(EXISTS "${TensorRT_INCLUDE_DIR}/NvInferVersion.h")
0058     file(
0059         STRINGS
0060         "${TensorRT_INCLUDE_DIR}/NvInferVersion.h"
0061         TensorRT_MAJOR
0062         REGEX "^#define NV_TENSORRT_MAJOR [0-9]+.*$"
0063     )
0064     file(
0065         STRINGS
0066         "${TensorRT_INCLUDE_DIR}/NvInferVersion.h"
0067         TensorRT_MINOR
0068         REGEX "^#define NV_TENSORRT_MINOR [0-9]+.*$"
0069     )
0070     file(
0071         STRINGS
0072         "${TensorRT_INCLUDE_DIR}/NvInferVersion.h"
0073         TensorRT_PATCH
0074         REGEX "^#define NV_TENSORRT_PATCH [0-9]+.*$"
0075     )
0076     file(
0077         STRINGS
0078         "${TensorRT_INCLUDE_DIR}/NvInferVersion.h"
0079         TensorRT_TWEAK
0080         REGEX "^#define NV_TENSORRT_BUILD [0-9]+.*$"
0081     )
0082 
0083     string(
0084         REGEX REPLACE
0085         "^#define NV_TENSORRT_MAJOR ([0-9]+).*$"
0086         "\\1"
0087         TensorRT_VERSION_MAJOR
0088         "${TensorRT_MAJOR}"
0089     )
0090     string(
0091         REGEX REPLACE
0092         "^#define NV_TENSORRT_MINOR ([0-9]+).*$"
0093         "\\1"
0094         TensorRT_VERSION_MINOR
0095         "${TensorRT_MINOR}"
0096     )
0097     string(
0098         REGEX REPLACE
0099         "^#define NV_TENSORRT_PATCH ([0-9]+).*$"
0100         "\\1"
0101         TensorRT_VERSION_PATCH
0102         "${TensorRT_PATCH}"
0103     )
0104     string(
0105         REGEX REPLACE
0106         "^#define NV_TENSORRT_BUILD ([0-9]+).*$"
0107         "\\1"
0108         TensorRT_VERSION_TWEAK
0109         "${TensorRT_TWEAK}"
0110     )
0111     set(TensorRT_VERSION
0112         "${TensorRT_VERSION_MAJOR}.${TensorRT_VERSION_MINOR}.${TensorRT_VERSION_PATCH}.${TensorRT_VERSION_TWEAK}"
0113     )
0114 endif()
0115 
0116 function(_find_trt_component component)
0117     # Find library for component (ie nvinfer, nvparsers, etc...)
0118     find_library(
0119         TensorRT_${component}_LIBRARY
0120         NAMES ${component}
0121         PATHS ${TensorRT_ROOT} ${TENSORRT_LIBRARY_DIR}
0122         ENV TensorRT_ROOT
0123     )
0124 
0125     string(FIND ${TensorRT_${component}_LIBRARY} "NOTFOUND" _library_not_found)
0126 
0127     if(NOT TensorRT_LIBRARY_DIR)
0128         get_filename_component(_path ${TensorRT_${component}_LIBRARY} DIRECTORY)
0129         set(TensorRT_LIBRARY_DIR
0130             "${_path}"
0131             CACHE INTERNAL
0132             "TensorRT_LIBRARY_DIR"
0133         )
0134     endif()
0135 
0136     if(NOT TensorRT_LIBRARY_DIRS)
0137         get_filename_component(_path ${TensorRT_${component}_LIBRARY} DIRECTORY)
0138         set(TensorRT_LIBRARY_DIRS
0139             "${_path}"
0140             CACHE INTERNAL
0141             "TensorRT_LIBRARY_DIRS"
0142         )
0143     endif()
0144 
0145     # Library found, and doesn't already exists
0146     if(_library_not_found EQUAL -1 AND NOT TARGET trt::${component})
0147         set(TensorRT_${component}_FOUND
0148             TRUE
0149             CACHE INTERNAL
0150             "Found ${component}"
0151         )
0152 
0153         # Create a target
0154         add_library(trt::${component} IMPORTED INTERFACE)
0155         target_include_directories(
0156             trt::${component}
0157             SYSTEM
0158             INTERFACE "${TensorRT_INCLUDE_DIRS}"
0159         )
0160         target_link_libraries(
0161             trt::${component}
0162             INTERFACE "${TensorRT_${component}_LIBRARY}"
0163         )
0164         set(TensorRT_LIBRARIES
0165             ${TensorRT_LIBRARIES}
0166             ${TensorRT_${component}_LIBRARY}
0167         )
0168     endif()
0169 endfunction()
0170 
0171 # Find each components
0172 foreach(component IN LISTS TensorRT_FIND_COMPONENTS)
0173     _find_trt_component(${component})
0174 endforeach()
0175 
0176 include(FindPackageHandleStandardArgs)
0177 find_package_handle_standard_args(
0178     TensorRT
0179     HANDLE_COMPONENTS
0180     VERSION_VAR TensorRT_VERSION
0181     REQUIRED_VARS TensorRT_INCLUDE_DIR
0182 )