10 #ifndef vtk_m_cont_tbb_internal_RuntimeDeviceConfigurationTBB_h
11 #define vtk_m_cont_tbb_internal_RuntimeDeviceConfigurationTBB_h
16 VTKM_THIRDPARTY_PRE_INCLUDE
17 #if TBB_VERSION_MAJOR >= 2020
18 #define TBB_PREVIEW_GLOBAL_CONTROL
19 #include <tbb/global_control.h>
20 #include <tbb/task_arena.h>
24 VTKM_THIRDPARTY_POST_INCLUDE
36 class RuntimeDeviceConfiguration<
vtkm::cont::DeviceAdapterTagTBB>
37 :
public vtkm::cont::internal::RuntimeDeviceConfigurationBase
41 RuntimeDeviceConfiguration<vtkm::cont::DeviceAdapterTagTBB>()
43 #if TBB_VERSION_MAJOR >= 2020
44 HardwareMaxThreads(::tbb::task_arena{}.max_concurrency())
47 HardwareMaxThreads(::tbb::task_scheduler_init::default_num_threads())
50 CurrentNumThreads(this->HardwareMaxThreads)
56 return vtkm::cont::DeviceAdapterTagTBB{};
59 VTKM_CONT virtual RuntimeDeviceConfigReturnCode SetThreads(
const vtkm::Id& value)
override final
61 this->CurrentNumThreads = value > 0 ? value : this->HardwareMaxThreads;
62 #if TBB_VERSION_MAJOR >= 2020
63 GlobalControl.reset(new ::tbb::global_control(::tbb::global_control::max_allowed_parallelism,
64 this->CurrentNumThreads));
66 TaskSchedulerInit.reset(
67 new ::tbb::task_scheduler_init(
static_cast<int>(this->CurrentNumThreads)));
69 return RuntimeDeviceConfigReturnCode::SUCCESS;
72 VTKM_CONT virtual RuntimeDeviceConfigReturnCode GetThreads(
vtkm::Id& value)
const override final
74 #if TBB_VERSION_MAJOR >= 2020
75 value = ::tbb::global_control::active_value(::tbb::global_control::max_allowed_parallelism);
77 value = this->CurrentNumThreads;
79 return RuntimeDeviceConfigReturnCode::SUCCESS;
82 VTKM_CONT virtual RuntimeDeviceConfigReturnCode GetMaxThreads(
83 vtkm::Id& value)
const override final
85 value = this->HardwareMaxThreads;
86 return RuntimeDeviceConfigReturnCode::SUCCESS;
90 #if TBB_VERSION_MAJOR >= 2020
91 std::unique_ptr<::tbb::global_control> GlobalControl;
93 std::unique_ptr<::tbb::task_scheduler_init> TaskSchedulerInit;
102 #endif //vtk_m_cont_tbb_internal_RuntimeDeviceConfigurationTBB_h