From 4ebe4501fcca571c9eead24e34f19cc4398c1e67 Mon Sep 17 00:00:00 2001 From: Muxianesty Date: Sat, 17 Aug 2024 01:22:09 +0300 Subject: [PATCH] Simulation output path option was added. --- src/main.cpp | 3 ++- src/model/dfcxx/include/dfcxx/kernel.h | 2 +- src/model/dfcxx/includeDev/dfcxx/simulator.h | 2 +- src/model/dfcxx/lib/dfcxx/kernel.cpp | 5 +++-- src/model/dfcxx/lib/dfcxx/simulator.cpp | 2 +- src/options.h | 13 +++++++++++++ 6 files changed, 21 insertions(+), 6 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 796abc2..5bf925e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -53,7 +53,8 @@ int hlsMain(const HlsContext &context) { int simMain(const SimContext &context) { auto kernel = start(); - return !kernel->simulate(context.options.dataFiles(), std::cout); + return !kernel->simulate(context.options.dataFiles(), + context.options.outFilePath); } int main(int argc, char **argv) { diff --git a/src/model/dfcxx/include/dfcxx/kernel.h b/src/model/dfcxx/include/dfcxx/kernel.h index ce19d63..64b1071 100644 --- a/src/model/dfcxx/include/dfcxx/kernel.h +++ b/src/model/dfcxx/include/dfcxx/kernel.h @@ -71,7 +71,7 @@ class Kernel { const Scheduler &sched); bool simulate(const std::vector &dataPaths, - std::ostream &stream); + const std::string &outFilePath); }; diff --git a/src/model/dfcxx/includeDev/dfcxx/simulator.h b/src/model/dfcxx/includeDev/dfcxx/simulator.h index d81fa4a..eeb7aa9 100644 --- a/src/model/dfcxx/includeDev/dfcxx/simulator.h +++ b/src/model/dfcxx/includeDev/dfcxx/simulator.h @@ -53,7 +53,7 @@ namespace dfcxx { class DFCXXSimulator { public: - bool simulate(std::ifstream &in, std::ostream &out, std::vector nodes); + bool simulate(std::ifstream &in, std::ofstream &out, std::vector nodes); }; } // namespace dfcxx diff --git a/src/model/dfcxx/lib/dfcxx/kernel.cpp b/src/model/dfcxx/lib/dfcxx/kernel.cpp index 7198c37..d417095 100644 --- a/src/model/dfcxx/lib/dfcxx/kernel.cpp +++ b/src/model/dfcxx/lib/dfcxx/kernel.cpp @@ -83,15 +83,16 @@ bool Kernel::compile(const DFLatencyConfig &config, bool Kernel::simulate(const std::vector &dataPaths, - std::ostream &stream) { + const std::string &outFilePath) { bool result = true; std::vector sorted = topSort(graph.startNodes, graph.outputs, graph.nodes.size()); DFCXXSimulator sim; + std::ofstream out(outFilePath, std::ios::out); for (const std::string &path : dataPaths) { std::ifstream input(path, std::ios::in); - sim.simulate(input, stream, sorted); + sim.simulate(input, out, sorted); } return result; diff --git a/src/model/dfcxx/lib/dfcxx/simulator.cpp b/src/model/dfcxx/lib/dfcxx/simulator.cpp index 0b1b9a7..965dd97 100644 --- a/src/model/dfcxx/lib/dfcxx/simulator.cpp +++ b/src/model/dfcxx/lib/dfcxx/simulator.cpp @@ -5,7 +5,7 @@ namespace dfcxx { bool DFCXXSimulator::simulate(std::ifstream &in, - std::ostream &out, + std::ofstream &out, std::vector nodes) { return true; } diff --git a/src/options.h b/src/options.h index ad67e79..25cd6f9 100644 --- a/src/options.h +++ b/src/options.h @@ -42,6 +42,7 @@ #define OUT_FIRRTL_JSON "out_firrtl" #define SIM_ID_JSON "sim" +#define SIM_OUT_JSON "out" //===----------------------------------------------------------------------===// // CLI args/flags definitions @@ -59,6 +60,7 @@ #define OUT_FIRRTL_ARG CLI_ARG("out-firrtl") #define SIM_USAGE_FILES_ARG "files" +#define SIM_OUT_ARG CLI_ARG("out") //===----------------------------------------------------------------------===// @@ -319,6 +321,11 @@ struct SimOptions final : public AppOptions { SimOptions(AppOptions &parent): AppOptions(parent, SIM_CMD, "DFCxx simulation") { //options->formatter(std::make_shared()); + + // Named options. + options->add_option(SIM_OUT_ARG, + outFilePath, + "Simulation output path")->expected(1); // For processing data files' paths. options->allow_extras(); auto *var = options; // Used for lambda variable passing. @@ -332,6 +339,12 @@ struct SimOptions final : public AppOptions { std::vector dataFiles() const { return options->remaining(); } + + void fromJson(Json json) override { + get(json, SIM_OUT_JSON, outFilePath); + } + + std::string outFilePath; }; struct Options final : public AppOptions {