25 #include <boost/thread/shared_mutex.hpp>
28 namespace SourceXtractor {
51 static int optimal_dims[] = {
52 1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
53 11, 12, 13, 14, 15, 16, 18, 18, 20, 20, 21,
54 22, 24, 24, 25, 26, 27, 28, 30, 30, 32, 32,
55 33, 35, 35, 36, 39, 39, 39, 40, 42, 42, 44,
56 44, 45, 48, 48, 48, 49, 50, 52, 52, 54, 54,
57 55, 56, 60, 60, 60, 60, 63, 63, 63, 64, 65,
58 66, 70, 70, 70, 70, 72, 72, 75, 75, 75, 77,
59 77, 78, 80, 80, 81, 84, 84, 84, 88, 88, 88,
60 88, 90, 90, 91, 96, 96, 96, 96, 96, 98, 98,
61 99, 100, 104, 104, 104, 104, 105, 108, 108, 108, 110,
62 110, 112, 112, 117, 117, 117, 117, 117, 120, 120, 120,
63 125, 125, 125, 125, 125, 126, 128, 128, 130, 130, 132,
64 132, 135, 135, 135, 140, 140, 140, 140, 140, 144, 144,
65 144, 144, 147, 147, 147, 150, 150, 150, 154, 154, 154,
66 154, 156, 156, 160, 160, 160, 160, 162, 162, 165, 165,
67 165, 168, 168, 168, 175, 175, 175, 175, 175, 175, 175,
68 176, 180, 180, 180, 180, 182, 182, 189, 189, 189, 189,
69 189, 189, 189, 192, 192, 192, 195, 195, 195, 196, 198,
70 198, 200, 200, 208, 208, 208, 208, 208, 208, 208, 208,
71 210, 210, 216, 216, 216, 216, 216, 216, 220, 220, 220,
72 220, 224, 224, 224, 224, 225, 231, 231, 231, 231, 231,
73 231, 234, 234, 234, 240, 240, 240, 240, 240, 240, 243,
74 243, 243, 245, 245, 250, 250, 250, 250, 250, 252, 252,
75 256, 256, 256, 256, 260, 260, 260, 260, 264, 264, 264,
76 264, 270, 270, 270, 270, 270, 270, 273, 273, 273, 275,
77 275, 280, 280, 280, 280, 280, 288, 288, 288, 288, 288,
78 288, 288, 288, 294, 294, 294, 294, 294, 294, 297, 297,
79 297, 300, 300, 300, 308, 308, 308, 308, 308, 308, 308,
80 308, 312, 312, 312, 312, 315, 315, 315, 320, 320, 320,
81 320, 320, 324, 324, 324, 324, 325, 330, 330, 330, 330,
82 330, 336, 336, 336, 336, 336, 336, 343, 343, 343, 343,
83 343, 343, 343, 350, 350, 350, 350, 350, 350, 350, 351,
84 352, 360, 360, 360, 360, 360, 360, 360, 360, 364, 364,
85 364, 364, 375, 375, 375, 375, 375, 375, 375, 375, 375,
86 375, 375, 378, 378, 378, 384, 384, 384, 384, 384, 384,
87 385, 390, 390, 390, 390, 390, 392, 392, 396, 396, 396,
88 396, 400, 400, 400, 400, 405, 405, 405, 405, 405, 416,
89 416, 416, 416, 416, 416, 416, 416, 416, 416, 416, 420,
90 420, 420, 420, 432, 432, 432, 432, 432, 432, 432, 432,
91 432, 432, 432, 432, 440, 440, 440, 440, 440, 440, 440,
92 440, 441, 448, 448, 448, 448, 448, 448, 448, 450, 450,
93 455, 455, 455, 455, 455, 462, 462, 462, 462, 462, 462,
94 462, 468, 468, 468, 468, 468, 468, 480, 480, 480, 480,
95 480, 480, 480, 480, 480, 480, 480, 480, 486, 486, 486,
96 486, 486, 486, 490, 490, 490, 490, 495, 495, 495, 495,
97 495, 500, 500, 500, 500, 500, 504, 504, 504, 504, 512,
98 512, 512, 512, 512, 512, 512, 512, 520, 520, 520, 520,
99 520, 520, 520, 520, 525, 525, 525, 525, 525, 528, 528,
100 528, 539, 539, 539, 539, 539, 539, 539, 539, 539, 539,
101 539, 540, 546, 546, 546, 546, 546, 546, 550, 550, 550,
102 550, 560, 560, 560, 560, 560, 560, 560, 560, 560, 560,
103 567, 567, 567, 567, 567, 567, 567, 576, 576, 576, 576,
104 576, 576, 576, 576, 576, 585, 585, 585, 585, 585, 585,
105 585, 585, 585, 588, 588, 588, 594, 594, 594, 594, 594,
106 594, 600, 600, 600, 600, 600, 600, 616, 616, 616, 616,
107 616, 616, 616, 616, 616, 616, 616, 616, 616, 616, 616,
108 616, 624, 624, 624, 624, 624, 624, 624, 624, 625, 630,
109 630, 630, 630, 630, 637, 637, 637, 637, 637, 637, 637,
110 640, 640, 640, 648, 648, 648, 648, 648, 648, 648, 648,
111 650, 650, 660, 660, 660, 660, 660, 660, 660, 660, 660,
112 660, 672, 672, 672, 672, 672, 672, 672, 672, 672, 672,
113 672, 672, 675, 675, 675, 686, 686, 686, 686, 686, 686,
114 686, 686, 686, 686, 686, 693, 693, 693, 693, 693, 693,
115 693, 700, 700, 700, 700, 700, 700, 700, 702, 702, 704,
116 704, 720, 720, 720, 720, 720, 720, 720, 720, 720, 720,
117 720, 720, 720, 720, 720, 720, 728, 728, 728, 728, 728,
118 728, 728, 728, 729, 735, 735, 735, 735, 735, 735, 750,
119 750, 750, 750, 750, 750, 750, 750, 750, 750, 750, 750,
120 750, 750, 750, 756, 756, 756, 756, 756, 756, 768, 768,
121 768, 768, 768, 768, 768, 768, 768, 768, 768, 768, 770,
122 770, 780, 780, 780, 780, 780, 780, 780, 780, 780, 780,
123 784, 784, 784, 784, 792, 792, 792, 792, 792, 792, 792,
124 792, 800, 800, 800, 800, 800, 800, 800, 800, 810, 810,
125 810, 810, 810, 810, 810, 810, 810, 810, 819, 819, 819,
126 819, 819, 819, 819, 819, 819, 825, 825, 825, 825, 825,
127 825, 832, 832, 832, 832, 832, 832, 832, 840, 840, 840,
128 840, 840, 840, 840, 840, 864, 864, 864, 864, 864, 864,
129 864, 864, 864, 864, 864, 864, 864, 864, 864, 864, 864,
130 864, 864, 864, 864, 864, 864, 864, 875, 875, 875, 875,
131 875, 875, 875, 875, 875, 875, 875, 880, 880, 880, 880,
132 880, 882, 882, 891, 891, 891, 891, 891, 891, 891, 891,
133 891, 896, 896, 896, 896, 896, 900, 900, 900, 900, 910,
134 910, 910, 910, 910, 910, 910, 910, 910, 910, 924, 924,
135 924, 924, 924, 924, 924, 924, 924, 924, 924, 924, 924,
136 924, 936, 936, 936, 936, 936, 936, 936, 936, 936, 936,
137 936, 936, 945, 945, 945, 945, 945, 945, 945, 945, 945,
138 960, 960, 960, 960, 960, 960, 960, 960, 960, 960, 960,
139 960, 960, 960, 960, 972, 972, 972, 972, 972, 972, 972,
140 972, 972, 972, 972, 972, 975, 975, 975, 980, 980, 980,
141 980, 980, 990, 990, 990, 990, 990, 990, 990, 990, 990,
142 990, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000,
143 1008, 1008, 1008, 1008, 1008, 1008, 1008, 1008, 1024, 1024, 1024,
145 static int n_optimal_dims =
sizeof(optimal_dims) /
sizeof(
int);
147 if (size < n_optimal_dims) {
148 return optimal_dims[size];
150 return (size / 512 + (size % 512 != 0)) * 512;
154 template <
typename T>
157 assert(in.size() >=
static_cast<size_t>(width * height * howmany));
158 assert(out.size() >=
static_cast<size_t>(width * height * howmany));
161 static boost::shared_mutex
mutex;
164 boost::upgrade_lock<boost::shared_mutex> read_lock{mutex};
167 if (
pi != plan_cache.
end()) {
172 boost::upgrade_to_unique_lock<boost::shared_mutex> write_lock{read_lock};
175 int dims[] = {height, width};
176 int total_size = height * width;
178 int istride = 1, ostride = 1;
179 int idist = total_size;
180 int odist = total_size;
185 fftw_traits::func_plan_fwd(
187 in.data(),
nullptr, istride, idist,
188 reinterpret_cast<typename fftw_traits::complex_t*
>(out.data()),
nullptr, ostride, odist,
189 FFTW_MEASURE | FFTW_DESTROY_INPUT
191 fftw_traits::func_destroy_plan
198 template <
typename T>
201 assert(in.size() >=
static_cast<size_t>(width * height * howmany));
202 assert(out.size() >=
static_cast<size_t>(width * height * howmany));
205 static boost::shared_mutex
mutex;
208 boost::upgrade_lock<boost::shared_mutex> read_lock{mutex};
211 if (
pi != plan_cache.
end()) {
216 boost::upgrade_to_unique_lock<boost::shared_mutex> write_lock{read_lock};
219 int dims[] = {height, width};
220 int total_size = height * width;
222 int istride = 1, ostride = 1;
223 int idist = total_size;
224 int odist = total_size;
229 fftw_traits::func_plan_inv(
231 reinterpret_cast<typename fftw_traits::complex_t*>(in.data()),
nullptr, istride, idist,
232 out.data(),
nullptr, ostride, odist,
233 FFTW_MEASURE | FFTW_DESTROY_INPUT
235 fftw_traits::func_destroy_plan
245 fftw_traits::func_execute_fwd(plan.
get(), in.
data(),
reinterpret_cast<typename fftw_traits::complex_t *
>(out.
data()));
251 fftw_traits::func_execute_inv(plan.
get(),
reinterpret_cast<typename fftw_traits::complex_t *
>(in.
data()), out.
data());