ITK  5.2.0
Insight Toolkit
itkFFTWGlobalConfiguration.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright NumFOCUS
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0.txt
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *=========================================================================*/
18 #ifndef itkFFTWGlobalConfiguration_h
19 #define itkFFTWGlobalConfiguration_h
20 
21 #include "itkObject.h"
22 // NOTE: Need to have at least one itk include before
23 // the next defines in order to have ITK_USE_FFTWF,ITK_USE_FFTWD defined
24 #if defined(ITK_USE_FFTWF) || defined(ITK_USE_FFTWD)
25 
26 # include "ITKFFTExport.h"
27 # include <mutex>
28 # include "itkSingletonMacro.h"
29 # include "itksys/SystemTools.hxx"
30 # include "itksys/SystemInformation.hxx"
31 # if defined(ITK_USE_CUFFTW)
32 # include "cufftw.h"
33 # else
34 # include "fftw3.h"
35 # endif
36 # include <algorithm>
37 # include <cctype>
38 
39 struct FFTWGlobalConfigurationGlobals;
40 
41 //* The fftw utilities help control the various strategies
42 // available for controlling optimizations for the FFTW library.
43 //
44 // Environmental variables:
45 // ITK_FFTW_PLAN_RIGOR - Defines how aggressive the generation of
46 // wisdom should be.
47 // ITK_FFTW_READ_WISDOM_CACHE - Defines if a wisdom file cache should
48 // be read if found. (it is "On" by default)
49 // ITK_FFTW_WRITE_WISDOM_CACHE - Defines if generated wisdom file cache
50 // should be written (it is "Off" by default)
51 // ITK_FFTW_WISDOM_CACHE_BASE - Defines the base directory where the
52 // fftw wisdom cache will be placed,
53 // this is intended to be used with auto-
54 // generated cache file names
55 // ITK_FFTW_WISDOM_CACHE_FILE - Defines the full name of the cache
56 // file to be generated. If this is
57 // set, then ITK_FFTW_WISDOM_CACHE_BASE
58 // is ignored.
59 //
60 // The above behaviors can also be controlled by the application.
61 //
62 
63 namespace itk
64 {
70 struct FFTWGlobalConfigurationGlobals;
71 
72 # ifdef _WIN32
73 # define FFTWPathSep "\\"
74 # else
75 # define FFTWPathSep "/"
76 # endif
77 
78 class ITKFFT_EXPORT WisdomFilenameGeneratorBase
79 {
80 public:
81  // The baseCacheDirectory from which to build the cache hierarchy
82  virtual std::string
83  GenerateWisdomFilename(const std::string & baseCacheDirectory) const = 0;
85  virtual ~WisdomFilenameGeneratorBase();
86 
87 private:
88 };
89 
91 {
92 public:
93  ManualWisdomFilenameGenerator(std::string wfn);
94  void
95  SetWisdomFilename(const std::string & wfn);
96  std::string
97  GenerateWisdomFilename(const std::string & baseCacheDirectory) const override;
98 
99 private:
100  std::string m_WisdomFilename;
101 };
102 
104 {
105 public:
106  std::string
107  GenerateWisdomFilename(const std::string & baseCacheDirectory) const override;
108 };
109 
111 {
112 public:
113  std::string
114  GenerateWisdomFilename(const std::string & baseCacheDirectory) const override;
115 };
116 
118 {
119 public:
121 
122  std::string
123  GenerateWisdomFilename(const std::string & baseCacheDirectory) const override;
124 
125  void
126  SetUseOSName(const bool flag);
127  void
128  SetUseOSRelease(const bool flag);
129  void
130  SetUseOSVersion(const bool flag);
131  void
132  SetUseOSPlatform(const bool flag);
133  void
134  SetUseOSBitSize(const bool flag);
135  void
136  SetUseNumberOfProcessors(const bool flag);
137  void
138  SetUseVendorString(const bool flag);
139  void
140  SetUseTypeID(const bool flag);
141  void
142  SetUseFamilyID(const bool flag);
143  void
144  SetUseModelID(const bool flag);
145  void
146  SetUseSteppingCode(const bool flag);
147 
148  bool
149  GetUseOSName() const;
150  bool
151  GetUseOSRelease() const;
152  bool
153  GetUseOSVersion() const;
154  bool
155  GetUseOSPlatform() const;
156  bool
157  GetUseOSBitSize() const;
158  bool
159  GetUseNumberOfProcessors() const;
160  bool
161  GetUseVendorString() const;
162  bool
163  GetUseTypeID() const;
164  bool
165  GetUseFamilyID() const;
166  bool
167  GetUseModelID() const;
168  bool
169  GetUseSteppingCode() const;
170 
171 private:
172  bool m_UseOSName{ true };
173  bool m_UseOSRelease{ false };
174  bool m_UseOSVersion{ false };
175  bool m_UseOSPlatform{ true };
176  bool m_UseOSBitSize{ true };
177  bool m_UseNumberOfProcessors{ true };
178  bool m_UseVendorString{ true };
179  bool m_UseVendorID{ false };
180  bool m_UseTypeID{ true };
181  bool m_UseFamilyID{ true };
182  bool m_UseModelID{ true };
183  bool m_UseSteppingCode{ true };
184 };
185 
203 class ITKFFT_EXPORT FFTWGlobalConfiguration : public Object
204 {
205 public:
206  ITK_DISALLOW_COPY_AND_MOVE(FFTWGlobalConfiguration);
207 
213  using MutexType = std::mutex;
214 
216  itkTypeMacro(FFTWGlobalConfiguration, Object);
217 
219  static std::mutex &
220  GetLockMutex();
221 
226  static void
227  SetNewWisdomAvailable(const bool & v);
228  static bool
229  GetNewWisdomAvailable();
231 
240  static void
241  SetPlanRigor(const int & v);
242 
243  static int
244  GetPlanRigor();
245  static void
246  SetPlanRigor(const std::string & name);
247 
249  static int
250  GetPlanRigorValue(const std::string & name);
251 
253  static std::string
254  GetPlanRigorName(const int & value);
255 
263  static void
264  SetReadWisdomCache(const bool & v);
265  static bool
266  GetReadWisdomCache();
268 
276  static void
277  SetWriteWisdomCache(const bool & v);
278  static bool
279  GetWriteWisdomCache();
281 
288  static void
289  SetWisdomCacheBase(const std::string & v);
290  static std::string
291  GetWisdomCacheBase();
293 
306  static void
307  SetWisdomFilenameGenerator(WisdomFilenameGeneratorBase * wfg);
308 
322  static std::string
323  GetWisdomFileDefaultBaseName();
324 
326  static bool
327  ImportWisdomFileDouble(const std::string & fname);
328  static bool
329  ExportWisdomFileDouble(const std::string & fname);
331 
333  static bool
334  ImportWisdomFileFloat(const std::string & fname);
335  static bool
336  ExportWisdomFileFloat(const std::string & fname);
338 
340  static bool
341  ImportDefaultWisdomFileDouble();
342  static bool
343  ExportDefaultWisdomFileDouble();
345 
347  static bool
348  ImportDefaultWisdomFileFloat();
349  static bool
350  ExportDefaultWisdomFileFloat();
352 
354  static bool
355  ImportDefaultWisdomFile();
356  static bool
357  ExportDefaultWisdomFile();
359 
360 private:
361  FFTWGlobalConfiguration(); // This will process env variables
362  ~FFTWGlobalConfiguration() override; // This will write cache file if requested.
363 
365  static Pointer
366  GetInstance();
367 
368  itkGetGlobalDeclarationMacro(FFTWGlobalConfigurationGlobals, PimplGlobals);
369 
370 
375  itkFactorylessNewMacro(Self);
376 
377  static FFTWGlobalConfigurationGlobals * m_PimplGlobals;
378 
379  std::mutex m_Lock;
380  bool m_NewWisdomAvailable{ false };
381  int m_PlanRigor{ 0 };
382  bool m_WriteWisdomCache{ false };
383  bool m_ReadWisdomCache{ true };
384  std::string m_WisdomCacheBase;
385  // m_WriteWisdomCache Controls the behavior of default
386  // wisdom file creation policies.
388 };
389 } // namespace itk
390 #endif
391 #endif
itk::FFTWGlobalConfiguration::MutexType
std::mutex MutexType
Definition: itkFFTWGlobalConfiguration.h:213
itk::ManualWisdomFilenameGenerator::m_WisdomFilename
std::string m_WisdomFilename
Definition: itkFFTWGlobalConfiguration.h:100
itk::FFTWGlobalConfiguration::m_Lock
std::mutex m_Lock
Definition: itkFFTWGlobalConfiguration.h:379
itkSingletonMacro.h
itk::SmartPointer< Self >
itk::FFTWGlobalConfiguration::m_WisdomCacheBase
std::string m_WisdomCacheBase
Definition: itkFFTWGlobalConfiguration.h:384
itk::ManualWisdomFilenameGenerator
Definition: itkFFTWGlobalConfiguration.h:90
itk::FFTWGlobalConfiguration
Definition: itkFFTWGlobalConfiguration.h:203
itk::LightObject
Light weight base class for most itk classes.
Definition: itkLightObject.h:59
itk::FFTWGlobalConfiguration::m_PimplGlobals
static FFTWGlobalConfigurationGlobals * m_PimplGlobals
Definition: itkFFTWGlobalConfiguration.h:375
itk::FFTWGlobalConfiguration::m_WisdomFilenameGenerator
WisdomFilenameGeneratorBase * m_WisdomFilenameGenerator
Definition: itkFFTWGlobalConfiguration.h:387
itk::WisdomFilenameGeneratorBase
Definition: itkFFTWGlobalConfiguration.h:78
itk::HostnameWisdomFilenameGenerator
Definition: itkFFTWGlobalConfiguration.h:110
itk::HardwareWisdomFilenameGenerator
Definition: itkFFTWGlobalConfiguration.h:117
itkObject.h
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnnulusOperator.h:24
itkGetGlobalDeclarationMacro
#define itkGetGlobalDeclarationMacro(Type, VarName)
Definition: itkSingletonMacro.h:35
itk::Object
Base class for most ITK classes.
Definition: itkObject.h:62
itk::SimpleWisdomFilenameGenerator
Definition: itkFFTWGlobalConfiguration.h:103