BeamCenterFFTCPU: run the capture's independent 2-D transforms at the same time
PointSurfaces made three forward and four inverse transforms of the padded detector (8748 x 8400 on a 16M) one after the other on the main thread - ~3.5 s of one core in a CPU-only run. The forwards do not depend on each other, nor do the inverse products; each group now runs at the same time, one workspace per transform. A workspace is built as the single one was - its own std::vector buffers and its own FFTW_ESTIMATE plan for them - so the same plan runs on the same data and the result is bit-identical. Costs about 2 GB more transient memory on a 16M detector. CPU-only 16M rotation run: md5-identical, 216 -> 210 s. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01D1G8gJVAy6gp1K5Dz3NE5C
This commit is contained in:
1 parent
4b1d7feebd
commit
c7a8fabc7e
1 file changed
+25
-8
@@ -6,6 +6,8 @@
|
||||
#include <algorithm>
|
||||
#include <complex>
|
||||
#include <cstring>
|
||||
#include <future>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <stdexcept>
|
||||
|
||||
@@ -89,19 +91,34 @@ std::vector<float> Transpose(const std::vector<float> &src, int64_t h, int64_t w
|
||||
BeamCenterConvSurfaces2D BeamCenterFFTCPU::PointSurfaces(const std::vector<float> &a,
|
||||
const std::vector<float> &m, int64_t h,
|
||||
int64_t w) {
|
||||
Rfft2 fft(BeamCenterFFTPadSize(2 * h), BeamCenterFFTPadSize(2 * w));
|
||||
const auto A = fft.Forward(a, h, w);
|
||||
const auto M = fft.Forward(m, h, w);
|
||||
// The three forward transforms are independent of each other, and so are the four inverse ones,
|
||||
// so each group runs at the same time, one workspace per transform. A workspace is built exactly
|
||||
// as a single one was - its own buffers and its own plan for them - so every transform is the one
|
||||
// it was, bit for bit; the four inverse ones reuse the three forward workspaces and one more.
|
||||
const int64_t ny = BeamCenterFFTPadSize(2 * h), nx = BeamCenterFFTPadSize(2 * w);
|
||||
std::vector<std::unique_ptr<Rfft2>> fft;
|
||||
for (int i = 0; i < 4; i++)
|
||||
fft.push_back(std::make_unique<Rfft2>(ny, nx));
|
||||
|
||||
std::vector<float> a2(a.size());
|
||||
for (size_t i = 0; i < a2.size(); i++)
|
||||
a2[i] = a[i] * a[i];
|
||||
const auto A2 = fft.Forward(a2, h, w);
|
||||
auto fA = std::async(std::launch::async, [&] { return fft[0]->Forward(a, h, w); });
|
||||
auto fM = std::async(std::launch::async, [&] { return fft[1]->Forward(m, h, w); });
|
||||
auto fA2 = std::async(std::launch::async, [&] { return fft[2]->Forward(a2, h, w); });
|
||||
const auto A = fA.get();
|
||||
const auto M = fM.get();
|
||||
const auto A2 = fA2.get();
|
||||
|
||||
BeamCenterConvSurfaces2D out;
|
||||
out.C = fft.InverseProduct(A, A, 2 * h, 2 * w);
|
||||
out.S = fft.InverseProduct(A, M, 2 * h, 2 * w);
|
||||
out.Q = fft.InverseProduct(A2, M, 2 * h, 2 * w);
|
||||
out.D = fft.InverseProduct(M, M, 2 * h, 2 * w);
|
||||
auto fC = std::async(std::launch::async, [&] { return fft[0]->InverseProduct(A, A, 2 * h, 2 * w); });
|
||||
auto fS = std::async(std::launch::async, [&] { return fft[1]->InverseProduct(A, M, 2 * h, 2 * w); });
|
||||
auto fQ = std::async(std::launch::async, [&] { return fft[2]->InverseProduct(A2, M, 2 * h, 2 * w); });
|
||||
auto fD = std::async(std::launch::async, [&] { return fft[3]->InverseProduct(M, M, 2 * h, 2 * w); });
|
||||
out.C = fC.get();
|
||||
out.S = fS.get();
|
||||
out.Q = fQ.get();
|
||||
out.D = fD.get();
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user