Skip to content

Commit

Permalink
Update alpaka nbody to C++20 and simplify
Browse files Browse the repository at this point in the history
  • Loading branch information
bernhardmgruber committed Jan 6, 2024
1 parent 1e2c4bc commit 1fa8e77
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 16 deletions.
2 changes: 1 addition & 1 deletion examples/alpaka/nbody/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ if (NOT TARGET llama::llama)
endif()
find_package(alpaka 1.0 REQUIRED)
alpaka_add_executable(${PROJECT_NAME} nbody.cpp ../../common/Stopwatch.hpp)
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_17)
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_20)
target_link_libraries(${PROJECT_NAME} PRIVATE llama::llama fmt::fmt alpaka::alpaka xsimd)

if (MSVC)
Expand Down
23 changes: 8 additions & 15 deletions examples/alpaka/nbody/nbody.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,18 +166,7 @@ LLAMA_FN_HOST_ACC_INLINE void pPInteraction(const Acc& acc, ParticleRefI& pis, P
template<int ThreadsPerBlock, int SharedElementsPerBlock, int ElementsPerThread, typename QuotedSMMapping>
struct UpdateKernel
{
// TODO(bgruber): make this an IILE in C++20
template<typename Mapping, typename Acc, std::size_t... Is>
ALPAKA_FN_HOST_ACC auto makeSharedViewHelper(const Acc& acc, std::index_sequence<Is...>) const
{
return llama::View{
Mapping{},
llama::Array<std::byte*, sizeof...(Is)>{
alpaka::declareSharedVar<std::byte[Mapping{}.blobSize(Is)], Is>(acc)...}};
}

template<typename Acc, typename View>
ALPAKA_FN_HOST_ACC void operator()(const Acc& acc, View particles) const
ALPAKA_FN_HOST_ACC void operator()(const auto& acc, auto particles) const
{
auto sharedView = [&]
{
Expand All @@ -191,7 +180,12 @@ struct UpdateKernel
{
using Mapping = typename QuotedSMMapping::
template fn<llama::ArrayExtents<int, SharedElementsPerBlock>, SharedMemoryParticle>;
return makeSharedViewHelper<Mapping>(acc, std::make_index_sequence<Mapping::blobCount>{});
return [&]<std::size_t... Is>(std::index_sequence<Is...>)
{
return llama::View{
Mapping{},
llama::Array{alpaka::declareSharedVar<std::byte[Mapping{}.blobSize(Is)], Is>(acc)...}};
}(std::make_index_sequence<Mapping::blobCount>{});
}
}();

Expand All @@ -217,8 +211,7 @@ struct UpdateKernel
template<int ElementsPerThread>
struct MoveKernel
{
template<typename Acc, typename View>
ALPAKA_FN_HOST_ACC void operator()(const Acc& acc, View particles) const
ALPAKA_FN_HOST_ACC void operator()(const auto& acc, auto particles) const
{
const auto ti = alpaka::getIdx<alpaka::Grid, alpaka::Threads>(acc)[0];
const auto i = ti * ElementsPerThread;
Expand Down

0 comments on commit 1fa8e77

Please sign in to comment.