From c223329cba0c8aed9e539cafbf522f3015cd1b11 Mon Sep 17 00:00:00 2001 From: Bernhard Manfred Gruber Date: Fri, 23 Apr 2021 15:59:25 +0200 Subject: [PATCH] add arrayDims() getter to all mappings This avoids accessing the arrayDimsSize member and thus allows mappings which do not store their size in the mapping object itself. --- include/llama/Concepts.hpp | 1 + include/llama/DumpMapping.hpp | 2 +- include/llama/Proofs.hpp | 2 +- include/llama/View.hpp | 4 ++-- include/llama/mapping/AoS.hpp | 6 ++++++ include/llama/mapping/AoSoA.hpp | 6 ++++++ include/llama/mapping/Heatmap.hpp | 5 +++++ include/llama/mapping/One.hpp | 9 +++++++++ include/llama/mapping/SoA.hpp | 6 ++++++ include/llama/mapping/Split.hpp | 8 ++++++-- include/llama/mapping/Trace.hpp | 5 +++++ tests/iterator.cpp | 2 +- tests/proofs.cpp | 12 ++++++++++++ 13 files changed, 61 insertions(+), 7 deletions(-) diff --git a/include/llama/Concepts.hpp b/include/llama/Concepts.hpp index 4f9e097af9..15166f4568 100644 --- a/include/llama/Concepts.hpp +++ b/include/llama/Concepts.hpp @@ -15,6 +15,7 @@ namespace llama concept Mapping = requires(M m) { typename M::ArrayDims; typename M::RecordDim; + { m.arrayDims() } -> std::same_as; { M::blobCount } -> std::convertible_to; Array{}; // validates constexpr-ness { m.blobSize(std::size_t{}) } -> std::same_as; diff --git a/include/llama/DumpMapping.hpp b/include/llama/DumpMapping.hpp index 44bd21bdb4..503e54ae29 100644 --- a/include/llama/DumpMapping.hpp +++ b/include/llama/DumpMapping.hpp @@ -120,7 +120,7 @@ namespace llama std::vector> infos; - for (auto adCoord : ArrayDimsIndexRange{mapping.arrayDimsSize}) + for (auto adCoord : ArrayDimsIndexRange{mapping.arrayDims()}) { forEachLeaf( [&](auto coord) diff --git a/include/llama/Proofs.hpp b/include/llama/Proofs.hpp index 0ba8be9d8a..78c0ec034a 100644 --- a/include/llama/Proofs.hpp +++ b/include/llama/Proofs.hpp @@ -74,7 +74,7 @@ namespace llama { if (collision) return; - for (auto ad : llama::ArrayDimsIndexRange{m.arrayDimsSize}) + for (auto ad : llama::ArrayDimsIndexRange{m.arrayDims()}) { using Type = llama::GetType; diff --git a/include/llama/View.hpp b/include/llama/View.hpp index 463074ca8d..33e04ca83e 100644 --- a/include/llama/View.hpp +++ b/include/llama/View.hpp @@ -938,12 +938,12 @@ namespace llama auto begin() -> iterator { - return {ArrayDimsIndexRange{mapping.arrayDimsSize}.begin(), this}; + return {ArrayDimsIndexRange{mapping.arrayDims()}.begin(), this}; } auto end() -> iterator { - return {ArrayDimsIndexRange{mapping.arrayDimsSize}.end(), this}; + return {ArrayDimsIndexRange{mapping.arrayDims()}.end(), this}; } Mapping mapping; diff --git a/include/llama/mapping/AoS.hpp b/include/llama/mapping/AoS.hpp index a380583266..bd255723e4 100644 --- a/include/llama/mapping/AoS.hpp +++ b/include/llama/mapping/AoS.hpp @@ -30,6 +30,11 @@ namespace llama::mapping { } + LLAMA_FN_HOST_ACC_INLINE constexpr auto arrayDims() const -> ArrayDims + { + return arrayDimsSize; + } + LLAMA_FN_HOST_ACC_INLINE constexpr auto blobSize(std::size_t) const -> std::size_t { return LinearizeArrayDimsFunctor{}.size(arrayDimsSize) * sizeOf; @@ -43,6 +48,7 @@ namespace llama::mapping return {0, offset}; } + private: ArrayDims arrayDimsSize; }; diff --git a/include/llama/mapping/AoSoA.hpp b/include/llama/mapping/AoSoA.hpp index f6995a180c..386a2b96a5 100644 --- a/include/llama/mapping/AoSoA.hpp +++ b/include/llama/mapping/AoSoA.hpp @@ -47,6 +47,11 @@ namespace llama::mapping { } + LLAMA_FN_HOST_ACC_INLINE constexpr auto arrayDims() const -> ArrayDims + { + return arrayDimsSize; + } + LLAMA_FN_HOST_ACC_INLINE constexpr auto blobSize(std::size_t) const -> std::size_t { return LinearizeArrayDimsFunctor{}.size(arrayDimsSize) * sizeOf; @@ -64,6 +69,7 @@ namespace llama::mapping return {0, offset}; } + private: ArrayDims arrayDimsSize; }; diff --git a/include/llama/mapping/Heatmap.hpp b/include/llama/mapping/Heatmap.hpp index 46c4aeba8d..7865bbc467 100644 --- a/include/llama/mapping/Heatmap.hpp +++ b/include/llama/mapping/Heatmap.hpp @@ -33,6 +33,11 @@ namespace llama::mapping Heatmap(Heatmap&&) noexcept = default; auto operator=(Heatmap&&) noexcept -> Heatmap& = default; + LLAMA_FN_HOST_ACC_INLINE constexpr auto arrayDims() const -> ArrayDims + { + return mapping.arrayDims(); + } + LLAMA_FN_HOST_ACC_INLINE constexpr auto blobSize(std::size_t i) const -> std::size_t { LLAMA_FORCE_INLINE_RECURSIVE diff --git a/include/llama/mapping/One.hpp b/include/llama/mapping/One.hpp index a004cf2bc3..5be894fac0 100644 --- a/include/llama/mapping/One.hpp +++ b/include/llama/mapping/One.hpp @@ -25,6 +25,15 @@ namespace llama::mapping { } + LLAMA_FN_HOST_ACC_INLINE constexpr auto arrayDims() const -> ArrayDims + { + // TODO: not sure if this is the right approach, since we take any ArrayDims in the ctor + ArrayDims ad; + for (auto i = 0; i < ArrayDims::rank; i++) + ad[i] = 1; + return ad; + } + LLAMA_FN_HOST_ACC_INLINE constexpr auto blobSize(std::size_t) const -> std::size_t { return sizeOf; diff --git a/include/llama/mapping/SoA.hpp b/include/llama/mapping/SoA.hpp index 0d7d757d4e..d921a76874 100644 --- a/include/llama/mapping/SoA.hpp +++ b/include/llama/mapping/SoA.hpp @@ -32,6 +32,11 @@ namespace llama::mapping { } + LLAMA_FN_HOST_ACC_INLINE constexpr auto arrayDims() const -> ArrayDims + { + return arrayDimsSize; + } + LLAMA_FN_HOST_ACC_INLINE constexpr auto blobSize(std::size_t blobIndex) const -> std::size_t { @@ -95,6 +100,7 @@ namespace llama::mapping } } + private: ArrayDims arrayDimsSize; }; diff --git a/include/llama/mapping/Split.hpp b/include/llama/mapping/Split.hpp index 487e4db062..18469cef99 100644 --- a/include/llama/mapping/Split.hpp +++ b/include/llama/mapping/Split.hpp @@ -80,10 +80,15 @@ namespace llama::mapping constexpr Split() = default; LLAMA_FN_HOST_ACC_INLINE - constexpr Split(ArrayDims size) : arrayDimsSize(size), mapping1(size), mapping2(size) + constexpr Split(ArrayDims size) : mapping1(size), mapping2(size) { } + LLAMA_FN_HOST_ACC_INLINE constexpr auto arrayDims() const -> ArrayDims + { + return mapping1.arrayDims(); + } + LLAMA_FN_HOST_ACC_INLINE constexpr auto blobSize(std::size_t i) const -> std::size_t { if constexpr (SeparateBlobs) @@ -135,7 +140,6 @@ namespace llama::mapping } public: - ArrayDims arrayDimsSize = {}; Mapping1 mapping1; Mapping2 mapping2; }; diff --git a/include/llama/mapping/Trace.hpp b/include/llama/mapping/Trace.hpp index a5493cf2a4..733c91423d 100644 --- a/include/llama/mapping/Trace.hpp +++ b/include/llama/mapping/Trace.hpp @@ -64,6 +64,11 @@ namespace llama::mapping } } + LLAMA_FN_HOST_ACC_INLINE constexpr auto arrayDims() const -> ArrayDims + { + return mapping.arrayDims(); + } + LLAMA_FN_HOST_ACC_INLINE constexpr auto blobSize(std::size_t i) const -> std::size_t { LLAMA_FORCE_INLINE_RECURSIVE diff --git a/tests/iterator.cpp b/tests/iterator.cpp index c2b1561a92..f72cea0777 100644 --- a/tests/iterator.cpp +++ b/tests/iterator.cpp @@ -89,7 +89,7 @@ TEST_CASE("iterator.transform_reduce") vd(tag::Y{}) = ++i; vd(tag::Z{}) = ++i; } - // returned type is a llama::One + // returned type is a llama::One auto [sumX, sumY, sumZ] = std::transform_reduce(begin(aosView), end(aosView), begin(soaView), llama::One{}); diff --git a/tests/proofs.cpp b/tests/proofs.cpp index 2ceaa6ad43..63a021b5be 100644 --- a/tests/proofs.cpp +++ b/tests/proofs.cpp @@ -57,6 +57,11 @@ namespace { } + LLAMA_FN_HOST_ACC_INLINE constexpr auto arrayDims() const -> ArrayDims + { + return arrayDimsSize; + } + constexpr auto blobSize(std::size_t) const -> std::size_t { return std::reduce(std::begin(arrayDimsSize), std::end(arrayDimsSize), std::size_t{1}, std::multiplies{}) @@ -69,6 +74,7 @@ namespace return {0, 0}; } + private: ArrayDims arrayDimsSize; }; } // namespace @@ -100,6 +106,11 @@ namespace { } + LLAMA_FN_HOST_ACC_INLINE constexpr auto arrayDims() const -> ArrayDims + { + return arrayDimsSize; + } + constexpr auto blobSize(std::size_t) const -> std::size_t { return Modulus * llama::sizeOf; @@ -114,6 +125,7 @@ namespace return {blob, offset}; } + private: ArrayDims arrayDimsSize; }; } // namespace