From fae50875ec425a401e62c1a31cda81e18957f574 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Constantin=20F=C3=BCrst?= Date: Sun, 26 Nov 2023 15:14:53 +0100 Subject: [PATCH] add nlohmann::json as submodule for json parsing, add helper that can read and write task description --- .gitmodules | 3 ++ benchmarks/error.hpp | 29 ------------- benchmarks/json | 1 + benchmarks/logging-helper.hpp | 70 ++++++++++++++++++++++++++++++++ benchmarks/task-description.json | 13 ++++++ 5 files changed, 87 insertions(+), 29 deletions(-) delete mode 100644 benchmarks/error.hpp create mode 160000 benchmarks/json create mode 100644 benchmarks/logging-helper.hpp create mode 100644 benchmarks/task-description.json diff --git a/.gitmodules b/.gitmodules index c74fdc1..2d9be9d 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,6 @@ [submodule "gosh"] path = thesis/gosh url = https://github.com/nfeske/gosh.git +[submodule "benchmarks/json"] + path = benchmarks/json + url = https://github.com/nlohmann/json diff --git a/benchmarks/error.hpp b/benchmarks/error.hpp deleted file mode 100644 index 045b6e7..0000000 --- a/benchmarks/error.hpp +++ /dev/null @@ -1,29 +0,0 @@ -#pragma once - -#include - -#include - -inline std::ostream& operator<<(std::ostream& strm, const dml::status_code code) { - switch(code) { - case dml::status_code::ok: strm << "[ok]"; break; - case dml::status_code::false_predicate: strm << "[false predicate]"; break; - case dml::status_code::partial_completion: strm << "[partial completion]"; break; - case dml::status_code::nullptr_error: strm << "[nullptr error]"; break; - case dml::status_code::bad_size: strm << "[bad size]"; break; - case dml::status_code::bad_length: strm << "[bad length]"; break; - case dml::status_code::inconsistent_size: strm << "[inconsistent size]"; break; - case dml::status_code::dualcast_bad_padding: strm << "[dualcast bad padding]"; break; - case dml::status_code::bad_alignment: strm << "[bad alignment]"; break; - case dml::status_code::buffers_overlapping: strm << "[buffers overlapping]"; break; - case dml::status_code::delta_delta_empty: strm << "[delta delta empty]"; break; - case dml::status_code::batch_overflow: strm << "[batch overflow]"; break; - case dml::status_code::execution_failed: strm << "[execution failed]"; break; - case dml::status_code::unsupported_operation: strm << "[unsupported operation]"; break; - case dml::status_code::queue_busy: strm << "[queue busy]"; break; - case dml::status_code::error: strm << "[unknown error]"; break; - case dml::status_code::config_error: strm << "[config error]"; break; - default: strm << "[unhandled error]"; break; - } - return strm; -} \ No newline at end of file diff --git a/benchmarks/json b/benchmarks/json new file mode 160000 index 0000000..360ce45 --- /dev/null +++ b/benchmarks/json @@ -0,0 +1 @@ +Subproject commit 360ce457f46f03111332f473fdbb3a353f16723c diff --git a/benchmarks/logging-helper.hpp b/benchmarks/logging-helper.hpp new file mode 100644 index 0000000..c98312d --- /dev/null +++ b/benchmarks/logging-helper.hpp @@ -0,0 +1,70 @@ +#pragma once + +#include + +#include "json/single_include/nlohmann/json.hpp" + +#include "execute-move.hpp" + +inline const std::string StatusCodeToString(const dml::status_code code) { + switch(code) { + case dml::status_code::ok: return "[ok]"; + case dml::status_code::false_predicate: return "[false predicate]"; + case dml::status_code::partial_completion: return "[partial completion]"; + case dml::status_code::nullptr_error: return "[nullptr error]"; + case dml::status_code::bad_size: return "[bad size]"; + case dml::status_code::bad_length: return "[bad length]"; + case dml::status_code::inconsistent_size: return "[inconsistent size]"; + case dml::status_code::dualcast_bad_padding: return "[dualcast bad padding]"; + case dml::status_code::bad_alignment: return "[bad alignment]"; + case dml::status_code::buffers_overlapping: return "[buffers overlapping]"; + case dml::status_code::delta_delta_empty: return "[delta delta empty]"; + case dml::status_code::batch_overflow: return "[batch overflow]"; + case dml::status_code::execution_failed: return "[execution failed]"; + case dml::status_code::unsupported_operation: return "[unsupported operation]"; + case dml::status_code::queue_busy: return "[queue busy]"; + case dml::status_code::error: return "[unknown error]"; + case dml::status_code::config_error: return "[config error]"; + default: return "[unhandled error]"; + } +} + +inline void to_json(nlohmann::json& j, const ThreadArgs& a) { + j = nlohmann::json{ + {"node", a.numa_node}, {"core", a.core}, {"size", a.size}, + {"nnode_src", a.nnode_src}, {"nnode_dst", a.nnode_dst}, + {"time_us", a.duration.count()}, + {"status", StatusCodeToString(a.status)} + }; +} + +inline void from_json(const nlohmann::json& j, ThreadArgs& a) { + j.at("node").get_to(a.numa_node); + j.at("core").get_to(a.core); + j.at("size").get_to(a.size); + j.at("nnode_src").get_to(a.nnode_src); + j.at("nnode_dst").get_to(a.nnode_dst); +} + +inline void WriteResultLog(const std::vector& args, const std::string& path, std::ostream& os) { + nlohmann::json json; + + json["count"] = args.size(); + json["path"] = path; + json["list"] = args; + + os << std::setw(4) << json; +} + +inline void ReadWorkDescription(std::vector& args, std::string& path, std::istream& is) { + nlohmann::json json; + is >> json; + + const uint32_t count = json.at("count"); + args.resize(count); + path = json.at("path"); + + for (uint32_t i = 0; i < count; i++) { + args[i] = json["list"][i].template get(); + } +} \ No newline at end of file diff --git a/benchmarks/task-description.json b/benchmarks/task-description.json new file mode 100644 index 0000000..ac6df86 --- /dev/null +++ b/benchmarks/task-description.json @@ -0,0 +1,13 @@ +{ + "count": 1, + "path" : "sw", + "list": [ + { + "core": 0, + "nnode_dst": 0, + "nnode_src": 0, + "node": 0, + "size": 4096 + } + ] +} \ No newline at end of file