diff --git a/device/alpaka/include/traccc/alpaka/utils/vecmem_types.hpp b/device/alpaka/include/traccc/alpaka/utils/vecmem_types.hpp new file mode 100644 index 0000000000..17525fcf05 --- /dev/null +++ b/device/alpaka/include/traccc/alpaka/utils/vecmem_types.hpp @@ -0,0 +1,103 @@ +/** + * 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 + +// 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 { +// 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; +}; +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; +}; +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::host_memory_resource; + using device_copy = ::vecmem::sycl::copy; +}; +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 f7e8b19668..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,24 +42,7 @@ #include "detray/navigation/navigator.hpp" #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_types.hpp" // System include(s). #include @@ -75,24 +59,19 @@ int seq_run(const traccc::opts::track_seeding& seeding_opts, const traccc::opts::performance& performance_opts, const traccc::opts::accelerator& accelerator_opts) { -#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::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; + 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}; -#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 6a8adb3075..2e2d398ed9 100644 --- a/examples/run/alpaka/seq_example_alpaka.cpp +++ b/examples/run/alpaka/seq_example_alpaka.cpp @@ -6,11 +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_types.hpp" #include "traccc/clusterization/clusterization_algorithm.hpp" #include "traccc/efficiency/seeding_performance_writer.hpp" #include "traccc/io/read_cells.hpp" @@ -31,22 +33,6 @@ #include "traccc/seeding/silicon_pixel_spacepoint_formation_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 - // System include(s). #include #include @@ -74,22 +60,18 @@ 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. - 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_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. traccc::silicon_detector_description::host host_det_descr{host_mr}; diff --git a/tests/alpaka/test_cca.cpp b/tests/alpaka/test_cca.cpp index 52c4343f68..6fa02a76c4 100644 --- a/tests/alpaka/test_cca.cpp +++ b/tests/alpaka/test_cca.cpp @@ -7,43 +7,37 @@ #include +#include +#include #include #include #include "tests/cca_test.hpp" #include "traccc/alpaka/clusterization/clusterization_algorithm.hpp" +#include "traccc/alpaka/utils/vecmem_types.hpp" #include "traccc/geometry/silicon_detector_description.hpp" -#if defined(ALPAKA_ACC_GPU_CUDA_ENABLED) -#include -#include -#include -#elif defined(ALPAKA_ACC_GPU_HIP_ENABLED) -#include -#include -#include -#endif - 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; - -#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 + 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);