96 lines
3.6 KiB
C++
96 lines
3.6 KiB
C++
// Copyright (2019-2022) Paul Scherrer Institute
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
#include <future>
|
|
|
|
#include "../image_analysis/RadialIntegration.h"
|
|
#include "../common/Logger.h"
|
|
#include "../writer/HDF5Objects.h"
|
|
|
|
Logger logger{"RadialIntegrationCPUTest"};
|
|
|
|
void RunRadialIntegrationThread(const std::vector<uint16_t>& mapping,
|
|
uint32_t nbins, uint32_t pixel_split,
|
|
int16_t* image, size_t nimages,
|
|
size_t image0, size_t stride,
|
|
size_t npixel) {
|
|
|
|
RadialIntegration integration(mapping, nbins, pixel_split);
|
|
|
|
for (size_t i = image0; i < nimages; i += stride)
|
|
integration.ProcessOneImage(image + i * npixel, npixel);
|
|
}
|
|
|
|
auto TestRadialIntegration(const DiffractionExperiment &experiment,
|
|
int16_t* image, size_t nimages,
|
|
uint32_t nthreads,
|
|
uint32_t pixel_split) {
|
|
uint32_t nredo = 5;
|
|
RadialIntegrationMapping mapping(experiment);
|
|
|
|
std::vector<float> result;
|
|
|
|
auto start_time = std::chrono::system_clock::now();
|
|
for (int redo = 0; redo < nredo; redo++) {
|
|
std::vector<std::future<void>> futures;
|
|
for (int i = 0; i < nthreads; i++) {
|
|
if (pixel_split == 1)
|
|
futures.emplace_back(std::async(std::launch::async, &RunRadialIntegrationThread,
|
|
std::ref(mapping.GetPixelToBinMapping()), mapping.GetBinNumber(), 1,
|
|
image, nimages,
|
|
i, nthreads,
|
|
experiment.GetPixelsNum()));
|
|
else
|
|
futures.emplace_back(std::async(std::launch::async, &RunRadialIntegrationThread,
|
|
mapping.GetPixelToBinMappingSplitTo4(), mapping.GetBinNumber(), 4,
|
|
image, nimages,
|
|
i, nthreads,
|
|
experiment.GetPixelsNum()));
|
|
|
|
}
|
|
for (auto &f: futures)
|
|
f.get();
|
|
}
|
|
auto end_time = std::chrono::system_clock::now();
|
|
auto elapsed = std::chrono::duration_cast<std::chrono::microseconds>(end_time - start_time);
|
|
|
|
return elapsed.count() / (1000.0 * (double) nimages * nredo);
|
|
}
|
|
|
|
int main(int argc, char **argv) {
|
|
if (argc > 3) {
|
|
logger.Info("Usage: ./DataAnalysisPerfTest {<number of threads=1>} {<number of images=100>}");
|
|
exit(EXIT_FAILURE);
|
|
}
|
|
|
|
uint32_t nthreads = 1;
|
|
if (argc >= 2)
|
|
nthreads = atol(argv[1]);
|
|
|
|
uint64_t nimages = 100;
|
|
if (argc == 3)
|
|
nimages = atol(argv[2]);
|
|
|
|
if ((nthreads <= 0) || (nimages <= 0)) {
|
|
std::cerr << "Error in input parameters" << std::endl;
|
|
exit(EXIT_FAILURE);
|
|
}
|
|
|
|
DiffractionExperiment x(DetectorGeometry(8, 2, 8, 36));
|
|
|
|
logger.Info("Number of threads: {}", nthreads);
|
|
logger.Info("Number of images in the dataset: {}", nimages);
|
|
|
|
x.Mode(DetectorMode::Conversion);
|
|
|
|
std::vector<int16_t> image_conv ( nimages * x.GetPixelsNum(), 30);
|
|
|
|
x.BeamX_pxl(1090).BeamY_pxl(1136).DetectorDistance_mm(75).PhotonEnergy_keV(WVL_1A_IN_KEV);
|
|
std::vector<uint8_t> one_byte_mask(x.GetPixelsNum(), 1);
|
|
|
|
logger.Info("{:30s} {:8.1f} ms/image", "Radial int. pxlspl 1 (CPU)",
|
|
TestRadialIntegration(x, image_conv.data(), nimages, nthreads, 1));
|
|
logger.Info("{:30s} {:8.1f} ms/image", "Radial int. pxlspl 2 (CPU)",
|
|
TestRadialIntegration(x, image_conv.data(), nimages, nthreads, 4));
|
|
}
|