diff --git a/.gitignore b/.gitignore index c1d362c..22f7f94 100644 --- a/.gitignore +++ b/.gitignore @@ -19,4 +19,6 @@ demo/BDD100K_val cmake-build-minsizerel/* scripts/COCO_val2017/* scripts/COCO_val2017.zip -scripts/all_labels.txt \ No newline at end of file +scripts/all_labels.txt +/cmake/cuda_script +/cmake-build-debug/ diff --git a/CMakeLists.txt b/CMakeLists.txt index b163a9d..7cc9e33 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,15 +1,65 @@ cmake_minimum_required(VERSION 3.15) - -project (tkDNN) +project(tkDNN) set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake) -if(UNIX) -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 -fPIC -Wno-unused-variable ") -endif() -if(WIN32) set(CMAKE_CXX_STANDARD 14) -set(CMAKE_CXX_FLAGS "/O2 /FS /EHsc") + +option(ENABLE_OPENCV_CUDA_CONTRIB "Enable OpenCV CUDA Contrib" OFF ) + +find_package(CUDA 9.0 REQUIRED) +if (CUDA_FOUND) + set(OUTPUTFILE ${CMAKE_CURRENT_SOURCE_DIR}/cmake/cuda_script) # No suffix required + execute_process(COMMAND "rm ${OUTPUTFILE}") + set(CUDAFILE ${CMAKE_CURRENT_SOURCE_DIR}/cmake/getCudaArch.cu) + execute_process(COMMAND ${CUDA_NVCC_EXECUTABLE} -lcuda ${CUDAFILE} -o ${OUTPUTFILE}) + execute_process(COMMAND ${OUTPUTFILE} + RESULT_VARIABLE CUDA_RETURN_CODE + OUTPUT_VARIABLE ARCH) + + if(${CUDA_RETURN_CODE} EQUAL 0) + set(CUDA_SUCCESS "TRUE") + else() + set(CUDA_SUCCESS "FALSE") + endif() + + if (${CUDA_SUCCESS}) + message(STATUS "CUDA Architecture: ${ARCH}") + message(STATUS "CUDA Version: ${CUDA_VERSION_STRING}") + message(STATUS "CUDA Path: ${CUDA_TOOLKIT_ROOT_DIR}") + message(STATUS "CUDA Libararies: ${CUDA_LIBRARIES}") + message(STATUS "CUDA Performance Primitives: ${CUDA_npp_LIBRARY}") + set(CUDA_NVCC_FLAGS "${ARCH}") + else() + message(WARNING ${ARCH}) + endif() +endif() + +SET(CUDA_SEPARABLE_COMPILATION ON) + +if(UNIX) + if(CMAKE_BUILD_TYPE MATCHES Release) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -Wno-deprecated-declarations -Wno-unused-variable -O3") + set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} --maxrregcount=32) + endif() + + if(CMAKE_BUILD_TYPE MATCHES Debug) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -Wno-deprecated-declarations -Wno-unused-variable -g3") + set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} --maxrregcount=32 -G -g) + endif() +endif() + +if(WIN32) + if(CMAKE_BUILD_TYPE MATCHES Release) + set(CMAKE_CXX_FLAGS "/O2 /FS /EHsc /MD") + set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} --maxrregcount=32) + endif() + + if(CMAKE_BUILD_TYPE MATCHES Debug) + set(CMAKE_CXX_FLAGS "/Od /FS /EHsc /MDd") + set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} --maxrregcount=32 -G -g) + endif() set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON) endif(WIN32) + include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include/tkDNN) # project specific flags @@ -18,7 +68,7 @@ if(DEBUG) endif() if(TKDNN_PATH) - message("SET TKDNN_PATH:"${TKDNN_PATH}) + message("SET TKDNN_PATH:" ${TKDNN_PATH}) add_definitions(-DTKDNN_PATH="${TKDNN_PATH}") else() add_definitions(-DTKDNN_PATH="${CMAKE_CURRENT_SOURCE_DIR}") @@ -28,20 +78,20 @@ endif() #------------------------------------------------------------------------------- # CUDA #------------------------------------------------------------------------------- -find_package(CUDA 9.0 REQUIRED) -SET(CUDA_SEPARABLE_COMPILATION ON) + #set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS} -arch=sm_30 --compiler-options '-fPIC'") -set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} --maxrregcount=32) + find_package(CUDNN REQUIRED) include_directories(${CUDNN_INCLUDE_DIR}) # compile -file(GLOB tkdnn_CUSRC "src/kernels/*.cu" "src/sorting.cu") +file(GLOB tkdnn_CUSRC "src/kernels/*.cu" "src/sorting.cu" "src/pluginsRT/*.cpp") cuda_include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include ${CUDA_INCLUDE_DIRS} ${CUDNN_INCLUDE_DIRS}) cuda_add_library(kernels SHARED ${tkdnn_CUSRC}) -target_link_libraries(kernels ${CUDA_CUBLAS_LIBRARIES}) +target_link_libraries(kernels ${CUDA_CUBLAS_LIBRARIES} ${CUDA_LIBRARIES} ${CUDNN_LIBRARIES}) + #------------------------------------------------------------------------------- @@ -53,6 +103,21 @@ include_directories(${EIGEN3_INCLUDE_DIR}) find_package(OpenCV REQUIRED) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DOPENCV") +if(ENABLE_OPENCV_CUDA_CONTRIB) + if (OpenCV_FOUND) + find_package(OpenCV COMPONENTS cudawarping cudaarithm) + if(OpenCV_cudawarping_FOUND AND OpenCV_cudaarithm_FOUND) + add_compile_definitions(OPENCV_CUDACONTRIB) + message("OpenCV Cuda Contrib modules found") + else() + message("OpenCV Cuda Contrib modules not found") + set(ENABLE_OPENCV_CUDA_CONTRIB OFF) + endif() + endif() +endif() +# if(OpenCV_CUDA_VERSION) +# add_compile_definitions(OPENCV_CUDACONTRIB) +# endif() # gives problems in cross-compiling, probably malformed cmake config find_package(yaml-cpp REQUIRED) @@ -66,7 +131,7 @@ set(tkdnn_LIBS kernels ${CUDA_LIBRARIES} ${CUDA_CUBLAS_LIBRARIES} ${CUDNN_LIBRAR set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include ${CUDA_INCLUDE_DIRS} ${OPENCV_INCLUDE_DIRS} ${NVINFER_INCLUDES}) add_library(tkDNN SHARED ${tkdnn_SRC}) -target_link_libraries(tkDNN ${tkdnn_LIBS}) +target_link_libraries(tkDNN ${tkdnn_LIBS} ${CUDA_CUBLAS_LIBRARIES}) #static #add_library(tkDNN_static STATIC ${tkdnn_SRC}) @@ -119,6 +184,24 @@ target_link_libraries(test_resnet101_cnet tkDNN) add_executable(test_dla34_cnet tests/centernet/dla34_cnet/dla34_cnet.cpp) target_link_libraries(test_dla34_cnet tkDNN) +add_executable(test_dla34_cnet3d tests/centernet/dla34_cnet3d/dla34_cnet3d.cpp) +target_link_libraries(test_dla34_cnet3d tkDNN) + +# CENTERTRACK + +add_executable(test_dla34_ctrack tests/centertrack/dla34_ctrack/dla34_ctrack.cpp) +target_link_libraries(test_dla34_ctrack tkDNN) + +# SHELFNET +add_executable(test_shelfnet tests/shelfnet/shelfnet.cpp) +target_link_libraries(test_shelfnet tkDNN) + +add_executable(test_shelfnet_berkeley tests/shelfnet/shelfnet_berkeley.cpp) +target_link_libraries(test_shelfnet_berkeley tkDNN) + +add_executable(test_shelfnet_mapillary tests/shelfnet/shelfnet_mapillary.cpp) +target_link_libraries(test_shelfnet_mapillary tkDNN) + # DEMOS add_executable(test_rtinference tests/test_rtinference/rtinference.cpp) target_link_libraries(test_rtinference tkDNN) @@ -129,6 +212,15 @@ target_link_libraries(map_demo tkDNN) add_executable(demo demo/demo/demo.cpp) target_link_libraries(demo tkDNN) +add_executable(demo3D demo/demo/demo3D.cpp) +target_link_libraries(demo3D tkDNN) + +add_executable(demoTracker demo/demo/demoTracker.cpp) +target_link_libraries(demoTracker tkDNN) + +add_executable(seg_demo demo/demo/seg_demo.cpp) +target_link_libraries(seg_demo tkDNN) + #------------------------------------------------------------------------------- # Install #------------------------------------------------------------------------------- @@ -138,7 +230,7 @@ target_link_libraries(demo tkDNN) #endif() message("install dir:" ${CMAKE_INSTALL_PREFIX}) install(DIRECTORY include/ DESTINATION include/) -install(TARGETS tkDNN kernels DESTINATION lib) +install(TARGETS tkDNN DESTINATION lib) install(TARGETS test_simple test_mnist test_mnistRT test_rtinference demo map_demo DESTINATION bin) install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/cmake/" # source directory DESTINATION "share/tkDNN/cmake/" # target directory diff --git a/Issues.md b/Issues.md deleted file mode 100644 index 4875b13..0000000 --- a/Issues.md +++ /dev/null @@ -1 +0,0 @@ -1)error C2131 @ Yolo3Detection.cpp(97) -> expression doesnt evaluate to a constant caused to read of variable outside its lifetime \ No newline at end of file diff --git a/README.md b/README.md index 2325eb5..d07ac42 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,10 @@ If you use tkDNN in your research, please cite the [following paper](https://iee } ``` +### What's new (November 2021) +- [x] Support to sematic segmentation on cuda 11+ [README](docs/README_seg.md) +- [x] Support to TensorRT8 + ## FPS Results Inference FPS of yolov4 with tkDNN, average of 1200 images with the same dimension as the input size, on * RTX 2080Ti (CUDA 10.2, TensorRT 7.0.0, Cudnn 7.6.5); @@ -66,56 +70,49 @@ Results for COCO val 2017 (5k images), on RTX 2080Ti, with conf threshold=0.001 - [tkDNN](#tkdnn) - [Index](#index) - [Dependencies](#dependencies) - - [About OpenCV](#about-opencv) - [How to compile this repo](#how-to-compile-this-repo) - [Workflow](#workflow) - - [How to export weights](#how-to-export-weights) - - [1)Export weights from darknet](#1export-weights-from-darknet) - - [2)Export weights for DLA34 and ResNet101](#2export-weights-for-dla34-and-resnet101) - - [3)Export weights for CenterNet](#3export-weights-for-centernet) - - [4)Export weights for MobileNetSSD](#4export-weights-for-mobilenetssd) - - [Run the demo](#run-the-demo) - - [FP16 inference](#fp16-inference) - - [INT8 inference](#int8-inference) - - [mAP demo](#map-demo) + - [Exporting weights](#exporting-weights) + - [Run the demos](#run-the-demos) + - [tkDNN on Windows 10 or Windows 11](#tkdnn-on-windows-10-or-windows-11) - [Existing tests and supported networks](#existing-tests-and-supported-networks) - [References](#references) - - [tkDNN on Windows 10 (experimental)](#tkdnn-on-windows-10-experimental) - - [Dependencies-Windows](#dependencies-windows) - - [Compiling tkDNN on Windows](#compiling-tkdnn-on-windows) - - [Run the demo on Windows](#run-the-demo-on-windows) - - [FP16 inference windows](#fp16-inference-windows) - - [INT8 inference windows](#int8-inference-windows) - - [Known issues with tkDNN on Windows](#known-issues-with-tkdnn-on-windows) - - - ## Dependencies -This branch works on every NVIDIA GPU that supports the dependencies: -* CUDA 10.0 -* CUDNN 7.603 -* TENSORRT 6.01 -* OPENCV 3.4 -* yaml-cpp 0.5.2 (sudo apt install libyaml-cpp-dev) +This branch works on every NVIDIA GPU that supports the following (latest tested) dependencies: +* CUDA 11.3 (or >= 10.2) [the segmentation only works with CUDA 10 for now] +* cuDNN 8.2.1 (or >= 8.0.4) +* TensorRT 8.0.3 (or >=7.2) +* OpenCV 4.5.4 (or >=4) +* cmake 3.21 (or >= 3.15) +* yaml-cpp 0.5.2 +* eigen3 3.3.4 +* curl 7.58 -## About OpenCV +``` +sudo apt install libyaml-cpp-dev curl libeigen3-dev + +``` + +#### About OpenCV To compile and install OpenCV4 with contrib us the script ```install_OpenCV4.sh```. It will download and compile OpenCV in Download folder. ``` bash scripts/install_OpenCV4.sh ``` -When using openCV not compiled with contrib, comment the definition of OPENCV_CUDACONTRIBCONTRIB in include/tkDNN/DetectionNN.h. When commented, the preprocessing of the networks is computed on the CPU, otherwise on the GPU. In the latter case some milliseconds are saved in the end-to-end latency. +If you have OpenCV compiled with cuda and contrib and want to use it with tkDNN pass ```ENABLE_OPENCV_CUDA_CONTRIB=ON``` flag when compiling tkDBB +. If the flag is not passed,the preprocessing of the networks is computed on the CPU, otherwise on the GPU. In the latter case some milliseconds are saved in the end-to-end latency. ## How to compile this repo -Build with cmake. If using Ubuntu 18.04 a new version of cmake is needed (3.15 or above). +Build with cmake. If using Ubuntu 18.04 a new version of cmake is needed (3.15 or above). +On both linux and windows ,the ```CMAKE_BUILD_TYPE``` variable needs to be defined as either ```Release``` or ```Debug```. ``` git clone https://github.com/ceccocats/tkDNN cd tkDNN mkdir build cd build -cmake .. -make +cmake -DCMAKE_BUILD_TYPE=Release -G"Ninja" .. +ninja ``` ## Workflow @@ -126,214 +123,23 @@ Steps needed to do inference on tkDNN with a custom neural network. * Create a new test and define the network, layer by layer using the weights extracted and the output to check the results. * Do inference. -## How to export weights +## Exporting weights -Weights are essential for any network to run inference. For each test a folder organized as follow is needed (in the build folder): -``` - test_nn - |---- layers/ (folder containing a binary file for each layer with the corresponding wieghts and bias) - |---- debug/ (folder containing a binary file for each layer with the corresponding outputs) -``` -Therefore, once the weights have been exported, the folders layers and debug should be placed in the corresponding test. +For specific details on how to export weights see [HERE](./docs/exporting_weights.md). -### 1)Export weights from darknet -To export weights for NNs that are defined in darknet framework, use [this](https://git.hipert.unimore.it/fgatti/darknet.git) fork of darknet and follow these steps to obtain a correct debug and layers folder, ready for tkDNN. - -``` -git clone https://git.hipert.unimore.it/fgatti/darknet.git -cd darknet -make -mkdir layers debug -./darknet export layers -``` -N.b. Use compilation with CPU (leave GPU=0 in Makefile) if you also want debug. - -### 2)Export weights for DLA34 and ResNet101 -To get weights and outputs needed to run the tests dla34 and resnet101 use the Python script and the Anaconda environment included in the repository. - -Create Anaconda environment and activate it: -``` -conda env create -f file_name.yml -source activate env_name -python