diff --git a/.cmake-format b/.cmake-format index 53f329b..1c0bdc4 100644 --- a/.cmake-format +++ b/.cmake-format @@ -2,13 +2,42 @@ format: disable: false line_width: 100 tab_size: 2 - max_subgroups_hwrap: 3 + max_subgroups_hwrap: 2 dangle_parens: true enable_markup: false parse: additional_commands: + cpmaddpackage: + pargs: + nargs: '*' + flags: [] + spelling: CPMAddPackage + kwargs: &cpmaddpackagekwargs + NAME: 1 + FORCE: 1 + VERSION: 1 + GIT_TAG: 1 + DOWNLOAD_ONLY: 1 + GITHUB_REPOSITORY: 1 + GITLAB_REPOSITORY: 1 + GIT_REPOSITORY: 1 + SVN_REPOSITORY: 1 + SVN_REVISION: 1 + SOURCE_DIR: 1 + DOWNLOAD_COMMAND: 1 + FIND_PACKAGE_ARGUMENTS: 1 + NO_CACHE: 1 + GIT_SHALLOW: 1 + URL: 1 + URL_HASH: 1 + URL_MD5: 1 + DOWNLOAD_NAME: 1 + DOWNLOAD_NO_EXTRACT: 1 + HTTP_USERNAME: 1 + HTTP_PASSWORD: 1 + OPTIONS: + cpmfindpackage: pargs: nargs: '*' diff --git a/CMakeLists.txt b/CMakeLists.txt index bc0e4a9..42bb54d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,12 +1,18 @@ cmake_minimum_required(VERSION 3.15) cmake_policy(SET CMP0148 OLD) -project(dmt VERSION 0.1.0 LANGUAGES CXX) +project( + dmt + VERSION 0.1.0 + LANGUAGES CXX +) # Configuration options option(BUILD_DOCS "Build documentation" OFF) option(BUILD_PYTHON "Build Python bindings" ON) option(BUILD_TESTING "Build tests" OFF) +option(ENABLE_COVERAGE "Enable coverage reporting" OFF) +option(BUILD_BENCHMARKS "Build benchmarks" OFF) option(ENABLE_FAST_MATH "Enable fast math flags" ON) set(CMAKE_CXX_STANDARD 17) @@ -30,7 +36,6 @@ endif() include(GNUInstallDirs) include(cmake/CPM.cmake) - # Build the C++ library set(LIBRARY_NAME dmt) add_subdirectory(lib) @@ -42,6 +47,10 @@ endif() if(BUILD_TESTING) add_subdirectory(tests/cpp) endif() +# Build benchmarks +if(BUILD_BENCHMARKS) + add_subdirectory(bench) +endif() # Install targets and configuration install( @@ -52,7 +61,11 @@ install( ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} ) -install(EXPORT dmt_config NAMESPACE dmt:: DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/dmt) +install( + EXPORT dmt_config + NAMESPACE dmt:: + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/dmt +) install(DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) # This prints a summary of found dependencies diff --git a/README.md b/README.md index 030cad5..0f9e1fb 100644 --- a/README.md +++ b/README.md @@ -27,4 +27,11 @@ thefdmt = FDMT(f_min, f_max, nchans, nsamps, tsamp, dt_max=dt_max, dt_min=0, dt_ dmt_transform = thefdmt.execute(frb.astype(np.float32)) ``` +## Benchmarks + +```python +f_min = 704.0, f_max = 1216.0, nchans = 4096, tsamp = 0.00008192, dt_max = 2048, nsamps = n; +``` +![](bench/results/bench.png) + diff --git a/bench/CMakeLists.txt b/bench/CMakeLists.txt new file mode 100644 index 0000000..ef5eff6 --- /dev/null +++ b/bench/CMakeLists.txt @@ -0,0 +1,13 @@ +CPMAddPackage( + NAME benchmark + VERSION 1.8.0 + GITHUB_REPOSITORY google/benchmark + OPTIONS "BENCHMARK_ENABLE_TESTING Off" +) + +set(TARGET_BENCHMARKS ${PROJECT_NAME}_bench) +file(GLOB TEST_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp) + +add_executable(${TARGET_BENCHMARKS} ${TEST_SOURCES}) +target_include_directories(${TARGET_BENCHMARKS} PUBLIC ${CMAKE_SOURCE_DIR}/include) +target_link_libraries(${TARGET_BENCHMARKS} PRIVATE ${LIBRARY_NAME} benchmark::benchmark) diff --git a/bench/bench_plots.py b/bench/bench_plots.py new file mode 100644 index 0000000..54aad3f --- /dev/null +++ b/bench/bench_plots.py @@ -0,0 +1,56 @@ +import json +import sys +from pathlib import Path + +import pandas as pd +import seaborn as sns +from matplotlib import pyplot as plt + +filename = sys.argv[1] +basename = filename.split(".")[0] + +# load benchmarks data +with Path(filename).open("r") as jfile: + jdata = json.load(jfile) +bench_df = pd.DataFrame(jdata["benchmarks"]) + +# only keep names with /, i.e. drop avg/rms/etc entries +bench_df = bench_df.loc[bench_df.name.str.contains("/")] + +# create a column with complexity n +bench_df[["benchmark_name", "benchmark_type", "n"]] = bench_df.name.str.split( + "/BM_|_|/", + expand=True, +).apply( + lambda x: ["_".join([x[1], x[2]]), "_".join([x[3], x[4]]), x[5]], + axis=1, + result_type="expand", +) +bench_df["n"] = bench_df["n"].astype("uint32") +bench_df = bench_df[["benchmark_name", "n", "cpu_time", "benchmark_type"]] +benchmarks = bench_df.benchmark_name.unique() + +palette = sns.color_palette("husl", len(benchmarks)) +fig, axes = plt.subplots(2, 2, figsize=(10, 6), sharex=True) +for i, benchmark in enumerate(benchmarks): + ax = axes[0, i] if i < 2 else axes[1, i - 2] + data = bench_df[bench_df["benchmark_name"] == benchmark] + sns.lineplot( + x="n", + y="cpu_time", + hue="benchmark_type", + data=data, + ax=ax, + color=palette[i], + marker="o", + markersize=8, + ) + ax.set_title(benchmark) + ax.set_xscale("log") + ax.set_yscale("log") + ax.set_xlabel("n") + ax.set_ylabel("Time (s)") + ax.legend() + +fig.tight_layout() +fig.savefig(f"{basename}.png", bbox_inches="tight", dpi=120) diff --git a/bench/fdmt_b.cpp b/bench/fdmt_b.cpp new file mode 100644 index 0000000..e9ce707 --- /dev/null +++ b/bench/fdmt_b.cpp @@ -0,0 +1,101 @@ +#include + +#include +#include +#include +#include + +class FDMTFixture : public benchmark::Fixture { +public: + void SetUp(const ::benchmark::State& state) { + f_min = 704.0F; + f_max = 1216.0F; + nchans = 4096; + tsamp = 0.00008192F; + dt_max = 2048; + nsamps = state.range(0); + } + + void TearDown(const ::benchmark::State&) {} + + template + std::vector generate_vector(size_t size, std::mt19937& gen) { + std::vector vec(size); + std::uniform_real_distribution dis(0.0, 1.0); + std::generate(vec.begin(), vec.end(), [&]() { return dis(gen); }); + return vec; + } + + float f_min; + float f_max; + size_t nchans; + float tsamp; + size_t dt_max; + size_t nsamps; +}; + +BENCHMARK_DEFINE_F(FDMTFixture, BM_fdmt_plan_seq_cpu)(benchmark::State& state) { + for (auto _ : state) { + FDMT fdmt(f_min, f_max, nchans, nsamps, tsamp, dt_max); + } +} + +BENCHMARK_DEFINE_F(FDMTFixture, BM_fdmt_initialise_seq_cpu)(benchmark::State& state) { + FDMT fdmt(f_min, f_max, nchans, nsamps, tsamp, dt_max); + + std::random_device rd; + std::mt19937 gen(rd()); + auto waterfall = generate_vector(nchans * nsamps, gen); + std::vector state_init( + nchans * fdmt.get_dt_grid_init().size() * nsamps, 0.0F); + for (auto _ : state) { + fdmt.initialise(waterfall.data(), state_init.data()); + } +} + +BENCHMARK_DEFINE_F(FDMTFixture, BM_fdmt_execute_seq_cpu)(benchmark::State& state) { + FDMT fdmt(f_min, f_max, nchans, nsamps, tsamp, dt_max); + + std::random_device rd; + std::mt19937 gen(rd()); + auto waterfall = generate_vector(nchans * nsamps, gen); + std::vector dmt(fdmt.get_dt_grid_final().size() * nsamps, 0.0F); + for (auto _ : state) { + fdmt.execute(waterfall.data(), waterfall.size(), dmt.data(), + dmt.size()); + } +} + +BENCHMARK_DEFINE_F(FDMTFixture, BM_fdmt_overall_seq_cpu)(benchmark::State& state) { + std::random_device rd; + std::mt19937 gen(rd()); + auto waterfall = generate_vector(nchans * nsamps, gen); + + for (auto _ : state) { + FDMT fdmt(f_min, f_max, nchans, nsamps, tsamp, dt_max); + state.PauseTiming(); + std::vector dmt(fdmt.get_dt_grid_final().size() * nsamps, 0.0F); + state.ResumeTiming(); + + fdmt.execute(waterfall.data(), waterfall.size(), dmt.data(), + dmt.size()); + } +} + +constexpr size_t min_nsamps = 1 << 11; +constexpr size_t max_nsamps = 1 << 16; + +BENCHMARK_REGISTER_F(FDMTFixture, BM_fdmt_plan_seq_cpu) + ->RangeMultiplier(2) + ->Range(min_nsamps, max_nsamps); +BENCHMARK_REGISTER_F(FDMTFixture, BM_fdmt_initialise_seq_cpu) + ->RangeMultiplier(2) + ->Range(min_nsamps, max_nsamps); +BENCHMARK_REGISTER_F(FDMTFixture, BM_fdmt_execute_seq_cpu) + ->RangeMultiplier(2) + ->Range(min_nsamps, max_nsamps); +BENCHMARK_REGISTER_F(FDMTFixture, BM_fdmt_overall_seq_cpu) + ->RangeMultiplier(2) + ->Range(min_nsamps, max_nsamps); + +BENCHMARK_MAIN(); diff --git a/bench/results/bench.json b/bench/results/bench.json new file mode 100644 index 0000000..80f69c1 --- /dev/null +++ b/bench/results/bench.json @@ -0,0 +1,376 @@ +{ + "context": { + "date": "2024-04-27T16:24:38+03:00", + "host_name": "pravir-XPS-15-9520", + "executable": "./bench/dmt_bench", + "num_cpus": 20, + "mhz_per_cpu": 4600, + "cpu_scaling_enabled": true, + "caches": [ + { + "type": "Data", + "level": 1, + "size": 49152, + "num_sharing": 2 + }, + { + "type": "Instruction", + "level": 1, + "size": 32768, + "num_sharing": 2 + }, + { + "type": "Unified", + "level": 2, + "size": 1310720, + "num_sharing": 2 + }, + { + "type": "Unified", + "level": 3, + "size": 25165824, + "num_sharing": 20 + } + ], + "load_avg": [0.864746,0.76709,0.866211], + "library_build_type": "release" + }, + "benchmarks": [ + { + "name": "FDMTFixture/BM_fdmt_plan_seq_cpu/2048", + "family_index": 0, + "per_family_instance_index": 0, + "run_name": "FDMTFixture/BM_fdmt_plan_seq_cpu/2048", + "run_type": "iteration", + "repetitions": 1, + "repetition_index": 0, + "threads": 1, + "iterations": 19, + "real_time": 3.5852266052595373e-02, + "cpu_time": 3.5851202789473686e-02, + "time_unit": "s" + }, + { + "name": "FDMTFixture/BM_fdmt_plan_seq_cpu/4096", + "family_index": 0, + "per_family_instance_index": 1, + "run_name": "FDMTFixture/BM_fdmt_plan_seq_cpu/4096", + "run_type": "iteration", + "repetitions": 1, + "repetition_index": 0, + "threads": 1, + "iterations": 10, + "real_time": 6.9962882699837789e-02, + "cpu_time": 6.9963295100000017e-02, + "time_unit": "s" + }, + { + "name": "FDMTFixture/BM_fdmt_plan_seq_cpu/8192", + "family_index": 0, + "per_family_instance_index": 2, + "run_name": "FDMTFixture/BM_fdmt_plan_seq_cpu/8192", + "run_type": "iteration", + "repetitions": 1, + "repetition_index": 0, + "threads": 1, + "iterations": 5, + "real_time": 1.3640636499985703e-01, + "cpu_time": 1.3640372600000000e-01, + "time_unit": "s" + }, + { + "name": "FDMTFixture/BM_fdmt_plan_seq_cpu/16384", + "family_index": 0, + "per_family_instance_index": 3, + "run_name": "FDMTFixture/BM_fdmt_plan_seq_cpu/16384", + "run_type": "iteration", + "repetitions": 1, + "repetition_index": 0, + "threads": 1, + "iterations": 3, + "real_time": 2.6750123033222434e-01, + "cpu_time": 2.6749946100000005e-01, + "time_unit": "s" + }, + { + "name": "FDMTFixture/BM_fdmt_plan_seq_cpu/32768", + "family_index": 0, + "per_family_instance_index": 4, + "run_name": "FDMTFixture/BM_fdmt_plan_seq_cpu/32768", + "run_type": "iteration", + "repetitions": 1, + "repetition_index": 0, + "threads": 1, + "iterations": 1, + "real_time": 5.2668406100201537e-01, + "cpu_time": 5.2667077600000001e-01, + "time_unit": "s" + }, + { + "name": "FDMTFixture/BM_fdmt_plan_seq_cpu/65536", + "family_index": 0, + "per_family_instance_index": 5, + "run_name": "FDMTFixture/BM_fdmt_plan_seq_cpu/65536", + "run_type": "iteration", + "repetitions": 1, + "repetition_index": 0, + "threads": 1, + "iterations": 1, + "real_time": 1.0396124110011442e+00, + "cpu_time": 1.0395500830000000e+00, + "time_unit": "s" + }, + { + "name": "FDMTFixture/BM_fdmt_initialise_seq_cpu/2048", + "family_index": 1, + "per_family_instance_index": 0, + "run_name": "FDMTFixture/BM_fdmt_initialise_seq_cpu/2048", + "run_type": "iteration", + "repetitions": 1, + "repetition_index": 0, + "threads": 1, + "iterations": 49, + "real_time": 1.4374950714246014e-02, + "cpu_time": 1.4373672571428579e-02, + "time_unit": "s" + }, + { + "name": "FDMTFixture/BM_fdmt_initialise_seq_cpu/4096", + "family_index": 1, + "per_family_instance_index": 1, + "run_name": "FDMTFixture/BM_fdmt_initialise_seq_cpu/4096", + "run_type": "iteration", + "repetitions": 1, + "repetition_index": 0, + "threads": 1, + "iterations": 25, + "real_time": 2.8491261080052937e-02, + "cpu_time": 2.8490377560000012e-02, + "time_unit": "s" + }, + { + "name": "FDMTFixture/BM_fdmt_initialise_seq_cpu/8192", + "family_index": 1, + "per_family_instance_index": 2, + "run_name": "FDMTFixture/BM_fdmt_initialise_seq_cpu/8192", + "run_type": "iteration", + "repetitions": 1, + "repetition_index": 0, + "threads": 1, + "iterations": 12, + "real_time": 5.9919000666620072e-02, + "cpu_time": 5.9918737666666701e-02, + "time_unit": "s" + }, + { + "name": "FDMTFixture/BM_fdmt_initialise_seq_cpu/16384", + "family_index": 1, + "per_family_instance_index": 3, + "run_name": "FDMTFixture/BM_fdmt_initialise_seq_cpu/16384", + "run_type": "iteration", + "repetitions": 1, + "repetition_index": 0, + "threads": 1, + "iterations": 6, + "real_time": 1.1758171900025143e-01, + "cpu_time": 1.1757960366666668e-01, + "time_unit": "s" + }, + { + "name": "FDMTFixture/BM_fdmt_initialise_seq_cpu/32768", + "family_index": 1, + "per_family_instance_index": 4, + "run_name": "FDMTFixture/BM_fdmt_initialise_seq_cpu/32768", + "run_type": "iteration", + "repetitions": 1, + "repetition_index": 0, + "threads": 1, + "iterations": 3, + "real_time": 2.2490310100086694e-01, + "cpu_time": 2.2489666599999994e-01, + "time_unit": "s" + }, + { + "name": "FDMTFixture/BM_fdmt_initialise_seq_cpu/65536", + "family_index": 1, + "per_family_instance_index": 5, + "run_name": "FDMTFixture/BM_fdmt_initialise_seq_cpu/65536", + "run_type": "iteration", + "repetitions": 1, + "repetition_index": 0, + "threads": 1, + "iterations": 2, + "real_time": 4.5874230949993944e-01, + "cpu_time": 4.5872174600000015e-01, + "time_unit": "s" + }, + { + "name": "FDMTFixture/BM_fdmt_execute_seq_cpu/2048", + "family_index": 2, + "per_family_instance_index": 0, + "run_name": "FDMTFixture/BM_fdmt_execute_seq_cpu/2048", + "run_type": "iteration", + "repetitions": 1, + "repetition_index": 0, + "threads": 1, + "iterations": 20, + "real_time": 3.4325324800011006e-02, + "cpu_time": 3.4324657300000005e-02, + "time_unit": "s" + }, + { + "name": "FDMTFixture/BM_fdmt_execute_seq_cpu/4096", + "family_index": 2, + "per_family_instance_index": 1, + "run_name": "FDMTFixture/BM_fdmt_execute_seq_cpu/4096", + "run_type": "iteration", + "repetitions": 1, + "repetition_index": 0, + "threads": 1, + "iterations": 9, + "real_time": 7.2530441444541793e-02, + "cpu_time": 7.2528060111110904e-02, + "time_unit": "s" + }, + { + "name": "FDMTFixture/BM_fdmt_execute_seq_cpu/8192", + "family_index": 2, + "per_family_instance_index": 2, + "run_name": "FDMTFixture/BM_fdmt_execute_seq_cpu/8192", + "run_type": "iteration", + "repetitions": 1, + "repetition_index": 0, + "threads": 1, + "iterations": 5, + "real_time": 1.5036192940024193e-01, + "cpu_time": 1.5035812360000023e-01, + "time_unit": "s" + }, + { + "name": "FDMTFixture/BM_fdmt_execute_seq_cpu/16384", + "family_index": 2, + "per_family_instance_index": 3, + "run_name": "FDMTFixture/BM_fdmt_execute_seq_cpu/16384", + "run_type": "iteration", + "repetitions": 1, + "repetition_index": 0, + "threads": 1, + "iterations": 2, + "real_time": 3.0738760999884107e-01, + "cpu_time": 3.0737046499999998e-01, + "time_unit": "s" + }, + { + "name": "FDMTFixture/BM_fdmt_execute_seq_cpu/32768", + "family_index": 2, + "per_family_instance_index": 4, + "run_name": "FDMTFixture/BM_fdmt_execute_seq_cpu/32768", + "run_type": "iteration", + "repetitions": 1, + "repetition_index": 0, + "threads": 1, + "iterations": 1, + "real_time": 6.1063822199866991e-01, + "cpu_time": 6.1061422699999923e-01, + "time_unit": "s" + }, + { + "name": "FDMTFixture/BM_fdmt_execute_seq_cpu/65536", + "family_index": 2, + "per_family_instance_index": 5, + "run_name": "FDMTFixture/BM_fdmt_execute_seq_cpu/65536", + "run_type": "iteration", + "repetitions": 1, + "repetition_index": 0, + "threads": 1, + "iterations": 1, + "real_time": 1.2311497049995523e+00, + "cpu_time": 1.2310870969999996e+00, + "time_unit": "s" + }, + { + "name": "FDMTFixture/BM_fdmt_overall_seq_cpu/2048", + "family_index": 3, + "per_family_instance_index": 0, + "run_name": "FDMTFixture/BM_fdmt_overall_seq_cpu/2048", + "run_type": "iteration", + "repetitions": 1, + "repetition_index": 0, + "threads": 1, + "iterations": 9, + "real_time": 7.2772332777175402e-02, + "cpu_time": 7.2768525666666292e-02, + "time_unit": "s" + }, + { + "name": "FDMTFixture/BM_fdmt_overall_seq_cpu/4096", + "family_index": 3, + "per_family_instance_index": 1, + "run_name": "FDMTFixture/BM_fdmt_overall_seq_cpu/4096", + "run_type": "iteration", + "repetitions": 1, + "repetition_index": 0, + "threads": 1, + "iterations": 5, + "real_time": 1.4704085220000707e-01, + "cpu_time": 1.4703812379999945e-01, + "time_unit": "s" + }, + { + "name": "FDMTFixture/BM_fdmt_overall_seq_cpu/8192", + "family_index": 3, + "per_family_instance_index": 2, + "run_name": "FDMTFixture/BM_fdmt_overall_seq_cpu/8192", + "run_type": "iteration", + "repetitions": 1, + "repetition_index": 0, + "threads": 1, + "iterations": 2, + "real_time": 2.8918253599840682e-01, + "cpu_time": 2.8917640950000134e-01, + "time_unit": "s" + }, + { + "name": "FDMTFixture/BM_fdmt_overall_seq_cpu/16384", + "family_index": 3, + "per_family_instance_index": 3, + "run_name": "FDMTFixture/BM_fdmt_overall_seq_cpu/16384", + "run_type": "iteration", + "repetitions": 1, + "repetition_index": 0, + "threads": 1, + "iterations": 1, + "real_time": 5.7477077700241352e-01, + "cpu_time": 5.7475182799999658e-01, + "time_unit": "s" + }, + { + "name": "FDMTFixture/BM_fdmt_overall_seq_cpu/32768", + "family_index": 3, + "per_family_instance_index": 4, + "run_name": "FDMTFixture/BM_fdmt_overall_seq_cpu/32768", + "run_type": "iteration", + "repetitions": 1, + "repetition_index": 0, + "threads": 1, + "iterations": 1, + "real_time": 1.1282505420022062e+00, + "cpu_time": 1.1282340069999961e+00, + "time_unit": "s" + }, + { + "name": "FDMTFixture/BM_fdmt_overall_seq_cpu/65536", + "family_index": 3, + "per_family_instance_index": 5, + "run_name": "FDMTFixture/BM_fdmt_overall_seq_cpu/65536", + "run_type": "iteration", + "repetitions": 1, + "repetition_index": 0, + "threads": 1, + "iterations": 1, + "real_time": 2.2768951930011099e+00, + "cpu_time": 2.2767407790000007e+00, + "time_unit": "s" + } + ] +} diff --git a/bench/results/bench.png b/bench/results/bench.png new file mode 100644 index 0000000..e4dfcbd Binary files /dev/null and b/bench/results/bench.png differ diff --git a/include/dmt/fdmt.hpp b/include/dmt/fdmt.hpp index d33bc0b..52e521b 100644 --- a/include/dmt/fdmt.hpp +++ b/include/dmt/fdmt.hpp @@ -38,6 +38,7 @@ class FDMT { size_t get_niters() const; FDMTPlan get_plan() const; std::vector get_dm_arr() const; + void set_log_level(int level); void execute(const float* waterfall, size_t waterfall_size, float* dmt, size_t dmt_size); void initialise(const float* waterfall, float* state); diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index 73d588f..021c712 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -18,4 +18,4 @@ target_include_directories( $ ) target_include_directories(${LIBRARY_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}) -target_link_libraries(${LIBRARY_NAME} PUBLIC spdlog::spdlog_header_only) \ No newline at end of file +target_link_libraries(${LIBRARY_NAME} PUBLIC spdlog::spdlog_header_only) diff --git a/lib/fdmt.cpp b/lib/fdmt.cpp index 79e701a..7caeb11 100644 --- a/lib/fdmt.cpp +++ b/lib/fdmt.cpp @@ -19,8 +19,8 @@ FDMT::FDMT(float f_min, float f_max, size_t nchans, size_t nsamps, float tsamp, correction(df / 2), niters(calculate_niters(nchans)) { configure_fdmt_plan(); - spdlog::info("FDMT: df={}, dt_max={}, ndt_init={}, niters={}", df, dt_max, - get_dt_grid_init().size(), niters); + spdlog::debug("FDMT: df={}, dt_max={}, ndt_init={}, niters={}", df, dt_max, + get_dt_grid_init().size(), niters); dm_arr = fdmt::calculate_dm_arr(f_min, f_max, tsamp, dt_max, dt_step, dt_min); // Allocate memory for the state buffers @@ -41,6 +41,14 @@ size_t FDMT::get_niters() const { return niters; } FDMTPlan FDMT::get_plan() const { return fdmt_plan; } std::vector FDMT::get_dm_arr() const { return dm_arr; } +void FDMT::set_log_level(int level) { + if (level < static_cast(spdlog::level::trace) + || level > static_cast(spdlog::level::off)) { + spdlog::set_level(spdlog::level::info); + } + spdlog::set_level(static_cast(level)); +} + size_t FDMT::calculate_niters(size_t nchans) { return static_cast(std::ceil(std::log2(nchans))); } @@ -111,7 +119,8 @@ void FDMT::initialise(const float* waterfall, float* state) { } } - spdlog::info("FDMT: initialised dimensions: {}x{}x{}", nchans, ndt, nsamps); + spdlog::debug("FDMT: initialised dimensions: {}x{}x{}", nchans, ndt, + nsamps); } // Private methods @@ -124,7 +133,7 @@ void FDMT::check_inputs(size_t waterfall_size, size_t dmt_size) const { if (dmt_size != nchans_final * dt_final * nsamps_final) { throw std::invalid_argument("Invalid size of dmt"); } - spdlog::info("FDMT: Input dimensions: {}x{}", nchans, nsamps); + spdlog::debug("FDMT: Input dimensions: {}x{}", nchans, nsamps); } void FDMT::execute_iter(const float* state_in, float* state_out, @@ -133,8 +142,8 @@ void FDMT::execute_iter(const float* state_in, float* state_out, = fdmt_plan.state_shape[i_iter]; const auto& [nchans_prev, ndt_prev, nsamps_prev] = fdmt_plan.state_shape[i_iter - 1]; - spdlog::info("FDMT: Iteration {}, dimensions: {}x{}x{}", i_iter, nchans_cur, - ndt_cur, nsamps_cur); + spdlog::debug("FDMT: Iteration {}, dimensions: {}x{}x{}", i_iter, + nchans_cur, ndt_cur, nsamps_cur); for (size_t i_sub = 0; i_sub < nchans_cur; ++i_sub) { const auto& dt_grid_sub = fdmt_plan.sub_plan[i_iter][i_sub].dt_grid; for (size_t i_dt = 0; i_dt < dt_grid_sub.size(); ++i_dt) { @@ -150,8 +159,8 @@ void FDMT::execute_iter(const float* state_in, float* state_out, const float* head = &state_in[(2 * i_sub + 1) * ndt_prev * nsamps_prev + i_dt_head * nsamps_prev]; - fdmt::add_offset_kernel(tail, nsamps_prev, head, nsamps_prev, out, - nsamps_cur, offset); + fdmt::add_offset_kernel(tail, nsamps_prev, head, nsamps_prev, + out, nsamps_cur, offset); } } } @@ -170,7 +179,7 @@ void FDMT::configure_fdmt_plan() { for (size_t i_iter = 1; i_iter < niters + 1; ++i_iter) { make_fdmt_plan(i_iter); } - spdlog::info("FDMT: configured fdmt plan"); + spdlog::debug("FDMT: configured fdmt plan"); } void FDMT::make_fdmt_plan_iter0() { diff --git a/src/dmt_python.cpp b/src/dmt_python.cpp index a2503ff..f6e9c8d 100644 --- a/src/dmt_python.cpp +++ b/src/dmt_python.cpp @@ -68,6 +68,7 @@ PYBIND11_MODULE(libdmt, mod) { clsFDMT.def_property_readonly("niters", &FDMT::get_niters); clsFDMT.def_property_readonly( "dm_arr", [](FDMT& fdmt) { return as_pyarray(fdmt.get_dm_arr()); }); + clsFDMT.def("set_log_level", &FDMT::set_log_level); // execute take 2d array as input, and return 2d array as output clsFDMT.def("execute", [](FDMT& fdmt, diff --git a/tests/cpp/CMakeLists.txt b/tests/cpp/CMakeLists.txt index 1324521..7ab17f4 100644 --- a/tests/cpp/CMakeLists.txt +++ b/tests/cpp/CMakeLists.txt @@ -1,8 +1,8 @@ CPMFindPackage( - NAME Catch2 - VERSION 3.5.0 - GITHUB_REPOSITORY catchorg/Catch2 - ) + NAME Catch2 + VERSION 3.5.0 + GITHUB_REPOSITORY catchorg/Catch2 +) list(APPEND CMAKE_MODULE_PATH ${Catch2_DIR}) list(APPEND CMAKE_MODULE_PATH ${Catch2_SOURCE_DIR}/extras)