mirror of
https://gitlab.kitware.com/vtk/vtk-m
synced 2024-09-08 21:33:55 +00:00
Use TBB task_group for radix sort
TBB 2020 introduced a new class called `task_group`. TBB 2021 removed the old class `task` as its functionality was replaced by `task_group`. Our parallel radix sort for TBB was implemented using `task`s, so change it to use `task_group` (which actually cleans up the code a bit).
This commit is contained in:
parent
904e784e89
commit
1eea0bee12
@ -485,7 +485,7 @@ struct RunTask
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <typename ThreaderData = void*>
|
template <typename ThreaderData = void*>
|
||||||
void operator()(ThreaderData tData = nullptr)
|
void operator()(ThreaderData tData = nullptr) const
|
||||||
{
|
{
|
||||||
size_t num_nodes_at_current_height = (size_t)pow(2, (double)binary_tree_height_);
|
size_t num_nodes_at_current_height = (size_t)pow(2, (double)binary_tree_height_);
|
||||||
if (num_threads_ <= num_nodes_at_current_height)
|
if (num_threads_ <= num_nodes_at_current_height)
|
||||||
|
@ -53,7 +53,7 @@
|
|||||||
// correct settings so that we don't clobber any existing function
|
// correct settings so that we don't clobber any existing function
|
||||||
#include <vtkm/internal/Windows.h>
|
#include <vtkm/internal/Windows.h>
|
||||||
|
|
||||||
#include <tbb/task.h>
|
#include <tbb/tbb.h>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
|
|
||||||
#if defined(VTKM_MSVC)
|
#if defined(VTKM_MSVC)
|
||||||
@ -71,6 +71,7 @@ namespace sort
|
|||||||
|
|
||||||
const size_t MAX_CORES = std::thread::hardware_concurrency();
|
const size_t MAX_CORES = std::thread::hardware_concurrency();
|
||||||
|
|
||||||
|
#if TBB_VERSION_MAJOR < 2020
|
||||||
// Simple TBB task wrapper around a generic functor.
|
// Simple TBB task wrapper around a generic functor.
|
||||||
template <typename FunctorType>
|
template <typename FunctorType>
|
||||||
struct TaskWrapper : public ::tbb::task
|
struct TaskWrapper : public ::tbb::task
|
||||||
@ -94,7 +95,7 @@ struct RadixThreaderTBB
|
|||||||
size_t GetAvailableCores() const { return MAX_CORES; }
|
size_t GetAvailableCores() const { return MAX_CORES; }
|
||||||
|
|
||||||
template <typename TaskType>
|
template <typename TaskType>
|
||||||
void RunParentTask(TaskType task)
|
void RunParentTask(TaskType task) const
|
||||||
{
|
{
|
||||||
using Task = TaskWrapper<TaskType>;
|
using Task = TaskWrapper<TaskType>;
|
||||||
Task& root = *new (::tbb::task::allocate_root()) Task(task);
|
Task& root = *new (::tbb::task::allocate_root()) Task(task);
|
||||||
@ -102,7 +103,7 @@ struct RadixThreaderTBB
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <typename TaskType>
|
template <typename TaskType>
|
||||||
void RunChildTasks(TaskWrapper<TaskType>* wrapper, TaskType left, TaskType right)
|
void RunChildTasks(TaskWrapper<TaskType>* wrapper, TaskType left, TaskType right) const
|
||||||
{
|
{
|
||||||
using Task = TaskWrapper<TaskType>;
|
using Task = TaskWrapper<TaskType>;
|
||||||
::tbb::empty_task& p = *new (wrapper->allocate_continuation())::tbb::empty_task();
|
::tbb::empty_task& p = *new (wrapper->allocate_continuation())::tbb::empty_task();
|
||||||
@ -115,6 +116,34 @@ struct RadixThreaderTBB
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#else // TBB_VERSION_MAJOR >= 2020
|
||||||
|
|
||||||
|
// In TBB version 2020, the task class was deprecated. Instead, we use the simpler task_group.
|
||||||
|
|
||||||
|
struct RadixThreaderTBB
|
||||||
|
{
|
||||||
|
std::shared_ptr<::tbb::task_group> TaskGroup =
|
||||||
|
std::shared_ptr<::tbb::task_group>(new ::tbb::task_group);
|
||||||
|
|
||||||
|
size_t GetAvailableCores() const { return MAX_CORES; }
|
||||||
|
|
||||||
|
template <typename TaskType>
|
||||||
|
void RunParentTask(TaskType task) const
|
||||||
|
{
|
||||||
|
this->TaskGroup->run_and_wait(task);
|
||||||
|
// All tasks should be complete at this point.
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename TaskType>
|
||||||
|
void RunChildTasks(void*, TaskType left, TaskType right) const
|
||||||
|
{
|
||||||
|
this->TaskGroup->run(left);
|
||||||
|
this->TaskGroup->run(right);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
VTKM_INSTANTIATE_RADIX_SORT_FOR_THREADER(RadixThreaderTBB)
|
VTKM_INSTANTIATE_RADIX_SORT_FOR_THREADER(RadixThreaderTBB)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user