From 0f6714bc70f3a9d03204b05ac2d68856b7b729cd Mon Sep 17 00:00:00 2001 From: Bernhard Manfred Gruber Date: Mon, 1 Nov 2021 15:08:36 +0100 Subject: [PATCH] move RecordCoord string conversion into Core --- include/llama/Core.hpp | 25 +++++++++++ include/llama/DumpMapping.hpp | 78 +++++---------------------------- include/llama/mapping/Trace.hpp | 25 +---------- 3 files changed, 39 insertions(+), 89 deletions(-) diff --git a/include/llama/Core.hpp b/include/llama/Core.hpp index d4d1b9bf67..76196573b3 100644 --- a/include/llama/Core.hpp +++ b/include/llama/Core.hpp @@ -9,6 +9,7 @@ #include #include +#include #include namespace llama @@ -654,4 +655,28 @@ namespace llama using MergedRecordDims = typename decltype(internal::mergeRecordDimsImpl( boost::mp11::mp_identity{}, boost::mp11::mp_identity{}))::type; + + /// Returns the tags interspersed by '.' represented by the given record coord in the given record dimension. + template + auto recordCoordTags(RecordCoord) -> std::string + { + using Tags = GetTags>; + + std::string r; + boost::mp11::mp_for_each( + [&](auto tag) + { + using Tag = decltype(tag); + if(!r.empty()) + r += '.'; + if constexpr(isRecordCoord) + { + static_assert(Tag::size == 1); + r += std::to_string(Tag::front); // handle array indices + } + else + r += structName(tag); + }); + return r; + } } // namespace llama diff --git a/include/llama/DumpMapping.hpp b/include/llama/DumpMapping.hpp index 3baf24bd94..fcfc50fb2b 100644 --- a/include/llama/DumpMapping.hpp +++ b/include/llama/DumpMapping.hpp @@ -24,42 +24,6 @@ namespace llama return {Coords...}; } - template - auto tagToString(Tag tag) - { - return structName(tag); - } - - // handle array indices - template - auto tagToString(RecordCoord) - { - return std::to_string(N); - } - - template - void collectTagsAsStrings( - std::vector& v, - RecordCoord /*before*/, - RecordCoord /*after*/) - { - using Tag = GetTag>; - v.push_back(tagToString(Tag{})); - if constexpr(sizeof...(CoordsAfter) > 0) - collectTagsAsStrings( - v, - RecordCoord{}, - RecordCoord{}); - } - - template - auto tagsAsStrings(RecordCoord) -> std::vector - { - std::vector v; - collectTagsAsStrings(v, RecordCoord<>{}, RecordCoord{}); - return v; - } - inline auto color(const std::vector& recordCoord) -> std::size_t { auto c = boost::hash>{}(recordCoord) &0xFFFFFF; @@ -86,24 +50,12 @@ namespace llama } } - inline auto formatDDTags(const std::vector& tags) - { - std::string s; - for(const auto& tag : tags) - { - if(!s.empty()) - s += "."; - s += tag; - } - return s; - } - template struct FieldBox { ArrayIndex arrayIndex; std::vector recordCoord; - std::vector recordTags; + std::string recordTags; NrAndOffset nrAndOffset; std::size_t size; }; @@ -122,7 +74,7 @@ namespace llama infos.push_back( {ai, internal::toVec(rc), - internal::tagsAsStrings(rc), + recordCoordTags(rc), mapping.blobNrAndOffset(ai, rc), sizeof(GetType)}); }); @@ -149,6 +101,12 @@ namespace llama } return boxes; } + + inline auto cssClass(std::string tags) + { + std::replace(begin(tags), end(tags), '.', '_'); + return tags; + }; } // namespace internal /// Returns an SVG image visualizing the memory layout created by the given mapping. The created memory blocks are @@ -240,7 +198,7 @@ namespace llama x + width / 2, y + byteSizeInPixel * 3 / 4, internal::formatArrayIndex(info.arrayIndex), - internal::formatDDTags(info.recordTags)); + info.recordTags); if(cropBoxes) svg += R"( )"; @@ -273,18 +231,6 @@ namespace llama [](const auto& a, const auto& b) { return a.nrAndOffset == b.nrAndOffset; }), end(infos)); - auto cssClass = [](const std::vector& tags) - { - std::string s; - for(const auto& tag : tags) - { - if(!s.empty()) - s += "_"; - s += tag; - } - return s; - }; - std::string html; html += fmt::format( R"( @@ -325,7 +271,7 @@ namespace llama background-color: #{:X}; }} )", - cssClass(internal::tagsAsStrings(rc)), + internal::cssClass(recordCoordTags(rc)), byteSizeInPixel * size, internal::color(internal::toVec(rc))); }); @@ -355,9 +301,9 @@ namespace llama } html += fmt::format( R"(
{1} {2}
)", - cssClass(info.recordTags), + internal::cssClass(info.recordTags), internal::formatArrayIndex(info.arrayIndex), - internal::formatDDTags(info.recordTags)); + info.recordTags); } html += R"( )"; diff --git a/include/llama/mapping/Trace.hpp b/include/llama/mapping/Trace.hpp index 2585c46706..43733e6663 100644 --- a/include/llama/mapping/Trace.hpp +++ b/include/llama/mapping/Trace.hpp @@ -3,33 +3,12 @@ #include "Common.hpp" #include -#include #include #include #include -#include namespace llama::mapping { - namespace internal - { - template - auto coordName(RecordCoord) -> std::string - { - using Tags = GetTags>; - - std::string r; - boost::mp11::mp_for_each( - [&](auto tag) - { - if(!r.empty()) - r += '.'; - r += structName(tag); - }); - return r; - } - } // namespace internal - /// Forwards all calls to the inner mapping. Traces all accesses made through this mapping and prints a summary on /// destruction. /// \tparam Mapping The type of the inner mapping. @@ -48,7 +27,7 @@ namespace llama::mapping : mapping(mapping) , printOnDestruction(printOnDestruction) { - forEachLeafCoord([&](auto rc) { fieldHits[internal::coordName(rc)] = 0; }); + forEachLeafCoord([&](auto rc) { fieldHits[recordCoordTags(rc)] = 0; }); } Trace(const Trace&) = delete; @@ -78,7 +57,7 @@ namespace llama::mapping LLAMA_FN_HOST_ACC_INLINE auto blobNrAndOffset(ArrayIndex ai, RecordCoord rc = {}) const -> NrAndOffset { - const static auto name = internal::coordName(RecordCoord{}); + const static auto name = recordCoordTags(RecordCoord{}); fieldHits.at(name)++; LLAMA_FORCE_INLINE_RECURSIVE return mapping.blobNrAndOffset(ai, rc);