Skip to content

Commit

Permalink
Specialize gather/scatter for xsimd in n-body
Browse files Browse the repository at this point in the history
  • Loading branch information
bernhardmgruber committed Jan 1, 2024
1 parent abf44ef commit 1c2e499
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
16 changes: 16 additions & 0 deletions examples/alpaka/nbody/nbody.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,22 @@ struct llama::SimdTraits<Batch, std::enable_if_t<xsimd::is_batch<Batch>::value>>
{
batch.store_unaligned(mem);
}

static LLAMA_FORCE_INLINE auto indicesToReg(std::array<int, lanes> indices)
{
return [&]<std::size_t... Is>(std::index_sequence<Is...>)
{ return xsimd::batch<int, typename Batch::arch_type>(indices[Is]...); }(std::make_index_sequence<lanes>{});
}

static LLAMA_FORCE_INLINE auto gather(const value_type* mem, std::array<int, lanes> indices) -> Batch
{
return Batch::gather(mem, indicesToReg(indices));
}

static LLAMA_FORCE_INLINE void scatter(Batch batch, value_type* mem, std::array<int, lanes> indices)
{
batch.scatter(mem, indicesToReg(indices));
}
};

template<typename T>
Expand Down
16 changes: 16 additions & 0 deletions examples/nbody/nbody.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,22 @@ struct llama::SimdTraits<Batch, std::enable_if_t<xsimd::is_batch<Batch>::value>>
{
batch.store_unaligned(mem);
}

static LLAMA_FORCE_INLINE auto indicesToReg(std::array<int, lanes> indices)
{
return [&]<std::size_t... Is>(std::index_sequence<Is...>)
{ return xsimd::batch<int, typename Batch::arch_type>(indices[Is]...); }(std::make_index_sequence<lanes>{});
}

static LLAMA_FORCE_INLINE auto gather(const value_type* mem, std::array<int, lanes> indices) -> Batch
{
return Batch::gather(mem, indicesToReg(indices));
}

static LLAMA_FORCE_INLINE void scatter(Batch batch, value_type* mem, std::array<int, lanes> indices)
{
batch.scatter(mem, indicesToReg(indices));
}
};

template<typename T>
Expand Down

0 comments on commit 1c2e499

Please sign in to comment.