diff --git a/CMakeLists.txt b/CMakeLists.txt index a574fe5..cbb2fb6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,10 +3,12 @@ project(tkDNN) set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake) set(CMAKE_CXX_STANDARD 14) +option(ENABLE_OPENCV_CUDA_CONTRIB "Enable OpenCV CUDA Contrib" OFF ) + find_package(CUDA 9.0 REQUIRED) if (CUDA_FOUND) - #Get CUDA compute capability 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} @@ -25,10 +27,7 @@ if (CUDA_FOUND) 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}") - add_definitions(-DGPU) #You may not require this - else() message(WARNING ${ARCH}) endif() @@ -51,7 +50,7 @@ endif() if(WIN32) if(CMAKE_BUILD_TYPE MATCHES Release) - set(CMAKE_CXX_FLAGS "/O2 /FS /EHsc /Md") + set(CMAKE_CXX_FLAGS "/O2 /FS /EHsc /MD") set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} --maxrregcount=32) endif() @@ -70,7 +69,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}") @@ -105,6 +104,13 @@ 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) + add_compile_definitions(OPENCV_CUDACONTRIB) + message("OpenCV Cuda Contrib modules found") + endif() +endif() # if(OpenCV_CUDA_VERSION) # add_compile_definitions(OPENCV_CUDACONTRIB) # endif() diff --git a/README.md b/README.md index b630fec..2aea96a 100644 --- a/README.md +++ b/README.md @@ -104,14 +104,15 @@ 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. ## 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 @@ -136,7 +137,7 @@ For specific details on how to run: ![demo](https://user-images.githubusercontent.com/11562617/72547657-540e7800-388d-11ea-83c6-49dfea2a0607.gif) -## tkDNN on Windows 10 (experimental) +## tkDNN on Windows 10/11 (experimental) For specific details on how to run tkDNN on Windows 10 see [HERE](./docs/windows.md). diff --git a/demo/demo/demo.cpp b/demo/demo/demo.cpp index c3afcda..967c996 100644 --- a/demo/demo/demo.cpp +++ b/demo/demo/demo.cpp @@ -45,16 +45,16 @@ int main(int argc, char *argv[]) { char ntype = 'y'; if(argc > 2) - ntype = argv[2][0]; - int n_classes = 80; + input = argv[2]; if(argc > 3) - n_classes = atoi(argv[3]); + ntype = argv[3][0]; + int n_classes = 80; if(argc > 4) - cfgPath = argv[4]; + n_classes = atoi(argv[4]); if(argc > 5) - namePath = argv[5]; + cfgPath = argv[5]; if(argc > 6) - input = argv[6]; + namePath = argv[6]; int n_batch = 1; if(argc > 7) n_batch = atoi(argv[7]); diff --git a/docs/demo.md b/docs/demo.md index cc93dd4..93f3691 100644 --- a/docs/demo.md +++ b/docs/demo.md @@ -26,27 +26,35 @@ rm yolo4_fp32.rt # be sure to delete(or move) old tensorRT files ``` If you get problems in the creation, try to check the error activating the debug of TensorRT in this way: ``` -cmake .. -DDEBUG=True +cmake .. -DCMAKE_BUILD_TYPE=Debug -DDEBUG=True make ``` -Once you have successfully created your rt file, run the demo: +Once you have successfully created your rt file, run the demo(yolo) : ``` -./demo yolo4_fp32.rt ../demo/yolo_test.mp4 y +./demo yolo4_fp32.rt ../demo/yolo_test.mp4 y 80 ../tests/darknet/cfg/yolo4.cfg ../tests/darknet/names/cococ.names ``` + +To run demo for mobilenet and centernet for the created rt file : +``` +./demo mobilenetv2ssd_fp32.rt m 20 +``` + In general the demo program takes 7 parameters: ``` -./demo +./demo ``` where -* `````` is the rt file generated by a test -* ```<``` is the path to a video file or a camera input -* `````` is the type of network. Thee types are currently supported: ```y``` (YOLO family), ```c``` (CenterNet family) and ```m``` (MobileNet-SSD family) -* ``````is the number of classes the network is trained on -* `````` number of batches to use in inference (N.B. you should first export TKDNN_BATCHSIZE to the required n_batches and create again the rt file for the network). -* `````` if set to 0 the demo will not show the visualization but save the video into result.mp4 (if n-batches ==1) -* `````` confidence threshold for the detector. Only bounding boxes with threshold greater than conf-thresh will be displayed. +* `````` is the rt file generated by a test +* ```<``` is the path to a video file or a camera input +* `````` is the type of network. Thee types are currently supported: ```y``` (YOLO family), ```c``` (CenterNet family) and ```m``` (MobileNet-SSD family) +* ``````is the number of classes the network is trained on +* ``` ```is the relative path to the config file (only for darknet based networks) used to train the network +* ``````is the relative path to the names file (only for darknet based networks) used to train the network +* `````` number of batches to use in inference (N.B. you should first export TKDNN_BATCHSIZE to the required n_batches and create again the rt file for the network). +* `````` if set to 0 the demo will not show the visualization but save the video into result.mp4 (if n-batches ==1) +* `````` confidence threshold for the detector. Only bounding boxes with threshold greater than conf-thresh will be displayed. N.B. By default it is used FP32 inference diff --git a/docs/windows.md b/docs/windows.md index 60813c5..7ea52b1 100644 --- a/docs/windows.md +++ b/docs/windows.md @@ -7,17 +7,18 @@ - [Run the demo on Windows](#run-the-demo-on-windows) - [FP16 inference windows](#fp16-inference-windows) - [INT8 inference windows](#int8-inference-windows) + - [Run tkDNN on WSL2 with cuda](#tkdnn-on-cuda-wsl) - [Known issues with tkDNN on Windows](#known-issues-with-tkdnn-on-windows) ### Dependencies-Windows This branch should work on every NVIDIA GPU supported in windows with the following dependencies: * WINDOWS 10 1803 or HIGHER -* CUDA 10.0 (Recommended CUDA 11.2 ) -* CUDNN 7.6 (Recommended CUDNN 8.1.1 ) -* TENSORRT 6.0.1 (Recommended TENSORRT 7.2.3.4 ) -* OPENCV 3.4 (Recommended OPENCV 4.2.0 ) -* MSVC 16.7 +* CUDA 11.2 +* CUDNN 8.1.1 +* TENSORRT 7.2.3 +* OPENCV 4.2 +* MSVC 16.9+ * YAML-CPP * EIGEN3 * 7ZIP (ADD TO PATH) @@ -58,7 +59,7 @@ To run the object detection file create .rt file bu running: Once the rt file has been successfully create,run the demo using the following command: ``` -.\demo.exe yolo4tiny_fp32.rt ..\demo\yolo_test.mp4 y +.\demo.exe yolo4_fp32.rt ..\demo\yolo_test.mp4 y 80 ..\tests\darknet\cfg\yolo4.cfg ..\tests\darknet\names\cococ.names ``` For general info on more demo paramters,check Run the demo section on top To run the test_all_tests.sh on windows,use git bash or msys2 @@ -85,11 +86,17 @@ del /f yolo4tiny_int8.rt # be sure to delete(or move) old tensorRT files ``` +### Run tkDNN on WSL2 with cuda +tkDNN works on wsl2 with cuda,although not all networks (centernet,mobilenet) work properly. +If you encounter issues with running the network as a result of driver not found or cuda launch error,running the following command should solve the issue +```cp /usr/lib/wsl/lib/lib* /usr/lib/x86_64-linux-gnu/ ``` + + + ### Known issues with tkDNN on Windows -Mobilenet and Centernet demos work properly only when built with msvc 16.7 in Release Mode,when built in debug mode for the mentioned networks one might encounter opencv assert errors +In theory all models (centernet,mobilenet,darknet,centertrack,cnet3d and shelfnet) should work on Windows. -All Darknet models work properly with demo using MSVC version(16.7-16.9) +On pascal cards(sm 6x) ,nvidia cuda wsl driver 510.06 don't work well with tkDNN both on windows and cuda wsl , Nvidia drivers >465+ and < 500 are completely supported . -It is recommended to use Nvidia Driver(465+),Cuda unknown errors have been observed when using older drivers on pascal(SM 61) devices. diff --git a/src/pluginsRT/DeformableConvRT.cpp b/src/pluginsRT/DeformableConvRT.cpp index 1c1df84..9b7222d 100644 --- a/src/pluginsRT/DeformableConvRT.cpp +++ b/src/pluginsRT/DeformableConvRT.cpp @@ -65,7 +65,6 @@ DeformableConvRT::~DeformableConvRT() { checkCuda( cudaFree(offset) ); checkCuda( cudaFree(mask) ); checkCuda( cudaFree(ones_d2) ); - cublasDestroy(handle); } DeformableConvRT::DeformableConvRT(const void *data, size_t length) { @@ -229,7 +228,9 @@ void DeformableConvRT::serialize(void *buffer) const NOEXCEPT { assert(buf == a + getSerializationSize()); } -void DeformableConvRT::destroy() NOEXCEPT { delete this; } +void DeformableConvRT::destroy() NOEXCEPT { + delete this; +} const char *DeformableConvRT::getPluginNamespace() const NOEXCEPT {