From a97b676b92bd90705613fb24e1e7811c0e14382e Mon Sep 17 00:00:00 2001 From: Derek Christ Date: Mon, 7 Apr 2025 12:58:13 +0200 Subject: [PATCH] Remove the concept of a resource directory The concept of a resource directory was confusing, error-prone and was only used to specify the directory of the base config json anyway. Therefore, remove the concept of the resource directory and use the parent directory of the base config directly. --- benches/simulation.cpp | 5 ++--- src/configuration/CMakeLists.txt | 5 ----- .../DRAMSys/config/DRAMSysConfiguration.cpp | 18 +++++++-------- .../DRAMSys/config/DRAMSysConfiguration.h | 3 +-- src/libdramsys/CMakeLists.txt | 1 + src/simulator/main.cpp | 10 ++------- src/simulator/simulator/Simulator.cpp | 9 ++++---- src/simulator/simulator/Simulator.h | 6 ++--- .../test_configuration.cpp | 2 +- tests/tests_regression/CMakeLists.txt | 22 +++++++++---------- tools/json_converter.cpp | 3 +-- 11 files changed, 35 insertions(+), 49 deletions(-) diff --git a/benches/simulation.cpp b/benches/simulation.cpp index fd8e025b..cb8ec352 100644 --- a/benches/simulation.cpp +++ b/benches/simulation.cpp @@ -52,13 +52,12 @@ static void example_simulation(benchmark::State& state, Args&&... args) { sc_core::sc_get_curr_simcontext()->reset(); - std::filesystem::path configFile(std::get<0>(args_tuple)); - std::filesystem::path resourceDirectory("configs"); + std::filesystem::path configFile = std::get<0>(args_tuple); DRAMSys::Config::Configuration configuration = DRAMSys::Config::from_path(configFile.c_str()); - Simulator simulator(std::move(configuration), std::move(resourceDirectory)); + Simulator simulator(std::move(configuration), configFile); simulator.run(); } diff --git a/src/configuration/CMakeLists.txt b/src/configuration/CMakeLists.txt index a0530342..0f8135a8 100644 --- a/src/configuration/CMakeLists.txt +++ b/src/configuration/CMakeLists.txt @@ -50,10 +50,5 @@ target_link_libraries(configuration nlohmann_json::nlohmann_json ) -target_compile_definitions(configuration - PUBLIC - DRAMSYS_RESOURCE_DIR="${DRAMSYS_RESOURCE_DIR}" -) - target_compile_features(configuration PUBLIC cxx_std_17) add_library(DRAMSys::config ALIAS configuration) diff --git a/src/configuration/DRAMSys/config/DRAMSysConfiguration.cpp b/src/configuration/DRAMSys/config/DRAMSysConfiguration.cpp index 56f7ad09..fb2bbde1 100644 --- a/src/configuration/DRAMSys/config/DRAMSysConfiguration.cpp +++ b/src/configuration/DRAMSys/config/DRAMSysConfiguration.cpp @@ -41,9 +41,10 @@ namespace DRAMSys::Config { -Configuration from_path(std::string_view path, std::string_view resourceDirectory) +Configuration from_path(std::filesystem::path baseConfig) { - std::ifstream file(path.data()); + std::ifstream file(baseConfig); + std::filesystem::path baseDir = baseConfig.parent_path(); enum class SubConfig { @@ -59,7 +60,7 @@ Configuration from_path(std::string_view path, std::string_view resourceDirector // with the actual json data. std::function parser_callback; - parser_callback = [&parser_callback, ¤t_sub_config, resourceDirectory]( + parser_callback = [&parser_callback, ¤t_sub_config, baseDir]( int depth, nlohmann::detail::parse_event_t event, json_t& parsed) -> bool { using nlohmann::detail::parse_event_t; @@ -90,12 +91,11 @@ Configuration from_path(std::string_view path, std::string_view resourceDirector if (event == parse_event_t::value && current_sub_config != SubConfig::Unkown) { // Replace name of json file with actual json data - auto parse_json = [&parser_callback, - resourceDirectory](std::string_view base_dir, - std::string_view sub_config_key, - const std::string& filename) -> json_t + auto parse_json = [&parser_callback, baseDir](std::string_view base_dir, + std::string_view sub_config_key, + const std::string& filename) -> json_t { - std::filesystem::path path(resourceDirectory); + std::filesystem::path path{baseDir}; path /= base_dir; path /= filename; @@ -129,7 +129,7 @@ Configuration from_path(std::string_view path, std::string_view resourceDirector json_t simulation = json_t::parse(file, parser_callback, true, true).at(Configuration::KEY); return simulation.get(); } - throw std::runtime_error("Failed to open file " + std::string(path)); + throw std::runtime_error("Failed to open file " + std::string(baseConfig)); } } // namespace DRAMSys::Config diff --git a/src/configuration/DRAMSys/config/DRAMSysConfiguration.h b/src/configuration/DRAMSys/config/DRAMSysConfiguration.h index 7b27df53..c66311fb 100644 --- a/src/configuration/DRAMSys/config/DRAMSysConfiguration.h +++ b/src/configuration/DRAMSys/config/DRAMSysConfiguration.h @@ -75,8 +75,7 @@ struct Configuration NLOHMANN_JSONIFY_ALL_THINGS( Configuration, addressmapping, mcconfig, memspec, simconfig, simulationid, tracesetup) -Configuration from_path(std::string_view path, - std::string_view resourceDirectory = DRAMSYS_RESOURCE_DIR); +Configuration from_path(std::filesystem::path baseConfig); } // namespace DRAMSys::Config diff --git a/src/libdramsys/CMakeLists.txt b/src/libdramsys/CMakeLists.txt index 2bcca32e..a32772e6 100644 --- a/src/libdramsys/CMakeLists.txt +++ b/src/libdramsys/CMakeLists.txt @@ -100,6 +100,7 @@ target_compile_features(libdramsys PUBLIC cxx_std_17) target_compile_definitions(libdramsys PUBLIC + DRAMSYS_RESOURCE_DIR="${DRAMSYS_RESOURCE_DIR}" $<$:DRAMPOWER> ) diff --git a/src/simulator/main.cpp b/src/simulator/main.cpp index 32484de1..428f87d4 100644 --- a/src/simulator/main.cpp +++ b/src/simulator/main.cpp @@ -42,21 +42,15 @@ int sc_main(int argc, char** argv) { std::filesystem::path resourceDirectory = DRAMSYS_RESOURCE_DIR; - if (argc >= 3) - { - resourceDirectory = argv[2]; - } - std::filesystem::path baseConfig = resourceDirectory / "ddr4-example.json"; if (argc >= 2) { baseConfig = argv[1]; } - DRAMSys::Config::Configuration configuration = - DRAMSys::Config::from_path(baseConfig.c_str(), resourceDirectory.c_str()); + DRAMSys::Config::Configuration configuration = DRAMSys::Config::from_path(baseConfig.c_str()); - Simulator simulator(std::move(configuration), std::move(resourceDirectory)); + Simulator simulator(std::move(configuration), std::move(baseConfig)); simulator.run(); return 0; diff --git a/src/simulator/simulator/Simulator.cpp b/src/simulator/simulator/Simulator.cpp index 09b87ff0..cd8235af 100644 --- a/src/simulator/simulator/Simulator.cpp +++ b/src/simulator/simulator/Simulator.cpp @@ -41,13 +41,12 @@ #include "player/StlPlayer.h" #include "util.h" -Simulator::Simulator(DRAMSys::Config::Configuration configuration, - std::filesystem::path resourceDirectory) : +Simulator::Simulator(DRAMSys::Config::Configuration configuration, std::filesystem::path baseConfig) : storageEnabled(configuration.simconfig.StoreMode == DRAMSys::Config::StoreModeType::Store), memoryManager(storageEnabled), configuration(std::move(configuration)), - resourceDirectory(std::move(resourceDirectory)), - dramSys(std::make_unique("DRAMSys", this->configuration)) + dramSys(std::make_unique("DRAMSys", this->configuration)), + baseConfig(baseConfig) { terminateInitiator = [this]() { @@ -104,7 +103,7 @@ Simulator::instantiateInitiator(const DRAMSys::Config::Initiator& initiator) } else if constexpr (std::is_same_v) { - std::filesystem::path tracePath = resourceDirectory / TRACE_DIRECTORY / config.name; + std::filesystem::path tracePath = baseConfig.parent_path() / TRACE_DIRECTORY / config.name; std::optional traceType; diff --git a/src/simulator/simulator/Simulator.h b/src/simulator/simulator/Simulator.h index 5255169c..5abeed6b 100644 --- a/src/simulator/simulator/Simulator.h +++ b/src/simulator/simulator/Simulator.h @@ -46,8 +46,7 @@ static constexpr std::string_view TRACE_DIRECTORY = "traces"; class Simulator { public: - Simulator(DRAMSys::Config::Configuration configuration, - std::filesystem::path resourceDirectory); + Simulator(DRAMSys::Config::Configuration configuration, std::filesystem::path baseConfig); void run(); @@ -58,7 +57,6 @@ private: MemoryManager memoryManager; DRAMSys::Config::Configuration configuration; - std::filesystem::path resourceDirectory; std::unique_ptr dramSys; std::vector> initiators; @@ -69,4 +67,6 @@ private: unsigned int terminatedInitiators = 0; uint64_t totalTransactions{}; uint64_t transactionsFinished = 0; + + std::filesystem::path baseConfig; }; diff --git a/tests/tests_configuration/test_configuration.cpp b/tests/tests_configuration/test_configuration.cpp index 10ffbed3..4144506f 100644 --- a/tests/tests_configuration/test_configuration.cpp +++ b/tests/tests_configuration/test_configuration.cpp @@ -291,7 +291,7 @@ TEST_F(ConfigurationTest, DumpConfiguration) TEST(Configuration, ResourceDirectory) { // Test should not throw exceptions - Configuration config = from_path("resources/ddr5-example.json", "resources"); + Configuration config = from_path("resources/ddr5-example.json"); } TEST(Configuration, FromPath) diff --git a/tests/tests_regression/CMakeLists.txt b/tests/tests_regression/CMakeLists.txt index 50909034..d04c77ae 100644 --- a/tests/tests_regression/CMakeLists.txt +++ b/tests/tests_regression/CMakeLists.txt @@ -48,7 +48,7 @@ set(TABLES_TO_COMPARE Power ) -function(test_standard standard test_name base_config resource_dir output_filename) +function(test_standard standard test_name base_config output_filename) if(NOT IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/${standard}) message(WARNING "Cannot find regression test ${standard}") return() @@ -61,7 +61,7 @@ function(test_standard standard test_name base_config resource_dir output_filena add_test( NAME Regression${test_name}.CreateDatabase WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${test_name} - COMMAND $ ${base_config} ${resource_dir} + COMMAND $ ${base_config} ) set_tests_properties(Regression${test_name}.CreateDatabase PROPERTIES FIXTURES_SETUP Regression${test_name}.CreateDatabase) @@ -89,12 +89,12 @@ function(test_standard standard test_name base_config resource_dir output_filena endforeach() endfunction() -test_standard(DDR3 DDR3 ${CMAKE_CURRENT_SOURCE_DIR}/DDR3/ddr3-example.json ${CMAKE_CURRENT_SOURCE_DIR}/DDR3 DRAMSys_ddr3-dual-rank_ddr3_ch0.tdb) -test_standard(DDR4 DDR4 ${CMAKE_CURRENT_SOURCE_DIR}/DDR4/ddr4-example.json ${CMAKE_CURRENT_SOURCE_DIR}/DDR4 DRAMSys_ddr4-bankgrp_ddr4_ch0.tdb) -test_standard(DDR5 DDR5.Ch0 ${CMAKE_CURRENT_SOURCE_DIR}/DDR5/ddr5-example.json ${CMAKE_CURRENT_SOURCE_DIR}/DDR5 DRAMSys_ddr5-example_ddr5_ch0.tdb) -test_standard(DDR5 DDR5.Ch1 ${CMAKE_CURRENT_SOURCE_DIR}/DDR5/ddr5-example.json ${CMAKE_CURRENT_SOURCE_DIR}/DDR5 DRAMSys_ddr5-example_ddr5_ch1.tdb) -test_standard(LPDDR4 LPDDR4 ${CMAKE_CURRENT_SOURCE_DIR}/LPDDR4/lpddr4-example.json ${CMAKE_CURRENT_SOURCE_DIR}/LPDDR4 DRAMSys_lpddr4-example_lpddr4_ch0.tdb) -test_standard(LPDDR5 LPDDR5 ${CMAKE_CURRENT_SOURCE_DIR}/LPDDR5/lpddr5-example.json ${CMAKE_CURRENT_SOURCE_DIR}/LPDDR5 DRAMSys_lpddr5-example_lpddr5_ch0.tdb) -test_standard(HBM2 HBM2.Ch0 ${CMAKE_CURRENT_SOURCE_DIR}/HBM2/hbm2-example.json ${CMAKE_CURRENT_SOURCE_DIR}/HBM2 DRAMSys_hbm2-example_hbm2_ch0.tdb) -test_standard(HBM2 HBM2.Ch1 ${CMAKE_CURRENT_SOURCE_DIR}/HBM2/hbm2-example.json ${CMAKE_CURRENT_SOURCE_DIR}/HBM2 DRAMSys_hbm2-example_hbm2_ch1.tdb) -test_standard(HBM3 HBM3 ${CMAKE_CURRENT_SOURCE_DIR}/HBM3/hbm3-example.json ${CMAKE_CURRENT_SOURCE_DIR}/HBM3 DRAMSys_hbm3-example_hbm3_ch0.tdb) +test_standard(DDR3 DDR3 ${CMAKE_CURRENT_SOURCE_DIR}/DDR3/ddr3-example.json DRAMSys_ddr3-dual-rank_ddr3_ch0.tdb) +test_standard(DDR4 DDR4 ${CMAKE_CURRENT_SOURCE_DIR}/DDR4/ddr4-example.json DRAMSys_ddr4-bankgrp_ddr4_ch0.tdb) +test_standard(DDR5 DDR5.Ch0 ${CMAKE_CURRENT_SOURCE_DIR}/DDR5/ddr5-example.json DRAMSys_ddr5-example_ddr5_ch0.tdb) +test_standard(DDR5 DDR5.Ch1 ${CMAKE_CURRENT_SOURCE_DIR}/DDR5/ddr5-example.json DRAMSys_ddr5-example_ddr5_ch1.tdb) +test_standard(LPDDR4 LPDDR4 ${CMAKE_CURRENT_SOURCE_DIR}/LPDDR4/lpddr4-example.json DRAMSys_lpddr4-example_lpddr4_ch0.tdb) +test_standard(LPDDR5 LPDDR5 ${CMAKE_CURRENT_SOURCE_DIR}/LPDDR5/lpddr5-example.json DRAMSys_lpddr5-example_lpddr5_ch0.tdb) +test_standard(HBM2 HBM2.Ch0 ${CMAKE_CURRENT_SOURCE_DIR}/HBM2/hbm2-example.json DRAMSys_hbm2-example_hbm2_ch0.tdb) +test_standard(HBM2 HBM2.Ch1 ${CMAKE_CURRENT_SOURCE_DIR}/HBM2/hbm2-example.json DRAMSys_hbm2-example_hbm2_ch1.tdb) +test_standard(HBM3 HBM3 ${CMAKE_CURRENT_SOURCE_DIR}/HBM3/hbm3-example.json DRAMSys_hbm3-example_hbm3_ch0.tdb) diff --git a/tools/json_converter.cpp b/tools/json_converter.cpp index 22f2afed..6cd7856b 100644 --- a/tools/json_converter.cpp +++ b/tools/json_converter.cpp @@ -54,9 +54,8 @@ int main(int argc, char** argv) } std::string pathToJson = argv[1]; - std::string resourceDirectory = argc <= 3 ? DRAMSYS_RESOURCE_DIR : argv[3]; - auto configuration = DRAMSys::Config::from_path(pathToJson, resourceDirectory); + auto configuration = DRAMSys::Config::from_path(pathToJson); nlohmann::json json; json["simulation"] = configuration;