Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make alpaka work with SYCL #785

Merged
merged 9 commits into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,6 @@ if( TRACCC_SETUP_ALPAKA )
# Default options for the Alpaka build.
set( alpaka_ACC_CPU_B_SEQ_T_THREADS_ENABLE TRUE CACHE BOOL
"Enable the serial backend of Alpaka" )

if( TRACCC_USE_SYSTEM_ALPAKA )
find_package( alpaka REQUIRED )
else()
Expand Down
13 changes: 13 additions & 0 deletions cmake/traccc-alpaka-functions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,16 @@ function( traccc_add_alpaka_library fullname basename )
endif()

endfunction( traccc_add_alpaka_library )

macro (traccc_enable_language_alpaka)
#enable_language cannot be called by a function: put it in a macro
if(alpaka_ACC_GPU_CUDA_ENABLE)
enable_language(CUDA)
include( traccc-compiler-options-cuda )
elseif(alpaka_ACC_GPU_HIP_ENABLE)
enable_language(HIP)
elseif(alpaka_ACC_SYCL_ENABLE)
enable_language(SYCL)
include( traccc-compiler-options-sycl )
endif()
endmacro(traccc_enable_language_alpaka)
9 changes: 5 additions & 4 deletions device/alpaka/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,16 @@ include( traccc-compiler-options-cpp )
set(PUBLIC_LIBRARIES traccc::core traccc::device_common vecmem::core covfie::core)
set(PRIVATE_LIBRARIES alpaka::alpaka traccc::Thrust)

if(alpaka_ACC_GPU_CUDA_ENABLE)
enable_language(CUDA)
include( traccc-compiler-options-cuda )
traccc_enable_language_alpaka()

if(alpaka_ACC_GPU_CUDA_ENABLE)
list(APPEND PRIVATE_LIBRARIES CUDA::cudart vecmem::cuda)
elseif(alpaka_ACC_GPU_HIP_ENABLE)
enable_language(HIP)
find_package( HIPToolkit REQUIRED )
list(APPEND PRIVATE_LIBRARIES HIP::hiprt vecmem::hip)
elseif(alpaka_ACC_SYCL_ENABLE)
include( traccc-compiler-options-sycl )
list(APPEND PRIVATE_LIBRARIES vecmem::sycl)
endif()

traccc_add_alpaka_library( traccc_alpaka alpaka TYPE SHARED
Expand Down
8 changes: 5 additions & 3 deletions device/alpaka/include/traccc/alpaka/utils/vecmem_types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#elif defined(ALPAKA_ACC_SYCL_ENABLED)
#include <vecmem/memory/sycl/device_memory_resource.hpp>
#include <vecmem/memory/sycl/host_memory_resource.hpp>
#include <vecmem/memory/sycl/shared_memory_resource.hpp>
#include <vecmem/utils/sycl/copy.hpp>

#else
Expand Down Expand Up @@ -52,7 +53,7 @@ class copy;
namespace sycl {
class host_memory_resource;
class device_memory_resource;
class managed_memory_resource;
class shared_memory_resource;
class copy;
} // namespace sycl
} // namespace vecmem
Expand Down Expand Up @@ -84,20 +85,21 @@ 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 managed_memory_resource = ::vecmem::sycl::shared_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 managed_memory_resource = ::vecmem::sycl::shared_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 managed_memory_resource = ::vecmem::sycl::shared_memory_resource;
using device_copy = ::vecmem::sycl::copy;
};
} // namespace traccc::alpaka::vecmem
11 changes: 7 additions & 4 deletions examples/run/alpaka/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,20 @@ set(TRACCC_ALPAKA_EXAMPLE_SOURCES
seeding_example_alpaka.cpp
)

include(traccc-alpaka-functions)
traccc_enable_language_alpaka()

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)
list (APPEND EXTRA_LIBS vecmem::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)
elseif(alpaka_ACC_SYCL_ENABLE)
list(APPEND EXTRA_LIBS vecmem::sycl)
set_source_files_properties(${TRACCC_ALPAKA_EXAMPLE_SOURCES} PROPERTIES LANGUAGE SYCL)
endif()

