@@ -12,6 +12,11 @@ Additional settings (High Level):
1212-sigma_th lower threshold for the local intensity scale
1313-grad_th ignore areas in the image where the gradient magnitude is lower than this value
1414
15+ -skipOutputMessages produce less output/debug messages
16+ -doNotSaveAPRs do not save output APR files (good for benchmarking)
17+ -r number of repetitions - default value = 1 means that all input files are processed only once
18+ for higher number input files are processed multiple times (good for benchmarking)
19+
1520Advanced (Direct) Settings:
1621===========================
1722-lambda lambda_value (directly set the value of the gradient smoothing parameter lambda (reasonable range 0.1-10, default: 3)
@@ -43,6 +48,11 @@ struct cmdLineOptions {
4348 float rel_error = 0.1 ;
4449
4550 bool neighborhood_optimization = true ;
51+
52+ int numOfRepetitions = 1 ;
53+ int numOfStreams = 3 ;
54+ bool doNotSaveAPRs = false ;
55+ bool skipOutputMessages = false ;
4656};
4757
4858bool command_option_exists (const char **begin, const char **end, const std::string &option)
@@ -112,10 +122,26 @@ cmdLineOptions read_command_line_options(const int argc, const char **argv) {
112122 options.neighborhood_optimization = false ;
113123 }
114124
125+ if (command_option_exists (argv, argv + argc, " -skipOutputMessages" )) {
126+ options.skipOutputMessages = true ;
127+ }
128+
129+ if (command_option_exists (argv, argv + argc, " -doNotSaveAPRs" )) {
130+ options.doNotSaveAPRs = true ;
131+ }
132+
133+ if (command_option_exists (argv, argv + argc, " -r" )) {
134+ options.numOfRepetitions = std::stoi (std::string (get_command_option (argv, argv + argc, " -r" )));
135+ }
136+
137+ if (command_option_exists (argv, argv + argc, " -numOfStreams" )) {
138+ options.numOfStreams = std::stoi (std::string (get_command_option (argv, argv + argc, " -numOfStreams" )));
139+ }
140+
115141 return options;
116142}
117143
118-
144+ /* Finds all tiff files (with possible different extensions) in provided directory */
119145auto getTiffFilesFromDir (const std::string &directory_path) {
120146 namespace fs = std::filesystem;
121147
@@ -124,8 +150,7 @@ auto getTiffFilesFromDir(const std::string &directory_path) {
124150 try {
125151 for (const auto & entry : fs::directory_iterator (directory_path)) {
126152 if (entry.is_regular_file ()) {
127- auto ext = entry.path ().extension ().string ();
128- if (ext == " .tif" || ext == " .tiff" || ext == " .TIF" || ext == " .TIFF" ) {
153+ if (auto ext = entry.path ().extension ().string (); ext == " .tif" || ext == " .tiff" || ext == " .TIF" || ext == " .TIFF" ) {
129154 tif_files.push_back (entry.path ());
130155 }
131156 }
@@ -191,44 +216,61 @@ int runAPR(const cmdLineOptions &options) {
191216 partIntensities.push_back (std::make_unique<VectorData<ImgType>>(VectorData<ImgType>{}));
192217 partIntensities_raw.push_back (partIntensities.back ().get ());
193218 }
219+ // To proces input image multiple times (for benchmarking etc.) we 'multiply input data' by adding extra APR and particle intensity objects and
220+ // by copying input raw pointer to images to 'pretend' that we have a lot of input images.
221+ size_t numOfInputImages = input_images_raw.size ();
222+ for (int m = 1 ; m < options.numOfRepetitions ; m++) {
223+ for (size_t n = 0 ; n < numOfInputImages; n++) {
224+ input_images_raw.push_back (input_images[n].get ());
225+ APRs.push_back (std::make_unique<APR >(APR {}));
226+ APRs_raw.push_back (APRs.back ().get ());
227+ partIntensities.push_back (std::make_unique<VectorData<ImgType>>(VectorData<ImgType>{}));
228+ partIntensities_raw.push_back (partIntensities.back ().get ());
229+ }
230+ }
194231
195232 std::cout << std::endl;
196233
197- APRTimer timer (true );
234+ APRTimer timer (false );
198235 timer.start_timer (" GPU pipeline (mem allocation, processing, sampling) " );
199- if (aprConverter.get_apr_cuda_multistreams (APRs_raw, input_images_raw, partIntensities_raw)) {
236+ if (aprConverter.get_apr_cuda_multistreams (APRs_raw, input_images_raw, partIntensities_raw, options. numOfStreams )) {
200237 timer.stop_timer ();
201- size_t numOfImages = input_images_raw.size ();
202- std::cout << std::endl;
238+ size_t numOfImagesToProcess = input_images_raw.size (); // might be 'processInputMultipleTimes' times bigger than num of input images
239+ if (!options. skipOutputMessages ) std::cout << std::endl;
203240
204- for (size_t i = 0 ; i < numOfImages ; i++) {
205- std::cout << " Postprocessing " << i+1 << " /" << numOfImages << " image...\n " ;
241+ for (size_t i = 0 ; i < numOfImagesToProcess && !options. doNotSaveAPRs ; i++) {
242+ if (!options. skipOutputMessages ) std::cout << " Postprocessing " << i+1 << " /" << numOfImagesToProcess << " image...\n " ;
206243 auto &apr = *APRs[i].get (); // currently process APR
207244 auto &particle_intensities = *partIntensities[i].get (); // intensities sampled for current APR
208245
209246
210247 // ------------ TODO: remove me later, this is quick test for Cpu vs Gpu before real test is written
211248 // std::cout << apr.linearAccess.y_vec.size() << " particles in APR" << std::endl;
212249 // std::cout << particle_intensities.size() << " intensities in CPU in APR" << std::endl;
213- // if (apr.linearAccess.y_vec.size() != particle_intensities.size()) {std::cerr << "CPU vs GPU number of particles differ!" << std::endl;}
250+ if (apr.linearAccess .y_vec .size () != particle_intensities.size ()) {std::cerr << " CPU vs GPU number of particles differ!" << std::endl;}
214251 ParticleData<ImgType> particle_intensities_cpu;
215- particle_intensities_cpu.sample_image (apr, *input_images[i].get ()); // sample your particles from your image
252+ particle_intensities_cpu.sample_image (apr, *input_images_raw[i]); // sample your particles from your image
253+ int errorCnt = 0 ;
216254 for (size_t j = 0 ; j < particle_intensities.size (); ++j) {
217255 if (particle_intensities_cpu[j] != particle_intensities[j]) {
218- std::cout << " Mismatch at " << j << " CPU: " << particle_intensities_cpu[j] << " GPU: " << particle_intensities[j] << std::endl;
256+ errorCnt++;
257+ // std::cout << "Mismatch at " << j << " CPU: " << particle_intensities_cpu[j] << " GPU: " << particle_intensities[j] << std::endl;
219258 }
220259 }
260+ if (errorCnt > 0 ) std::cout << errorCnt << " errors for index=" << i << std::endl;
221261 // ---------------------------------------------------------------------------------------------------
222262
223263 // Output name is like base of input filename + extension ".apr"
264+ // Extra number is added for 'multiplied' input images
224265 auto outputDir = std::filesystem::path (options.output_dir );
225- const std::filesystem::path& p (tifFiles[i]);
226- std::string outpuFileName = p.stem ().string () + " .apr" ;
266+ const std::filesystem::path& p (tifFiles[i % numOfInputImages]);
267+ std::string num = (i >= numOfInputImages) ? std::to_string (i) : " " ;
268+ std::string outputFileName = p.stem ().string () + num + " .apr" ;
227269
228270 // write the APR to hdf5 file
229271 timer.start_timer (" writing output" );
230272 APRFile aprFile;
231- aprFile.open (outputDir / outpuFileName );
273+ aprFile.open (outputDir / outputFileName );
232274 aprFile.write_apr (apr, 0 , " t" , false );
233275 ParticleData<ImgType> pd;
234276 pd.data = std::move (particle_intensities);
@@ -239,10 +281,13 @@ int runAPR(const cmdLineOptions &options) {
239281 float aprImageSizeInMB = aprFile.current_file_size_MB ();
240282 double originalImageSizeInMB = sizeof (ImgType) * static_cast <double >(apr.org_dims (0 ) * apr.org_dims (1 ) * apr.org_dims (2 )) / 1'000'000.0 ;
241283
242- std::cout << " Computational Ratio (Pixels/Particles): " << apr.computational_ratio () << std::endl;
243- std::cout << " Original / APR image size: " << originalImageSizeInMB << " / " << aprImageSizeInMB <<" MB" << std::endl;
244- std::cout << " Lossy Compression Ratio: " << originalImageSizeInMB/aprImageSizeInMB << std::endl;
245- std::cout << std::endl;
284+ if (!options.skipOutputMessages ) {
285+ std::cout << " Save filename: [" << outputFileName << " ]" << std::endl;
286+ std::cout << " Computational Ratio (Pixels/Particles): " << apr.computational_ratio () << std::endl;
287+ std::cout << " Original / APR image size: " << originalImageSizeInMB << " / " << aprImageSizeInMB <<" MB" << std::endl;
288+ std::cout << " Lossy Compression Ratio: " << originalImageSizeInMB/aprImageSizeInMB << std::endl;
289+ std::cout << std::endl;
290+ }
246291 }
247292 }
248293 else {
0 commit comments