ITK 6.0.0
Insight Toolkit
 
Loading...
Searching...
No Matches
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{
69
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};
87
89{
90public:
92 void
93 SetWisdomFilename(const std::string & wfn);
94 std::string
95 GenerateWisdomFilename(const std::string & baseCacheDirectory) const override;
96
97private:
98 std::string m_WisdomFilename{};
99};
100
102{
103public:
104 std::string
105 GenerateWisdomFilename(const std::string & baseCacheDirectory) const override;
106};
107
109{
110public:
111 std::string
112 GenerateWisdomFilename(const std::string & baseCacheDirectory) const override;
113};
114
116{
117public:
119
120 std::string
121 GenerateWisdomFilename(const std::string & baseCacheDirectory) const override;
122
123 void
124 SetUseOSName(const bool flag);
125 void
126 SetUseOSRelease(const bool flag);
127 void
128 SetUseOSVersion(const bool flag);
129 void
130 SetUseOSPlatform(const bool flag);
131 void
132 SetUseOSBitSize(const bool flag);
133 void
134 SetUseNumberOfProcessors(const bool flag);
135 void
136 SetUseVendorString(const bool flag);
137 void
138 SetUseTypeID(const bool flag);
139 void
140 SetUseFamilyID(const bool flag);
141 void
142 SetUseModelID(const bool flag);
143 void
144 SetUseSteppingCode(const bool flag);
145
146 bool
148 bool
150 bool
152 bool
154 bool
156 bool
158 bool
160 bool
162 bool
164 bool
166 bool
168
169private:
170 bool m_UseOSName{ true };
171 bool m_UseOSRelease{ false };
172 bool m_UseOSVersion{ false };
173 bool m_UseOSPlatform{ true };
174 bool m_UseOSBitSize{ true };
176 bool m_UseVendorString{ true };
177 bool m_UseVendorID{ false };
178 bool m_UseTypeID{ true };
179 bool m_UseFamilyID{ true };
180 bool m_UseModelID{ true };
181 bool m_UseSteppingCode{ true };
182};
183
201class ITKFFT_EXPORT FFTWGlobalConfiguration : public Object
202{
203public:
204 ITK_DISALLOW_COPY_AND_MOVE(FFTWGlobalConfiguration);
205
211 using MutexType = std::mutex;
212
214 itkOverrideGetNameOfClassMacro(FFTWGlobalConfiguration);
215
217 static std::mutex &
219
224 static void
226 static bool
228
237 static void
238 SetPlanRigor(const int v);
239
240 static int
242 static void
243 SetPlanRigor(const std::string & name);
244
246 static int
247 GetPlanRigorValue(const std::string & name);
248
250 static std::string
251 GetPlanRigorName(const int value);
252
260 static void
261 SetReadWisdomCache(const bool v);
262 static bool
264
272 static void
273 SetWriteWisdomCache(const bool v);
274 static bool
276
283 static void
284 SetWisdomCacheBase(const std::string & v);
285 static std::string
287
300 static void
302
316 static std::string
318
320 static bool
321 ImportWisdomFileDouble(const std::string & fname);
322 static bool
323 ExportWisdomFileDouble(const std::string & fname);
324
326 static bool
327 ImportWisdomFileFloat(const std::string & fname);
328 static bool
329 ExportWisdomFileFloat(const std::string & fname);
330
332 static bool
334 static bool
336
338 static bool
340 static bool
342
344 static bool
346 static bool
348
349private:
350 FFTWGlobalConfiguration(); // This will process env variables
351 ~FFTWGlobalConfiguration() override; // This will write cache file if requested.
352
354 static Pointer
356
357 itkGetGlobalDeclarationMacro(FFTWGlobalConfigurationGlobals, PimplGlobals);
358
359
364 itkFactorylessNewMacro(Self);
365
366 static FFTWGlobalConfigurationGlobals * m_PimplGlobals;
367
368 std::mutex m_Mutex;
369 bool m_NewWisdomAvailable{ false };
370 int m_PlanRigor{ 0 };
371 bool m_WriteWisdomCache{ false };
372 bool m_ReadWisdomCache{ true };
373 std::string m_WisdomCacheBase;
374 // m_WriteWisdomCache Controls the behavior of default
375 // wisdom file creation policies.
377};
378} // namespace itk
379#endif
380#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()
static std::string GetWisdomCacheBase()
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)
SmartPointer< const Self > ConstPointer
static std::string GetPlanRigorName(const int value)
static bool GetWriteWisdomCache()
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
ManualWisdomFilenameGenerator(std::string wfn)
std::string GenerateWisdomFilename(const std::string &baseCacheDirectory) const override
void SetWisdomFilename(const std::string &wfn)
std::string GenerateWisdomFilename(const std::string &baseCacheDirectory) const override
Implements transparent reference counting.
virtual std::string GenerateWisdomFilename(const std::string &baseCacheDirectory) const =0
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....