VTK-m  2.2
RuntimeDeviceConfigurationTBB.h
Go to the documentation of this file.
1 //============================================================================
2 // Copyright (c) Kitware, Inc.
3 // All rights reserved.
4 // See LICENSE.txt for details.
5 //
6 // This software is distributed WITHOUT ANY WARRANTY; without even
7 // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
8 // PURPOSE. See the above copyright notice for more information.
9 //============================================================================
10 #ifndef vtk_m_cont_tbb_internal_RuntimeDeviceConfigurationTBB_h
11 #define vtk_m_cont_tbb_internal_RuntimeDeviceConfigurationTBB_h
12 
15 
17 #if TBB_VERSION_MAJOR >= 2020
18 #define TBB_PREVIEW_GLOBAL_CONTROL
19 #include <tbb/global_control.h>
20 #include <tbb/task_arena.h>
21 #else
22 #include <tbb/tbb.h>
23 #endif
25 
26 #include <memory>
27 
28 namespace vtkm
29 {
30 namespace cont
31 {
32 namespace internal
33 {
34 
35 template <>
36 class RuntimeDeviceConfiguration<vtkm::cont::DeviceAdapterTagTBB>
37  : public vtkm::cont::internal::RuntimeDeviceConfigurationBase
38 {
39 public:
40  VTKM_CONT
41  RuntimeDeviceConfiguration<vtkm::cont::DeviceAdapterTagTBB>()
42  :
43 #if TBB_VERSION_MAJOR >= 2020
44  HardwareMaxThreads(::tbb::task_arena{}.max_concurrency())
45  ,
46 #else
47  HardwareMaxThreads(::tbb::task_scheduler_init::default_num_threads())
48  ,
49 #endif
50  CurrentNumThreads(this->HardwareMaxThreads)
51  {
52  }
53 
54  VTKM_CONT vtkm::cont::DeviceAdapterId GetDevice() const final
55  {
57  }
58 
59  VTKM_CONT RuntimeDeviceConfigReturnCode SetThreads(const vtkm::Id& value) final
60  {
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));
65 #else
66  TaskSchedulerInit.reset(
67  new ::tbb::task_scheduler_init(static_cast<int>(this->CurrentNumThreads)));
68 #endif
69  return RuntimeDeviceConfigReturnCode::SUCCESS;
70  }
71 
72  VTKM_CONT RuntimeDeviceConfigReturnCode GetThreads(vtkm::Id& value) const final
73  {
74 #if TBB_VERSION_MAJOR >= 2020
75  value = ::tbb::global_control::active_value(::tbb::global_control::max_allowed_parallelism);
76 #else
77  value = this->CurrentNumThreads;
78 #endif
79  return RuntimeDeviceConfigReturnCode::SUCCESS;
80  }
81 
82  VTKM_CONT RuntimeDeviceConfigReturnCode GetMaxThreads(vtkm::Id& value) const final
83  {
84  value = this->HardwareMaxThreads;
85  return RuntimeDeviceConfigReturnCode::SUCCESS;
86  }
87 
88 private:
89 #if TBB_VERSION_MAJOR >= 2020
90  std::unique_ptr<::tbb::global_control> GlobalControl;
91 #else
92  std::unique_ptr<::tbb::task_scheduler_init> TaskSchedulerInit;
93 #endif
94  vtkm::Id HardwareMaxThreads;
95  vtkm::Id CurrentNumThreads;
96 };
97 } // namespace vktm::cont::internal
98 } // namespace vtkm::cont
99 } // namespace vtkm
100 
101 #endif //vtk_m_cont_tbb_internal_RuntimeDeviceConfigurationTBB_h
VTKM_THIRDPARTY_POST_INCLUDE
#define VTKM_THIRDPARTY_POST_INCLUDE
Definition: Configure.h:192
vtkm
Groups connected points that have the same field value.
Definition: Atomic.h:19
DeviceAdapterTagTBB.h
RuntimeDeviceConfiguration.h
VTKM_CONT
#define VTKM_CONT
Definition: ExportMacros.h:57
vtkm::cont::DeviceAdapterTagTBB
Tag for a device adapter that uses the Intel Threading Building Blocks library to run algorithms on m...
Definition: DeviceAdapterTagTBB.h:27
vtkm::Id
vtkm::Int64 Id
Base type to use to index arrays.
Definition: Types.h:227
vtkm::cont::DeviceAdapterId
An object used to specify a device.
Definition: DeviceAdapterTag.h:58
VTKM_THIRDPARTY_PRE_INCLUDE
#define VTKM_THIRDPARTY_PRE_INCLUDE
Definition: Configure.h:191