File indexing completed on 2026-07-07 08:47:25
0001
0002 #include <catch.hpp>
0003
0004 #include <JANA/JApplication.h>
0005 #include <JANA/JFactoryGenerator.h>
0006 #include <JANA/CLI/JBenchmarker.h>
0007 #include <JANA/JEventUnfolder.h>
0008 #include <JANA/JEventProcessor.h>
0009 #include <JANA/JEventSource.h>
0010 #include <JANA/Utils/JBenchUtils.h>
0011
0012
0013 namespace jana::perftest::tapchain {
0014
0015 struct Data { size_t x; };
0016
0017 struct Src : public JEventSource {
0018
0019 Output<Data> data_out {this};
0020 Parameter<int> latency_us {this, "latency_us", 0};
0021
0022 Src() {
0023 SetPrefix("src");
0024 SetCallbackStyle(CallbackStyle::ExpertMode);
0025 data_out.SetShortName("1");
0026 }
0027 JEventSource::Result Emit(JEvent& evt) override {
0028 data_out().push_back(new Data {evt.GetEventNumber()*3 });
0029 JBenchUtils::consume_cpu_us(*latency_us);
0030 return Result::Success;
0031 };
0032 };
0033
0034 struct Fac : public JFactory {
0035 Input<Data> data_in {this};
0036 Output<Data> data_out {this};
0037 Parameter<int> latency_us {this, "latency_us", 0};
0038
0039 Fac() {
0040 SetPrefix("fac");
0041 data_in.SetDatabundleName("1");
0042 data_out.SetShortName("2");
0043 }
0044 void Process(const JEvent&) override {
0045 auto x = data_in().at(0)->x + 7;
0046 data_out().push_back(new Data {x});
0047 JBenchUtils::consume_cpu_us(*latency_us);
0048 };
0049 };
0050
0051 struct Proc : public JEventProcessor {
0052 Input<Data> data_in {this};
0053 Parameter<int> latency_us {this, "latency_us", 0};
0054 Proc() {
0055 SetPrefix("proc");
0056 SetCallbackStyle(CallbackStyle::ExpertMode);
0057 data_in.SetDatabundleName("2");
0058 }
0059 void ProcessSequential(const JEvent&) override {
0060 (void) (data_in().at(0)->x);
0061 JBenchUtils::consume_cpu_us(*latency_us);
0062 };
0063 };
0064
0065
0066 TEST_CASE("TapChainTopology_1_Mini") {
0067
0068 LOG << "Running TapChainTopology_1_Mini";
0069
0070 JApplication app;
0071 app.Add(new Src);
0072 app.Add(new JFactoryGeneratorT<Fac>);
0073 app.Add(new Proc);
0074
0075 app.SetParameterValue("src:latency_us", 0);
0076 app.SetParameterValue("fac:latency_us", 0);
0077 app.SetParameterValue("proc:latency_us", 0);
0078 app.SetParameterValue("benchmark:resultsdir", "docs/perf_tests");
0079 app.SetParameterValue("benchmark:rates_filename", "tapchain_1_mini.dat");
0080 app.SetParameterValue("benchmark:use_log_scale", true);
0081 app.SetParameterValue("benchmark:minthreads", "1");
0082 app.SetParameterValue("benchmark:maxthreads", "32");
0083
0084 JBenchmarker benchmarker(&app);
0085 benchmarker.RunUntilFinished();
0086 }
0087
0088 TEST_CASE("TapChainTopology_4_Mini") {
0089
0090 LOG << "Running TapChainTopology_4_Mini";
0091
0092 JApplication app;
0093 app.Add(new Src);
0094 app.Add(new JFactoryGeneratorT<Fac>);
0095 for (int i=0; i<4; ++i) {
0096 app.Add(new Proc);
0097 }
0098
0099 app.SetParameterValue("benchmark:resultsdir", "docs/perf_tests");
0100 app.SetParameterValue("benchmark:rates_filename", "tapchain_4_mini.dat");
0101 app.SetParameterValue("benchmark:use_log_scale", true);
0102 app.SetParameterValue("benchmark:minthreads", "1");
0103 app.SetParameterValue("benchmark:maxthreads", "32");
0104
0105 JBenchmarker benchmarker(&app);
0106 benchmarker.RunUntilFinished();
0107 }
0108
0109 TEST_CASE("TapChainTopology_16_Mini") {
0110
0111 LOG << "Running TapChainTopology_16_Mini";
0112
0113 JApplication app;
0114 app.Add(new Src);
0115 app.Add(new JFactoryGeneratorT<Fac>);
0116 for (int i=0; i<16; ++i) {
0117 app.Add(new Proc);
0118 }
0119
0120 app.SetParameterValue("src:latency_us", 0);
0121 app.SetParameterValue("fac:latency_us", 0);
0122 app.SetParameterValue("proc:latency_us", 0);
0123 app.SetParameterValue("benchmark:resultsdir", "docs/perf_tests");
0124 app.SetParameterValue("benchmark:rates_filename", "tapchain_16_mini.dat");
0125 app.SetParameterValue("benchmark:use_log_scale", true);
0126 app.SetParameterValue("benchmark:minthreads", "1");
0127 app.SetParameterValue("benchmark:maxthreads", "32");
0128
0129 JBenchmarker benchmarker(&app);
0130 benchmarker.RunUntilFinished();
0131 }
0132
0133 TEST_CASE("TapChainTopology_1_Small") {
0134
0135 LOG << "Running TapChainTopology_1_Small";
0136
0137 JApplication app;
0138 app.Add(new Src);
0139 app.Add(new JFactoryGeneratorT<Fac>);
0140 app.Add(new Proc);
0141
0142 app.SetParameterValue("src:latency_us", 0);
0143 app.SetParameterValue("fac:latency_us", 1'000'000 / 5000);
0144 app.SetParameterValue("proc:latency_us", 0);
0145 app.SetParameterValue("benchmark:resultsdir", "docs/perf_tests");
0146 app.SetParameterValue("benchmark:rates_filename", "tapchain_1_small.dat");
0147 app.SetParameterValue("benchmark:use_log_scale", true);
0148 app.SetParameterValue("benchmark:minthreads", "1");
0149 app.SetParameterValue("benchmark:maxthreads", "32");
0150
0151 JBenchmarker benchmarker(&app);
0152 benchmarker.RunUntilFinished();
0153 }
0154
0155 TEST_CASE("TapChainTopology_4_Small") {
0156
0157 LOG << "Running TapChainTopology_4_Small";
0158
0159 JApplication app;
0160 app.Add(new Src);
0161 app.Add(new JFactoryGeneratorT<Fac>);
0162 for (int i=0; i<4; ++i) {
0163 app.Add(new Proc);
0164 }
0165
0166 app.SetParameterValue("src:latency_us", 0);
0167 app.SetParameterValue("fac:latency_us", 1'000'000 / 5000);
0168 app.SetParameterValue("proc:latency_us", 0);
0169 app.SetParameterValue("benchmark:resultsdir", "docs/perf_tests");
0170 app.SetParameterValue("benchmark:rates_filename", "tapchain_4_small.dat");
0171 app.SetParameterValue("benchmark:use_log_scale", true);
0172 app.SetParameterValue("benchmark:minthreads", "1");
0173 app.SetParameterValue("benchmark:maxthreads", "32");
0174
0175 JBenchmarker benchmarker(&app);
0176 benchmarker.RunUntilFinished();
0177 }
0178
0179 TEST_CASE("TapChainTopology_16_Small") {
0180
0181 LOG << "Running TapChainTopology_16_Small";
0182
0183 JApplication app;
0184 app.Add(new Src);
0185 app.Add(new JFactoryGeneratorT<Fac>);
0186 for (int i=0; i<16; ++i) {
0187 app.Add(new Proc);
0188 }
0189
0190 app.SetParameterValue("src:latency_us", 0);
0191 app.SetParameterValue("fac:latency_us", 1'000'000 / 5000);
0192 app.SetParameterValue("proc:latency_us", 0);
0193 app.SetParameterValue("benchmark:resultsdir", "docs/perf_tests");
0194 app.SetParameterValue("benchmark:rates_filename", "tapchain_16_small.dat");
0195 app.SetParameterValue("benchmark:use_log_scale", true);
0196 app.SetParameterValue("benchmark:minthreads", "1");
0197 app.SetParameterValue("benchmark:maxthreads", "32");
0198
0199 JBenchmarker benchmarker(&app);
0200 benchmarker.RunUntilFinished();
0201 }
0202
0203
0204 TEST_CASE("TapChainTopology_1_Medium") {
0205
0206 LOG << "Running TapChainTopology_1_Medium";
0207
0208 JApplication app;
0209 app.Add(new Src);
0210 app.Add(new JFactoryGeneratorT<Fac>);
0211 app.Add(new Proc);
0212
0213 app.SetParameterValue("src:latency_us", 0);
0214 app.SetParameterValue("fac:latency_us", 1'000'000 / 100);
0215 app.SetParameterValue("proc:latency_us", 0);
0216 app.SetParameterValue("benchmark:resultsdir", "docs/perf_tests");
0217 app.SetParameterValue("benchmark:rates_filename", "tapchain_1_medium.dat");
0218 app.SetParameterValue("benchmark:use_log_scale", true);
0219 app.SetParameterValue("benchmark:minthreads", "1");
0220 app.SetParameterValue("benchmark:maxthreads", "32");
0221
0222 JBenchmarker benchmarker(&app);
0223 benchmarker.RunUntilFinished();
0224 }
0225
0226 TEST_CASE("TapChainTopology_4_Medium") {
0227
0228 LOG << "Running TapChainTopology_4_Medium";
0229
0230 JApplication app;
0231 app.Add(new Src);
0232 app.Add(new JFactoryGeneratorT<Fac>);
0233 for (int i=0; i<4; ++i) {
0234 app.Add(new Proc);
0235 }
0236
0237 app.SetParameterValue("src:latency_us", 0);
0238 app.SetParameterValue("fac:latency_us", 1'000'000 / 100);
0239 app.SetParameterValue("proc:latency_us", 0);
0240 app.SetParameterValue("benchmark:resultsdir", "docs/perf_tests");
0241 app.SetParameterValue("benchmark:rates_filename", "tapchain_4_medium.dat");
0242 app.SetParameterValue("benchmark:use_log_scale", true);
0243 app.SetParameterValue("benchmark:minthreads", "1");
0244 app.SetParameterValue("benchmark:maxthreads", "32");
0245
0246 JBenchmarker benchmarker(&app);
0247 benchmarker.RunUntilFinished();
0248 }
0249
0250 TEST_CASE("TapChainTopology_16_Medium") {
0251
0252 LOG << "Running TapChainTopology_16_Medium";
0253
0254 JApplication app;
0255 app.Add(new Src);
0256 app.Add(new JFactoryGeneratorT<Fac>);
0257 for (int i=0; i<16; ++i) {
0258 app.Add(new Proc);
0259 }
0260
0261 app.SetParameterValue("src:latency_us", 0);
0262 app.SetParameterValue("fac:latency_us", 1'000'000 / 100);
0263 app.SetParameterValue("proc:latency_us", 0);
0264 app.SetParameterValue("benchmark:resultsdir", "docs/perf_tests");
0265 app.SetParameterValue("benchmark:rates_filename", "tapchain_16_medium.dat");
0266 app.SetParameterValue("benchmark:use_log_scale", true);
0267 app.SetParameterValue("benchmark:minthreads", "1");
0268 app.SetParameterValue("benchmark:maxthreads", "32");
0269
0270 JBenchmarker benchmarker(&app);
0271 benchmarker.RunUntilFinished();
0272 }
0273
0274 TEST_CASE("TapChainTopology_1_Large") {
0275
0276 LOG << "Running TapChainTopology_1_Large";
0277
0278 JApplication app;
0279 app.Add(new Src);
0280 app.Add(new JFactoryGeneratorT<Fac>);
0281 app.Add(new Proc);
0282
0283 app.SetParameterValue("src:latency_us", 0);
0284 app.SetParameterValue("fac:latency_us", 1'000'000 / 5);
0285 app.SetParameterValue("proc:latency_us", 0);
0286 app.SetParameterValue("benchmark:resultsdir", "docs/perf_tests");
0287 app.SetParameterValue("benchmark:rates_filename", "tapchain_1_large.dat");
0288 app.SetParameterValue("benchmark:use_log_scale", true);
0289 app.SetParameterValue("benchmark:minthreads", "1");
0290 app.SetParameterValue("benchmark:maxthreads", "32");
0291
0292 JBenchmarker benchmarker(&app);
0293 benchmarker.RunUntilFinished();
0294 }
0295
0296 TEST_CASE("TapChainTopology_4_Large") {
0297
0298 LOG << "Running TapChainTopology_4_Large";
0299
0300 JApplication app;
0301 app.Add(new Src);
0302 app.Add(new JFactoryGeneratorT<Fac>);
0303 for (int i=0; i<4; ++i) {
0304 app.Add(new Proc);
0305 }
0306
0307 app.SetParameterValue("src:latency_us", 0);
0308 app.SetParameterValue("fac:latency_us", 1'000'000 / 5);
0309 app.SetParameterValue("proc:latency_us", 0);
0310 app.SetParameterValue("benchmark:resultsdir", "docs/perf_tests");
0311 app.SetParameterValue("benchmark:rates_filename", "tapchain_4_large.dat");
0312 app.SetParameterValue("benchmark:use_log_scale", true);
0313 app.SetParameterValue("benchmark:minthreads", "1");
0314 app.SetParameterValue("benchmark:maxthreads", "32");
0315
0316 JBenchmarker benchmarker(&app);
0317 benchmarker.RunUntilFinished();
0318 }
0319
0320 TEST_CASE("TapChainTopology_16_Large") {
0321
0322 LOG << "Running TapChainTopology_16_Large";
0323
0324 JApplication app;
0325 app.Add(new Src);
0326 app.Add(new JFactoryGeneratorT<Fac>);
0327 for (int i=0; i<16; ++i) {
0328 app.Add(new Proc);
0329 }
0330
0331 app.SetParameterValue("src:latency_us", 0);
0332 app.SetParameterValue("fac:latency_us", 1'000'000 / 5);
0333 app.SetParameterValue("proc:latency_us", 0);
0334 app.SetParameterValue("benchmark:resultsdir", "docs/perf_tests");
0335 app.SetParameterValue("benchmark:rates_filename", "tapchain_16_large.dat");
0336 app.SetParameterValue("benchmark:use_log_scale", true);
0337 app.SetParameterValue("benchmark:minthreads", "1");
0338 app.SetParameterValue("benchmark:maxthreads", "32");
0339
0340 JBenchmarker benchmarker(&app);
0341 benchmarker.RunUntilFinished();
0342 }
0343
0344 TEST_CASE("TapChainTopology_Pipelining") {
0345
0346 LOG << "Running TapChainTopology_Pipelining";
0347
0348 JApplication app;
0349 app.Add(new Src);
0350 app.Add(new JFactoryGeneratorT<Fac>);
0351 for (int i=0; i<4; ++i) {
0352 app.Add(new Proc);
0353 }
0354
0355 app.SetParameterValue("src:latency_us", 1'000'000 / 100);
0356 app.SetParameterValue("fac:latency_us", 1'000'000 / 100);
0357 app.SetParameterValue("proc:latency_us", 1'000'000 / 100);
0358 app.SetParameterValue("benchmark:resultsdir", "docs/perf_tests");
0359 app.SetParameterValue("benchmark:rates_filename", "tapchain_pipelining.dat");
0360 app.SetParameterValue("benchmark:use_log_scale", false);
0361 app.SetParameterValue("benchmark:minthreads", "1");
0362 app.SetParameterValue("benchmark:maxthreads", "16");
0363
0364 JBenchmarker benchmarker(&app);
0365 benchmarker.RunUntilFinished();
0366 }
0367
0368
0369 }
0370
0371
0372