From 82de6315e790f56ed59a671462615a4c2d905040 Mon Sep 17 00:00:00 2001 From: Stephen Nicholas Swatman Date: Tue, 25 Jun 2024 15:51:27 +0200 Subject: [PATCH 1/2] test --- .../traccc/seeding/doublet_finding_helper.hpp | 16 + device/cuda/CMakeLists.txt | 5 + .../cuda/seeding2/kernels/kd_tree_kernel.hpp | 24 + .../seeding2/kernels/seed_finding_kernel.hpp | 27 + .../seeding2/kernels/write_output_kernel.hpp | 26 + .../traccc/cuda/seeding2/seed_finding.hpp | 35 + .../cuda/seeding2/types/internal_sp.hpp | 35 + .../traccc/cuda/seeding2/types/kd_tree.hpp | 36 + .../traccc/cuda/seeding2/types/range3d.hpp | 73 ++ .../traccc/cuda/utils/device_traits.hpp | 56 ++ .../cuda/include/traccc/cuda/utils/sort.hpp | 120 +++ .../cuda/include/traccc/cuda/utils/sync.hpp | 40 + .../src/seeding2/kernels/kd_tree_kernel.cu | 833 ++++++++++++++++++ .../seeding2/kernels/seed_finding_kernel.cu | 706 +++++++++++++++ .../seeding2/kernels/write_output_kernel.cu | 82 ++ device/cuda/src/seeding2/seed_finding2.cu | 96 ++ 16 files changed, 2210 insertions(+) create mode 100644 device/cuda/include/traccc/cuda/seeding2/kernels/kd_tree_kernel.hpp create mode 100644 device/cuda/include/traccc/cuda/seeding2/kernels/seed_finding_kernel.hpp create mode 100644 device/cuda/include/traccc/cuda/seeding2/kernels/write_output_kernel.hpp create mode 100644 device/cuda/include/traccc/cuda/seeding2/seed_finding.hpp create mode 100644 device/cuda/include/traccc/cuda/seeding2/types/internal_sp.hpp create mode 100644 device/cuda/include/traccc/cuda/seeding2/types/kd_tree.hpp create mode 100644 device/cuda/include/traccc/cuda/seeding2/types/range3d.hpp create mode 100644 device/cuda/include/traccc/cuda/utils/device_traits.hpp create mode 100644 device/cuda/include/traccc/cuda/utils/sort.hpp create mode 100644 device/cuda/include/traccc/cuda/utils/sync.hpp create mode 100644 device/cuda/src/seeding2/kernels/kd_tree_kernel.cu create mode 100644 device/cuda/src/seeding2/kernels/seed_finding_kernel.cu create mode 100644 device/cuda/src/seeding2/kernels/write_output_kernel.cu create mode 100644 device/cuda/src/seeding2/seed_finding2.cu diff --git a/core/include/traccc/seeding/doublet_finding_helper.hpp b/core/include/traccc/seeding/doublet_finding_helper.hpp index 224b13da03..dfb9b96765 100644 --- a/core/include/traccc/seeding/doublet_finding_helper.hpp +++ b/core/include/traccc/seeding/doublet_finding_helper.hpp @@ -34,6 +34,11 @@ struct doublet_finding_helper { const internal_spacepoint& sp2, const seedfinder_config& config); + static inline TRACCC_HOST_DEVICE bool isCompatible( + bool top, const internal_spacepoint& sp1, + const internal_spacepoint& sp2, + const seedfinder_config& config); + /// Do the conformal transformation on doublet's coordinate /// /// @param sp1 is middle spacepoint @@ -48,6 +53,17 @@ struct doublet_finding_helper { const internal_spacepoint& sp2); }; +bool doublet_finding_helper::isCompatible( + bool top, const internal_spacepoint& sp1, + const internal_spacepoint& sp2, + const seedfinder_config& config) { + if (top) { + return isCompatible(sp1, sp2, config); + } else { + return isCompatible(sp1, sp2, config); + } +} + template bool TRACCC_HOST_DEVICE doublet_finding_helper::isCompatible(const internal_spacepoint& sp1, diff --git a/device/cuda/CMakeLists.txt b/device/cuda/CMakeLists.txt index 1321e547b5..0e7067222f 100644 --- a/device/cuda/CMakeLists.txt +++ b/device/cuda/CMakeLists.txt @@ -39,6 +39,11 @@ traccc_add_library( traccc_cuda cuda TYPE SHARED "src/seeding/spacepoint_binning.cu" "include/traccc/cuda/seeding/experimental/spacepoint_formation.hpp" "src/seeding/experimental/spacepoint_formation.cu" + # Alternate seeding. + "src/seeding2/seed_finding2.cu" + "src/seeding2/kernels/seed_finding_kernel.cu" + "src/seeding2/kernels/kd_tree_kernel.cu" + "src/seeding2/kernels/write_output_kernel.cu" # Clusterization "include/traccc/cuda/clusterization/clusterization_algorithm.hpp" "src/clusterization/clusterization_algorithm.cu" diff --git a/device/cuda/include/traccc/cuda/seeding2/kernels/kd_tree_kernel.hpp b/device/cuda/include/traccc/cuda/seeding2/kernels/kd_tree_kernel.hpp new file mode 100644 index 0000000000..4ce1325af7 --- /dev/null +++ b/device/cuda/include/traccc/cuda/seeding2/kernels/kd_tree_kernel.hpp @@ -0,0 +1,24 @@ +/** TRACCC library, part of the ACTS project (R&D line) + * + * (c) 2022 CERN for the benefit of the ACTS project + * + * Mozilla Public License Version 2.0 + */ + +#pragma once + +#include +#include +#include +#include +#include + +namespace traccc::cuda { +/** + * @brief Creates a k-d tree from a given set of spacepoints. + * + * @return A pair containing the k-d tree nodes as well as the number of nodes. + */ +std::tuple create_kd_tree( + vecmem::memory_resource&, internal_sp_owning_t&&, uint32_t); +} // namespace traccc::cuda diff --git a/device/cuda/include/traccc/cuda/seeding2/kernels/seed_finding_kernel.hpp b/device/cuda/include/traccc/cuda/seeding2/kernels/seed_finding_kernel.hpp new file mode 100644 index 0000000000..464b4dd2af --- /dev/null +++ b/device/cuda/include/traccc/cuda/seeding2/kernels/seed_finding_kernel.hpp @@ -0,0 +1,27 @@ +/** TRACCC library, part of the ACTS project (R&D line) + * + * (c) 2022 CERN for the benefit of the ACTS project + * + * Mozilla Public License Version 2.0 + */ + +#pragma once + +#include +#include +#include +#include +#include +#include + +namespace traccc::cuda { +/** + * @brief Execute the seed finding kernel itself. + * + * @return A pair containing the list of internal seeds as well as the number + * of seeds. + */ +std::pair, uint32_t> run_seeding( + seedfinder_config, seedfilter_config, vecmem::memory_resource&, + internal_sp_t, kd_tree_t); +} // namespace traccc::cuda diff --git a/device/cuda/include/traccc/cuda/seeding2/kernels/write_output_kernel.hpp b/device/cuda/include/traccc/cuda/seeding2/kernels/write_output_kernel.hpp new file mode 100644 index 0000000000..0bddf482d0 --- /dev/null +++ b/device/cuda/include/traccc/cuda/seeding2/kernels/write_output_kernel.hpp @@ -0,0 +1,26 @@ +/** TRACCC library, part of the ACTS project (R&D line) + * + * (c) 2022 CERN for the benefit of the ACTS project + * + * Mozilla Public License Version 2.0 + */ + +#pragma once + +#include +#include +#include +#include +#include +#include + +namespace traccc::cuda { +/** + * @brief Kernel to write output data back into traccc's EDM. + * + * @return A vector buffer containing the output seeds. + */ +alt_seed_collection_types::buffer write_output(const traccc::memory_resource &, + uint32_t, const internal_sp_t, + const alt_seed *const); +} // namespace traccc::cuda diff --git a/device/cuda/include/traccc/cuda/seeding2/seed_finding.hpp b/device/cuda/include/traccc/cuda/seeding2/seed_finding.hpp new file mode 100644 index 0000000000..a350a73730 --- /dev/null +++ b/device/cuda/include/traccc/cuda/seeding2/seed_finding.hpp @@ -0,0 +1,35 @@ +/** TRACCC library, part of the ACTS project (R&D line) + * + * (c) 2022 CERN for the benefit of the ACTS project + * + * Mozilla Public License Version 2.0 + */ + +#pragma once + +#include +#include +#include +#include +#include +#include + +namespace traccc::cuda { +/** + * @brief Alternative seed finding algorithm, using orthogonal range search + * implemented through a k-d tree. + */ +class seed_finding2 : public algorithm { + public: + seed_finding2(const traccc::memory_resource& mr); + + output_type operator()( + const spacepoint_collection_types::const_view& sps) const override; + + private: + traccc::memory_resource m_output_mr; + seedfinder_config m_finder_conf; + seedfilter_config m_filter_conf; +}; +} // namespace traccc::cuda diff --git a/device/cuda/include/traccc/cuda/seeding2/types/internal_sp.hpp b/device/cuda/include/traccc/cuda/seeding2/types/internal_sp.hpp new file mode 100644 index 0000000000..94b375ff4d --- /dev/null +++ b/device/cuda/include/traccc/cuda/seeding2/types/internal_sp.hpp @@ -0,0 +1,35 @@ +/** TRACCC library, part of the ACTS project (R&D line) + * + * (c) 2022 CERN for the benefit of the ACTS project + * + * Mozilla Public License Version 2.0 + */ + +#pragma once + +#include +#include +#include +#include +#include +#include + +namespace traccc::cuda { +template