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

Require multiple threads for Alpaka CCL code #644

Merged
merged 1 commit into from
Jul 17, 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
3 changes: 3 additions & 0 deletions device/alpaka/src/clusterization/clusterization_algorithm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ clusterization_algorithm::output_type clusterization_algorithm::operator()(
// Launch ccl kernel. Each thread will handle a single cell.
const device::details::ccl_kernel_helper helper{
m_target_cells_per_partition, num_cells};
static_assert(accSupportsMultiThreadBlocks<Acc>(),
"Clustering algorithm must be compiled for an accelerator "
"with support for multi-thread blocks.");
auto workDiv =
makeWorkDiv<Acc>(helper.num_partitions, helper.threads_per_partition);

Expand Down
15 changes: 13 additions & 2 deletions device/alpaka/src/utils/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,22 @@ static constexpr std::size_t warpSize =
4;
#endif

template <typename TAcc>
constexpr bool accSupportsMultiThreadBlocks() {
if constexpr (::alpaka::accMatchesTags<TAcc, ::alpaka::TagGpuCudaRt> ||
::alpaka::accMatchesTags<TAcc, ::alpaka::TagGpuHipRt> ||
::alpaka::accMatchesTags<TAcc, ::alpaka::TagCpuOmp2Threads> ||
::alpaka::accMatchesTags<TAcc, ::alpaka::TagCpuThreads>) {
return true;
} else {
return false;
}
}

template <typename TAcc>
inline WorkDiv makeWorkDiv(Idx blocks, Idx threadsOrElements) {
const Idx blocksPerGrid = std::max(Idx{1}, blocks);
if constexpr (::alpaka::accMatchesTags<TAcc, ::alpaka::TagGpuCudaRt> ||
::alpaka::accMatchesTags<TAcc, ::alpaka::TagGpuHipRt>) {
if constexpr (accSupportsMultiThreadBlocks<TAcc>()) {
const Idx threadsPerBlock(threadsOrElements);
const Idx elementsPerThread = Idx{1};
return WorkDiv{blocksPerGrid, threadsPerBlock, elementsPerThread};
Expand Down
Loading