Viskores  1.0
RuntimeDeviceConfigurationTBB.h
Go to the documentation of this file.
1 //============================================================================
2 // The contents of this file are covered by the Viskores license. See
3 // LICENSE.txt for details.
4 //
5 // By contributing to this file, all contributors agree to the Developer
6 // Certificate of Origin Version 1.1 (DCO 1.1) as stated in DCO.txt.
7 //============================================================================
8 
9 //============================================================================
10 // Copyright (c) Kitware, Inc.
11 // All rights reserved.
12 // See LICENSE.txt for details.
13 //
14 // This software is distributed WITHOUT ANY WARRANTY; without even
15 // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
16 // PURPOSE. See the above copyright notice for more information.
17 //============================================================================
18 #ifndef viskores_cont_tbb_internal_RuntimeDeviceConfigurationTBB_h
19 #define viskores_cont_tbb_internal_RuntimeDeviceConfigurationTBB_h
20 
23 
25 #if TBB_VERSION_MAJOR >= 2020
26 #define TBB_PREVIEW_GLOBAL_CONTROL
27 #include <tbb/global_control.h>
28 #include <tbb/task_arena.h>
29 #else
30 #include <tbb/tbb.h>
31 #endif
33 
34 #include <memory>
35 
36 namespace viskores
37 {
38 namespace cont
39 {
40 namespace internal
41 {
42 
43 template <>
44 class RuntimeDeviceConfiguration<viskores::cont::DeviceAdapterTagTBB>
45  : public viskores::cont::internal::RuntimeDeviceConfigurationBase
46 {
47 public:
49  RuntimeDeviceConfiguration<viskores::cont::DeviceAdapterTagTBB>()
50  :
51 #if TBB_VERSION_MAJOR >= 2020
52  HardwareMaxThreads(::tbb::task_arena{}.max_concurrency())
53  ,
54 #else
55  HardwareMaxThreads(::tbb::task_scheduler_init::default_num_threads())
56  ,
57 #endif
58  CurrentNumThreads(this->HardwareMaxThreads)
59  {
60  }
61 
62  VISKORES_CONT viskores::cont::DeviceAdapterId GetDevice() const final
63  {
65  }
66 
67  VISKORES_CONT RuntimeDeviceConfigReturnCode SetThreads(const viskores::Id& value) final
68  {
69  this->CurrentNumThreads = value > 0 ? value : this->HardwareMaxThreads;
70 #if TBB_VERSION_MAJOR >= 2020
71  GlobalControl.reset(new ::tbb::global_control(::tbb::global_control::max_allowed_parallelism,
72  this->CurrentNumThreads));
73 #else
74  TaskSchedulerInit.reset(
75  new ::tbb::task_scheduler_init(static_cast<int>(this->CurrentNumThreads)));
76 #endif
77  return RuntimeDeviceConfigReturnCode::SUCCESS;
78  }
79 
80  VISKORES_CONT RuntimeDeviceConfigReturnCode GetThreads(viskores::Id& value) const final
81  {
82 #if TBB_VERSION_MAJOR >= 2020
83  value = ::tbb::global_control::active_value(::tbb::global_control::max_allowed_parallelism);
84 #else
85  value = this->CurrentNumThreads;
86 #endif
87  return RuntimeDeviceConfigReturnCode::SUCCESS;
88  }
89 
90  VISKORES_CONT RuntimeDeviceConfigReturnCode GetMaxThreads(viskores::Id& value) const final
91  {
92  value = this->HardwareMaxThreads;
93  return RuntimeDeviceConfigReturnCode::SUCCESS;
94  }
95 
96 private:
97 #if TBB_VERSION_MAJOR >= 2020
98  std::unique_ptr<::tbb::global_control> GlobalControl;
99 #else
100  std::unique_ptr<::tbb::task_scheduler_init> TaskSchedulerInit;
101 #endif
102  viskores::Id HardwareMaxThreads;
103  viskores::Id CurrentNumThreads;
104 };
105 } // namespace vktm::cont::internal
106 } // namespace viskores::cont
107 } // namespace viskores
108 
109 #endif //viskores_cont_tbb_internal_RuntimeDeviceConfigurationTBB_h
VISKORES_THIRDPARTY_POST_INCLUDE
#define VISKORES_THIRDPARTY_POST_INCLUDE
Definition: Configure.h:200
DeviceAdapterTagTBB.h
viskores::Id
viskores::Int64 Id
Base type to use to index arrays.
Definition: Types.h:235
VISKORES_CONT
#define VISKORES_CONT
Definition: ExportMacros.h:65
viskores
Groups connected points that have the same field value.
Definition: Atomic.h:27
RuntimeDeviceConfiguration.h
viskores::cont::DeviceAdapterId
An object used to specify a device.
Definition: DeviceAdapterTag.h:66
viskores::cont::DeviceAdapterTagTBB
Tag for a device adapter that uses the Intel Threading Building Blocks library to run algorithms on m...
Definition: DeviceAdapterTagTBB.h:37
VISKORES_THIRDPARTY_PRE_INCLUDE
#define VISKORES_THIRDPARTY_PRE_INCLUDE
Definition: Configure.h:199