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 
204 class ITKFFT_EXPORT FFTWGlobalConfiguration : public Object
205 {
206 public:
207  ITK_DISALLOW_COPY_AND_ASSIGN(FFTWGlobalConfiguration);
208 
214  using MutexType = std::mutex;
215 
217  itkTypeMacro(FFTWGlobalConfiguration, Object);
218 
220  static std::mutex &
221  GetLockMutex();
222 
227  static void
228  SetNewWisdomAvailable(const bool & v);
229  static bool
230  GetNewWisdomAvailable();
232 
241  static void
242  SetPlanRigor(const int & v);
243 
244  static int
245  GetPlanRigor();
246  static void
247  SetPlanRigor(const std::string & name);
248 
250  static int
251  GetPlanRigorValue(const std::string & name);
252 
254  static std::string
255  GetPlanRigorName(const int & value);
256 
264  static void
265  SetReadWisdomCache(const bool & v);
266  static bool
267  GetReadWisdomCache();
269 
277  static void
278  SetWriteWisdomCache(const bool & v);
279  static bool
280  GetWriteWisdomCache();
282 
289  static void
290  SetWisdomCacheBase(const std::string & v);
291  static std::string
292  GetWisdomCacheBase();
294 
307  static void
308  SetWisdomFilenameGenerator(WisdomFilenameGeneratorBase * wfg);
309 
323  static std::string
324  GetWisdomFileDefaultBaseName();
325 
327  static bool
328  ImportWisdomFileDouble(const std::string & fname);
329  static bool
330  ExportWisdomFileDouble(const std::string & fname);
332 
334  static bool
335  ImportWisdomFileFloat(const std::string & fname);
336  static bool
337  ExportWisdomFileFloat(const std::string & fname);
339 
341  static bool
342  ImportDefaultWisdomFileDouble();
343  static bool
344  ExportDefaultWisdomFileDouble();
346 
348  static bool
349  ImportDefaultWisdomFileFloat();
350  static bool
351  ExportDefaultWisdomFileFloat();
353 
355  static bool
356  ImportDefaultWisdomFile();
357  static bool
358  ExportDefaultWisdomFile();
360 
361 private:
362  FFTWGlobalConfiguration(); // This will process env variables
363  ~FFTWGlobalConfiguration() override; // This will write cache file if requested.
364 
366  static Pointer
367  GetInstance();
368 
369  itkGetGlobalDeclarationMacro(FFTWGlobalConfigurationGlobals, PimplGlobals);
370 
371 
376  itkFactorylessNewMacro(Self);
377 
378  static FFTWGlobalConfigurationGlobals * m_PimplGlobals;
379 
380  std::mutex m_Lock;
381  bool m_NewWisdomAvailable{ false };
382  int m_PlanRigor{ 0 };
383  bool m_WriteWisdomCache{ false };
384  bool m_ReadWisdomCache{ true };
385  std::string m_WisdomCacheBase;
386  // m_WriteWisdomCache Controls the behavior of default
387  // wisdom file creation policies.
389 };
390 } // namespace itk
391 #endif
392 #endif
itk::FFTWGlobalConfiguration::MutexType
std::mutex MutexType
Definition: itkFFTWGlobalConfiguration.h:214
itk::ManualWisdomFilenameGenerator::m_WisdomFilename
std::string m_WisdomFilename
Definition: itkFFTWGlobalConfiguration.h:100
itk::FFTWGlobalConfiguration::m_Lock
std::mutex m_Lock
Definition: itkFFTWGlobalConfiguration.h:380
itkSingletonMacro.h
itk::SmartPointer< Self >
itk::FFTWGlobalConfiguration::m_WisdomCacheBase
std::string m_WisdomCacheBase
Definition: itkFFTWGlobalConfiguration.h:385
itk::ManualWisdomFilenameGenerator
Definition: itkFFTWGlobalConfiguration.h:90
itk::FFTWGlobalConfiguration
Definition: itkFFTWGlobalConfiguration.h:204
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:376
itk::FFTWGlobalConfiguration::m_WisdomFilenameGenerator
WisdomFilenameGeneratorBase * m_WisdomFilenameGenerator
Definition: itkFFTWGlobalConfiguration.h:388
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:34
itk::Object
Base class for most ITK classes.
Definition: itkObject.h:60
itk::SimpleWisdomFilenameGenerator
Definition: itkFFTWGlobalConfiguration.h:103