ITK  5.0.0
Insight Segmentation and Registration Toolkit
itkFFTWGlobalConfiguration.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
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 GenerateWisdomFilename(const std::string &baseCacheDirectory) const = 0;
84  virtual ~WisdomFilenameGeneratorBase();
85  private:
86 };
87 
88 class ITKFFT_EXPORT ManualWisdomFilenameGenerator:
90 {
91  public:
92  ManualWisdomFilenameGenerator(std::string wfn);
93  void SetWisdomFilename(const std::string &wfn);
94  std::string GenerateWisdomFilename(const std::string &baseCacheDirectory ) const override;
95  private:
96  std::string m_WisdomFilename;
97 };
98 
100 {
101  public:
102  std::string GenerateWisdomFilename(const std::string &baseCacheDirectory) const override;
103 };
104 
106 {
107  public:
108  std::string GenerateWisdomFilename(const std::string &baseCacheDirectory) const override;
109 };
110 
112 {
113 public:
115 
116  std::string GenerateWisdomFilename(const std::string &baseCacheDirectory) const override;
117 
118  void SetUseOSName(const bool flag);
119  void SetUseOSRelease(const bool flag);
120  void SetUseOSVersion(const bool flag);
121  void SetUseOSPlatform(const bool flag);
122  void SetUseOSBitSize(const bool flag);
123  void SetUseNumberOfProcessors(const bool flag);
124  void SetUseVendorString(const bool flag);
125  void SetUseTypeID(const bool flag);
126  void SetUseFamilyID(const bool flag);
127  void SetUseModelID(const bool flag);
128  void SetUseSteppingCode(const bool flag);
129 
130  bool GetUseOSName() const;
131  bool GetUseOSRelease() const;
132  bool GetUseOSVersion() const;
133  bool GetUseOSPlatform() const;
134  bool GetUseOSBitSize() const;
135  bool GetUseNumberOfProcessors() const;
136  bool GetUseVendorString() const;
137  bool GetUseTypeID() const;
138  bool GetUseFamilyID() const;
139  bool GetUseModelID() const;
140  bool GetUseSteppingCode() const;
141 
142 private:
155 };
156 
175 class ITKFFT_EXPORT FFTWGlobalConfiguration
176  : public Object
177 {
178 public:
179  ITK_DISALLOW_COPY_AND_ASSIGN(FFTWGlobalConfiguration);
180 
186  using MutexType = std::mutex;
187 
189  itkTypeMacro(FFTWGlobalConfiguration, Object);
190 
192  static std::mutex & GetLockMutex();
193 
198  static void SetNewWisdomAvailable( const bool & v );
199  static bool GetNewWisdomAvailable();
201 
210  static void SetPlanRigor( const int & v );
211 
212  static int GetPlanRigor();
213  static void SetPlanRigor( const std::string & name );
214 
216  static int GetPlanRigorValue( const std::string & name );
217 
219  static std::string GetPlanRigorName( const int & value );
220 
228  static void SetReadWisdomCache( const bool & v );
229  static bool GetReadWisdomCache();
231 
239  static void SetWriteWisdomCache( const bool & v );
240  static bool GetWriteWisdomCache();
242 
249  static void SetWisdomCacheBase( const std::string & v );
250  static std::string GetWisdomCacheBase();
252 
265  static void SetWisdomFilenameGenerator( WisdomFilenameGeneratorBase *wfg);
266 
280  static std::string GetWisdomFileDefaultBaseName();
281 
283  static bool ImportWisdomFileDouble( const std::string &fname );
284  static bool ExportWisdomFileDouble( const std::string &fname );
286 
288  static bool ImportWisdomFileFloat( const std::string &fname );
289  static bool ExportWisdomFileFloat( const std::string &fname );
291 
293  static bool ImportDefaultWisdomFileDouble();
294  static bool ExportDefaultWisdomFileDouble();
296 
298  static bool ImportDefaultWisdomFileFloat();
299  static bool ExportDefaultWisdomFileFloat();
301 
303  static bool ImportDefaultWisdomFile();
304  static bool ExportDefaultWisdomFile();
306 
307 private:
308  FFTWGlobalConfiguration(); //This will process env variables
309  ~FFTWGlobalConfiguration() override; //This will write cache file if requested.
310 
312  static Pointer GetInstance();
313 
314  itkGetGlobalDeclarationMacro(FFTWGlobalConfigurationGlobals, PimplGlobals);
315 
316 
321  itkFactorylessNewMacro(Self);
322 
323  static FFTWGlobalConfigurationGlobals *m_PimplGlobals;
324 
325  std::mutex m_Lock;
330  std::string m_WisdomCacheBase;
331  //m_WriteWisdomCache Controls the behavior of default
332  //wisdom file creation policies.
334 };
335 }
336 #endif
337 #endif
WisdomFilenameGeneratorBase * m_WisdomFilenameGenerator
Light weight base class for most itk classes.
#define itkGetGlobalDeclarationMacro(Type, VarName)
static FFTWGlobalConfigurationGlobals * m_PimplGlobals
Base class for most ITK classes.
Definition: itkObject.h:60