From 7dbdf6ba951dc9ae4f8f4d2cd4aa59775e2dc0e2 Mon Sep 17 00:00:00 2001 From: "Stewart Martin-Haugh stewart.martin-haugh@stfc.ac.uk" Date: Tue, 6 Aug 2024 14:30:51 +0100 Subject: [PATCH 1/9] Move vecmem ifdefs to separate file --- .../traccc/alpaka/utils/vecmem_typedefs.hpp | 62 +++++++++++++++++++ tests/alpaka/test_cca.cpp | 23 +------ 2 files changed, 65 insertions(+), 20 deletions(-) create mode 100644 device/alpaka/include/traccc/alpaka/utils/vecmem_typedefs.hpp diff --git a/device/alpaka/include/traccc/alpaka/utils/vecmem_typedefs.hpp b/device/alpaka/include/traccc/alpaka/utils/vecmem_typedefs.hpp new file mode 100644 index 0000000000..9d3f2cc1b5 --- /dev/null +++ b/device/alpaka/include/traccc/alpaka/utils/vecmem_typedefs.hpp @@ -0,0 +1,62 @@ +/** + * traccc library, part of the ACTS project (R&D line) + * + * (c) 2024 CERN for the benefit of the ACTS project + * + * Mozilla Public License Version 2.0 + */ + +#pragma once + +// VecMem include(s). +#ifdef ALPAKA_ACC_GPU_CUDA_ENABLED +#include +#include +#include +#endif + +#elif defined(ALPAKA_ACC_GPU_HIP_ENABLED) +#include +#include +#include +#endif + +#elif defined(ALPAKA_ACC_SYCL_ENABLED) +#include +#include +#include +#else +#include +#include +#endif + +namespace traccc::alpaka::vecmem { + +#if defined(ALPAKA_ACC_GPU_CUDA_ENABLED) +/// Device memory resource +typedef ::vecmem::cuda::device_memory_resource device_memory_resource; +/// Host memory resource +typedef ::vecmem::cuda::host_memory_resource host_memory_resource; +/// Memory copy object +typedef ::vecmem::cuda::copy device_copy; +#elif defined(ALPAKA_ACC_GPU_HIP_ENABLED) +/// Device memory resource +typedef ::vecmem::hip::device_memory_resource device_memory_resource; +/// Host memory resource +typedef ::vecmem::hip::host_memory_resource host_memory_resource; +/// Memory copy object +typedef ::vecmem::hip::copy device_copy; +#elif defined(ALPAKA_ACC_SYCL_ENABLED) +/// Device memory resource +typedef ::vecmem::sycl::device_memory_resource device_memory_resource; +/// Host memory resource +typedef ::vecmem::sycl::host_memory_resource host_memory_resource; +/// Memory copy object +typedef ::vecmem::sycl::copy device_copy; +#else // host-only +/// Device memory resource +typedef ::vecmem::memory_resource device_memory_resource; +typedef ::vecmem::copy device_copy; +#endif + +} // namespace traccc::alpaka::vecmem diff --git a/tests/alpaka/test_cca.cpp b/tests/alpaka/test_cca.cpp index 91a9cec90c..1c13495c7a 100644 --- a/tests/alpaka/test_cca.cpp +++ b/tests/alpaka/test_cca.cpp @@ -12,16 +12,7 @@ #include "tests/cca_test.hpp" #include "traccc/alpaka/clusterization/clusterization_algorithm.hpp" - -#if defined(ALPAKA_ACC_GPU_CUDA_ENABLED) -#include -#include -#include -#elif defined(ALPAKA_ACC_GPU_HIP_ENABLED) -#include -#include -#include -#endif +#include "traccc/alpaka/utils/vecmem_typedefs.hpp" namespace { @@ -33,16 +24,8 @@ cca_function_t get_f_with(traccc::clustering_config cfg) { vecmem::host_memory_resource host_mr; -#if defined(ALPAKA_ACC_GPU_CUDA_ENABLED) - vecmem::cuda::copy copy; - vecmem::cuda::device_memory_resource device_mr; -#elif defined(ALPAKA_ACC_GPU_HIP_ENABLED) - vecmem::hip::copy copy; - vecmem::hip::device_memory_resource device_mr; -#else - vecmem::copy copy; - vecmem::host_memory_resource device_mr; -#endif + traccc::alpaka::vecmem::device_copy copy; + traccc::alpaka::vecmem::device_memory_resource device_mr; traccc::alpaka::clusterization_algorithm cc({device_mr}, copy, cfg); From 923e1b61edc502b440bf3f06acae11c33c2a8843 Mon Sep 17 00:00:00 2001 From: "Stewart Martin-Haugh stewart.martin-haugh@stfc.ac.uk" Date: Tue, 6 Aug 2024 14:33:16 +0100 Subject: [PATCH 2/9] fix ifdefs --- device/alpaka/include/traccc/alpaka/utils/vecmem_typedefs.hpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/device/alpaka/include/traccc/alpaka/utils/vecmem_typedefs.hpp b/device/alpaka/include/traccc/alpaka/utils/vecmem_typedefs.hpp index 9d3f2cc1b5..2bdac0289a 100644 --- a/device/alpaka/include/traccc/alpaka/utils/vecmem_typedefs.hpp +++ b/device/alpaka/include/traccc/alpaka/utils/vecmem_typedefs.hpp @@ -13,18 +13,17 @@ #include #include #include -#endif #elif defined(ALPAKA_ACC_GPU_HIP_ENABLED) #include #include #include -#endif #elif defined(ALPAKA_ACC_SYCL_ENABLED) #include #include #include + #else #include #include From cb0bcdffbc055727243bd592ef8441462c7b5c52 Mon Sep 17 00:00:00 2001 From: "Stewart Martin-Haugh stewart.martin-haugh@stfc.ac.uk" Date: Tue, 6 Aug 2024 15:39:44 +0100 Subject: [PATCH 3/9] Use host memory as device memory in host-only mode --- device/alpaka/include/traccc/alpaka/utils/vecmem_typedefs.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/device/alpaka/include/traccc/alpaka/utils/vecmem_typedefs.hpp b/device/alpaka/include/traccc/alpaka/utils/vecmem_typedefs.hpp index 2bdac0289a..1b7b619f7d 100644 --- a/device/alpaka/include/traccc/alpaka/utils/vecmem_typedefs.hpp +++ b/device/alpaka/include/traccc/alpaka/utils/vecmem_typedefs.hpp @@ -54,7 +54,7 @@ typedef ::vecmem::sycl::host_memory_resource host_memory_resource; typedef ::vecmem::sycl::copy device_copy; #else // host-only /// Device memory resource -typedef ::vecmem::memory_resource device_memory_resource; +typedef ::vecmem::host_memory_resource device_memory_resource; typedef ::vecmem::copy device_copy; #endif From 7ec74957cb18e69345c53ecdef8f15743ec4533d Mon Sep 17 00:00:00 2001 From: "Stewart Martin-Haugh stewart.martin-haugh@stfc.ac.uk" Date: Mon, 12 Aug 2024 14:17:05 +0100 Subject: [PATCH 4/9] Move seq and seed examples over to typedefs --- .../traccc/alpaka/utils/vecmem_typedefs.hpp | 17 ++++---- .../run/alpaka/seeding_example_alpaka.cpp | 39 +++---------------- examples/run/alpaka/seq_example_alpaka.cpp | 35 +++-------------- 3 files changed, 17 insertions(+), 74 deletions(-) diff --git a/device/alpaka/include/traccc/alpaka/utils/vecmem_typedefs.hpp b/device/alpaka/include/traccc/alpaka/utils/vecmem_typedefs.hpp index 1b7b619f7d..f119af2a89 100644 --- a/device/alpaka/include/traccc/alpaka/utils/vecmem_typedefs.hpp +++ b/device/alpaka/include/traccc/alpaka/utils/vecmem_typedefs.hpp @@ -12,11 +12,13 @@ #ifdef ALPAKA_ACC_GPU_CUDA_ENABLED #include #include +#include #include #elif defined(ALPAKA_ACC_GPU_HIP_ENABLED) #include #include +#include #include #elif defined(ALPAKA_ACC_SYCL_ENABLED) @@ -32,29 +34,24 @@ namespace traccc::alpaka::vecmem { #if defined(ALPAKA_ACC_GPU_CUDA_ENABLED) -/// Device memory resource typedef ::vecmem::cuda::device_memory_resource device_memory_resource; -/// Host memory resource typedef ::vecmem::cuda::host_memory_resource host_memory_resource; -/// Memory copy object +typedef ::vecmem::cuda::managed_memory_resource managed_memory_resource; typedef ::vecmem::cuda::copy device_copy; #elif defined(ALPAKA_ACC_GPU_HIP_ENABLED) -/// Device memory resource typedef ::vecmem::hip::device_memory_resource device_memory_resource; -/// Host memory resource typedef ::vecmem::hip::host_memory_resource host_memory_resource; -/// Memory copy object +typedef ::vecmem::hip::managed_memory_resource managed_memory_resource; typedef ::vecmem::hip::copy device_copy; #elif defined(ALPAKA_ACC_SYCL_ENABLED) -/// Device memory resource typedef ::vecmem::sycl::device_memory_resource device_memory_resource; -/// Host memory resource typedef ::vecmem::sycl::host_memory_resource host_memory_resource; -/// Memory copy object +typedef ::vecmem::hip::managed_memory_resource managed_memory_resource; typedef ::vecmem::sycl::copy device_copy; #else // host-only -/// Device memory resource typedef ::vecmem::host_memory_resource device_memory_resource; +typedef ::vecmem::host_memory_resource host_memory_resource; +typedef ::vecmem::host_memory_resource managed_memory_resource; typedef ::vecmem::copy device_copy; #endif diff --git a/examples/run/alpaka/seeding_example_alpaka.cpp b/examples/run/alpaka/seeding_example_alpaka.cpp index fe401b8e50..30ab96c79b 100644 --- a/examples/run/alpaka/seeding_example_alpaka.cpp +++ b/examples/run/alpaka/seeding_example_alpaka.cpp @@ -44,23 +44,7 @@ #include "detray/propagator/propagator.hpp" #include "detray/propagator/rk_stepper.hpp" -// VecMem include(s). -#ifdef ALPAKA_ACC_GPU_CUDA_ENABLED -#include -#include -#include -#include -#endif - -#ifdef ALPAKA_ACC_GPU_HIP_ENABLED -#include -#include -#include -#include -#endif - -#include -#include +#include "traccc/alpaka/utils/vecmem_typedefs.hpp" // System include(s). #include @@ -80,24 +64,11 @@ int seq_run(const traccc::opts::track_seeding& seeding_opts, /// Type declarations using host_detector_type = detray::detector<>; -#if defined(ALPAKA_ACC_GPU_CUDA_ENABLED) - vecmem::cuda::copy copy; - vecmem::cuda::host_memory_resource host_mr; - vecmem::cuda::device_memory_resource device_mr; - vecmem::cuda::managed_memory_resource mng_mr; + traccc::alpaka::vecmem::device_copy copy; + traccc::alpaka::vecmem::host_memory_resource host_mr; + traccc::alpaka::vecmem::device_memory_resource device_mr; + traccc::alpaka::vecmem::managed_memory_resource mng_mr; traccc::memory_resource mr{device_mr, &host_mr}; -#elif defined(ALPAKA_ACC_GPU_HIP_ENABLED) - vecmem::hip::copy copy; - vecmem::hip::host_memory_resource host_mr; - vecmem::hip::device_memory_resource device_mr; - vecmem::hip::managed_memory_resource mng_mr; - traccc::memory_resource mr{device_mr, &host_mr}; -#else - vecmem::copy copy; - vecmem::host_memory_resource host_mr; - vecmem::host_memory_resource mng_mr; - traccc::memory_resource mr{host_mr, &host_mr}; -#endif // Performance writer traccc::seeding_performance_writer sd_performance_writer( diff --git a/examples/run/alpaka/seq_example_alpaka.cpp b/examples/run/alpaka/seq_example_alpaka.cpp index d42a1ffb2b..8bfe446efb 100644 --- a/examples/run/alpaka/seq_example_alpaka.cpp +++ b/examples/run/alpaka/seq_example_alpaka.cpp @@ -31,21 +31,7 @@ #include "traccc/seeding/seeding_algorithm.hpp" #include "traccc/seeding/track_params_estimation.hpp" -// VecMem include(s). -#ifdef ALPAKA_ACC_GPU_CUDA_ENABLED -#include -#include -#include -#endif - -#ifdef ALPAKA_ACC_GPU_HIP_ENABLED -#include -#include -#include -#endif - -#include -#include +#include "traccc/alpaka/utils/vecmem_typedefs.hpp" // System include(s). #include @@ -86,21 +72,10 @@ int seq_run(const traccc::opts::detector& detector_opts, seeding_opts.seedfinder.bFieldInZ}; // Memory resources used by the application. - vecmem::host_memory_resource host_mr; -#ifdef ALPAKA_ACC_GPU_CUDA_ENABLED - vecmem::cuda::copy copy; - vecmem::cuda::host_memory_resource cuda_host_mr; - vecmem::cuda::device_memory_resource device_mr; - traccc::memory_resource mr{device_mr, &cuda_host_mr}; -#elif ALPAKA_ACC_GPU_HIP_ENABLED - vecmem::hip::copy copy; - vecmem::hip::host_memory_resource hip_host_mr; - vecmem::hip::device_memory_resource hip_device_mr; - traccc::memory_resource mr{hip_device_mr, &hip_host_mr}; -#else - vecmem::copy copy; - traccc::memory_resource mr{host_mr, &host_mr}; -#endif + traccc::alpaka::vecmem::host_memory_resource host_mr; + traccc::alpaka::vecmem::device_copy copy; + traccc::alpaka::vecmem::device_memory_resource device_mr; + traccc::memory_resource mr{device_mr, &host_mr}; traccc::host::clusterization_algorithm ca(host_mr); traccc::host::spacepoint_formation_algorithm sf(host_mr); From c31bcb2f30b785c370489a11fa84f2dbc5091ff0 Mon Sep 17 00:00:00 2001 From: "Stewart Martin-Haugh stewart.martin-haugh@stfc.ac.uk" Date: Mon, 12 Aug 2024 14:22:48 +0100 Subject: [PATCH 5/9] Formatting --- examples/run/alpaka/seeding_example_alpaka.cpp | 1 - examples/run/alpaka/seq_example_alpaka.cpp | 3 +-- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/examples/run/alpaka/seeding_example_alpaka.cpp b/examples/run/alpaka/seeding_example_alpaka.cpp index 30ab96c79b..51e857d2ff 100644 --- a/examples/run/alpaka/seeding_example_alpaka.cpp +++ b/examples/run/alpaka/seeding_example_alpaka.cpp @@ -43,7 +43,6 @@ #include "detray/navigation/navigator.hpp" #include "detray/propagator/propagator.hpp" #include "detray/propagator/rk_stepper.hpp" - #include "traccc/alpaka/utils/vecmem_typedefs.hpp" // System include(s). diff --git a/examples/run/alpaka/seq_example_alpaka.cpp b/examples/run/alpaka/seq_example_alpaka.cpp index 8bfe446efb..22b3497aa4 100644 --- a/examples/run/alpaka/seq_example_alpaka.cpp +++ b/examples/run/alpaka/seq_example_alpaka.cpp @@ -11,6 +11,7 @@ #include "traccc/alpaka/clusterization/spacepoint_formation_algorithm.hpp" #include "traccc/alpaka/seeding/seeding_algorithm.hpp" #include "traccc/alpaka/seeding/track_params_estimation.hpp" +#include "traccc/alpaka/utils/vecmem_typedefs.hpp" #include "traccc/clusterization/clusterization_algorithm.hpp" #include "traccc/clusterization/spacepoint_formation_algorithm.hpp" #include "traccc/efficiency/seeding_performance_writer.hpp" @@ -31,8 +32,6 @@ #include "traccc/seeding/seeding_algorithm.hpp" #include "traccc/seeding/track_params_estimation.hpp" -#include "traccc/alpaka/utils/vecmem_typedefs.hpp" - // System include(s). #include #include From 286b2c4fbd0f67fb913ae57ba67c6b1af36a47d0 Mon Sep 17 00:00:00 2001 From: "Stewart Martin-Haugh stewart.martin-haugh@stfc.ac.uk" Date: Mon, 4 Nov 2024 17:17:28 +0000 Subject: [PATCH 6/9] Move to type traits --- .../alpaka/utils/vecmem_type_traits.hpp | 66 +++++++++++++++++++ .../traccc/alpaka/utils/vecmem_typedefs.hpp | 58 ---------------- .../run/alpaka/seeding_example_alpaka.cpp | 10 +-- examples/run/alpaka/seq_example_alpaka.cpp | 8 +-- tests/alpaka/test_cca.cpp | 6 +- 5 files changed, 78 insertions(+), 70 deletions(-) create mode 100644 device/alpaka/include/traccc/alpaka/utils/vecmem_type_traits.hpp delete mode 100644 device/alpaka/include/traccc/alpaka/utils/vecmem_typedefs.hpp diff --git a/device/alpaka/include/traccc/alpaka/utils/vecmem_type_traits.hpp b/device/alpaka/include/traccc/alpaka/utils/vecmem_type_traits.hpp new file mode 100644 index 0000000000..344eaa7d06 --- /dev/null +++ b/device/alpaka/include/traccc/alpaka/utils/vecmem_type_traits.hpp @@ -0,0 +1,66 @@ +/** + * traccc library, part of the ACTS project (R&D line) + * + * (c) 2024 CERN for the benefit of the ACTS project + * + * Mozilla Public License Version 2.0 + */ + +#pragma once + +// VecMem include(s). +#ifdef ALPAKA_ACC_GPU_CUDA_ENABLED +#include +#include +#include +#include + +#elif defined(ALPAKA_ACC_GPU_HIP_ENABLED) +#include +#include +#include +#include + +#elif defined(ALPAKA_ACC_SYCL_ENABLED) +#include +#include +#include + +#else +#include +#include +#endif + +#include + +namespace traccc::alpaka::vecmem { +#if defined(ALPAKA_ACC_GPU_CUDA_ENABLED) + struct host_device_traits { + using device_memory_resource = ::vecmem::cuda::device_memory_resource; + using host_memory_resource = ::vecmem::cuda::host_memory_resource ; + using managed_memory_resource = ::vecmem::cuda::managed_memory_resource; + using device_copy = ::vecmem::cuda::copy; + }; // struct host_device_traits +#elif defined(ALPAKA_ACC_GPU_HIP_ENABLED) + struct host_device_traits { + using device_memory_resource = ::vecmem::hip::device_memory_resource; + using host_memory_resource = ::vecmem::hip::host_memory_resource ; + using managed_memory_resource = ::vecmem::hip::managed_memory_resource; + using device_copy = ::vecmem::hip::copy; + }; // struct host_device_traits +#elif defined(ALPAKA_ACC_SYCL_ENABLED) + struct host_device_traits { + using device_memory_resource = ::vecmem::sycl::device_memory_resource; + using host_memory_resource = ::vecmem::sycl::host_memory_resource ; + using managed_memory_resource = ::vecmem::sycl::managed_memory_resource; + using device_copy = ::vecmem::sycl::copy; + }; // struct host_device_traits +#else // host-only + struct host_device_traits { + using device_memory_resource = ::vecmem::host_memory_resource; + using host_memory_resource = ::vecmem::host_memory_resource ; + using managed_memory_resource = ::vecmem::managed_memory_resource; + using device_copy = ::vecmem::copy; + }; // struct host_device_traits +#endif +} // namespace traccc::alpaka::vecmem diff --git a/device/alpaka/include/traccc/alpaka/utils/vecmem_typedefs.hpp b/device/alpaka/include/traccc/alpaka/utils/vecmem_typedefs.hpp deleted file mode 100644 index f119af2a89..0000000000 --- a/device/alpaka/include/traccc/alpaka/utils/vecmem_typedefs.hpp +++ /dev/null @@ -1,58 +0,0 @@ -/** - * traccc library, part of the ACTS project (R&D line) - * - * (c) 2024 CERN for the benefit of the ACTS project - * - * Mozilla Public License Version 2.0 - */ - -#pragma once - -// VecMem include(s). -#ifdef ALPAKA_ACC_GPU_CUDA_ENABLED -#include -#include -#include -#include - -#elif defined(ALPAKA_ACC_GPU_HIP_ENABLED) -#include -#include -#include -#include - -#elif defined(ALPAKA_ACC_SYCL_ENABLED) -#include -#include -#include - -#else -#include -#include -#endif - -namespace traccc::alpaka::vecmem { - -#if defined(ALPAKA_ACC_GPU_CUDA_ENABLED) -typedef ::vecmem::cuda::device_memory_resource device_memory_resource; -typedef ::vecmem::cuda::host_memory_resource host_memory_resource; -typedef ::vecmem::cuda::managed_memory_resource managed_memory_resource; -typedef ::vecmem::cuda::copy device_copy; -#elif defined(ALPAKA_ACC_GPU_HIP_ENABLED) -typedef ::vecmem::hip::device_memory_resource device_memory_resource; -typedef ::vecmem::hip::host_memory_resource host_memory_resource; -typedef ::vecmem::hip::managed_memory_resource managed_memory_resource; -typedef ::vecmem::hip::copy device_copy; -#elif defined(ALPAKA_ACC_SYCL_ENABLED) -typedef ::vecmem::sycl::device_memory_resource device_memory_resource; -typedef ::vecmem::sycl::host_memory_resource host_memory_resource; -typedef ::vecmem::hip::managed_memory_resource managed_memory_resource; -typedef ::vecmem::sycl::copy device_copy; -#else // host-only -typedef ::vecmem::host_memory_resource device_memory_resource; -typedef ::vecmem::host_memory_resource host_memory_resource; -typedef ::vecmem::host_memory_resource managed_memory_resource; -typedef ::vecmem::copy device_copy; -#endif - -} // namespace traccc::alpaka::vecmem diff --git a/examples/run/alpaka/seeding_example_alpaka.cpp b/examples/run/alpaka/seeding_example_alpaka.cpp index 51e857d2ff..a4f6c6b5e1 100644 --- a/examples/run/alpaka/seeding_example_alpaka.cpp +++ b/examples/run/alpaka/seeding_example_alpaka.cpp @@ -43,7 +43,7 @@ #include "detray/navigation/navigator.hpp" #include "detray/propagator/propagator.hpp" #include "detray/propagator/rk_stepper.hpp" -#include "traccc/alpaka/utils/vecmem_typedefs.hpp" +#include "traccc/alpaka/utils/vecmem_type_traits.hpp" // System include(s). #include @@ -63,10 +63,10 @@ int seq_run(const traccc::opts::track_seeding& seeding_opts, /// Type declarations using host_detector_type = detray::detector<>; - traccc::alpaka::vecmem::device_copy copy; - traccc::alpaka::vecmem::host_memory_resource host_mr; - traccc::alpaka::vecmem::device_memory_resource device_mr; - traccc::alpaka::vecmem::managed_memory_resource mng_mr; + traccc::alpaka::vecmem::host_device_traits::device_copy copy; + traccc::alpaka::vecmem::host_device_traits::host_memory_resource host_mr; + traccc::alpaka::vecmem::host_device_traits::device_memory_resource device_mr; + traccc::alpaka::vecmem::host_device_traits::managed_memory_resource mng_mr; traccc::memory_resource mr{device_mr, &host_mr}; // Performance writer diff --git a/examples/run/alpaka/seq_example_alpaka.cpp b/examples/run/alpaka/seq_example_alpaka.cpp index 22b3497aa4..2e26bc2df8 100644 --- a/examples/run/alpaka/seq_example_alpaka.cpp +++ b/examples/run/alpaka/seq_example_alpaka.cpp @@ -11,7 +11,7 @@ #include "traccc/alpaka/clusterization/spacepoint_formation_algorithm.hpp" #include "traccc/alpaka/seeding/seeding_algorithm.hpp" #include "traccc/alpaka/seeding/track_params_estimation.hpp" -#include "traccc/alpaka/utils/vecmem_typedefs.hpp" +#include "traccc/alpaka/utils/vecmem_type_traits.hpp" #include "traccc/clusterization/clusterization_algorithm.hpp" #include "traccc/clusterization/spacepoint_formation_algorithm.hpp" #include "traccc/efficiency/seeding_performance_writer.hpp" @@ -71,9 +71,9 @@ int seq_run(const traccc::opts::detector& detector_opts, seeding_opts.seedfinder.bFieldInZ}; // Memory resources used by the application. - traccc::alpaka::vecmem::host_memory_resource host_mr; - traccc::alpaka::vecmem::device_copy copy; - traccc::alpaka::vecmem::device_memory_resource device_mr; + traccc::alpaka::vecmem::host_device_traits::host_memory_resource host_mr; + traccc::alpaka::vecmem::host_device_traits::device_copy copy; + traccc::alpaka::vecmem::host_device_traits::device_memory_resource device_mr; traccc::memory_resource mr{device_mr, &host_mr}; traccc::host::clusterization_algorithm ca(host_mr); diff --git a/tests/alpaka/test_cca.cpp b/tests/alpaka/test_cca.cpp index 1c13495c7a..635afef281 100644 --- a/tests/alpaka/test_cca.cpp +++ b/tests/alpaka/test_cca.cpp @@ -12,7 +12,7 @@ #include "tests/cca_test.hpp" #include "traccc/alpaka/clusterization/clusterization_algorithm.hpp" -#include "traccc/alpaka/utils/vecmem_typedefs.hpp" +#include "traccc/alpaka/utils/vecmem_type_traits.hpp" namespace { @@ -24,8 +24,8 @@ cca_function_t get_f_with(traccc::clustering_config cfg) { vecmem::host_memory_resource host_mr; - traccc::alpaka::vecmem::device_copy copy; - traccc::alpaka::vecmem::device_memory_resource device_mr; + traccc::alpaka::vecmem::host_device_traits::device_copy copy; + traccc::alpaka::vecmem::host_device_traits::device_memory_resource device_mr; traccc::alpaka::clusterization_algorithm cc({device_mr}, copy, cfg); From fb1cfaa75fc67d5a49834f40f71c520111669f3b Mon Sep 17 00:00:00 2001 From: "Stewart Martin-Haugh stewart.martin-haugh@stfc.ac.uk" Date: Mon, 4 Nov 2024 17:28:52 +0000 Subject: [PATCH 7/9] Fix formatting --- .../alpaka/utils/vecmem_type_traits.hpp | 48 +++++++++---------- .../run/alpaka/seeding_example_alpaka.cpp | 3 +- examples/run/alpaka/seq_example_alpaka.cpp | 3 +- tests/alpaka/test_cca.cpp | 3 +- 4 files changed, 30 insertions(+), 27 deletions(-) diff --git a/device/alpaka/include/traccc/alpaka/utils/vecmem_type_traits.hpp b/device/alpaka/include/traccc/alpaka/utils/vecmem_type_traits.hpp index 344eaa7d06..06f2c848c4 100644 --- a/device/alpaka/include/traccc/alpaka/utils/vecmem_type_traits.hpp +++ b/device/alpaka/include/traccc/alpaka/utils/vecmem_type_traits.hpp @@ -35,32 +35,32 @@ namespace traccc::alpaka::vecmem { #if defined(ALPAKA_ACC_GPU_CUDA_ENABLED) - struct host_device_traits { - using device_memory_resource = ::vecmem::cuda::device_memory_resource; - using host_memory_resource = ::vecmem::cuda::host_memory_resource ; - using managed_memory_resource = ::vecmem::cuda::managed_memory_resource; - using device_copy = ::vecmem::cuda::copy; - }; // struct host_device_traits +struct host_device_traits { + using device_memory_resource = ::vecmem::cuda::device_memory_resource; + using host_memory_resource = ::vecmem::cuda::host_memory_resource; + using managed_memory_resource = ::vecmem::cuda::managed_memory_resource; + using device_copy = ::vecmem::cuda::copy; +}; // struct host_device_traits #elif defined(ALPAKA_ACC_GPU_HIP_ENABLED) - struct host_device_traits { - using device_memory_resource = ::vecmem::hip::device_memory_resource; - using host_memory_resource = ::vecmem::hip::host_memory_resource ; - using managed_memory_resource = ::vecmem::hip::managed_memory_resource; - using device_copy = ::vecmem::hip::copy; - }; // struct host_device_traits +struct host_device_traits { + using device_memory_resource = ::vecmem::hip::device_memory_resource; + using host_memory_resource = ::vecmem::hip::host_memory_resource; + using managed_memory_resource = ::vecmem::hip::managed_memory_resource; + using device_copy = ::vecmem::hip::copy; +}; // struct host_device_traits #elif defined(ALPAKA_ACC_SYCL_ENABLED) - struct host_device_traits { - using device_memory_resource = ::vecmem::sycl::device_memory_resource; - using host_memory_resource = ::vecmem::sycl::host_memory_resource ; - using managed_memory_resource = ::vecmem::sycl::managed_memory_resource; - using device_copy = ::vecmem::sycl::copy; - }; // struct host_device_traits +struct host_device_traits { + using device_memory_resource = ::vecmem::sycl::device_memory_resource; + using host_memory_resource = ::vecmem::sycl::host_memory_resource; + using managed_memory_resource = ::vecmem::sycl::managed_memory_resource; + using device_copy = ::vecmem::sycl::copy; +}; // struct host_device_traits #else // host-only - struct host_device_traits { - using device_memory_resource = ::vecmem::host_memory_resource; - using host_memory_resource = ::vecmem::host_memory_resource ; - using managed_memory_resource = ::vecmem::managed_memory_resource; - using device_copy = ::vecmem::copy; - }; // struct host_device_traits +struct host_device_traits { + using device_memory_resource = ::vecmem::host_memory_resource; + using host_memory_resource = ::vecmem::host_memory_resource; + using managed_memory_resource = ::vecmem::managed_memory_resource; + using device_copy = ::vecmem::copy; +}; // struct host_device_traits #endif } // namespace traccc::alpaka::vecmem diff --git a/examples/run/alpaka/seeding_example_alpaka.cpp b/examples/run/alpaka/seeding_example_alpaka.cpp index b27465645a..e7271d3a9e 100644 --- a/examples/run/alpaka/seeding_example_alpaka.cpp +++ b/examples/run/alpaka/seeding_example_alpaka.cpp @@ -60,7 +60,8 @@ int seq_run(const traccc::opts::track_seeding& seeding_opts, traccc::alpaka::vecmem::host_device_traits::device_copy copy; traccc::alpaka::vecmem::host_device_traits::host_memory_resource host_mr; - traccc::alpaka::vecmem::host_device_traits::device_memory_resource device_mr; + traccc::alpaka::vecmem::host_device_traits::device_memory_resource + device_mr; traccc::alpaka::vecmem::host_device_traits::managed_memory_resource mng_mr; traccc::memory_resource mr{device_mr, &host_mr}; diff --git a/examples/run/alpaka/seq_example_alpaka.cpp b/examples/run/alpaka/seq_example_alpaka.cpp index 1cce4ac1c5..ae1879393f 100644 --- a/examples/run/alpaka/seq_example_alpaka.cpp +++ b/examples/run/alpaka/seq_example_alpaka.cpp @@ -62,7 +62,8 @@ int seq_run(const traccc::opts::detector& detector_opts, // Memory resources used by the application. traccc::alpaka::vecmem::host_device_traits::host_memory_resource host_mr; traccc::alpaka::vecmem::host_device_traits::device_copy copy; - traccc::alpaka::vecmem::host_device_traits::device_memory_resource device_mr; + traccc::alpaka::vecmem::host_device_traits::device_memory_resource + device_mr; traccc::memory_resource mr{device_mr, &host_mr}; // Construct the detector description object. diff --git a/tests/alpaka/test_cca.cpp b/tests/alpaka/test_cca.cpp index 5e0f7192ad..8a55f2310c 100644 --- a/tests/alpaka/test_cca.cpp +++ b/tests/alpaka/test_cca.cpp @@ -26,7 +26,8 @@ cca_function_t get_f_with(traccc::clustering_config cfg) { vecmem::host_memory_resource host_mr; traccc::alpaka::vecmem::host_device_traits::device_copy copy; - traccc::alpaka::vecmem::host_device_traits::device_memory_resource device_mr; + traccc::alpaka::vecmem::host_device_traits::device_memory_resource + device_mr; traccc::alpaka::clusterization_algorithm cc({device_mr}, copy, cfg); From 056984dfe2bbc6aa6f9e17669d473f1ac5b04c32 Mon Sep 17 00:00:00 2001 From: "Stewart Martin-Haugh stewart.martin-haugh@stfc.ac.uk" Date: Tue, 5 Nov 2024 16:12:33 +0000 Subject: [PATCH 8/9] Complete vecmem types implementation --- ...ecmem_type_traits.hpp => vecmem_types.hpp} | 77 ++++++++++++++----- examples/run/alpaka/CMakeLists.txt | 15 +++- .../run/alpaka/seeding_example_alpaka.cpp | 20 +++-- examples/run/alpaka/seq_example_alpaka.cpp | 17 ++-- tests/alpaka/test_cca.cpp | 20 +++-- 5 files changed, 112 insertions(+), 37 deletions(-) rename device/alpaka/include/traccc/alpaka/utils/{vecmem_type_traits.hpp => vecmem_types.hpp} (52%) diff --git a/device/alpaka/include/traccc/alpaka/utils/vecmem_type_traits.hpp b/device/alpaka/include/traccc/alpaka/utils/vecmem_types.hpp similarity index 52% rename from device/alpaka/include/traccc/alpaka/utils/vecmem_type_traits.hpp rename to device/alpaka/include/traccc/alpaka/utils/vecmem_types.hpp index 06f2c848c4..e8f09fbea1 100644 --- a/device/alpaka/include/traccc/alpaka/utils/vecmem_type_traits.hpp +++ b/device/alpaka/include/traccc/alpaka/utils/vecmem_types.hpp @@ -31,36 +31,73 @@ #include #endif -#include +#include + +//Forward declarations so we can compile the types below +namespace vecmem { +class host_memory_resource; +class copy; +namespace cuda { +class host_memory_resource; +class device_memory_resource; +class managed_memory_resource; +class copy; +} // namespace cuda +namespace hip { +class host_memory_resource; +class device_memory_resource; +class managed_memory_resource; +class copy; +} // namespace hip +namespace sycl { +class host_memory_resource; +class device_memory_resource; +class managed_memory_resource; +class copy; +} // namespace sycl +} // namespace vecmem namespace traccc::alpaka::vecmem { -#if defined(ALPAKA_ACC_GPU_CUDA_ENABLED) -struct host_device_traits { - using device_memory_resource = ::vecmem::cuda::device_memory_resource; +//For all CPU accelerators (except SYCL), just use host +template +struct host_device_types { + using device_memory_resource = ::vecmem::host_memory_resource; + using host_memory_resource = ::vecmem::host_memory_resource; + using managed_memory_resource = ::vecmem::host_memory_resource; + using device_copy = ::vecmem::copy; +}; +template <> +struct host_device_types<::alpaka::TagGpuCudaRt> { + using device_memory_resource = ::vecmem::cuda::host_memory_resource; using host_memory_resource = ::vecmem::cuda::host_memory_resource; using managed_memory_resource = ::vecmem::cuda::managed_memory_resource; using device_copy = ::vecmem::cuda::copy; -}; // struct host_device_traits -#elif defined(ALPAKA_ACC_GPU_HIP_ENABLED) -struct host_device_traits { +}; +template <> +struct host_device_types<::alpaka::TagGpuHipRt> { using device_memory_resource = ::vecmem::hip::device_memory_resource; using host_memory_resource = ::vecmem::hip::host_memory_resource; using managed_memory_resource = ::vecmem::hip::managed_memory_resource; using device_copy = ::vecmem::hip::copy; -}; // struct host_device_traits -#elif defined(ALPAKA_ACC_SYCL_ENABLED) -struct host_device_traits { +}; +template <> +struct host_device_types<::alpaka::TagCpuSycl> { using device_memory_resource = ::vecmem::sycl::device_memory_resource; using host_memory_resource = ::vecmem::sycl::host_memory_resource; - using managed_memory_resource = ::vecmem::sycl::managed_memory_resource; + using managed_memory_resource = ::vecmem::sycl::host_memory_resource; using device_copy = ::vecmem::sycl::copy; -}; // struct host_device_traits -#else // host-only -struct host_device_traits { - using device_memory_resource = ::vecmem::host_memory_resource; - using host_memory_resource = ::vecmem::host_memory_resource; - using managed_memory_resource = ::vecmem::managed_memory_resource; - using device_copy = ::vecmem::copy; -}; // struct host_device_traits -#endif +}; +template <> +struct host_device_types<::alpaka::TagFpgaSyclIntel> { + using device_memory_resource = ::vecmem::sycl::device_memory_resource; + using host_memory_resource = ::vecmem::sycl::host_memory_resource; + using managed_memory_resource = ::vecmem::sycl::host_memory_resource; + using device_copy = ::vecmem::sycl::copy; +}; +template <> +struct host_device_types<::alpaka::TagGpuSyclIntel> { + using device_memory_resource = ::vecmem::sycl::device_memory_resource; + using host_memory_resource = ::vecmem::sycl::host_memory_resource; + using device_copy = ::vecmem::sycl::copy; +}; } // namespace traccc::alpaka::vecmem diff --git a/examples/run/alpaka/CMakeLists.txt b/examples/run/alpaka/CMakeLists.txt index 795541274a..765bb875c5 100644 --- a/examples/run/alpaka/CMakeLists.txt +++ b/examples/run/alpaka/CMakeLists.txt @@ -6,15 +6,21 @@ set(EXTRA_LIBS) +set(TRACCC_ALPAKA_EXAMPLE_SOURCES + seq_example_alpaka.cpp + seeding_example_alpaka.cpp +) + if(alpaka_ACC_GPU_CUDA_ENABLE) enable_language(CUDA) include( traccc-compiler-options-cuda ) + set_source_files_properties(${TRACCC_ALPAKA_EXAMPLE_SOURCES} PROPERTIES LANGUAGE CUDA) list (APPEND EXTRA_LIBS vecmem::cuda traccc::cuda) elseif(alpaka_ACC_GPU_HIP_ENABLE) enable_language(HIP) find_package( HIPToolkit REQUIRED ) - + set_source_files_properties(${TRACCC_ALPAKA_EXAMPLE_SOURCES} PROPERTIES LANGUAGE HIP) list(APPEND EXTRA_LIBS HIP::hiprt vecmem::hip) endif() @@ -27,3 +33,10 @@ traccc_add_executable( seq_example_alpaka "seq_example_alpaka.cpp" traccc_add_executable( seeding_example_alpaka "seeding_example_alpaka.cpp" LINK_LIBRARIES ${LIBRARIES} ) +#Can only do this once target is defined, so need another if here +if(alpaka_ACC_GPU_HIP_ENABLE) + set_target_properties( traccc_seq_example_alpaka PROPERTIES + POSITION_INDEPENDENT_CODE TRUE ) + set_target_properties( traccc_seeding_example_alpaka PROPERTIES + POSITION_INDEPENDENT_CODE TRUE ) +endif() diff --git a/examples/run/alpaka/seeding_example_alpaka.cpp b/examples/run/alpaka/seeding_example_alpaka.cpp index e7271d3a9e..af0472fb72 100644 --- a/examples/run/alpaka/seeding_example_alpaka.cpp +++ b/examples/run/alpaka/seeding_example_alpaka.cpp @@ -34,6 +34,7 @@ #include "traccc/seeding/track_params_estimation.hpp" // Detray include(s). +#include "alpaka/example/ExampleDefaultAcc.hpp" #include "detray/core/detector.hpp" #include "detray/core/detector_metadata.hpp" #include "detray/detectors/bfield.hpp" @@ -41,7 +42,7 @@ #include "detray/navigation/navigator.hpp" #include "detray/propagator/propagator.hpp" #include "detray/propagator/rk_stepper.hpp" -#include "traccc/alpaka/utils/vecmem_type_traits.hpp" +#include "traccc/alpaka/utils/vecmem_types.hpp" // System include(s). #include @@ -58,11 +59,18 @@ int seq_run(const traccc::opts::track_seeding& seeding_opts, const traccc::opts::performance& performance_opts, const traccc::opts::accelerator& accelerator_opts) { - traccc::alpaka::vecmem::host_device_traits::device_copy copy; - traccc::alpaka::vecmem::host_device_traits::host_memory_resource host_mr; - traccc::alpaka::vecmem::host_device_traits::device_memory_resource - device_mr; - traccc::alpaka::vecmem::host_device_traits::managed_memory_resource mng_mr; + using Dim = ::alpaka::DimInt<1>; + using Idx = uint32_t; + + using Acc = ::alpaka::ExampleDefaultAcc; + traccc::alpaka::vecmem::host_device_types< + ::alpaka::trait::AccToTag::type>::device_copy copy; + traccc::alpaka::vecmem::host_device_types< + ::alpaka::trait::AccToTag::type>::host_memory_resource host_mr; + traccc::alpaka::vecmem::host_device_types< + ::alpaka::trait::AccToTag::type>::device_memory_resource device_mr; + traccc::alpaka::vecmem::host_device_types< + ::alpaka::trait::AccToTag::type>::managed_memory_resource mng_mr; traccc::memory_resource mr{device_mr, &host_mr}; // Performance writer diff --git a/examples/run/alpaka/seq_example_alpaka.cpp b/examples/run/alpaka/seq_example_alpaka.cpp index ae1879393f..2e2d398ed9 100644 --- a/examples/run/alpaka/seq_example_alpaka.cpp +++ b/examples/run/alpaka/seq_example_alpaka.cpp @@ -6,12 +6,13 @@ */ // Project include(s). +#include "alpaka/example/ExampleDefaultAcc.hpp" #include "traccc/alpaka/clusterization/clusterization_algorithm.hpp" #include "traccc/alpaka/clusterization/measurement_sorting_algorithm.hpp" #include "traccc/alpaka/seeding/seeding_algorithm.hpp" #include "traccc/alpaka/seeding/spacepoint_formation_algorithm.hpp" #include "traccc/alpaka/seeding/track_params_estimation.hpp" -#include "traccc/alpaka/utils/vecmem_type_traits.hpp" +#include "traccc/alpaka/utils/vecmem_types.hpp" #include "traccc/clusterization/clusterization_algorithm.hpp" #include "traccc/efficiency/seeding_performance_writer.hpp" #include "traccc/io/read_cells.hpp" @@ -59,11 +60,17 @@ int seq_run(const traccc::opts::detector& detector_opts, const traccc::vector3 field_vec = {0.f, 0.f, seeding_opts.seedfinder.bFieldInZ}; + using Dim = ::alpaka::DimInt<1>; + using Idx = uint32_t; + + using Acc = ::alpaka::ExampleDefaultAcc; // Memory resources used by the application. - traccc::alpaka::vecmem::host_device_traits::host_memory_resource host_mr; - traccc::alpaka::vecmem::host_device_traits::device_copy copy; - traccc::alpaka::vecmem::host_device_traits::device_memory_resource - device_mr; + traccc::alpaka::vecmem::host_device_types< + alpaka::trait::AccToTag::type>::host_memory_resource host_mr; + traccc::alpaka::vecmem::host_device_types< + alpaka::trait::AccToTag::type>::device_copy copy; + traccc::alpaka::vecmem::host_device_types< + alpaka::trait::AccToTag::type>::device_memory_resource device_mr; traccc::memory_resource mr{device_mr, &host_mr}; // Construct the detector description object. diff --git a/tests/alpaka/test_cca.cpp b/tests/alpaka/test_cca.cpp index 8a55f2310c..6fa02a76c4 100644 --- a/tests/alpaka/test_cca.cpp +++ b/tests/alpaka/test_cca.cpp @@ -7,26 +7,36 @@ #include +#include +#include #include #include #include "tests/cca_test.hpp" #include "traccc/alpaka/clusterization/clusterization_algorithm.hpp" -#include "traccc/alpaka/utils/vecmem_type_traits.hpp" +#include "traccc/alpaka/utils/vecmem_types.hpp" #include "traccc/geometry/silicon_detector_description.hpp" namespace { +// template cca_function_t get_f_with(traccc::clustering_config cfg) { return [cfg](const traccc::edm::silicon_cell_collection::host& cells, const traccc::silicon_detector_description::host& dd) { std::map> result; - vecmem::host_memory_resource host_mr; - - traccc::alpaka::vecmem::host_device_traits::device_copy copy; - traccc::alpaka::vecmem::host_device_traits::device_memory_resource + using namespace alpaka; + using Dim = DimInt<1>; + using Idx = uint32_t; + + using Acc = ExampleDefaultAcc; + traccc::alpaka::vecmem::host_device_types< + alpaka::trait::AccToTag::type>::host_memory_resource host_mr; + traccc::alpaka::vecmem::host_device_types< + alpaka::trait::AccToTag::type>::device_copy copy; + traccc::alpaka::vecmem::host_device_types< + alpaka::trait::AccToTag::type>::device_memory_resource device_mr; traccc::alpaka::clusterization_algorithm cc({device_mr}, copy, cfg); From 7cabd3d57cda268cfed9d2077b73026a455bf997 Mon Sep 17 00:00:00 2001 From: "Stewart Martin-Haugh stewart.martin-haugh@stfc.ac.uk" Date: Tue, 5 Nov 2024 16:33:20 +0000 Subject: [PATCH 9/9] Formatting --- device/alpaka/include/traccc/alpaka/utils/vecmem_types.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/device/alpaka/include/traccc/alpaka/utils/vecmem_types.hpp b/device/alpaka/include/traccc/alpaka/utils/vecmem_types.hpp index e8f09fbea1..17525fcf05 100644 --- a/device/alpaka/include/traccc/alpaka/utils/vecmem_types.hpp +++ b/device/alpaka/include/traccc/alpaka/utils/vecmem_types.hpp @@ -33,7 +33,7 @@ #include -//Forward declarations so we can compile the types below +// Forward declarations so we can compile the types below namespace vecmem { class host_memory_resource; class copy; @@ -58,7 +58,7 @@ class copy; } // namespace vecmem namespace traccc::alpaka::vecmem { -//For all CPU accelerators (except SYCL), just use host +// For all CPU accelerators (except SYCL), just use host template struct host_device_types { using device_memory_resource = ::vecmem::host_memory_resource;