From 7c9f8fbb71886c917bbfb91cebe5f6484c27f64b Mon Sep 17 00:00:00 2001 From: John Demme Date: Tue, 3 Sep 2024 23:24:34 +0000 Subject: [PATCH] [ESI][Runtime] Fixing Windows build and logging bug - Fixed MSVC build warning. - Fixed MSVC build errors. - Respect minLevel. --- lib/Dialect/ESI/runtime/cpp/include/esi/Logging.h | 7 ++++--- lib/Dialect/ESI/runtime/cpp/lib/Logging.cpp | 2 ++ lib/Dialect/ESI/runtime/cpp/lib/Services.cpp | 4 ++-- lib/Dialect/ESI/runtime/cpp/lib/backends/Cosim.cpp | 4 +++- 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/lib/Dialect/ESI/runtime/cpp/include/esi/Logging.h b/lib/Dialect/ESI/runtime/cpp/include/esi/Logging.h index df076805a616..dd493af41ee7 100644 --- a/lib/Dialect/ESI/runtime/cpp/include/esi/Logging.h +++ b/lib/Dialect/ESI/runtime/cpp/include/esi/Logging.h @@ -27,6 +27,7 @@ #include #include #include +#include #include namespace esi { @@ -34,11 +35,11 @@ namespace esi { class Logger { public: enum class Level { - Error, // Many errors will be followed by exceptions which may get caught. - Warning, // May indicate a problem. - Info, // General information, like connecting to an accelerator. Debug, // Everything and the kitchen sink, possibly including _all_ // messages written and read. + Info, // General information, like connecting to an accelerator. + Warning, // May indicate a problem. + Error, // Many errors will be followed by exceptions which may get caught. }; Logger(bool debugEnabled) : debugEnabled(debugEnabled) {} virtual ~Logger() = default; diff --git a/lib/Dialect/ESI/runtime/cpp/lib/Logging.cpp b/lib/Dialect/ESI/runtime/cpp/lib/Logging.cpp index 97b924cc657e..6201ab692863 100644 --- a/lib/Dialect/ESI/runtime/cpp/lib/Logging.cpp +++ b/lib/Dialect/ESI/runtime/cpp/lib/Logging.cpp @@ -34,6 +34,8 @@ StreamLogger::StreamLogger(Level minLevel) void StreamLogger::logImpl(Level level, const std::string &subsystem, const std::string &msg, const std::map *details) { + if (level < minLevel) + return; std::ostream &os = level == Level::Error ? errorStream : outStream; unsigned indentSpaces = 0; diff --git a/lib/Dialect/ESI/runtime/cpp/lib/Services.cpp b/lib/Dialect/ESI/runtime/cpp/lib/Services.cpp index 2288189bd050..6f760779cc53 100644 --- a/lib/Dialect/ESI/runtime/cpp/lib/Services.cpp +++ b/lib/Dialect/ESI/runtime/cpp/lib/Services.cpp @@ -61,7 +61,7 @@ MMIO::MMIO(Context &ctxt, AppIDPath idPath, std::string implName, throw std::runtime_error("MMIO client missing 'offset' option"); Constant offset = std::any_cast(offsetIter->second); uint64_t offsetVal = std::any_cast(offset.value); - if (offsetVal >= 1ul << 32) + if (offsetVal >= 1ull << 32) throw std::runtime_error("MMIO client offset mustn't exceed 32 bits"); auto sizeIter = client.implOptions.find("size"); @@ -69,7 +69,7 @@ MMIO::MMIO(Context &ctxt, AppIDPath idPath, std::string implName, throw std::runtime_error("MMIO client missing 'size' option"); Constant size = std::any_cast(sizeIter->second); uint64_t sizeVal = std::any_cast(size.value); - if (sizeVal >= 1ul << 32) + if (sizeVal >= 1ull << 32) throw std::runtime_error("MMIO client size mustn't exceed 32 bits"); regions[client.relPath] = RegionDescriptor{(uint32_t)offsetVal, (uint32_t)sizeVal}; diff --git a/lib/Dialect/ESI/runtime/cpp/lib/backends/Cosim.cpp b/lib/Dialect/ESI/runtime/cpp/lib/backends/Cosim.cpp index b49f4f0cff13..fbe884dc2e38 100644 --- a/lib/Dialect/ESI/runtime/cpp/lib/backends/Cosim.cpp +++ b/lib/Dialect/ESI/runtime/cpp/lib/backends/Cosim.cpp @@ -378,11 +378,13 @@ class CosimMMIO : public MMIO { cmdMMIO->connect(); } +#pragma pack(push, 1) struct MMIOCmd { uint64_t data; uint32_t offset; bool write; - } __attribute__((packed)); + }; +#pragma pack(pop) // Call the read function and wait for a response. uint64_t read(uint32_t addr) const override {