diff --git a/cpp/drafts/CMakeLists.txt b/cpp/drafts/CMakeLists.txt index 149b1755f..08226d969 100644 --- a/cpp/drafts/CMakeLists.txt +++ b/cpp/drafts/CMakeLists.txt @@ -13,7 +13,6 @@ add_subdirectory(ChessboardDetection) add_subdirectory(Calibration) add_subdirectory(Compute) add_subdirectory(MatchPropagation) -add_subdirectory(NeuralNetworks) add_subdirectory(NuScenes) add_subdirectory(Taskflow) diff --git a/cpp/drafts/NeuralNetworks/CMakeLists.txt b/cpp/drafts/NeuralNetworks/CMakeLists.txt deleted file mode 100644 index 8c5587e96..000000000 --- a/cpp/drafts/NeuralNetworks/CMakeLists.txt +++ /dev/null @@ -1,2 +0,0 @@ -add_subdirectory(Darknet) -add_subdirectory(TensorRT) diff --git a/cpp/drafts/NeuralNetworks/Darknet/CMakeLists.txt b/cpp/drafts/NeuralNetworks/Darknet/CMakeLists.txt deleted file mode 100644 index b17fcaa44..000000000 --- a/cpp/drafts/NeuralNetworks/Darknet/CMakeLists.txt +++ /dev/null @@ -1,12 +0,0 @@ -file(GLOB DO_Sara_Darknet_SOURCE_FILES FILES *.hpp *.cpp) - -add_library(DO_Sara_Darknet ${DO_Sara_Darknet_SOURCE_FILES}) -add_library(DO::Sara::Darknet ALIAS DO_Sara_Darknet) - -target_link_libraries(DO_Sara_Darknet PUBLIC DO::Sara::Core - DO::Sara::ImageProcessing - Boost::filesystem) -set_property(TARGET DO_Sara_Darknet PROPERTY FOLDER "Libraries/Sara") - -add_subdirectory(test) -add_subdirectory(examples) diff --git a/cpp/drafts/NeuralNetworks/TensorRT/CMakeLists.txt b/cpp/drafts/NeuralNetworks/TensorRT/CMakeLists.txt deleted file mode 100644 index 97616cc83..000000000 --- a/cpp/drafts/NeuralNetworks/TensorRT/CMakeLists.txt +++ /dev/null @@ -1,37 +0,0 @@ -if(NOT CMAKE_CUDA_COMPILER OR NOT TensorRT_FOUND) - return() -endif () - -add_library( - DO_Sara_TensorRT # - Helpers.hpp # - IO.hpp # - IO.cpp # - InferenceExecutor.hpp # - InferenceExecutor.cpp # - DarknetParser.hpp # - DarknetParser.cpp # - Yolo.cpp - Yolo.hpp - YoloImpl.hpp - YoloImpl.cu) -add_library(DO::Sara::TensorRT ALIAS DO_Sara_TensorRT) -if (SARA_BUILD_SHARED_LIBS) - target_compile_definitions(DO_Sara_TensorRT PRIVATE DO_SARA_EXPORTS) -else () - target_compile_definitions(DO_Sara_TensorRT PUBLIC DO_SARA_STATIC) -endif () - -target_link_libraries( - DO_Sara_TensorRT - PUBLIC $<$:CUDA::cudart> # - TensorRT::TensorRT # - DO::Shakti::Cuda::Utilities - DO::Sara::Darknet) -set_property(TARGET DO_Sara_TensorRT PROPERTY FOLDER "Libraries/Sara") - -add_subdirectory(examples) - -if(SARA_BUILD_TESTS) - add_subdirectory(test) -endif() diff --git a/cpp/examples/Sara/CMakeLists.txt b/cpp/examples/Sara/CMakeLists.txt index d2a8d5929..dd71f81b5 100644 --- a/cpp/examples/Sara/CMakeLists.txt +++ b/cpp/examples/Sara/CMakeLists.txt @@ -12,3 +12,5 @@ add_subdirectory(MultiViewGeometry) if (SARA_BUILD_VIDEOIO) add_subdirectory(VideoIO) endif () + +add_subdirectory(NeuralNetworks) diff --git a/cpp/drafts/NeuralNetworks/Darknet/examples/CMakeLists.txt b/cpp/examples/Sara/NeuralNetworks/CMakeLists.txt similarity index 96% rename from cpp/drafts/NeuralNetworks/Darknet/examples/CMakeLists.txt rename to cpp/examples/Sara/NeuralNetworks/CMakeLists.txt index 746e222a1..eb658ae7c 100644 --- a/cpp/drafts/NeuralNetworks/Darknet/examples/CMakeLists.txt +++ b/cpp/examples/Sara/NeuralNetworks/CMakeLists.txt @@ -13,7 +13,6 @@ foreach (file ${neuralnetworks_SOURCE_FILES}) DO::Sara::ImageIO DO::Sara::VideoIO DO::Sara::Darknet - Boost::filesystem $<$:OpenMP::OpenMP_CXX>) set_target_properties(${filename} PROPERTIES diff --git a/cpp/drafts/NeuralNetworks/Darknet/examples/yolo_v4_example.cpp b/cpp/examples/Sara/NeuralNetworks/yolo_v4_example.cpp similarity index 95% rename from cpp/drafts/NeuralNetworks/Darknet/examples/yolo_v4_example.cpp rename to cpp/examples/Sara/NeuralNetworks/yolo_v4_example.cpp index 3f6563b99..e98b4d3a9 100644 --- a/cpp/drafts/NeuralNetworks/Darknet/examples/yolo_v4_example.cpp +++ b/cpp/examples/Sara/NeuralNetworks/yolo_v4_example.cpp @@ -9,29 +9,31 @@ // you can obtain one at http://mozilla.org/MPL/2.0/. // ========================================================================== // -#include -#include -#include - #include #include + +#include + #include #include -#include #include -#include +#include +#include +#include + +#include #include #ifdef _OPENMP -#include +# include #endif namespace sara = DO::Sara; namespace d = DO::Sara::Darknet; -namespace fs = boost::filesystem; +namespace fs = std::filesystem; // The API. diff --git a/cpp/examples/Shakti/CMakeLists.txt b/cpp/examples/Shakti/CMakeLists.txt index 15423754d..c84ed6a0e 100644 --- a/cpp/examples/Shakti/CMakeLists.txt +++ b/cpp/examples/Shakti/CMakeLists.txt @@ -15,3 +15,5 @@ endif() add_subdirectory(OpenCL) add_subdirectory(Vulkan) + +add_subdirectory(TensorRT) diff --git a/cpp/drafts/NeuralNetworks/TensorRT/examples/CMakeLists.txt b/cpp/examples/Shakti/TensorRT/CMakeLists.txt similarity index 91% rename from cpp/drafts/NeuralNetworks/TensorRT/examples/CMakeLists.txt rename to cpp/examples/Shakti/TensorRT/CMakeLists.txt index 695e5f524..b59ba19b5 100644 --- a/cpp/drafts/NeuralNetworks/TensorRT/examples/CMakeLists.txt +++ b/cpp/examples/Shakti/TensorRT/CMakeLists.txt @@ -16,9 +16,9 @@ foreach(file ${TRT_SOURCE_FILES}) DO::Sara::VideoIO DO::Sara::ImageProcessing DO::Sara::Darknet - DO::Sara::TensorRT DO::Shakti::Cuda::MultiArray - DO::Shakti::Cuda::Utilities) + DO::Shakti::Cuda::Utilities + DO::Shakti::Cuda::TensorRT) set_target_properties( ${filename} PROPERTIES COMPILE_FLAGS ${SARA_DEFINITIONS} diff --git a/cpp/drafts/NeuralNetworks/TensorRT/examples/tensorrt_yolov4_tiny_example.cpp b/cpp/examples/Shakti/TensorRT/tensorrt_yolov4_tiny_example.cpp similarity index 95% rename from cpp/drafts/NeuralNetworks/TensorRT/examples/tensorrt_yolov4_tiny_example.cpp rename to cpp/examples/Shakti/TensorRT/tensorrt_yolov4_tiny_example.cpp index 691f9b357..d6a102460 100644 --- a/cpp/drafts/NeuralNetworks/TensorRT/examples/tensorrt_yolov4_tiny_example.cpp +++ b/cpp/examples/Shakti/TensorRT/tensorrt_yolov4_tiny_example.cpp @@ -9,20 +9,20 @@ // you can obtain one at http://mozilla.org/MPL/2.0/. // ========================================================================== // -#include -#include -#include +#include +#include #include #include #include +#include #include -#include +#include namespace sara = DO::Sara; -namespace fs = boost::filesystem; +namespace fs = std::filesystem; namespace trt = sara::TensorRT; namespace d = sara::Darknet; diff --git a/cpp/src/DO/Sara/CMakeLists.txt b/cpp/src/DO/Sara/CMakeLists.txt index e4a3a3b65..9011f2cad 100644 --- a/cpp/src/DO/Sara/CMakeLists.txt +++ b/cpp/src/DO/Sara/CMakeLists.txt @@ -31,3 +31,5 @@ include(UseDOSaraMultiViewGeometry) include(UseDOSaraRANSAC) include(UseDOSaraVisualization) + +add_subdirectory(NeuralNetworks) diff --git a/cpp/src/DO/Sara/NeuralNetworks/CMakeLists.txt b/cpp/src/DO/Sara/NeuralNetworks/CMakeLists.txt new file mode 100644 index 000000000..94836c4e0 --- /dev/null +++ b/cpp/src/DO/Sara/NeuralNetworks/CMakeLists.txt @@ -0,0 +1 @@ +add_subdirectory(Darknet) diff --git a/cpp/src/DO/Sara/NeuralNetworks/Darknet/CMakeLists.txt b/cpp/src/DO/Sara/NeuralNetworks/Darknet/CMakeLists.txt new file mode 100644 index 000000000..5f71f0fa9 --- /dev/null +++ b/cpp/src/DO/Sara/NeuralNetworks/Darknet/CMakeLists.txt @@ -0,0 +1,10 @@ +file(GLOB DO_Sara_Darknet_SOURCE_FILES FILES *.hpp *.cpp) + +add_library(DO_Sara_Darknet ${DO_Sara_Darknet_SOURCE_FILES}) +add_library(DO::Sara::Darknet ALIAS DO_Sara_Darknet) + +target_link_libraries( + DO_Sara_Darknet + PUBLIC DO::Sara::Core DO::Sara::ImageProcessing + PRIVATE Boost::filesystem) +set_property(TARGET DO_Sara_Darknet PROPERTY FOLDER "Libraries/Sara") diff --git a/cpp/drafts/NeuralNetworks/Darknet/Debug.hpp b/cpp/src/DO/Sara/NeuralNetworks/Darknet/Debug.hpp similarity index 97% rename from cpp/drafts/NeuralNetworks/Darknet/Debug.hpp rename to cpp/src/DO/Sara/NeuralNetworks/Darknet/Debug.hpp index f6d61ff0d..97a35548c 100644 --- a/cpp/drafts/NeuralNetworks/Darknet/Debug.hpp +++ b/cpp/src/DO/Sara/NeuralNetworks/Darknet/Debug.hpp @@ -11,13 +11,11 @@ #pragma once -#include - #include #include +#include -#include - +#include #include @@ -45,7 +43,7 @@ namespace DO::Sara::Darknet { // CAVEAT: this is sensitive to the CPU architecture endianness. inline auto read_all_intermediate_outputs(const std::string& dir_path) { - namespace fs = boost::filesystem; + namespace fs = std::filesystem; auto stringify = [](int n) { std::ostringstream ss; @@ -169,7 +167,7 @@ namespace DO::Sara::Darknet { inline auto check_yolov4_tiny_implementation(Network& model, const std::string& output_dir) { - namespace fs = boost::filesystem; + namespace fs = std::filesystem; if (!fs::exists(output_dir)) throw std::runtime_error{"Ouput directory " + output_dir + diff --git a/cpp/drafts/NeuralNetworks/Darknet/Layer.cpp b/cpp/src/DO/Sara/NeuralNetworks/Darknet/Layer.cpp similarity index 99% rename from cpp/drafts/NeuralNetworks/Darknet/Layer.cpp rename to cpp/src/DO/Sara/NeuralNetworks/Darknet/Layer.cpp index b042afaa0..4f48fb9a5 100644 --- a/cpp/drafts/NeuralNetworks/Darknet/Layer.cpp +++ b/cpp/src/DO/Sara/NeuralNetworks/Darknet/Layer.cpp @@ -9,7 +9,9 @@ // you can obtain one at http://mozilla.org/MPL/2.0/. // ========================================================================== // -#include +#include + +#include using namespace DO::Sara::Darknet; diff --git a/cpp/drafts/NeuralNetworks/Darknet/Layer.hpp b/cpp/src/DO/Sara/NeuralNetworks/Darknet/Layer.hpp similarity index 99% rename from cpp/drafts/NeuralNetworks/Darknet/Layer.hpp rename to cpp/src/DO/Sara/NeuralNetworks/Darknet/Layer.hpp index 387b90cfb..f75752007 100644 --- a/cpp/drafts/NeuralNetworks/Darknet/Layer.hpp +++ b/cpp/src/DO/Sara/NeuralNetworks/Darknet/Layer.hpp @@ -14,7 +14,7 @@ #include #include -#include +#include namespace DO::Sara::Darknet { diff --git a/cpp/drafts/NeuralNetworks/Darknet/Network.hpp b/cpp/src/DO/Sara/NeuralNetworks/Darknet/Network.hpp similarity index 98% rename from cpp/drafts/NeuralNetworks/Darknet/Network.hpp rename to cpp/src/DO/Sara/NeuralNetworks/Darknet/Network.hpp index 782bcb2c9..8b4300a93 100644 --- a/cpp/drafts/NeuralNetworks/Darknet/Network.hpp +++ b/cpp/src/DO/Sara/NeuralNetworks/Darknet/Network.hpp @@ -13,10 +13,8 @@ #include #include - #include - -#include +#include #include diff --git a/cpp/drafts/NeuralNetworks/Darknet/Parser.cpp b/cpp/src/DO/Sara/NeuralNetworks/Darknet/Parser.cpp similarity index 97% rename from cpp/drafts/NeuralNetworks/Darknet/Parser.cpp rename to cpp/src/DO/Sara/NeuralNetworks/Darknet/Parser.cpp index 7d2f201f0..c902bde8f 100644 --- a/cpp/drafts/NeuralNetworks/Darknet/Parser.cpp +++ b/cpp/src/DO/Sara/NeuralNetworks/Darknet/Parser.cpp @@ -9,7 +9,9 @@ // you can obtain one at http://mozilla.org/MPL/2.0/. // ========================================================================== // -#include +#include + +#include #include @@ -206,7 +208,7 @@ namespace DO::Sara::Darknet { } - auto load_yolov4_tiny_model(const boost::filesystem::path& model_dir_path) + auto load_yolov4_tiny_model(const std::filesystem::path& model_dir_path) -> Network { const auto cfg_filepath = model_dir_path / "yolov4-tiny.cfg"; diff --git a/cpp/drafts/NeuralNetworks/Darknet/Parser.hpp b/cpp/src/DO/Sara/NeuralNetworks/Darknet/Parser.hpp similarity index 89% rename from cpp/drafts/NeuralNetworks/Darknet/Parser.hpp rename to cpp/src/DO/Sara/NeuralNetworks/Darknet/Parser.hpp index 9ffb1d97d..98c04a4a1 100644 --- a/cpp/drafts/NeuralNetworks/Darknet/Parser.hpp +++ b/cpp/src/DO/Sara/NeuralNetworks/Darknet/Parser.hpp @@ -11,10 +11,10 @@ #pragma once -#include -#include +#include +#include -#include +#include namespace DO::Sara::Darknet { @@ -66,7 +66,7 @@ namespace DO::Sara::Darknet { }; - auto load_yolov4_tiny_model(const boost::filesystem::path& model_dir_path) + auto load_yolov4_tiny_model(const std::filesystem::path& model_dir_path) -> Network; } // namespace DO::Sara::Darknet diff --git a/cpp/drafts/NeuralNetworks/Darknet/YoloUtilities.cpp b/cpp/src/DO/Sara/NeuralNetworks/Darknet/YoloUtilities.cpp similarity index 98% rename from cpp/drafts/NeuralNetworks/Darknet/YoloUtilities.cpp rename to cpp/src/DO/Sara/NeuralNetworks/Darknet/YoloUtilities.cpp index bad965e58..e282dcbe7 100644 --- a/cpp/drafts/NeuralNetworks/Darknet/YoloUtilities.cpp +++ b/cpp/src/DO/Sara/NeuralNetworks/Darknet/YoloUtilities.cpp @@ -9,7 +9,7 @@ // you can obtain one at http://mozilla.org/MPL/2.0/. // ========================================================================== // -#include +#include namespace DO::Sara::Darknet { diff --git a/cpp/drafts/NeuralNetworks/Darknet/YoloUtilities.hpp b/cpp/src/DO/Sara/NeuralNetworks/Darknet/YoloUtilities.hpp similarity index 100% rename from cpp/drafts/NeuralNetworks/Darknet/YoloUtilities.hpp rename to cpp/src/DO/Sara/NeuralNetworks/Darknet/YoloUtilities.hpp diff --git a/cpp/src/DO/Shakti/Cuda/CMakeLists.txt b/cpp/src/DO/Shakti/Cuda/CMakeLists.txt index 98ccb5dad..7c7c8309d 100644 --- a/cpp/src/DO/Shakti/Cuda/CMakeLists.txt +++ b/cpp/src/DO/Shakti/Cuda/CMakeLists.txt @@ -15,3 +15,5 @@ if (NvidiaVideoCodec_ROOT) endif () add_subdirectory(FeatureDetectors) + +add_subdirectory(TensorRT) diff --git a/cpp/src/DO/Shakti/Cuda/TensorRT/CMakeLists.txt b/cpp/src/DO/Shakti/Cuda/TensorRT/CMakeLists.txt new file mode 100644 index 000000000..957699d8e --- /dev/null +++ b/cpp/src/DO/Shakti/Cuda/TensorRT/CMakeLists.txt @@ -0,0 +1,31 @@ +if(NOT CMAKE_CUDA_COMPILER OR NOT TensorRT_FOUND) + return() +endif() + +add_library( + DO_Shakti_Cuda_TensorRT # + Helpers.hpp # + IO.hpp # + IO.cpp # + InferenceExecutor.hpp # + InferenceExecutor.cpp # + DarknetParser.hpp # + DarknetParser.cpp # + Yolo.cpp + Yolo.hpp + YoloImpl.hpp + YoloImpl.cu) +add_library(DO::Shakti::Cuda::TensorRT ALIAS DO_Shakti_Cuda_TensorRT) +if(SARA_BUILD_SHARED_LIBS) + target_compile_definitions(DO_Shakti_Cuda_TensorRT PRIVATE DO_SARA_EXPORTS) +else() + target_compile_definitions(DO_Shakti_Cuda_TensorRT PUBLIC DO_SARA_STATIC) +endif() + +target_link_libraries( + DO_Shakti_Cuda_TensorRT + PUBLIC $<$:CUDA::cudart> # + TensorRT::TensorRT # + DO::Shakti::Cuda::Utilities # + DO::Sara::Darknet) +set_property(TARGET DO_Shakti_Cuda_TensorRT PROPERTY FOLDER "Libraries/Shakti") diff --git a/cpp/drafts/NeuralNetworks/TensorRT/DarknetParser.cpp b/cpp/src/DO/Shakti/Cuda/TensorRT/DarknetParser.cpp similarity index 98% rename from cpp/drafts/NeuralNetworks/TensorRT/DarknetParser.cpp rename to cpp/src/DO/Shakti/Cuda/TensorRT/DarknetParser.cpp index 8979a59ab..c8805188f 100644 --- a/cpp/drafts/NeuralNetworks/TensorRT/DarknetParser.cpp +++ b/cpp/src/DO/Shakti/Cuda/TensorRT/DarknetParser.cpp @@ -9,12 +9,15 @@ // you can obtain one at http://mozilla.org/MPL/2.0/. // ========================================================================== // -#include -#include -#include +#include +#include + +#include namespace DO::Sara::TensorRT { + using nvinfer1::IPluginV2; + static inline auto shape(const nvinfer1::ITensor& t) -> Eigen::Vector4i { @@ -293,7 +296,7 @@ namespace DO::Sara::TensorRT { // Create the YOLO plugin. const auto yolo_plugin = - std::unique_ptr{ + std::unique_ptr{ yolo_plugin_creator->createPlugin("", &fc), delete_plugin}; assert(yolo_plugin.get() != nullptr); diff --git a/cpp/drafts/NeuralNetworks/TensorRT/DarknetParser.hpp b/cpp/src/DO/Shakti/Cuda/TensorRT/DarknetParser.hpp similarity index 93% rename from cpp/drafts/NeuralNetworks/TensorRT/DarknetParser.hpp rename to cpp/src/DO/Shakti/Cuda/TensorRT/DarknetParser.hpp index 07f588e0b..f9733bba7 100644 --- a/cpp/drafts/NeuralNetworks/TensorRT/DarknetParser.hpp +++ b/cpp/src/DO/Shakti/Cuda/TensorRT/DarknetParser.hpp @@ -11,11 +11,11 @@ #pragma once -#include -#include -#include +#include +#include #include +#include #include @@ -59,7 +59,8 @@ namespace DO::Sara::TensorRT { std::vector& fmaps) const -> void; auto add_maxpool_layer(const int layer_idx, - std::vector& fmaps) const -> void; + std::vector& fmaps) const + -> void; auto add_upsample_layer(const int layer_idx, std::vector& fmaps) const diff --git a/cpp/drafts/NeuralNetworks/TensorRT/Helpers.hpp b/cpp/src/DO/Shakti/Cuda/TensorRT/Helpers.hpp similarity index 100% rename from cpp/drafts/NeuralNetworks/TensorRT/Helpers.hpp rename to cpp/src/DO/Shakti/Cuda/TensorRT/Helpers.hpp diff --git a/cpp/drafts/NeuralNetworks/TensorRT/IO.cpp b/cpp/src/DO/Shakti/Cuda/TensorRT/IO.cpp similarity index 96% rename from cpp/drafts/NeuralNetworks/TensorRT/IO.cpp rename to cpp/src/DO/Shakti/Cuda/TensorRT/IO.cpp index aa2f9e33d..0aecedcd7 100644 --- a/cpp/drafts/NeuralNetworks/TensorRT/IO.cpp +++ b/cpp/src/DO/Shakti/Cuda/TensorRT/IO.cpp @@ -9,7 +9,7 @@ // you can obtain one at http://mozilla.org/MPL/2.0/. // ========================================================================== // -#include +#include namespace DO::Sara::TensorRT { diff --git a/cpp/drafts/NeuralNetworks/TensorRT/IO.hpp b/cpp/src/DO/Shakti/Cuda/TensorRT/IO.hpp similarity index 96% rename from cpp/drafts/NeuralNetworks/TensorRT/IO.hpp rename to cpp/src/DO/Shakti/Cuda/TensorRT/IO.hpp index 69ea3b9a7..9e2369cda 100644 --- a/cpp/drafts/NeuralNetworks/TensorRT/IO.hpp +++ b/cpp/src/DO/Shakti/Cuda/TensorRT/IO.hpp @@ -11,7 +11,7 @@ #pragma once -#include +#include #include #include diff --git a/cpp/drafts/NeuralNetworks/TensorRT/InferenceExecutor.cpp b/cpp/src/DO/Shakti/Cuda/TensorRT/InferenceExecutor.cpp similarity index 97% rename from cpp/drafts/NeuralNetworks/TensorRT/InferenceExecutor.cpp rename to cpp/src/DO/Shakti/Cuda/TensorRT/InferenceExecutor.cpp index d11c4cb3a..0d07f7e40 100644 --- a/cpp/drafts/NeuralNetworks/TensorRT/InferenceExecutor.cpp +++ b/cpp/src/DO/Shakti/Cuda/TensorRT/InferenceExecutor.cpp @@ -9,7 +9,7 @@ // you can obtain one at http://mozilla.org/MPL/2.0/. // ========================================================================== // -#include +#include namespace DO::Sara::TensorRT { diff --git a/cpp/drafts/NeuralNetworks/TensorRT/InferenceExecutor.hpp b/cpp/src/DO/Shakti/Cuda/TensorRT/InferenceExecutor.hpp similarity index 96% rename from cpp/drafts/NeuralNetworks/TensorRT/InferenceExecutor.hpp rename to cpp/src/DO/Shakti/Cuda/TensorRT/InferenceExecutor.hpp index 2d9582a64..8958cef87 100644 --- a/cpp/drafts/NeuralNetworks/TensorRT/InferenceExecutor.hpp +++ b/cpp/src/DO/Shakti/Cuda/TensorRT/InferenceExecutor.hpp @@ -17,11 +17,10 @@ #include -#include - #include #include +#include namespace DO::Sara::TensorRT { @@ -44,7 +43,7 @@ namespace DO::Sara::TensorRT { std::array, 2>& out, // const bool synchronize = true) const -> void; - // private: + // private: CudaStreamUniquePtr _cuda_stream = make_cuda_stream(); RuntimeUniquePtr _runtime = {nullptr, &runtime_deleter}; CudaEngineUniquePtr _engine = {nullptr, &engine_deleter}; diff --git a/cpp/drafts/NeuralNetworks/TensorRT/Yolo.cpp b/cpp/src/DO/Shakti/Cuda/TensorRT/Yolo.cpp similarity index 98% rename from cpp/drafts/NeuralNetworks/TensorRT/Yolo.cpp rename to cpp/src/DO/Shakti/Cuda/TensorRT/Yolo.cpp index 9906375aa..4dcd88d1d 100644 --- a/cpp/drafts/NeuralNetworks/TensorRT/Yolo.cpp +++ b/cpp/src/DO/Shakti/Cuda/TensorRT/Yolo.cpp @@ -9,9 +9,9 @@ // you can obtain one at http://mozilla.org/MPL/2.0/. // ========================================================================== // -#include -#include -#include +#include +#include +#include #include diff --git a/cpp/drafts/NeuralNetworks/TensorRT/Yolo.hpp b/cpp/src/DO/Shakti/Cuda/TensorRT/Yolo.hpp similarity index 100% rename from cpp/drafts/NeuralNetworks/TensorRT/Yolo.hpp rename to cpp/src/DO/Shakti/Cuda/TensorRT/Yolo.hpp diff --git a/cpp/drafts/NeuralNetworks/TensorRT/YoloImpl.cu b/cpp/src/DO/Shakti/Cuda/TensorRT/YoloImpl.cu similarity index 98% rename from cpp/drafts/NeuralNetworks/TensorRT/YoloImpl.cu rename to cpp/src/DO/Shakti/Cuda/TensorRT/YoloImpl.cu index b2efea219..0b8bd1b45 100644 --- a/cpp/drafts/NeuralNetworks/TensorRT/YoloImpl.cu +++ b/cpp/src/DO/Shakti/Cuda/TensorRT/YoloImpl.cu @@ -10,7 +10,8 @@ // ========================================================================== // #include -#include + +#include namespace DO::Sara::TensorRT { diff --git a/cpp/drafts/NeuralNetworks/TensorRT/YoloImpl.hpp b/cpp/src/DO/Shakti/Cuda/TensorRT/YoloImpl.hpp similarity index 100% rename from cpp/drafts/NeuralNetworks/TensorRT/YoloImpl.hpp rename to cpp/src/DO/Shakti/Cuda/TensorRT/YoloImpl.hpp diff --git a/cpp/test/Sara/CMakeLists.txt b/cpp/test/Sara/CMakeLists.txt index d9e46edcf..c438612de 100644 --- a/cpp/test/Sara/CMakeLists.txt +++ b/cpp/test/Sara/CMakeLists.txt @@ -33,3 +33,5 @@ add_subdirectory(KalmanFilter) add_subdirectory(MultipleObjectTracking) add_subdirectory(Visualization) + +add_subdirectory(NeuralNetworks) diff --git a/cpp/drafts/NeuralNetworks/Darknet/test/CMakeLists.txt b/cpp/test/Sara/NeuralNetworks/CMakeLists.txt similarity index 100% rename from cpp/drafts/NeuralNetworks/Darknet/test/CMakeLists.txt rename to cpp/test/Sara/NeuralNetworks/CMakeLists.txt diff --git a/cpp/drafts/NeuralNetworks/Darknet/test/test_neuralnetworks_config_parsing.cpp b/cpp/test/Sara/NeuralNetworks/test_neuralnetworks_yolo_v4_config_parsing.cpp similarity index 75% rename from cpp/drafts/NeuralNetworks/Darknet/test/test_neuralnetworks_config_parsing.cpp rename to cpp/test/Sara/NeuralNetworks/test_neuralnetworks_yolo_v4_config_parsing.cpp index 2bc8a3183..a7b2468d8 100644 --- a/cpp/drafts/NeuralNetworks/Darknet/test/test_neuralnetworks_config_parsing.cpp +++ b/cpp/test/Sara/NeuralNetworks/test_neuralnetworks_yolo_v4_config_parsing.cpp @@ -13,14 +13,15 @@ #include -#include -#include +#include +#include -#include #include +#include -namespace fs = boost::filesystem; + +namespace fs = std::filesystem; namespace sara = DO::Sara; @@ -28,17 +29,15 @@ BOOST_AUTO_TEST_SUITE(TestLayers) BOOST_AUTO_TEST_CASE(test_yolov4_tiny_config_parsing) { - namespace fs = boost::filesystem; - - const auto data_dir_path = - fs::canonical(fs::path{src_path("data")}); + const auto data_dir_path = fs::canonical(fs::path{src_path("data")}); const auto cfg_filepath = data_dir_path / "trained_models" / "yolov4-tiny.cfg"; const auto weights_filepath = data_dir_path / "trained_models" / "yolov4-tiny.weights"; BOOST_CHECK(fs::exists(cfg_filepath)); - auto net = sara::Darknet::NetworkParser{}.parse_config_file(cfg_filepath.string()); + auto net = + sara::Darknet::NetworkParser{}.parse_config_file(cfg_filepath.string()); if (fs::exists(weights_filepath)) sara::Darknet::NetworkWeightLoader{weights_filepath.string()}.load(net); } diff --git a/cpp/test/Shakti/Cuda/CMakeLists.txt b/cpp/test/Shakti/Cuda/CMakeLists.txt index 8c5eac01c..2116465f2 100644 --- a/cpp/test/Shakti/Cuda/CMakeLists.txt +++ b/cpp/test/Shakti/Cuda/CMakeLists.txt @@ -10,3 +10,5 @@ add_subdirectory(MultiArray) # TODO: update code for CUDA 12. add_subdirectory(ImageProcessing) add_subdirectory(Segmentation) add_subdirectory(FeatureDetectors) + +add_subdirectory(TensorRT) diff --git a/cpp/drafts/NeuralNetworks/TensorRT/test/CMakeLists.txt b/cpp/test/Shakti/Cuda/TensorRT/CMakeLists.txt similarity index 74% rename from cpp/drafts/NeuralNetworks/TensorRT/test/CMakeLists.txt rename to cpp/test/Shakti/Cuda/TensorRT/CMakeLists.txt index 446c9f495..7931f2e5f 100644 --- a/cpp/drafts/NeuralNetworks/TensorRT/test/CMakeLists.txt +++ b/cpp/test/Shakti/Cuda/TensorRT/CMakeLists.txt @@ -13,14 +13,18 @@ foreach(file ${test_tensorrt_SOURCE_FILES}) target_link_libraries( ${filename} PRIVATE ${Boost_LIBRARIES} # - DO::Sara::ImageIO DO::Sara::ImageProcessing DO::Sara::TensorRT - DO::Shakti::Cuda::MultiArray DO::Shakti::Cuda::Utilities) + DO::Sara::ImageIO # + DO::Sara::ImageProcessing # + DO::Shakti::Cuda::MultiArray # + DO::Shakti::Cuda::Utilities # + DO::Shakti::Cuda::TensorRT) set_target_properties( ${filename} PROPERTIES COMPILE_FLAGS ${SARA_DEFINITIONS} RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin") - set_property(TARGET ${filename} PROPERTY FOLDER "Tests/Shakti/NeuralNetworks") + set_property(TARGET ${filename} # + PROPERTY FOLDER "Tests/Shakti/CUDA/NeuralNetworks") add_test(NAME ${filename} COMMAND $) endforeach() diff --git a/cpp/drafts/NeuralNetworks/TensorRT/test/test_neuralnetworks_tensorrt.cpp b/cpp/test/Shakti/Cuda/TensorRT/test_neuralnetworks_tensorrt.cpp similarity index 92% rename from cpp/drafts/NeuralNetworks/TensorRT/test/test_neuralnetworks_tensorrt.cpp rename to cpp/test/Shakti/Cuda/TensorRT/test_neuralnetworks_tensorrt.cpp index 1e048f25b..716d70c56 100644 --- a/cpp/drafts/NeuralNetworks/TensorRT/test/test_neuralnetworks_tensorrt.cpp +++ b/cpp/test/Shakti/Cuda/TensorRT/test_neuralnetworks_tensorrt.cpp @@ -1,3 +1,14 @@ +// ========================================================================== // +// This file is part of DO-CV, a basic set of libraries in C++ for computer +// vision. +// +// Copyright (C) 2023 David Ok +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License v. 2.0. If a copy of the MPL was not distributed with this file, +// you can obtain one at http://mozilla.org/MPL/2.0/. +// ========================================================================== // + #define BOOST_TEST_MODULE "NeuralNetworks/TensorRT/Basic Operations" #include @@ -7,11 +18,10 @@ #include #include +#include +#include #include -#include -#include - #include #include @@ -255,7 +265,9 @@ BOOST_AUTO_TEST_CASE(test_convolution_2d_operation) }; // Enqueue the CPU pinned <-> GPU tranfers and the convolution task. - if (!context->enqueueV2(device_buffers.data(), *cuda_stream, nullptr)) + auto placeholder = + context->enqueueV2(device_buffers.data(), *cuda_stream, nullptr); + if (!placeholder) { SARA_DEBUG << termcolor::red << "Execution failed!" << termcolor::reset << std::endl; diff --git a/cpp/drafts/NeuralNetworks/TensorRT/test/test_neuralnetworks_tensorrt_darknet_parser.cpp b/cpp/test/Shakti/Cuda/TensorRT/test_neuralnetworks_tensorrt_darknet_parser.cpp similarity index 91% rename from cpp/drafts/NeuralNetworks/TensorRT/test/test_neuralnetworks_tensorrt_darknet_parser.cpp rename to cpp/test/Shakti/Cuda/TensorRT/test_neuralnetworks_tensorrt_darknet_parser.cpp index dd1b29dd5..a41f360b5 100644 --- a/cpp/drafts/NeuralNetworks/TensorRT/test/test_neuralnetworks_tensorrt_darknet_parser.cpp +++ b/cpp/test/Shakti/Cuda/TensorRT/test_neuralnetworks_tensorrt_darknet_parser.cpp @@ -1,3 +1,14 @@ +// ========================================================================== // +// This file is part of DO-CV, a basic set of libraries in C++ for computer +// vision. +// +// Copyright (C) 2023 David Ok +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License v. 2.0. If a copy of the MPL was not distributed with this file, +// you can obtain one at http://mozilla.org/MPL/2.0/. +// ========================================================================== // + #define BOOST_TEST_MODULE "NeuralNetworks/TensorRT/Yolo-V4-Tiny" #include @@ -6,18 +17,16 @@ #include #include #include +#include #include +#include +#include +#include #include -#include -#include -#include -#include - - -namespace fs = boost::filesystem; +namespace fs = std::filesystem; namespace sara = DO::Sara; namespace shakti = DO::Shakti; namespace d = sara::Darknet; diff --git a/cpp/drafts/NeuralNetworks/TensorRT/test/test_neuralnetworks_tensorrt_inference_executor.cpp b/cpp/test/Shakti/Cuda/TensorRT/test_neuralnetworks_tensorrt_inference_executor.cpp similarity index 73% rename from cpp/drafts/NeuralNetworks/TensorRT/test/test_neuralnetworks_tensorrt_inference_executor.cpp rename to cpp/test/Shakti/Cuda/TensorRT/test_neuralnetworks_tensorrt_inference_executor.cpp index 73256406e..87cda1f31 100644 --- a/cpp/drafts/NeuralNetworks/TensorRT/test/test_neuralnetworks_tensorrt_inference_executor.cpp +++ b/cpp/test/Shakti/Cuda/TensorRT/test_neuralnetworks_tensorrt_inference_executor.cpp @@ -1,21 +1,31 @@ +// ========================================================================== // +// This file is part of DO-CV, a basic set of libraries in C++ for computer +// vision. +// +// Copyright (C) 2023 David Ok +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License v. 2.0. If a copy of the MPL was not distributed with this file, +// you can obtain one at http://mozilla.org/MPL/2.0/. +// ========================================================================== // + #define BOOST_TEST_MODULE "NeuralNetworks/TensorRT/InferenceExecutor" #include #include #include +#include #include - -#include -#include -#include -#include +#include +#include +#include #include #include -namespace fs = boost::filesystem; +namespace fs = std::filesystem; namespace sara = DO::Sara; namespace shakti = DO::Shakti; namespace d = sara::Darknet; diff --git a/cpp/drafts/NeuralNetworks/TensorRT/test/test_neuralnetworks_tensorrt_onnx_parser.cpp b/cpp/test/Shakti/Cuda/TensorRT/test_neuralnetworks_tensorrt_onnx_parser.cpp similarity index 89% rename from cpp/drafts/NeuralNetworks/TensorRT/test/test_neuralnetworks_tensorrt_onnx_parser.cpp rename to cpp/test/Shakti/Cuda/TensorRT/test_neuralnetworks_tensorrt_onnx_parser.cpp index 2b2c727ae..1cef5f0d2 100644 --- a/cpp/drafts/NeuralNetworks/TensorRT/test/test_neuralnetworks_tensorrt_onnx_parser.cpp +++ b/cpp/test/Shakti/Cuda/TensorRT/test_neuralnetworks_tensorrt_onnx_parser.cpp @@ -1,3 +1,14 @@ +// ========================================================================== // +// This file is part of DO-CV, a basic set of libraries in C++ for computer +// vision. +// +// Copyright (C) 2023 David Ok +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License v. 2.0. If a copy of the MPL was not distributed with this file, +// you can obtain one at http://mozilla.org/MPL/2.0/. +// ========================================================================== // + #define BOOST_TEST_MODULE "NeuralNetworks/TensorRT/YoloX-Tiny-ONNX-Conversion" #include @@ -8,11 +19,10 @@ #include #include +#include +#include #include -#include -#include - #include diff --git a/cpp/drafts/NeuralNetworks/TensorRT/test/test_neuralnetworks_tensorrt_yolo_plugin.cpp b/cpp/test/Shakti/Cuda/TensorRT/test_neuralnetworks_tensorrt_yolo_plugin.cpp similarity index 83% rename from cpp/drafts/NeuralNetworks/TensorRT/test/test_neuralnetworks_tensorrt_yolo_plugin.cpp rename to cpp/test/Shakti/Cuda/TensorRT/test_neuralnetworks_tensorrt_yolo_plugin.cpp index c4ce9ae32..bf5b30307 100644 --- a/cpp/drafts/NeuralNetworks/TensorRT/test/test_neuralnetworks_tensorrt_yolo_plugin.cpp +++ b/cpp/test/Shakti/Cuda/TensorRT/test_neuralnetworks_tensorrt_yolo_plugin.cpp @@ -1,17 +1,27 @@ +// ========================================================================== // +// This file is part of DO-CV, a basic set of libraries in C++ for computer +// vision. +// +// Copyright (C) 2023 David Ok +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License v. 2.0. If a copy of the MPL was not distributed with this file, +// you can obtain one at http://mozilla.org/MPL/2.0/. +// ========================================================================== // + #define BOOST_TEST_MODULE "NeuralNetworks/TensorRT" #if (defined(_WIN32) || defined(_WIN32_WCE)) && !defined(NOMINMAX) # define NOMINMAX #endif -#include -#include +#include +#include +#include #include #include -#include - #include @@ -78,9 +88,8 @@ BOOST_AUTO_TEST_CASE(test_that_the_yolo_plugin_is_automatically_registered) fc.nbFields = static_cast(fields.size()); const auto yolo_plugin = yolo_plugin_creator->createPlugin("yolo", &fc); - BOOST_CHECK_NE( - std::string(yolo_plugin->getPluginNamespace()).find(""), - std::string::npos); + BOOST_CHECK_NE(std::string(yolo_plugin->getPluginNamespace()).find(""), + std::string::npos); #if defined(TODO) // Resize the host tensor.