ITK  6.0.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 * https://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
39struct 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
63namespace itk
64{
70struct FFTWGlobalConfigurationGlobals;
71
72# ifdef _WIN32
73# define FFTWPathSep "\\"
74# else
75# define FFTWPathSep "/"
76# endif
77
78class ITKFFT_EXPORT WisdomFilenameGeneratorBase
79{
80public:
81 // The baseCacheDirectory from which to build the cache hierarchy
82 virtual std::string
83 GenerateWisdomFilename(const std::string & baseCacheDirectory) const = 0;
86
87private:
88};
89
91{
92public:
94 void
95 SetWisdomFilename(const std::string & wfn);
96 std::string
97 GenerateWisdomFilename(const std::string & baseCacheDirectory) const override;
98
99private:
100 std::string m_WisdomFilename{};
101};
102
104{
105public:
106 std::string
107 GenerateWisdomFilename(const std::string & baseCacheDirectory) const override;
108};
109
111{
112public:
113 std::string
114 GenerateWisdomFilename(const std::string & baseCacheDirectory) const override;
115};
116
118{
119public:
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
150 bool
152 bool
154 bool
156 bool
158 bool
160 bool
162 bool
164 bool
166 bool
168 bool
170
171private:
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
203class ITKFFT_EXPORT FFTWGlobalConfiguration : public Object
204{
205public:
206 ITK_DISALLOW_COPY_AND_MOVE(FFTWGlobalConfiguration);
207
213 using MutexType = std::mutex;
214
216 itkOverrideGetNameOfClassMacro(FFTWGlobalConfiguration);
217
219 static std::mutex &
221
226 static void
228 static bool
240 static void
241 SetPlanRigor(const int v);
242
243 static int
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
276 static void
277 SetWriteWisdomCache(const bool v);
278 static bool
288 static void
289 SetWisdomCacheBase(const std::string & v);
290 static std::string
306 static void
308
322 static std::string
324
326 static bool
327 ImportWisdomFileDouble(const std::string & fname);
328 static bool
329 ExportWisdomFileDouble(const std::string & fname);
333 static bool
334 ImportWisdomFileFloat(const std::string & fname);
335 static bool
336 ExportWisdomFileFloat(const std::string & fname);
340 static bool
342 static bool
347 static bool
349 static bool
354 static bool
356 static bool
360private:
361 FFTWGlobalConfiguration(); // This will process env variables
362 ~FFTWGlobalConfiguration() override; // This will write cache file if requested.
363
365 static Pointer
367
368 itkGetGlobalDeclarationMacro(FFTWGlobalConfigurationGlobals, PimplGlobals);
369
370
375 itkFactorylessNewMacro(Self);
376
377 static FFTWGlobalConfigurationGlobals * m_PimplGlobals;
378
379 std::mutex m_Mutex;
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
static bool ExportWisdomFileDouble(const std::string &fname)
static bool ExportDefaultWisdomFileDouble()
static void SetPlanRigor(const int v)
Set the behavior of wisdom plan creation.
static bool ExportWisdomFileFloat(const std::string &fname)
static int GetPlanRigorValue(const std::string &name)
static FFTWGlobalConfigurationGlobals * m_PimplGlobals
static bool ImportDefaultWisdomFile()
static bool GetReadWisdomCache()
Set/Get the behavior of wisdom file caching.
static std::string GetWisdomCacheBase()
Define the directory where the wisdom cache will be placed. The environmental variable ITK_FFTW_WISDO...
static bool ImportDefaultWisdomFileFloat()
static std::string GetWisdomFileDefaultBaseName()
static bool ImportWisdomFileDouble(const std::string &fname)
static void SetWriteWisdomCache(const bool v)
Set/Get the behavior of wisdom file caching.
itkGetGlobalDeclarationMacro(FFTWGlobalConfigurationGlobals, PimplGlobals)
static std::string GetPlanRigorName(const int value)
static bool GetWriteWisdomCache()
Set/Get the behavior of wisdom file caching.
static Pointer GetInstance()
static bool ImportDefaultWisdomFileDouble()
static std::mutex & GetLockMutex()
static void SetNewWisdomAvailable(const bool v)
static void SetReadWisdomCache(const bool v)
Set/Get the behavior of wisdom file caching.
static bool ExportDefaultWisdomFileFloat()
static bool ImportWisdomFileFloat(const std::string &fname)
static bool ExportDefaultWisdomFile()
static void SetPlanRigor(const std::string &name)
static void SetWisdomCacheBase(const std::string &v)
Define the directory where the wisdom cache will be placed. The environmental variable ITK_FFTW_WISDO...
WisdomFilenameGeneratorBase * m_WisdomFilenameGenerator
static bool GetNewWisdomAvailable()
static void SetWisdomFilenameGenerator(WisdomFilenameGeneratorBase *wfg)
allows application developers to create arbitrary rules for auto-generating cache file names....
void SetUseFamilyID(const bool flag)
void SetUseOSVersion(const bool flag)
void SetUseTypeID(const bool flag)
void SetUseVendorString(const bool flag)
void SetUseModelID(const bool flag)
void SetUseSteppingCode(const bool flag)
void SetUseOSBitSize(const bool flag)
std::string GenerateWisdomFilename(const std::string &baseCacheDirectory) const override
void SetUseOSRelease(const bool flag)
void SetUseOSPlatform(const bool flag)
void SetUseNumberOfProcessors(const bool flag)
void SetUseOSName(const bool flag)
std::string GenerateWisdomFilename(const std::string &baseCacheDirectory) const override
Light weight base class for most itk classes.
ManualWisdomFilenameGenerator(std::string wfn)
std::string GenerateWisdomFilename(const std::string &baseCacheDirectory) const override
void SetWisdomFilename(const std::string &wfn)
Base class for most ITK classes.
Definition: itkObject.h:62
std::string GenerateWisdomFilename(const std::string &baseCacheDirectory) const override
virtual std::string GenerateWisdomFilename(const std::string &baseCacheDirectory) const =0
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....