set(LIBRARIES vecmem::core traccc::io traccc::performance
Expand Down
20 changes: 20 additions & 0 deletions examples/run/alpaka/seeding_example_alpaka.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@
#include "detray/propagator/propagator.hpp"
#include "detray/propagator/rk_stepper.hpp"
#include "traccc/alpaka/utils/vecmem_types.hpp"
#ifdef ALPAKA_ACC_SYCL_ENABLED
#include <sycl/sycl.hpp>
#include <vecmem/utils/sycl/queue_wrapper.hpp>
#endif

// System include(s).
#include <exception>
Expand All @@ -63,6 +67,21 @@ int seq_run(const traccc::opts::track_seeding& seeding_opts,
using Idx = uint32_t;

using Acc = ::alpaka::ExampleDefaultAcc<Dim, Idx>;
#ifdef ALPAKA_ACC_SYCL_ENABLED
::sycl::queue q;
vecmem::sycl::queue_wrapper qw{&q};
traccc::alpaka::vecmem::host_device_types<
::alpaka::trait::AccToTag<Acc>::type>::device_copy copy(qw);
traccc::alpaka::vecmem::host_device_types<
::alpaka::trait::AccToTag<Acc>::type>::host_memory_resource host_mr(qw);
traccc::alpaka::vecmem::host_device_types<
::alpaka::trait::AccToTag<Acc>::type>::device_memory_resource
device_mr(qw);
traccc::alpaka::vecmem::host_device_types<
::alpaka::trait::AccToTag<Acc>::type>::managed_memory_resource
mng_mr(qw);
traccc::memory_resource mr{device_mr, &host_mr};
#else
traccc::alpaka::vecmem::host_device_types<
::alpaka::trait::AccToTag<Acc>::type>::device_copy copy;
traccc::alpaka::vecmem::host_device_types<
Expand All @@ -72,6 +91,7 @@ int seq_run(const traccc::opts::track_seeding& seeding_opts,
traccc::alpaka::vecmem::host_device_types<
::alpaka::trait::AccToTag<Acc>::type>::managed_memory_resource mng_mr;
traccc::memory_resource mr{device_mr, &host_mr};
#endif

// Performance writer
traccc::seeding_performance_writer sd_performance_writer(
Expand Down
19 changes: 18 additions & 1 deletion examples/run/alpaka/seq_example_alpaka.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@
#include "traccc/alpaka/seeding/spacepoint_formation_algorithm.hpp"
#include "traccc/alpaka/seeding/track_params_estimation.hpp"
#include "traccc/alpaka/utils/vecmem_types.hpp"
#ifdef ALPAKA_ACC_SYCL_ENABLED
#include <sycl/sycl.hpp>
#include <vecmem/utils/sycl/queue_wrapper.hpp>
#endif

#include "traccc/clusterization/clusterization_algorithm.hpp"
#include "traccc/efficiency/seeding_performance_writer.hpp"
#include "traccc/io/read_cells.hpp"
Expand Down Expand Up @@ -65,12 +70,24 @@ int seq_run(const traccc::opts::detector& detector_opts,

using Acc = ::alpaka::ExampleDefaultAcc<Dim, Idx>;
// Memory resources used by the application.
#ifdef ALPAKA_ACC_SYCL_ENABLED
::sycl::queue q;
vecmem::sycl::queue_wrapper qw{&q};
traccc::alpaka::vecmem::host_device_types<
alpaka::trait::AccToTag<Acc>::type>::host_memory_resource host_mr;
alpaka::trait::AccToTag<Acc>::type>::device_copy copy(qw);
traccc::alpaka::vecmem::host_device_types<
alpaka::trait::AccToTag<Acc>::type>::host_memory_resource host_mr(qw);
traccc::alpaka::vecmem::host_device_types<
alpaka::trait::AccToTag<Acc>::type>::device_memory_resource
device_mr(qw);
#else
traccc::alpaka::vecmem::host_device_types<
alpaka::trait::AccToTag<Acc>::type>::device_copy copy;
traccc::alpaka::vecmem::host_device_types<
alpaka::trait::AccToTag<Acc>::type>::host_memory_resource host_mr;
traccc::alpaka::vecmem::host_device_types<
alpaka::trait::AccToTag<Acc>::type>::device_memory_resource device_mr;
#endif
traccc::memory_resource mr{device_mr, &host_mr};

// Construct the detector description object.
Expand Down
10 changes: 7 additions & 3 deletions tests/alpaka/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,19 @@ set(TRACCC_ALPAKA_TEST_SOURCES
test_cca.cpp
)


include(traccc-alpaka-functions)
traccc_enable_language_alpaka()

if(alpaka_ACC_GPU_CUDA_ENABLE)
enable_language(CUDA)
set_source_files_properties(${TRACCC_ALPAKA_TEST_SOURCES} PROPERTIES LANGUAGE CUDA)
include( traccc-compiler-options-cuda )
list(APPEND DEVICE_LIBRARIES vecmem::cuda)
elseif(alpaka_ACC_GPU_HIP_ENABLE)
enable_language(HIP)
set_source_files_properties(${TRACCC_ALPAKA_TEST_SOURCES} PROPERTIES LANGUAGE HIP)
list(APPEND DEVICE_LIBRARIES vecmem::hip)
elseif(alpaka_ACC_SYCL_ENABLE)
list(APPEND DEVICE_LIBRARIES vecmem::sycl)
set_source_files_properties(${TRACCC_ALPAKA_TEST_SOURCES} PROPERTIES LANGUAGE SYCL)
endif()

traccc_add_test( alpaka
Expand Down
34 changes: 17 additions & 17 deletions tests/alpaka/alpaka_basic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,11 @@
#include <vecmem/memory/host_memory_resource.hpp>
#include <vecmem/utils/copy.hpp>

#if defined(ALPAKA_ACC_GPU_CUDA_ENABLED)
#include <vecmem/memory/cuda/device_memory_resource.hpp>
#include <vecmem/memory/cuda/host_memory_resource.hpp>
#include <vecmem/utils/cuda/copy.hpp>
#elif defined(ALPAKA_ACC_GPU_HIP_ENABLED)
#include <vecmem/memory/hip/device_memory_resource.hpp>
#include <vecmem/memory/hip/host_memory_resource.hpp>
#include <vecmem/utils/hip/copy.hpp>
#include "traccc/alpaka/utils/vecmem_types.hpp"

#ifdef ALPAKA_ACC_SYCL_ENABLED
#include <sycl/sycl.hpp>
#include <vecmem/utils/sycl/queue_wrapper.hpp>
#endif

// GoogleTest include(s).
Expand Down Expand Up @@ -139,18 +136,21 @@ GTEST_TEST(AlpakaBasic, VecMemOp) {
using WorkDiv = WorkDivMembers<Dim, Idx>;
auto workDiv = WorkDiv{blocksPerGrid, threadsPerBlock, elementsPerThread};

vecmem::host_memory_resource host_mr;
#if defined(ALPAKA_ACC_GPU_CUDA_ENABLED)
vecmem::cuda::copy vm_copy;
vecmem::cuda::device_memory_resource device_mr;
#elif defined(ALPAKA_ACC_GPU_HIP_ENABLED)
vecmem::hip::copy vm_copy;
vecmem::hip::device_memory_resource device_mr;
#ifdef ALPAKA_ACC_SYCL_ENABLED
::sycl::queue q;
vecmem::sycl::queue_wrapper qw{&q};
traccc::alpaka::vecmem::host_device_types<
alpaka::trait::AccToTag<Acc>::type>::device_copy vm_copy(qw);
#else
vecmem::copy vm_copy;
vecmem::host_memory_resource device_mr;
traccc::alpaka::vecmem::host_device_types<
alpaka::trait::AccToTag<Acc>::type>::device_copy vm_copy;
#endif

traccc::alpaka::vecmem::host_device_types<
alpaka::trait::AccToTag<Acc>::type>::host_memory_resource host_mr;
traccc::alpaka::vecmem::host_device_types<
alpaka::trait::AccToTag<Acc>::type>::device_memory_resource device_mr;

vecmem::vector<float> host_vector{n, &host_mr};

auto host_buffer = vecmem::get_data(host_vector);
Expand Down
18 changes: 18 additions & 0 deletions tests/alpaka/test_cca.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@
#include <functional>
#include <vecmem/memory/host_memory_resource.hpp>

#ifdef ALPAKA_ACC_SYCL_ENABLED
#include <sycl/sycl.hpp>
#include <vecmem/utils/sycl/queue_wrapper.hpp>
#endif

#include "tests/cca_test.hpp"
#include "traccc/alpaka/clusterization/clusterization_algorithm.hpp"
#include "traccc/alpaka/utils/vecmem_types.hpp"
Expand All @@ -31,13 +36,26 @@ cca_function_t get_f_with(traccc::clustering_config cfg) {
using Idx = uint32_t;

using Acc = ExampleDefaultAcc<Dim, Idx>;
#ifdef ALPAKA_ACC_SYCL_ENABLED
::sycl::queue q;
vecmem::sycl::queue_wrapper qw{&q};
traccc::alpaka::vecmem::host_device_types<
alpaka::trait::AccToTag<Acc>::type>::host_memory_resource
host_mr(qw);
traccc::alpaka::vecmem::host_device_types<
alpaka::trait::AccToTag<Acc>::type>::device_copy copy(qw);
traccc::alpaka::vecmem::host_device_types<
alpaka::trait::AccToTag<Acc>::type>::device_memory_resource
device_mr;
#else
traccc::alpaka::vecmem::host_device_types<
alpaka::trait::AccToTag<Acc>::type>::host_memory_resource host_mr;
traccc::alpaka::vecmem::host_device_types<
alpaka::trait::AccToTag<Acc>::type>::device_copy copy;
traccc::alpaka::vecmem::host_device_types<
alpaka::trait::AccToTag<Acc>::type>::device_memory_resource
device_mr;
#endif

traccc::alpaka::clusterization_algorithm cc({device_mr}, copy, cfg);

Expand Down
Loading