From 575c0ee2dcb7958019cf73c9d4a6b1d3afe387a5 Mon Sep 17 00:00:00 2001 From: Bernhard Manfred Gruber Date: Fri, 19 Jan 2024 21:41:18 +0100 Subject: [PATCH] Remove deprecated tree mapping --- docs/images/example_mapping.svg | 674 ---------- docs/images/example_mapping_raw.svg | 765 ------------ docs/images/example_tree.svg | 513 -------- docs/images/example_tree_raw.svg | 502 -------- docs/images/fused_tree_2.svg | 502 -------- docs/images/fused_tree_2_raw.svg | 501 -------- docs/images/layout_tree_2.svg | 423 ------- docs/images/layout_tree_2_raw.svg | 435 ------- docs/images/padding_tree_2.svg | 591 --------- docs/images/padding_tree_2_raw.svg | 576 --------- docs/images/soa_tree_2.svg | 538 -------- docs/images/soa_tree_2_raw.svg | 504 -------- docs/images/start_tree_2.svg | 502 -------- docs/images/start_tree_2_raw.svg | 472 ------- docs/images/ud_tree_2.svg | 135 -- docs/images/ud_tree_2_raw.svg | 181 --- docs/pages/api.rst | 19 +- docs/pages/mappings.rst | 115 -- examples/alpaka/asyncblur/asyncblur.cpp | 9 +- include/llama/llama.hpp | 1 - include/llama/mapping/tree/Functors.hpp | 249 ---- include/llama/mapping/tree/Mapping.hpp | 228 ---- .../llama/mapping/tree/TreeFromDimensions.hpp | 163 --- include/llama/mapping/tree/toString.hpp | 82 -- tests/common.hpp | 12 +- tests/core.cpp | 2 +- tests/mapping.Tree.cpp | 1101 ----------------- tests/view.cpp | 3 - 28 files changed, 14 insertions(+), 9784 deletions(-) delete mode 100644 docs/images/example_mapping.svg delete mode 100644 docs/images/example_mapping_raw.svg delete mode 100644 docs/images/example_tree.svg delete mode 100644 docs/images/example_tree_raw.svg delete mode 100644 docs/images/fused_tree_2.svg delete mode 100644 docs/images/fused_tree_2_raw.svg delete mode 100644 docs/images/layout_tree_2.svg delete mode 100644 docs/images/layout_tree_2_raw.svg delete mode 100644 docs/images/padding_tree_2.svg delete mode 100644 docs/images/padding_tree_2_raw.svg delete mode 100644 docs/images/soa_tree_2.svg delete mode 100644 docs/images/soa_tree_2_raw.svg delete mode 100644 docs/images/start_tree_2.svg delete mode 100644 docs/images/start_tree_2_raw.svg delete mode 100644 docs/images/ud_tree_2.svg delete mode 100644 docs/images/ud_tree_2_raw.svg delete mode 100644 include/llama/mapping/tree/Functors.hpp delete mode 100644 include/llama/mapping/tree/Mapping.hpp delete mode 100644 include/llama/mapping/tree/TreeFromDimensions.hpp delete mode 100644 include/llama/mapping/tree/toString.hpp delete mode 100644 tests/mapping.Tree.cpp diff --git a/docs/images/example_mapping.svg b/docs/images/example_mapping.svg deleted file mode 100644 index 6c0f534554..0000000000 --- a/docs/images/example_mapping.svg +++ /dev/null @@ -1,674 +0,0 @@ - - - - - - - - - - image/svg+xml - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/docs/images/example_mapping_raw.svg b/docs/images/example_mapping_raw.svg deleted file mode 100644 index 8bcd31746b..0000000000 --- a/docs/images/example_mapping_raw.svg +++ /dev/null @@ -1,765 +0,0 @@ - - - - - - - - - - image/svg+xml - - - - - - - - - - - - - - - - - - - - - - - - - - - - r - r - r - g - g - g - b - b - b - a - a - a - pad - r - r - r - g - g - g - b - b - b - a - a - a - pad - r - r - r - g - g - g - b - b - b - a - a - a - pad - r - r - r - g - g - g - b - b - b - a - a - a - pad - diff --git a/docs/images/example_tree.svg b/docs/images/example_tree.svg deleted file mode 100644 index 363395dde1..0000000000 --- a/docs/images/example_tree.svg +++ /dev/null @@ -1,513 +0,0 @@ - - - - - - image/svg+xml - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/docs/images/example_tree_raw.svg b/docs/images/example_tree_raw.svg deleted file mode 100644 index 0adff38b96..0000000000 --- a/docs/images/example_tree_raw.svg +++ /dev/null @@ -1,502 +0,0 @@ - - - - - - image/svg+xml - - - - - - - - - - - - - - - - - 1 - - - - - - color - - - - - 1 - - - - - - Pixel - - - - - 4 - - - - - - - - - - - - - - - pad - - - - - - - - 1 - - - - - float - - - g - - - - - 3 - - - - r - - - float - - - - 3 - - - char - - - alpha - - - - - 3 - - - float - - - b - - - - - 3 - - diff --git a/docs/images/fused_tree_2.svg b/docs/images/fused_tree_2.svg deleted file mode 100644 index 1b59e8128a..0000000000 --- a/docs/images/fused_tree_2.svg +++ /dev/null @@ -1,502 +0,0 @@ - - - - - - image/svg+xml - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/docs/images/fused_tree_2_raw.svg b/docs/images/fused_tree_2_raw.svg deleted file mode 100644 index 8fc65511af..0000000000 --- a/docs/images/fused_tree_2_raw.svg +++ /dev/null @@ -1,501 +0,0 @@ - - - - - - image/svg+xml - - - - - - - - - - - - - - - - - - - 128 - - - - - - - - color - - - - - - - 1 - - - - - - - - Pixel - - - - - - - 64 - - - - char - - - - alpha - - - - - - - 1 - - - - - - - - - - - - - - - - - - - - - - - - - float - - - b - - - - - 1 - - - - - float - - - g - - - - - 1 - - - - - - r - - - float - - - - 1 - - - - - - - - diff --git a/docs/images/layout_tree_2.svg b/docs/images/layout_tree_2.svg deleted file mode 100644 index fa24deb269..0000000000 --- a/docs/images/layout_tree_2.svg +++ /dev/null @@ -1,423 +0,0 @@ - - - - - - image/svg+xml - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/docs/images/layout_tree_2_raw.svg b/docs/images/layout_tree_2_raw.svg deleted file mode 100644 index 03152c4f66..0000000000 --- a/docs/images/layout_tree_2_raw.svg +++ /dev/null @@ -1,435 +0,0 @@ - - - - - - image/svg+xml - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - r - - - float - - - - 1 - - - - - - g - - - float - - - - 1 - - - - - - b - - - float - - - - 1 - - - - - - alpha - - - char - - - - 1 - - - - - - - - Color - - - - - 1 - - - - - - - - Pixel - - - - - 1 - - - - diff --git a/docs/images/padding_tree_2.svg b/docs/images/padding_tree_2.svg deleted file mode 100644 index d7a8ef8a4e..0000000000 --- a/docs/images/padding_tree_2.svg +++ /dev/null @@ -1,591 +0,0 @@ - - - - - - image/svg+xml - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/docs/images/padding_tree_2_raw.svg b/docs/images/padding_tree_2_raw.svg deleted file mode 100644 index 794415f1b6..0000000000 --- a/docs/images/padding_tree_2_raw.svg +++ /dev/null @@ -1,576 +0,0 @@ - - - - - - image/svg+xml - - - - - - - - - - - - - - - - - - - - - 1 - - - - - - - - color - - - - - - - 1 - - - - - - - - Pixel - - - - - - - 8 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - r - - - - float - - - - - 1024 - - - - float - - - - g - - - - - - - 1024 - - - - float - - - - b - - - - - - - 1024 - - - - - pad - - - - - - - - 1 - - - - - - - - char - - - - alpha - - - - - - - 1024 - - - - diff --git a/docs/images/soa_tree_2.svg b/docs/images/soa_tree_2.svg deleted file mode 100644 index a91b8e265e..0000000000 --- a/docs/images/soa_tree_2.svg +++ /dev/null @@ -1,538 +0,0 @@ - - - - - - image/svg+xml - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/docs/images/soa_tree_2_raw.svg b/docs/images/soa_tree_2_raw.svg deleted file mode 100644 index f18ab8a67e..0000000000 --- a/docs/images/soa_tree_2_raw.svg +++ /dev/null @@ -1,504 +0,0 @@ - - - - - - image/svg+xml - - - - - - - - - - - - - - - - - - - - - 1 - - - - - - - - color - - - - - - - 1 - - - - - - - - Pixel - - - - - - - 1 - - - - char - - - - alpha - - - - - - - 8192 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - r - - - float - - - - 8192 - - - - - float - - - g - - - - - 8192 - - - - - float - - - b - - - - - 8192 - - - - diff --git a/docs/images/start_tree_2.svg b/docs/images/start_tree_2.svg deleted file mode 100644 index 56d6b0cfbc..0000000000 --- a/docs/images/start_tree_2.svg +++ /dev/null @@ -1,502 +0,0 @@ - - - - - - image/svg+xml - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/docs/images/start_tree_2_raw.svg b/docs/images/start_tree_2_raw.svg deleted file mode 100644 index 2a3cb3a180..0000000000 --- a/docs/images/start_tree_2_raw.svg +++ /dev/null @@ -1,472 +0,0 @@ - - - - - - image/svg+xml - - - - - - - - - - - - - - - - - 128 - - - - - - color - - - - - 1 - - - - - - Pixel - - - - - 64 - - - char - - - alpha - - - - - 1 - - - - - - - - - - - - - float - - - b - - - - - 1 - - - - r - - - float - - - - 1 - - - float - - - g - - - - - 1 - - - - diff --git a/docs/images/ud_tree_2.svg b/docs/images/ud_tree_2.svg deleted file mode 100644 index 7c10a6cf51..0000000000 --- a/docs/images/ud_tree_2.svg +++ /dev/null @@ -1,135 +0,0 @@ - - - - - - image/svg+xml - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/docs/images/ud_tree_2_raw.svg b/docs/images/ud_tree_2_raw.svg deleted file mode 100644 index 8360a17ebf..0000000000 --- a/docs/images/ud_tree_2_raw.svg +++ /dev/null @@ -1,181 +0,0 @@ - - - - - - image/svg+xml - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 64 - - - - - - - 128 - - - - diff --git a/docs/pages/api.rst b/docs/pages/api.rst index ae9fa4f572..70315daeea 100644 --- a/docs/pages/api.rst +++ b/docs/pages/api.rst @@ -178,10 +178,10 @@ Acessors .. doxygenstruct:: llama::accessor::Restrict .. doxygenstruct:: llama::accessor::Atomic .. doxygenstruct:: llama::accessor::Stacked + RecordDim field permuters ^^^^^^^^^^^^^^^^^^^^^^^^^ - .. doxygenstruct:: llama::mapping::PermuteFieldsInOrder .. doxygenstruct:: llama::mapping::PermuteFieldsSorted .. doxygentypedef:: llama::mapping::PermuteFieldsIncreasingAlignment @@ -198,23 +198,6 @@ Common utilities .. doxygenstruct:: llama::mapping::LinearizeArrayIndexMorton :members: -Tree mapping (deprecated) -^^^^^^^^^^^^^^^^^^^^^^^^^ - -.. doxygenstruct:: llama::mapping::tree::Mapping - :members: - -For a detailed description of the tree mapping concept have a look at -:ref:`LLAMA tree mapping ` - -**Tree mapping functors** - -.. doxygenstruct:: llama::mapping::tree::functor::Idem -.. doxygenstruct:: llama::mapping::tree::functor::LeafOnlyRT -.. doxygenstruct:: llama::mapping::tree::functor::MoveRTDown - -.. FIXME: doxygen fails to parse the source code ... - Dumping ^^^^^^^ diff --git a/docs/pages/mappings.rst b/docs/pages/mappings.rst index 3d10ce1664..d750417e0f 100644 --- a/docs/pages/mappings.rst +++ b/docs/pages/mappings.rst @@ -375,121 +375,6 @@ It permutes the array indices before passing the index information to the inner view(1, 2, 3); // will pass {3, 1, 2} to inner mapping -.. _label-tree-mapping: - -Tree (deprecated) ------------------ - -WARNING: The tree mapping is currently not maintained and we consider deprecation. - -The LLAMA tree mapping is one approach to achieve the goal of mixing different mapping approaches. -Furthermore, it tries to establish a general mapping description language and mapping definition framework. -Let's take the example record dimension from the :ref:`dimensions section`: - -.. image:: ../images/layout_tree.svg - -As already mentioned this is a compile time tree. The idea of the tree mapping -is now to extend this model to a compile time tree with run time annotations -representing the repetition of branches and to define tree operations which -create new trees out of the old ones while providing methods to translate tree -coordinates from one tree to another. - -This is best demonstrated by an example. -First of all the array dimensions needs to be represented as such an tree too. -Let's assume array dimensions of :math:`128 \times 64`: - -.. image:: ../images/ud_tree_2.svg - -The record dimension is already a tree, but as it has no run time influence, only -:math:`1` is annotated for these tree nodes: - -.. image:: ../images/layout_tree_2.svg - -Now the two trees are connected so that we can represent array and record -dimensions with one tree: - -.. image:: ../images/start_tree_2.svg - -The mapping works now in this way that the tree is "flattened" from left to -right using a breadth first traversal. Annotations represent repetitions of the node -branches. So for this tree we would copy the record dimension :math:`64` times and -:math:`128` times again -- basically this results in an array of struct -approach, which is most probably not desired. - -So we want to transform the tree before flattening it. A struct of array -approach may look like this: - -.. image:: ../images/soa_tree_2.svg - -Struct of array but with a padding after each 1024 elements may look like this: - -.. image:: ../images/padding_tree_2.svg - -The size of the leaf type in "pad" of course needs to be determined based on the -desired alignment and sub tree sizes. - -Such a tree (with smaller array dimensions for easier drawing) … - -.. image:: ../images/example_tree.svg - -… may look like this mapped to memory: - -.. image:: ../images/example_mapping.svg - -In code a tree mapping is defined as :cpp:`llama::mapping::tree::Mapping`, but -takes one more template parameter for the type of a tuple of tree operations and -a further constructor parameter for the instantiation of this tuple. - -.. code-block:: C++ - - auto treeOperationList = llama::Tuple{ - llama::mapping::tree::functor::LeafOnlyRT() - }; - - using Mapping = llama::mapping::tree::Mapping< - ArrayExtents, - RecordDim, - decltype(treeOperationList) - >; - - Mapping mapping( - extents, - treeOperationList - ); - - // or using CTAD and an unused argument for the record dimension: - llama::mapping::tree::Mapping mapping( - extents, - llama::Tuple{ - llama::mapping::tree::functor::LeafOnlyRT() - }, - RecordDim{} - ); - -The following tree operations are defined: - -Idem -^^^^ -:cpp:`llama::mapping::tree::functor::Idem` does not change the tree at all. -Basically a test functor for testing, how much the number of tree operations -has an influence on the run time. - -LeafOnlyRT -^^^^^^^^^^^ -:cpp:`llama::mapping::tree::functor::LeafOnlyRT` moves all run time parts of -the tree to the leaves, basically creates a struct of array as seen above. -However unlike :cpp:`llama::mapping::SoA` a combination with other mapping would -be possible. - -MoveRTDown -^^^^^^^^^^ -:cpp:`llama::mapping::tree::functor::MoveRTDown` moves a runtime multiplier from a node identified by a tree coordinate one level downward. -This effectively divides the annotation at the node by a given factor and multiplies the direct child nodes by this factor. - -MoveRTDownFixed -^^^^^^^^^^^^^^^ -Same as MoveRTDown but with a compile time factor. - Dump visualizations ------------------- diff --git a/examples/alpaka/asyncblur/asyncblur.cpp b/examples/alpaka/asyncblur/asyncblur.cpp index a7e09d2b68..6068c3f99c 100644 --- a/examples/alpaka/asyncblur/asyncblur.cpp +++ b/examples/alpaka/asyncblur/asyncblur.cpp @@ -217,14 +217,9 @@ try // LLAMA using ArrayIndex = llama::ArrayIndex; - auto treeOperationList = llama::Tuple{llama::mapping::tree::functor::LeafOnlyRT()}; - const auto hostMapping = llama::mapping::tree::Mapping{ - llama::ArrayExtentsDynamic{bufferY, bufferX}, - treeOperationList, - Pixel{}}; - const auto devMapping = llama::mapping::tree::Mapping{ + const auto hostMapping = llama::mapping::SoA{llama::ArrayExtentsDynamic{bufferY, bufferX}, Pixel{}}; + const auto devMapping = llama::mapping::SoA{ llama::ArrayExtents{}, - treeOperationList, PixelOnAcc{}}; using DevMapping = std::decay_t; diff --git a/include/llama/llama.hpp b/include/llama/llama.hpp index 534281da56..052dcdd912 100644 --- a/include/llama/llama.hpp +++ b/include/llama/llama.hpp @@ -73,7 +73,6 @@ #include "mapping/Projection.hpp" #include "mapping/SoA.hpp" #include "mapping/Split.hpp" -#include "mapping/tree/Mapping.hpp" #if defined(__NVCC__) # ifdef __NVCC_DIAG_PRAGMA_SUPPORT__ diff --git a/include/llama/mapping/tree/Functors.hpp b/include/llama/mapping/tree/Functors.hpp deleted file mode 100644 index 2c986956cf..0000000000 --- a/include/llama/mapping/tree/Functors.hpp +++ /dev/null @@ -1,249 +0,0 @@ -// Copyright 2020 Alexander Matthes, Bernhard Manfred Gruber -// SPDX-License-Identifier: MPL-2.0 - -#pragma once - -#include "TreeFromDimensions.hpp" - -namespace llama::mapping::tree::functor -{ - /// Functor for \ref tree::Mapping. Does nothing with the mapping tree. Is used for testing. - struct Idem - { - template - LLAMA_FN_HOST_ACC_INLINE auto basicToResult(const Tree& tree) const -> Tree - { - return tree; - } - - template - LLAMA_FN_HOST_ACC_INLINE auto basicCoordToResultCoord(const TreeCoord& basicCoord, const Tree&) const - -> TreeCoord - { - return basicCoord; - } - - template - LLAMA_FN_HOST_ACC_INLINE auto resultCoordToBasicCoord(const TreeCoord& resultCoord, const Tree&) const - -> TreeCoord - { - return resultCoord; - } - }; - - /// Functor for \ref tree::Mapping. Moves all run time parts to the leaves, creating a SoA layout. - struct LeafOnlyRT - { - template - LLAMA_FN_HOST_ACC_INLINE auto basicToResult(Tree tree) const - { - return basicToResultImpl(tree, 1); - } - - template - LLAMA_FN_HOST_ACC_INLINE auto basicCoordToResultCoord(const BasicCoord& basicCoord, const Tree& tree) const - { - return basicCoordToResultCoordImpl(basicCoord, tree); - } - - template - LLAMA_FN_HOST_ACC_INLINE auto resultCoordToBasicCoord(const ResultCoord& resultCoord, const Tree& /*tree*/) - const -> ResultCoord - { - return resultCoord; - } - - private: - template - LLAMA_FN_HOST_ACC_INLINE static auto basicToResultImpl( - const Node& node, - std::size_t arraySize) - { - auto children = tupleTransform( - node.childs, - [&](auto element) { return basicToResultImpl(element, LLAMA_COPY(node.count) * arraySize); }); - return Node>{{}, children}; - } - - template - LLAMA_FN_HOST_ACC_INLINE static auto basicToResultImpl( - const Leaf& leaf, - std::size_t arraySize) - { - return Leaf{LLAMA_COPY(leaf.count) * arraySize}; - } - - template - LLAMA_FN_HOST_ACC_INLINE static auto basicCoordToResultCoordImpl( - const BasicCoord& basicCoord, - const NodeOrLeaf& nodeOrLeaf, - std::size_t arraySize = 0) - { - if constexpr(std::tuple_size_v == 1) - return Tuple{TreeCoordElement{ - arraySize + LLAMA_COPY(basicCoord.first().arrayIndex)}}; - else - { - const auto& branch = get(nodeOrLeaf.childs); - auto first = TreeCoordElement>{}; - - return tupleCat( - Tuple{first}, - basicCoordToResultCoordImpl( - basicCoord.rest(), - branch, - (arraySize + LLAMA_COPY(basicCoord.first().arrayIndex)) * LLAMA_COPY(branch.count))); - } - } - }; - - namespace internal - { - template - LLAMA_FN_HOST_ACC_INLINE auto getNode(const Node& node) - { - if constexpr(std::is_same_v>) - return node; - else - return getNode(get(node.childs)); - } - - template - LLAMA_FN_HOST_ACC_INLINE auto changeNodeRuntime( - const Node& tree, - std::size_t newValue) - { - if constexpr(std::is_same_v>) - return Node{newValue, tree.childs}; - else - { - auto current = get(tree.childs); - auto replacement = changeNodeRuntime(current, newValue); - auto children = tupleReplace(tree.childs, replacement); - return Node{tree.count, children}; - } - } - - template - LLAMA_FN_HOST_ACC_INLINE auto changeNodeRuntime( - const Leaf& /*tree*/, - std::size_t newValue) - { - return Leaf{newValue}; - } - - struct ChangeNodeChildsRuntimeFunctor - { - const std::size_t newValue; - - template - LLAMA_FN_HOST_ACC_INLINE auto operator()(const Node& element) const - { - return Node{element.count * newValue, element.childs}; - } - - template - LLAMA_FN_HOST_ACC_INLINE auto operator()(const Leaf& element) const - { - return Leaf{element.count * newValue}; - } - }; - - template - LLAMA_FN_HOST_ACC_INLINE auto changeNodeChildsRuntime( - const Node& tree, - std::size_t newValue) - { - if constexpr(std::is_same_v>) - { - auto children = tupleTransform(tree.childs, ChangeNodeChildsRuntimeFunctor{newValue}); - return Node{tree.count, children}; - } - else - { - auto current = get(tree.childs); - auto replacement = changeNodeChildsRuntime(current, newValue); - auto children = tupleReplace(tree.childs, replacement); - return Node{tree.count, children}; - } - } - - template - LLAMA_FN_HOST_ACC_INLINE auto changeNodeChildsRuntime( - const Leaf& tree, - std::size_t /*newValue*/) - { - return tree; - } - } // namespace internal - - /// Functor for \ref tree::Mapping. Move the run time part of a node one level down in direction of the leaves by - /// the given amount (runtime or compile time value). - /// \tparam TreeCoord tree coordinate in the mapping tree which's run time part shall be moved down one level - /// \see tree::Mapping - template - struct MoveRTDown - { - const Amount amount = {}; - - template - LLAMA_FN_HOST_ACC_INLINE auto basicToResult(const Tree& tree) const - { - return internal::changeNodeChildsRuntime( - internal::changeNodeRuntime( - tree, - // NOLINTNEXTLINE(clang-analyzer-core.DivideZero) - (internal::getNode(tree).count + amount - 1) / amount), - amount); - } - - template - LLAMA_FN_HOST_ACC_INLINE auto basicCoordToResultCoord(const BasicCoord& basicCoord, const Tree& tree) const - { - return basicCoordToResultCoordImpl(basicCoord, tree); - } - - template - LLAMA_FN_HOST_ACC_INLINE auto resultCoordToBasicCoord(const ResultCoord& resultCoord, const Tree&) const - -> ResultCoord - { - return resultCoord; - } - - private: - template - LLAMA_FN_HOST_ACC_INLINE auto basicCoordToResultCoordImpl(const BasicCoord& basicCoord, const Tree& tree) const - { - if constexpr(std::is_same_v>) - { - if constexpr(std::is_same_v>) - return Tuple{}; - else - { - const auto& childTree = get(tree.childs); - const auto rt1 = basicCoord.first().arrayIndex / amount; - const auto rt2 = basicCoord.first().arrayIndex % amount * childTree.count - + basicCoord.rest().first().arrayIndex; - auto rt1Child = TreeCoordElement{rt1}; - auto rt2Child = TreeCoordElement{rt2}; - return tupleCat(Tuple{rt1Child}, tupleCat(Tuple{rt2Child}, popFront(basicCoord.rest()))); - } - } - else - { - if constexpr(InternalTreeCoord::FirstElement::childIndex != BasicCoord::FirstElement::childIndex) - return basicCoord; - else - { - auto rest = basicCoordToResultCoordImpl( - popFront(basicCoord), - get(tree.childs)); - return tupleCat(Tuple{basicCoord.first()}, rest); - } - } - } - }; - - template - using MoveRTDownFixed = MoveRTDown>; -} // namespace llama::mapping::tree::functor diff --git a/include/llama/mapping/tree/Mapping.hpp b/include/llama/mapping/tree/Mapping.hpp deleted file mode 100644 index 4126717d6a..0000000000 --- a/include/llama/mapping/tree/Mapping.hpp +++ /dev/null @@ -1,228 +0,0 @@ -// Copyright 2020 Alexander Matthes, Bernhard Manfred Gruber -// SPDX-License-Identifier: MPL-2.0 - -#pragma once - -#include "../Common.hpp" -#include "Functors.hpp" -#include "TreeFromDimensions.hpp" -#include "toString.hpp" - -#include - -namespace llama::mapping::tree -{ - namespace internal - { - template - struct MergeFunctors - { - }; - - template - struct MergeFunctors> - { - mp_first> operation = {}; - using ResultTree = decltype(operation.basicToResult(Tree())); - ResultTree treeAfterOp; - MergeFunctors, 1>> next = {}; - - MergeFunctors() = default; - - LLAMA_FN_HOST_ACC_INLINE - MergeFunctors(const Tree& tree, const Tuple& treeOperationList) - : operation(treeOperationList.first()) - , treeAfterOp(operation.basicToResult(tree)) - , next(treeAfterOp, popFront(treeOperationList)) - { - } - - LLAMA_FN_HOST_ACC_INLINE - auto basicToResult(const Tree& tree) const - { - if constexpr(sizeof...(Operations) > 1) - return next.basicToResult(treeAfterOp); - else if constexpr(sizeof...(Operations) == 1) - return operation.basicToResult(tree); - else - return tree; - } - - template - LLAMA_FN_HOST_ACC_INLINE auto basicCoordToResultCoord(const TreeCoord& basicCoord, const Tree& tree) const - { - if constexpr(sizeof...(Operations) >= 1) - return next.basicCoordToResultCoord( - operation.basicCoordToResultCoord(basicCoord, tree), - treeAfterOp); - else - return basicCoord; - } - - template - LLAMA_FN_HOST_ACC_INLINE auto resultCoordToBasicCoord(const TreeCoord& resultCoord, const Tree& tree) const - { - if constexpr(sizeof...(Operations) >= 1) - return next.resultCoordToBasicCoord( - operation.resultCoordToBasicCoord(resultCoord, tree), - operation.basicToResult(tree)); - else - return resultCoord; - } - }; - - template - struct MergeFunctors> - { - MergeFunctors() = default; - - LLAMA_FN_HOST_ACC_INLINE - MergeFunctors(const Tree&, const Tuple<>&) - { - } - - LLAMA_FN_HOST_ACC_INLINE - auto basicToResult(const Tree& tree) const - { - return tree; - } - - template - LLAMA_FN_HOST_ACC_INLINE auto basicCoordToResultCoord(const TreeCoord& basicCoord, const Tree& /*tree*/) - const -> TreeCoord - { - return basicCoord; - } - - template - LLAMA_FN_HOST_ACC_INLINE auto resultCoordToBasicCoord(const TreeCoord& resultCoord, const Tree& /*tree*/) - const -> TreeCoord - { - return resultCoord; - } - }; - - template - LLAMA_FN_HOST_ACC_INLINE auto getTreeBlobSize(const Node& node) -> std::size_t; - - template - LLAMA_FN_HOST_ACC_INLINE auto getTreeBlobSize(const Leaf& leaf) -> std::size_t; - - template - LLAMA_FN_HOST_ACC_INLINE auto getChildrenBlobSize( - const Tuple& childs, - std::index_sequence /*ii*/, - const Count& count) -> std::size_t - { - return count * (getTreeBlobSize(get(childs)) + ...); - } - - template - LLAMA_FN_HOST_ACC_INLINE auto getTreeBlobSize(const Node& node) -> std::size_t - { - constexpr std::size_t childCount = mp_size>::value; - return getChildrenBlobSize(node.childs, std::make_index_sequence{}, LLAMA_COPY(node.count)); - } - - template - LLAMA_FN_HOST_ACC_INLINE auto getTreeBlobSize(const Leaf& leaf) -> std::size_t - { - return leaf.count * sizeof(Type); - } - - template - LLAMA_FN_HOST_ACC_INLINE auto getTreeBlobSize(const Childs& childs, const CountType& count) -> std::size_t - { - return getTreeBlobSize(Node{count, childs}); - } - - template - LLAMA_FN_HOST_ACC_INLINE auto sumChildrenSmallerThan( - const Node& node, - std::index_sequence) -> std::size_t - { - return ((getTreeBlobSize(get(node.childs)) * (Is < MaxPos)) + ...); - } - - template - LLAMA_FN_HOST_ACC_INLINE auto getTreeBlobByte(const Tree& tree, const Tuple& treeCoord) - -> std::size_t - { - const auto firstArrayIndex = treeCoord.first().arrayIndex; - if constexpr(sizeof...(Coords) > 1) - { - constexpr auto firstChildIndex = decltype(treeCoord.first().childIndex)::value; - return getTreeBlobSize(tree.childs, firstArrayIndex) - + sumChildrenSmallerThan( - tree, - std::make_index_sequence>{}) - + getTreeBlobByte(get(tree.childs), treeCoord.rest()); - } - else - return sizeof(typename Tree::Type) * firstArrayIndex; - } - } // namespace internal - - /// An experimental attempt to provide a general purpose description of a mapping. \ref Array and record - /// dimensions are represented by a compile time tree data structure. This tree is mapped into memory by means of a - /// breadth-first tree traversal. By specifying additional tree operations, the tree can be modified at compile - /// time before being mapped to memory. - template - struct Mapping : private TArrayExtents - { - using ArrayExtents = TArrayExtents; - using ArrayIndex = typename ArrayExtents::Index; - using RecordDim = TRecordDim; - - // TODO(bgruber): , support more than one blob - static constexpr std::size_t blobCount = 1; - - private: - using size_type = typename ArrayExtents::value_type; - - public: - using BasicTree = TreeFromDimensions; - using MergedFunctors = internal::MergeFunctors; - BasicTree basicTree; - MergedFunctors mergedFunctors; - - using ResultTree = decltype(mergedFunctors.basicToResult(basicTree)); - ResultTree resultTree; - - Mapping() = default; - - LLAMA_FN_HOST_ACC_INLINE - Mapping(ArrayExtents extents, TreeOperationList treeOperationList, RecordDim = {}) - : ArrayExtents(extents) - , basicTree(createTree(extents.toArray())) - , mergedFunctors(basicTree, treeOperationList) - , resultTree(mergedFunctors.basicToResult(basicTree)) - { - } - - LLAMA_FN_HOST_ACC_INLINE auto extents() const -> ArrayExtents - { - return static_cast(*this); - } - - LLAMA_FN_HOST_ACC_INLINE - auto blobSize(size_type const) const -> size_type - { - // TODO(bgruber): propagate use of size_type - return internal::getTreeBlobSize(resultTree); - } - - template - LLAMA_FN_HOST_ACC_INLINE auto blobNrAndOffset(ArrayIndex ai, RecordCoord = {}) const - -> NrAndOffset - { - // TODO(bgruber): propagate use of size_type - const auto basicTreeCoord = createTreeCoord>(ai); - const auto resultTreeCoord = mergedFunctors.basicCoordToResultCoord(basicTreeCoord, basicTree); - const auto offset = static_cast(internal::getTreeBlobByte( - resultTree, - resultTreeCoord)); // FIXME(bgruber): size_type should be propagated through getTreeBlobByte - return {0, offset}; - } - }; -} // namespace llama::mapping::tree diff --git a/include/llama/mapping/tree/TreeFromDimensions.hpp b/include/llama/mapping/tree/TreeFromDimensions.hpp deleted file mode 100644 index a089266086..0000000000 --- a/include/llama/mapping/tree/TreeFromDimensions.hpp +++ /dev/null @@ -1,163 +0,0 @@ -// Copyright 2020 Alexander Matthes, Bernhard Manfred Gruber -// SPDX-License-Identifier: MPL-2.0 -#pragma once - -#include "../../Core.hpp" -#include "../../Tuple.hpp" - -#include -#include -#include - -namespace llama::mapping::tree -{ - template - inline constexpr auto one = 1; - - template<> - inline constexpr auto one> = mp_size_t<1>{}; - - template - struct Leaf - { - using Identifier = TIdentifier; - using Type = TType; - - const CountType count = one; - }; - - template - struct Node - { - using Identifier = TIdentifier; - using ChildrenTuple = TChildrenTuple; - - const CountType count = one; - const ChildrenTuple childs = {}; - }; - - template - struct TreeCoordElement - { - static constexpr mp_size_t childIndex = {}; - const ArrayIndexType arrayIndex = {}; - }; - - template - using TreeCoord = Tuple>...>; - - namespace internal - { - template - auto treeCoordToString(Tuple treeCoord, std::index_sequence) -> std::string - { - auto s - = ((std::to_string(get(treeCoord).arrayIndex) + ":" + std::to_string(get(treeCoord).childIndex) - + ", ") - + ...); - s.resize(s.length() - 2); - return s; - } - } // namespace internal - - template - auto treeCoordToString(TreeCoord treeCoord) -> std::string - { - return std::string("[ ") - + internal::treeCoordToString(treeCoord, std::make_index_sequence>{}) - + std::string(" ]"); - } - - namespace internal - { - template - struct CreateTreeElement - { - using type = Leaf>; - }; - - template - struct CreateTreeElement, CountType> - { - using type = Node< - Tag, - Tuple, GetFieldType, mp_size_t<1>>::type...>, - CountType>; - }; - - template - struct CreateTreeElement - { - template - static auto createChildren(std::index_sequence) - { - return Tuple, ChildType, mp_size_t<1>>::type...>{}; - } - - using type = Node{})), CountType>; - }; - - template - struct WrapInNNodes - { - using type = Node::type>>; - }; - - template - struct WrapInNNodes - { - using type = Leaf; - }; - - template - using TreeFromRecordDimImpl = typename CreateTreeElement::type; - } // namespace internal - - template - using TreeFromRecordDim = internal::TreeFromRecordDimImpl; - - template - using TreeFromDimensions = - typename internal::WrapInNNodes, ArrayExtents::rank - 1>::type; - - template - LLAMA_FN_HOST_ACC_INLINE auto createTree(const ArrayIndex& size) - { - if constexpr(Pos == N - 1) - return TreeFromRecordDim{ - static_cast(size[N - 1])}; // FIXME(bgruber): propagate index type - else - { - Tuple inner{createTree(size)}; // NOLINT(misc-const-correctness) - return Node{ - static_cast(size[Pos]), - inner}; // FIXME(bgruber): propagate index type - } - }; - - namespace internal - { - template< - typename ArrayIndex, - std::size_t... ADIndices, - std::size_t FirstRecordCoord, - std::size_t... RecordCoords> - LLAMA_FN_HOST_ACC_INLINE auto createTreeCoord( - const ArrayIndex& ai, - std::index_sequence, - RecordCoord) - { - return Tuple{ - TreeCoordElement<(ADIndices == ArrayIndex::rank - 1 ? FirstRecordCoord : 0)>{static_cast( - ai[ADIndices])}..., // TODO(bgruber): we should keep the integer type from the array index - TreeCoordElement>{}..., - TreeCoordElement<0, mp_size_t<0>>{}}; - } - } // namespace internal - - template - LLAMA_FN_HOST_ACC_INLINE auto createTreeCoord(const ArrayIndex& ai) - { - return internal::createTreeCoord(ai, std::make_index_sequence{}, RecordCoord{}); - } -} // namespace llama::mapping::tree diff --git a/include/llama/mapping/tree/toString.hpp b/include/llama/mapping/tree/toString.hpp deleted file mode 100644 index eedefea908..0000000000 --- a/include/llama/mapping/tree/toString.hpp +++ /dev/null @@ -1,82 +0,0 @@ -// Copyright 2020 Alexander Matthes, Bernhard Manfred Gruber -// SPDX-License-Identifier: MPL-2.0 - -#pragma once - -#include "TreeFromDimensions.hpp" - -#include - -namespace llama::mapping::tree -{ - template - auto toString(T) -> std::string - { - return "Unknown"; - } - - // handles array indices - template - inline auto toString(RecordCoord) -> std::string - { - return ""; - } - - inline auto toString(NoName) -> std::string - { - return ""; - } - - template - auto toString(Tuple tree) -> std::string - { - if constexpr(sizeof...(Elements) > 1) - return toString(tree.first()) + " , " + toString(tree.rest()); - else - return toString(tree.first()); - } - - namespace internal - { - inline void replaceAll(std::string& str, const std::string& search, const std::string& replace) - { - std::string::size_type i = 0; - while((i = str.find(search, i)) != std::string::npos) - { - str.replace(i, search.length(), replace); - i += replace.length(); - } - } - - template - auto countAndIdentToString(const NodeOrLeaf& nodeOrLeaf) -> std::string - { - auto r = std::to_string(nodeOrLeaf.count); - if constexpr(std::is_same_v, std::size_t>) - r += "R"; // runtime - else - r += "C"; // compile time - r += std::string{" * "} + toString(typename NodeOrLeaf::Identifier{}); - return r; - } - } // namespace internal - - template - auto toString(const Node& node) -> std::string - { - return internal::countAndIdentToString(node) + "[ " + toString(node.childs) + " ]"; - } - - template - auto toString(const Leaf& leaf) -> std::string - { - auto raw = std::string{llama::structName()}; -#ifdef _MSC_VER - internal::replaceAll(raw, " __cdecl(void)", ""); -#endif -#ifdef __GNUG__ - internal::replaceAll(raw, " ()", ""); -#endif - return internal::countAndIdentToString(leaf) + "(" + raw + ")"; - } -} // namespace llama::mapping::tree diff --git a/tests/common.hpp b/tests/common.hpp index 4f74ea1ca7..937300ed33 100644 --- a/tests/common.hpp +++ b/tests/common.hpp @@ -71,12 +71,20 @@ using ParticleUnaligned = llama::Record< >; // clang-format on +inline void replaceAll(std::string& str, const std::string& search, const std::string& replace) +{ + std::string::size_type i = 0; + while((i = str.find(search, i)) != std::string::npos) + { + str.replace(i, search.length(), replace); + i += replace.length(); + } +} + // TODO(bgruber): replace by boost::core::type_name() once released and available template auto prettyPrintType(const T& t = {}) -> std::string { - using llama::mapping::tree::internal::replaceAll; - auto raw = boost::core::demangle(typeid(t).name()); #ifdef _MSC_VER // remove clutter in MSVC diff --git a/tests/core.cpp b/tests/core.cpp index 26df10586a..0b3fa41ad8 100644 --- a/tests/core.cpp +++ b/tests/core.cpp @@ -17,7 +17,7 @@ TEST_CASE("prettyPrintType") { auto str = prettyPrintType(); #ifdef _WIN32 - llama::mapping::tree::internal::replaceAll(str, "__int64", "long"); + replaceAll(str, "__int64", "long"); #endif const auto* const ref = R"(llama::Record< llama::Field< diff --git a/tests/mapping.Tree.cpp b/tests/mapping.Tree.cpp deleted file mode 100644 index abec31d040..0000000000 --- a/tests/mapping.Tree.cpp +++ /dev/null @@ -1,1101 +0,0 @@ -// Copyright 2022 Bernhard Manfred Gruber -// SPDX-License-Identifier: MPL-2.0 - -#include "common.hpp" - -#ifdef __NVCC__ -# pragma message("LLAMA tree mapping tests disabled for nvcc. Too many compiler bugs.") -#else - -namespace tree = llama::mapping::tree; - -namespace tag -{ - auto toString(Pos) - { - return "Pos"; - } - auto toString(X) - { - return "X"; - } - auto toString(Y) - { - return "Y"; - } - auto toString(Z) - { - return "Z"; - } - auto toString(Vel) - { - return "Vel"; - } - auto toString(Mass) - { - return "Mass"; - } - auto toString(Flags) - { - return "Flags"; - } -} // namespace tag - -TEST_CASE("mapping.Tree.empty") -{ - using ArrayExtents = llama::ArrayExtentsDynamic; - const ArrayExtents extents{16, 16}; - - auto treeOperationList = llama::Tuple{}; - using Mapping = tree::Mapping; - const Mapping mapping(extents, treeOperationList); - - CHECK( - tree::toString(mapping.basicTree) - == "16R * [ 16R * [ 1C * Pos[ 1C * X(double) , 1C * Y(double) , 1C * Z(double) ] , 1C * Mass(float) , 1C * " - "Vel[ 1C * X(double) , 1C * Y(double) , 1C * " - "Z(double) ] , 1C * Flags[ 1C * (bool) , 1C * (bool) , 1C * (bool) , 1C * (bool) ] ] ]"); - CHECK( - tree::toString(mapping.resultTree) - == "16R * [ 16R * [ 1C * Pos[ 1C * X(double) , 1C * Y(double) , 1C * Z(double) ] , 1C * Mass(float) , 1C * " - "Vel[ 1C * X(double) , 1C * Y(double) , 1C * " - "Z(double) ] , 1C * Flags[ 1C * (bool) , 1C * (bool) , 1C * (bool) , 1C * (bool) ] ] ]"); - - STATIC_REQUIRE(mapping.blobCount == 1); - CHECK(mapping.blobSize(0) == 14336); - - using ArrayIndex = typename Mapping::ArrayExtents::Index; - { - const auto ai = ArrayIndex{0, 0}; - CHECK(mapping.blobNrAndOffset<0, 0>(ai).offset == 0); - CHECK(mapping.blobNrAndOffset<0, 1>(ai).offset == 8); - CHECK(mapping.blobNrAndOffset<0, 2>(ai).offset == 16); - CHECK(mapping.blobNrAndOffset<1>(ai).offset == 24); - CHECK(mapping.blobNrAndOffset<2, 0>(ai).offset == 28); - CHECK(mapping.blobNrAndOffset<2, 1>(ai).offset == 36); - CHECK(mapping.blobNrAndOffset<2, 2>(ai).offset == 44); - CHECK(mapping.blobNrAndOffset<3, 0>(ai).offset == 52); - CHECK(mapping.blobNrAndOffset<3, 1>(ai).offset == 53); - CHECK(mapping.blobNrAndOffset<3, 2>(ai).offset == 54); - CHECK(mapping.blobNrAndOffset<3, 3>(ai).offset == 55); - } - - { - const auto ai = ArrayIndex{0, 1}; - CHECK(mapping.blobNrAndOffset<0, 0>(ai).offset == 56); - CHECK(mapping.blobNrAndOffset<0, 1>(ai).offset == 64); - CHECK(mapping.blobNrAndOffset<0, 2>(ai).offset == 72); - CHECK(mapping.blobNrAndOffset<1>(ai).offset == 80); - CHECK(mapping.blobNrAndOffset<2, 0>(ai).offset == 84); - CHECK(mapping.blobNrAndOffset<2, 1>(ai).offset == 92); - CHECK(mapping.blobNrAndOffset<2, 2>(ai).offset == 100); - CHECK(mapping.blobNrAndOffset<3, 0>(ai).offset == 108); - CHECK(mapping.blobNrAndOffset<3, 1>(ai).offset == 109); - CHECK(mapping.blobNrAndOffset<3, 2>(ai).offset == 110); - CHECK(mapping.blobNrAndOffset<3, 3>(ai).offset == 111); - } - - { - const auto ai = ArrayIndex{1, 0}; - CHECK(mapping.blobNrAndOffset<0, 0>(ai).offset == 896); - CHECK(mapping.blobNrAndOffset<0, 1>(ai).offset == 904); - CHECK(mapping.blobNrAndOffset<0, 2>(ai).offset == 912); - CHECK(mapping.blobNrAndOffset<1>(ai).offset == 920); - CHECK(mapping.blobNrAndOffset<2, 0>(ai).offset == 924); - CHECK(mapping.blobNrAndOffset<2, 1>(ai).offset == 932); - CHECK(mapping.blobNrAndOffset<2, 2>(ai).offset == 940); - CHECK(mapping.blobNrAndOffset<3, 0>(ai).offset == 948); - CHECK(mapping.blobNrAndOffset<3, 1>(ai).offset == 949); - CHECK(mapping.blobNrAndOffset<3, 2>(ai).offset == 950); - CHECK(mapping.blobNrAndOffset<3, 3>(ai).offset == 951); - } -} - -TEST_CASE("mapping.Tree.Idem") -{ - using ArrayExtents = llama::ArrayExtentsDynamic; - const ArrayExtents extents{16, 16}; - - auto treeOperationList = llama::Tuple{tree::functor::Idem()}; - using Mapping = tree::Mapping; - const Mapping mapping(extents, treeOperationList); - - CHECK( - tree::toString(mapping.basicTree) - == "16R * [ 16R * [ 1C * Pos[ 1C * X(double) , 1C * Y(double) , 1C * Z(double) ] , 1C * Mass(float) , 1C * " - "Vel[ 1C * X(double) , 1C * Y(double) , 1C * " - "Z(double) ] , 1C * Flags[ 1C * (bool) , 1C * (bool) , 1C * (bool) , 1C * (bool) ] ] ]"); - CHECK( - tree::toString(mapping.resultTree) - == "16R * [ 16R * [ 1C * Pos[ 1C * X(double) , 1C * Y(double) , 1C * Z(double) ] , 1C * Mass(float) , 1C * " - "Vel[ 1C * X(double) , 1C * Y(double) , 1C * " - "Z(double) ] , 1C * Flags[ 1C * (bool) , 1C * (bool) , 1C * (bool) , 1C * (bool) ] ] ]"); - - STATIC_REQUIRE(mapping.blobCount == 1); - CHECK(mapping.blobSize(0) == 14336); - - using ArrayIndex = typename Mapping::ArrayExtents::Index; - { - const auto ai = ArrayIndex{0, 0}; - CHECK(mapping.blobNrAndOffset<0, 0>(ai).offset == 0); - CHECK(mapping.blobNrAndOffset<0, 1>(ai).offset == 8); - CHECK(mapping.blobNrAndOffset<0, 2>(ai).offset == 16); - CHECK(mapping.blobNrAndOffset<1>(ai).offset == 24); - CHECK(mapping.blobNrAndOffset<2, 0>(ai).offset == 28); - CHECK(mapping.blobNrAndOffset<2, 1>(ai).offset == 36); - CHECK(mapping.blobNrAndOffset<2, 2>(ai).offset == 44); - CHECK(mapping.blobNrAndOffset<3, 0>(ai).offset == 52); - CHECK(mapping.blobNrAndOffset<3, 1>(ai).offset == 53); - CHECK(mapping.blobNrAndOffset<3, 2>(ai).offset == 54); - CHECK(mapping.blobNrAndOffset<3, 3>(ai).offset == 55); - } - - { - const auto ai = ArrayIndex{0, 1}; - CHECK(mapping.blobNrAndOffset<0, 0>(ai).offset == 56); - CHECK(mapping.blobNrAndOffset<0, 1>(ai).offset == 64); - CHECK(mapping.blobNrAndOffset<0, 2>(ai).offset == 72); - CHECK(mapping.blobNrAndOffset<1>(ai).offset == 80); - CHECK(mapping.blobNrAndOffset<2, 0>(ai).offset == 84); - CHECK(mapping.blobNrAndOffset<2, 1>(ai).offset == 92); - CHECK(mapping.blobNrAndOffset<2, 2>(ai).offset == 100); - CHECK(mapping.blobNrAndOffset<3, 0>(ai).offset == 108); - CHECK(mapping.blobNrAndOffset<3, 1>(ai).offset == 109); - CHECK(mapping.blobNrAndOffset<3, 2>(ai).offset == 110); - CHECK(mapping.blobNrAndOffset<3, 3>(ai).offset == 111); - } - - { - const auto ai = ArrayIndex{1, 0}; - CHECK(mapping.blobNrAndOffset<0, 0>(ai).offset == 896); - CHECK(mapping.blobNrAndOffset<0, 1>(ai).offset == 904); - CHECK(mapping.blobNrAndOffset<0, 2>(ai).offset == 912); - CHECK(mapping.blobNrAndOffset<1>(ai).offset == 920); - CHECK(mapping.blobNrAndOffset<2, 0>(ai).offset == 924); - CHECK(mapping.blobNrAndOffset<2, 1>(ai).offset == 932); - CHECK(mapping.blobNrAndOffset<2, 2>(ai).offset == 940); - CHECK(mapping.blobNrAndOffset<3, 0>(ai).offset == 948); - CHECK(mapping.blobNrAndOffset<3, 1>(ai).offset == 949); - CHECK(mapping.blobNrAndOffset<3, 2>(ai).offset == 950); - CHECK(mapping.blobNrAndOffset<3, 3>(ai).offset == 951); - } -} - -TEST_CASE("mapping.Tree.LeafOnlyRT") -{ - using ArrayExtents = llama::ArrayExtentsDynamic; - const ArrayExtents extents{16, 16}; - - auto treeOperationList = llama::Tuple{tree::functor::LeafOnlyRT()}; - using Mapping = tree::Mapping; - const Mapping mapping(extents, treeOperationList); - - CHECK( - tree::toString(mapping.basicTree) - == "16R * [ 16R * [ 1C * Pos[ 1C * X(double) , 1C * Y(double) , 1C * Z(double) ] , 1C * Mass(float) , 1C * " - "Vel[ 1C * X(double) , 1C * Y(double) , 1C * " - "Z(double) ] , 1C * Flags[ 1C * (bool) , 1C * (bool) , 1C * (bool) , 1C * (bool) ] ] ]"); - CHECK( - tree::toString(mapping.resultTree) - == "1C * [ 1C * [ 1C * Pos[ 256R * X(double) , 256R * Y(double) , 256R * Z(double) ] , 256R * Mass(float) , " - "1C * Vel[ 256R * X(double) , 256R * Y(double) " - ", 256R * Z(double) ] , 1C * Flags[ 256R * (bool) , 256R * (bool) , 256R * (bool) , 256R * (bool) ] ] ]"); - - STATIC_REQUIRE(mapping.blobCount == 1); - CHECK(mapping.blobSize(0) == 14336); - - using ArrayIndex = typename Mapping::ArrayExtents::Index; - { - const auto ai = ArrayIndex{0, 0}; - CHECK(mapping.blobNrAndOffset<0, 0>(ai).offset == 0); - CHECK(mapping.blobNrAndOffset<0, 1>(ai).offset == 2048); - CHECK(mapping.blobNrAndOffset<0, 2>(ai).offset == 4096); - CHECK(mapping.blobNrAndOffset<1>(ai).offset == 6144); - CHECK(mapping.blobNrAndOffset<2, 0>(ai).offset == 7168); - CHECK(mapping.blobNrAndOffset<2, 1>(ai).offset == 9216); - CHECK(mapping.blobNrAndOffset<2, 2>(ai).offset == 11264); - CHECK(mapping.blobNrAndOffset<3, 0>(ai).offset == 13312); - CHECK(mapping.blobNrAndOffset<3, 1>(ai).offset == 13568); - CHECK(mapping.blobNrAndOffset<3, 2>(ai).offset == 13824); - CHECK(mapping.blobNrAndOffset<3, 3>(ai).offset == 14080); - } - - { - const auto ai = ArrayIndex{0, 1}; - CHECK(mapping.blobNrAndOffset<0, 0>(ai).offset == 8); - CHECK(mapping.blobNrAndOffset<0, 1>(ai).offset == 2056); - CHECK(mapping.blobNrAndOffset<0, 2>(ai).offset == 4104); - CHECK(mapping.blobNrAndOffset<1>(ai).offset == 6148); - CHECK(mapping.blobNrAndOffset<2, 0>(ai).offset == 7176); - CHECK(mapping.blobNrAndOffset<2, 1>(ai).offset == 9224); - CHECK(mapping.blobNrAndOffset<2, 2>(ai).offset == 11272); - CHECK(mapping.blobNrAndOffset<3, 0>(ai).offset == 13313); - CHECK(mapping.blobNrAndOffset<3, 1>(ai).offset == 13569); - CHECK(mapping.blobNrAndOffset<3, 2>(ai).offset == 13825); - CHECK(mapping.blobNrAndOffset<3, 3>(ai).offset == 14081); - } - - { - const auto ai = ArrayIndex{1, 0}; - CHECK(mapping.blobNrAndOffset<0, 0>(ai).offset == 128); - CHECK(mapping.blobNrAndOffset<0, 1>(ai).offset == 2176); - CHECK(mapping.blobNrAndOffset<0, 2>(ai).offset == 4224); - CHECK(mapping.blobNrAndOffset<1>(ai).offset == 6208); - CHECK(mapping.blobNrAndOffset<2, 0>(ai).offset == 7296); - CHECK(mapping.blobNrAndOffset<2, 1>(ai).offset == 9344); - CHECK(mapping.blobNrAndOffset<2, 2>(ai).offset == 11392); - CHECK(mapping.blobNrAndOffset<3, 0>(ai).offset == 13328); - CHECK(mapping.blobNrAndOffset<3, 1>(ai).offset == 13584); - CHECK(mapping.blobNrAndOffset<3, 2>(ai).offset == 13840); - CHECK(mapping.blobNrAndOffset<3, 3>(ai).offset == 14096); - } -} - -TEST_CASE("mapping.Tree.MoveRTDown<>") -{ - using ArrayExtents = llama::ArrayExtentsDynamic; - const ArrayExtents extents{16, 16}; - - auto treeOperationList = llama::Tuple{tree::functor::MoveRTDown>{4}}; - using Mapping = tree::Mapping; - const Mapping mapping(extents, treeOperationList); - - CHECK( - tree::toString(mapping.basicTree) - == "16R * [ 16R * [ 1C * Pos[ 1C * X(double) , 1C * Y(double) , 1C * Z(double) ] , 1C * Mass(float) , 1C * " - "Vel[ 1C * X(double) , 1C * Y(double) , 1C * " - "Z(double) ] , 1C * Flags[ 1C * (bool) , 1C * (bool) , 1C * (bool) , 1C * (bool) ] ] ]"); - CHECK( - tree::toString(mapping.resultTree) - == "4R * [ 64R * [ 1C * Pos[ 1C * X(double) , 1C * Y(double) , 1C * Z(double) ] , 1C * Mass(float) , 1C * " - "Vel[ 1C * X(double) , 1C * Y(double) , 1C * " - "Z(double) ] , 1C * Flags[ 1C * (bool) , 1C * (bool) , 1C * (bool) , 1C * (bool) ] ] ]"); - - STATIC_REQUIRE(mapping.blobCount == 1); - CHECK(mapping.blobSize(0) == 14336); - - using ArrayIndex = typename Mapping::ArrayExtents::Index; - { - const auto ai = ArrayIndex{0, 0}; - CHECK(mapping.blobNrAndOffset<0, 0>(ai).offset == 0); - CHECK(mapping.blobNrAndOffset<0, 1>(ai).offset == 8); - CHECK(mapping.blobNrAndOffset<0, 2>(ai).offset == 16); - CHECK(mapping.blobNrAndOffset<1>(ai).offset == 24); - CHECK(mapping.blobNrAndOffset<2, 0>(ai).offset == 28); - CHECK(mapping.blobNrAndOffset<2, 1>(ai).offset == 36); - CHECK(mapping.blobNrAndOffset<2, 2>(ai).offset == 44); - } - - { - const auto ai = ArrayIndex{0, 1}; - CHECK(mapping.blobNrAndOffset<0, 0>(ai).offset == 56); - CHECK(mapping.blobNrAndOffset<0, 1>(ai).offset == 64); - CHECK(mapping.blobNrAndOffset<0, 2>(ai).offset == 72); - CHECK(mapping.blobNrAndOffset<1>(ai).offset == 80); - CHECK(mapping.blobNrAndOffset<2, 0>(ai).offset == 84); - CHECK(mapping.blobNrAndOffset<2, 1>(ai).offset == 92); - CHECK(mapping.blobNrAndOffset<2, 2>(ai).offset == 100); - } - - { - const auto ai = ArrayIndex{1, 0}; - CHECK(mapping.blobNrAndOffset<0, 0>(ai).offset == 896); - CHECK(mapping.blobNrAndOffset<0, 1>(ai).offset == 904); - CHECK(mapping.blobNrAndOffset<0, 2>(ai).offset == 912); - CHECK(mapping.blobNrAndOffset<1>(ai).offset == 920); - CHECK(mapping.blobNrAndOffset<2, 0>(ai).offset == 924); - CHECK(mapping.blobNrAndOffset<2, 1>(ai).offset == 932); - CHECK(mapping.blobNrAndOffset<2, 2>(ai).offset == 940); - } -} - -TEST_CASE("mapping.Tree.MoveRTDown<0>") -{ - using ArrayExtents = llama::ArrayExtentsDynamic; - const ArrayExtents extents{16, 16}; - - auto treeOperationList = llama::Tuple{tree::functor::MoveRTDown>{4}}; - using Mapping = tree::Mapping; - const Mapping mapping(extents, treeOperationList); - - CHECK( - tree::toString(mapping.basicTree) - == "16R * [ 16R * [ 1C * Pos[ 1C * X(double) , 1C * Y(double) , 1C * Z(double) ] , 1C * Mass(float) , 1C * " - "Vel[ 1C * X(double) , 1C * Y(double) , 1C * " - "Z(double) ] , 1C * Flags[ 1C * (bool) , 1C * (bool) , 1C * (bool) , 1C * (bool) ] ] ]"); - CHECK( - tree::toString(mapping.resultTree) - == "16R * [ 4R * [ 4R * Pos[ 1C * X(double) , 1C * Y(double) , 1C * Z(double) ] , 4R * Mass(float) , 4R * " - "Vel[ 1C * X(double) , 1C * Y(double) , 1C * " - "Z(double) ] , 4R * Flags[ 1C * (bool) , 1C * (bool) , 1C * (bool) , 1C * (bool) ] ] ]"); - - STATIC_REQUIRE(mapping.blobCount == 1); - CHECK(mapping.blobSize(0) == 14336); - - using ArrayIndex = typename Mapping::ArrayExtents::Index; - { - const auto ai = ArrayIndex{0, 0}; - CHECK(mapping.blobNrAndOffset<0, 0>(ai).offset == 0); - CHECK(mapping.blobNrAndOffset<0, 1>(ai).offset == 8); - CHECK(mapping.blobNrAndOffset<0, 2>(ai).offset == 16); - CHECK(mapping.blobNrAndOffset<1>(ai).offset == 96); - CHECK(mapping.blobNrAndOffset<2, 0>(ai).offset == 112); - CHECK(mapping.blobNrAndOffset<2, 1>(ai).offset == 120); - CHECK(mapping.blobNrAndOffset<2, 2>(ai).offset == 128); - } - - { - const auto ai = ArrayIndex{0, 1}; - CHECK(mapping.blobNrAndOffset<0, 0>(ai).offset == 24); - CHECK(mapping.blobNrAndOffset<0, 1>(ai).offset == 32); - CHECK(mapping.blobNrAndOffset<0, 2>(ai).offset == 40); - CHECK(mapping.blobNrAndOffset<1>(ai).offset == 100); - CHECK(mapping.blobNrAndOffset<2, 0>(ai).offset == 136); - CHECK(mapping.blobNrAndOffset<2, 1>(ai).offset == 144); - CHECK(mapping.blobNrAndOffset<2, 2>(ai).offset == 152); - } - - { - const auto ai = ArrayIndex{1, 0}; - CHECK(mapping.blobNrAndOffset<0, 0>(ai).offset == 896); - CHECK(mapping.blobNrAndOffset<0, 1>(ai).offset == 904); - CHECK(mapping.blobNrAndOffset<0, 2>(ai).offset == 912); - CHECK(mapping.blobNrAndOffset<1>(ai).offset == 992); - CHECK(mapping.blobNrAndOffset<2, 0>(ai).offset == 1008); - CHECK(mapping.blobNrAndOffset<2, 1>(ai).offset == 1016); - CHECK(mapping.blobNrAndOffset<2, 2>(ai).offset == 1024); - } -} - -TEST_CASE("mapping.Tree.MoveRTDown<0,0>") -{ - using ArrayExtents = llama::ArrayExtentsDynamic; - const ArrayExtents extents{16, 16}; - - auto treeOperationList = llama::Tuple{tree::functor::MoveRTDown>{4}}; - using Mapping = tree::Mapping; - const Mapping mapping(extents, treeOperationList); - - CHECK( - tree::toString(mapping.basicTree) - == "16R * [ 16R * [ 1C * Pos[ 1C * X(double) , 1C * Y(double) , 1C * Z(double) ] , 1C * Mass(float) , 1C * " - "Vel[ 1C * X(double) , 1C * Y(double) , 1C * " - "Z(double) ] , 1C * Flags[ 1C * (bool) , 1C * (bool) , 1C * (bool) , 1C * (bool) ] ] ]"); - CHECK( - tree::toString(mapping.resultTree) - == "16R * [ 16R * [ 1R * Pos[ 4R * X(double) , 4R * Y(double) , 4R * Z(double) ] , 1C * Mass(float) , 1C * " - "Vel[ 1C * X(double) , 1C * Y(double) , 1C * " - "Z(double) ] , 1C * Flags[ 1C * (bool) , 1C * (bool) , 1C * (bool) , 1C * (bool) ] ] ]"); - - STATIC_REQUIRE(mapping.blobCount == 1); - CHECK(mapping.blobSize(0) == 32768); - - using ArrayIndex = typename Mapping::ArrayExtents::Index; - { - const auto ai = ArrayIndex{0, 0}; - CHECK(mapping.blobNrAndOffset<0, 0>(ai).offset == 0); - CHECK(mapping.blobNrAndOffset<0, 1>(ai).offset == 32); - CHECK(mapping.blobNrAndOffset<0, 2>(ai).offset == 64); - CHECK(mapping.blobNrAndOffset<1>(ai).offset == 96); - CHECK(mapping.blobNrAndOffset<2, 0>(ai).offset == 100); - CHECK(mapping.blobNrAndOffset<2, 1>(ai).offset == 108); - CHECK(mapping.blobNrAndOffset<2, 2>(ai).offset == 116); - } - - { - const auto ai = ArrayIndex{0, 1}; - CHECK(mapping.blobNrAndOffset<0, 0>(ai).offset == 128); - CHECK(mapping.blobNrAndOffset<0, 1>(ai).offset == 160); - CHECK(mapping.blobNrAndOffset<0, 2>(ai).offset == 192); - CHECK(mapping.blobNrAndOffset<1>(ai).offset == 224); - CHECK(mapping.blobNrAndOffset<2, 0>(ai).offset == 228); - CHECK(mapping.blobNrAndOffset<2, 1>(ai).offset == 236); - CHECK(mapping.blobNrAndOffset<2, 2>(ai).offset == 244); - } - - { - const auto ai = ArrayIndex{1, 0}; - CHECK(mapping.blobNrAndOffset<0, 0>(ai).offset == 2048); - CHECK(mapping.blobNrAndOffset<0, 1>(ai).offset == 2080); - CHECK(mapping.blobNrAndOffset<0, 2>(ai).offset == 2112); - CHECK(mapping.blobNrAndOffset<1>(ai).offset == 2144); - CHECK(mapping.blobNrAndOffset<2, 0>(ai).offset == 2148); - CHECK(mapping.blobNrAndOffset<2, 1>(ai).offset == 2156); - CHECK(mapping.blobNrAndOffset<2, 2>(ai).offset == 2164); - } -} - -TEST_CASE("mapping.Tree.MoveRTDownFixed<>") -{ - using ArrayExtents = llama::ArrayExtentsDynamic; - const ArrayExtents extents{16, 16}; - - auto treeOperationList = llama::Tuple{tree::functor::MoveRTDownFixed, 4>{}}; - using Mapping = tree::Mapping; - const Mapping mapping(extents, treeOperationList); - - CHECK( - tree::toString(mapping.basicTree) - == "16R * [ 16R * [ 1C * Pos[ 1C * X(double) , 1C * Y(double) , 1C * Z(double) ] , 1C * Mass(float) , 1C * " - "Vel[ 1C * X(double) , 1C * Y(double) , 1C * " - "Z(double) ] , 1C * Flags[ 1C * (bool) , 1C * (bool) , 1C * (bool) , 1C * (bool) ] ] ]"); - CHECK( - tree::toString(mapping.resultTree) - == "4R * [ 64R * [ 1C * Pos[ 1C * X(double) , 1C * Y(double) , 1C * Z(double) ] , 1C * Mass(float) , 1C * " - "Vel[ 1C * X(double) , 1C * Y(double) , 1C * " - "Z(double) ] , 1C * Flags[ 1C * (bool) , 1C * (bool) , 1C * (bool) , 1C * (bool) ] ] ]"); - - STATIC_REQUIRE(mapping.blobCount == 1); - CHECK(mapping.blobSize(0) == 14336); - - using ArrayIndex = typename Mapping::ArrayExtents::Index; - { - const auto ai = ArrayIndex{0, 0}; - CHECK(mapping.blobNrAndOffset<0, 0>(ai).offset == 0); - CHECK(mapping.blobNrAndOffset<0, 1>(ai).offset == 8); - CHECK(mapping.blobNrAndOffset<0, 2>(ai).offset == 16); - CHECK(mapping.blobNrAndOffset<1>(ai).offset == 24); - CHECK(mapping.blobNrAndOffset<2, 0>(ai).offset == 28); - CHECK(mapping.blobNrAndOffset<2, 1>(ai).offset == 36); - CHECK(mapping.blobNrAndOffset<2, 2>(ai).offset == 44); - } - - { - const auto ai = ArrayIndex{0, 1}; - CHECK(mapping.blobNrAndOffset<0, 0>(ai).offset == 56); - CHECK(mapping.blobNrAndOffset<0, 1>(ai).offset == 64); - CHECK(mapping.blobNrAndOffset<0, 2>(ai).offset == 72); - CHECK(mapping.blobNrAndOffset<1>(ai).offset == 80); - CHECK(mapping.blobNrAndOffset<2, 0>(ai).offset == 84); - CHECK(mapping.blobNrAndOffset<2, 1>(ai).offset == 92); - CHECK(mapping.blobNrAndOffset<2, 2>(ai).offset == 100); - } - - { - const auto ai = ArrayIndex{1, 0}; - CHECK(mapping.blobNrAndOffset<0, 0>(ai).offset == 896); - CHECK(mapping.blobNrAndOffset<0, 1>(ai).offset == 904); - CHECK(mapping.blobNrAndOffset<0, 2>(ai).offset == 912); - CHECK(mapping.blobNrAndOffset<1>(ai).offset == 920); - CHECK(mapping.blobNrAndOffset<2, 0>(ai).offset == 924); - CHECK(mapping.blobNrAndOffset<2, 1>(ai).offset == 932); - CHECK(mapping.blobNrAndOffset<2, 2>(ai).offset == 940); - } -} - -TEST_CASE("mapping.Tree.MoveRTDownFixed<0>") -{ - using ArrayExtents = llama::ArrayExtentsDynamic; - const ArrayExtents extents{16, 16}; - - auto treeOperationList = llama::Tuple{tree::functor::MoveRTDownFixed, 4>{}}; - using Mapping = tree::Mapping; - const Mapping mapping(extents, treeOperationList); - - CHECK( - tree::toString(mapping.basicTree) - == "16R * [ 16R * [ 1C * Pos[ 1C * X(double) , 1C * Y(double) , 1C * Z(double) ] , 1C * Mass(float) , 1C * " - "Vel[ 1C * X(double) , 1C * Y(double) , 1C * " - "Z(double) ] , 1C * Flags[ 1C * (bool) , 1C * (bool) , 1C * (bool) , 1C * (bool) ] ] ]"); - CHECK( - tree::toString(mapping.resultTree) - == "16R * [ 4R * [ 4R * Pos[ 1C * X(double) , 1C * Y(double) , 1C * Z(double) ] , 4R * Mass(float) , 4R * " - "Vel[ 1C * X(double) , 1C * Y(double) , 1C * " - "Z(double) ] , 4R * Flags[ 1C * (bool) , 1C * (bool) , 1C * (bool) , 1C * (bool) ] ] ]"); - - STATIC_REQUIRE(mapping.blobCount == 1); - CHECK(mapping.blobSize(0) == 14336); - - using ArrayIndex = typename Mapping::ArrayExtents::Index; - { - const auto ai = ArrayIndex{0, 0}; - CHECK(mapping.blobNrAndOffset<0, 0>(ai).offset == 0); - CHECK(mapping.blobNrAndOffset<0, 1>(ai).offset == 8); - CHECK(mapping.blobNrAndOffset<0, 2>(ai).offset == 16); - CHECK(mapping.blobNrAndOffset<1>(ai).offset == 96); - CHECK(mapping.blobNrAndOffset<2, 0>(ai).offset == 112); - CHECK(mapping.blobNrAndOffset<2, 1>(ai).offset == 120); - CHECK(mapping.blobNrAndOffset<2, 2>(ai).offset == 128); - } - - { - const auto ai = ArrayIndex{0, 1}; - CHECK(mapping.blobNrAndOffset<0, 0>(ai).offset == 24); - CHECK(mapping.blobNrAndOffset<0, 1>(ai).offset == 32); - CHECK(mapping.blobNrAndOffset<0, 2>(ai).offset == 40); - CHECK(mapping.blobNrAndOffset<1>(ai).offset == 100); - CHECK(mapping.blobNrAndOffset<2, 0>(ai).offset == 136); - CHECK(mapping.blobNrAndOffset<2, 1>(ai).offset == 144); - CHECK(mapping.blobNrAndOffset<2, 2>(ai).offset == 152); - } - - { - const auto ai = ArrayIndex{1, 0}; - CHECK(mapping.blobNrAndOffset<0, 0>(ai).offset == 896); - CHECK(mapping.blobNrAndOffset<0, 1>(ai).offset == 904); - CHECK(mapping.blobNrAndOffset<0, 2>(ai).offset == 912); - CHECK(mapping.blobNrAndOffset<1>(ai).offset == 992); - CHECK(mapping.blobNrAndOffset<2, 0>(ai).offset == 1008); - CHECK(mapping.blobNrAndOffset<2, 1>(ai).offset == 1016); - CHECK(mapping.blobNrAndOffset<2, 2>(ai).offset == 1024); - } -} - -TEST_CASE("mapping.Tree.MoveRTDownFixed<0,0>") -{ - using ArrayExtents = llama::ArrayExtentsDynamic; - const ArrayExtents extents{16, 16}; - - auto treeOperationList = llama::Tuple{tree::functor::MoveRTDownFixed, 4>{}}; - using Mapping = tree::Mapping; - const Mapping mapping(extents, treeOperationList); - - CHECK( - tree::toString(mapping.basicTree) - == "16R * [ 16R * [ 1C * Pos[ 1C * X(double) , 1C * Y(double) , 1C * Z(double) ] , 1C * Mass(float) , 1C * " - "Vel[ 1C * X(double) , 1C * Y(double) , 1C * " - "Z(double) ] , 1C * Flags[ 1C * (bool) , 1C * (bool) , 1C * (bool) , 1C * (bool) ] ] ]"); - CHECK( - tree::toString(mapping.resultTree) - == "16R * [ 16R * [ 1R * Pos[ 4R * X(double) , 4R * Y(double) , 4R * Z(double) ] , 1C * Mass(float) , 1C * " - "Vel[ 1C * X(double) , 1C * Y(double) , 1C * " - "Z(double) ] , 1C * Flags[ 1C * (bool) , 1C * (bool) , 1C * (bool) , 1C * (bool) ] ] ]"); - - STATIC_REQUIRE(mapping.blobCount == 1); - CHECK(mapping.blobSize(0) == 32768); - - using ArrayIndex = typename Mapping::ArrayExtents::Index; - { - const auto ai = ArrayIndex{0, 0}; - CHECK(mapping.blobNrAndOffset<0, 0>(ai).offset == 0); - CHECK(mapping.blobNrAndOffset<0, 1>(ai).offset == 32); - CHECK(mapping.blobNrAndOffset<0, 2>(ai).offset == 64); - CHECK(mapping.blobNrAndOffset<1>(ai).offset == 96); - CHECK(mapping.blobNrAndOffset<2, 0>(ai).offset == 100); - CHECK(mapping.blobNrAndOffset<2, 1>(ai).offset == 108); - CHECK(mapping.blobNrAndOffset<2, 2>(ai).offset == 116); - } - - { - const auto ai = ArrayIndex{0, 1}; - CHECK(mapping.blobNrAndOffset<0, 0>(ai).offset == 128); - CHECK(mapping.blobNrAndOffset<0, 1>(ai).offset == 160); - CHECK(mapping.blobNrAndOffset<0, 2>(ai).offset == 192); - CHECK(mapping.blobNrAndOffset<1>(ai).offset == 224); - CHECK(mapping.blobNrAndOffset<2, 0>(ai).offset == 228); - CHECK(mapping.blobNrAndOffset<2, 1>(ai).offset == 236); - CHECK(mapping.blobNrAndOffset<2, 2>(ai).offset == 244); - } - - { - const auto ai = ArrayIndex{1, 0}; - CHECK(mapping.blobNrAndOffset<0, 0>(ai).offset == 2048); - CHECK(mapping.blobNrAndOffset<0, 1>(ai).offset == 2080); - CHECK(mapping.blobNrAndOffset<0, 2>(ai).offset == 2112); - CHECK(mapping.blobNrAndOffset<1>(ai).offset == 2144); - CHECK(mapping.blobNrAndOffset<2, 0>(ai).offset == 2148); - CHECK(mapping.blobNrAndOffset<2, 1>(ai).offset == 2156); - CHECK(mapping.blobNrAndOffset<2, 2>(ai).offset == 2164); - } -} - -TEST_CASE("mapping.Tree.vectorblocks.runtime") -{ - using ArrayExtents = llama::ArrayExtentsDynamic; - const ArrayExtents extents{16, 16}; - - const auto vectorWidth = 8; - - auto treeOperationList = llama::Tuple{ - tree::functor::MoveRTDown>{vectorWidth}, // move 8 down from ArrayExtents (to - // Position/Mass/Vel) - tree::functor::MoveRTDown>{vectorWidth}, // move 8 down from Position (to X/Y/Z) - tree::functor::MoveRTDown>{vectorWidth}, // move 8 down from Vel (to X/Y/Z) - }; - using Mapping = tree::Mapping; - const Mapping mapping(extents, treeOperationList); - - CHECK( - tree::toString(mapping.basicTree) - == "16R * [ 16R * [ 1C * Pos[ 1C * X(double) , 1C * Y(double) , 1C * Z(double) ] , 1C * Mass(float) , 1C * " - "Vel[ 1C * X(double) , 1C * Y(double) , 1C * " - "Z(double) ] , 1C * Flags[ 1C * (bool) , 1C * (bool) , 1C * (bool) , 1C * (bool) ] ] ]"); - CHECK( - tree::toString(mapping.resultTree) - == "16R * [ 2R * [ 1R * Pos[ 8R * X(double) , 8R * Y(double) , 8R * Z(double) ] , 8R * Mass(float) , " - "1R * Vel[ 8R * X(double) , 8R * Y(double) , 8R * Z(double) ] , 8R * Flags[ 1C * (bool) , 1C * (bool) " - ", 1C * (bool) , 1C * (bool) ] ] ]"); - - STATIC_REQUIRE(mapping.blobCount == 1); - CHECK(mapping.blobSize(0) == 14336); - - using ArrayIndex = typename Mapping::ArrayExtents::Index; - { - const auto ai = ArrayIndex{0, 0}; - CHECK(mapping.blobNrAndOffset<0, 0>(ai).offset == 0); - CHECK(mapping.blobNrAndOffset<0, 1>(ai).offset == 64); - CHECK(mapping.blobNrAndOffset<0, 2>(ai).offset == 128); - CHECK(mapping.blobNrAndOffset<1>(ai).offset == 192); - CHECK(mapping.blobNrAndOffset<2, 0>(ai).offset == 224); - CHECK(mapping.blobNrAndOffset<2, 1>(ai).offset == 288); - CHECK(mapping.blobNrAndOffset<2, 2>(ai).offset == 352); - } - - { - const auto ai = ArrayIndex{0, 1}; - CHECK(mapping.blobNrAndOffset<0, 0>(ai).offset == 8); - CHECK(mapping.blobNrAndOffset<0, 1>(ai).offset == 72); - CHECK(mapping.blobNrAndOffset<0, 2>(ai).offset == 136); - CHECK(mapping.blobNrAndOffset<1>(ai).offset == 196); - CHECK(mapping.blobNrAndOffset<2, 0>(ai).offset == 232); - CHECK(mapping.blobNrAndOffset<2, 1>(ai).offset == 296); - CHECK(mapping.blobNrAndOffset<2, 2>(ai).offset == 360); - } - - { - const auto ai = ArrayIndex{1, 0}; - CHECK(mapping.blobNrAndOffset<0, 0>(ai).offset == 896); - CHECK(mapping.blobNrAndOffset<0, 1>(ai).offset == 960); - CHECK(mapping.blobNrAndOffset<0, 2>(ai).offset == 1024); - CHECK(mapping.blobNrAndOffset<1>(ai).offset == 1088); - CHECK(mapping.blobNrAndOffset<2, 0>(ai).offset == 1120); - CHECK(mapping.blobNrAndOffset<2, 1>(ai).offset == 1184); - CHECK(mapping.blobNrAndOffset<2, 2>(ai).offset == 1248); - } -} - -TEST_CASE("mapping.Tree.vectorblocks.compiletime") -{ - using ArrayExtents = llama::ArrayExtentsDynamic; - const ArrayExtents extents{16, 16}; - - constexpr auto vectorWidth = 8; - - auto treeOperationList = llama::Tuple{ - tree::functor::MoveRTDownFixed, vectorWidth>{}, // move 8 down from ArrayExtents (to - // Position/Mass/Vel) - tree::functor::MoveRTDownFixed, vectorWidth>{}, // move 8 down from Position (to X/Y/Z) - tree::functor::MoveRTDownFixed, vectorWidth>{}, // move 8 down from Vel (to X/Y/Z) - }; - using Mapping = tree::Mapping; - const Mapping mapping(extents, treeOperationList); - - CHECK( - tree::toString(mapping.basicTree) - == "16R * [ 16R * [ 1C * Pos[ 1C * X(double) , 1C * Y(double) , 1C * Z(double) ] , 1C * Mass(float) , 1C * " - "Vel[ 1C * X(double) , 1C * Y(double) , 1C * " - "Z(double) ] , 1C * Flags[ 1C * (bool) , 1C * (bool) , 1C * (bool) , 1C * (bool) ] ] ]"); - CHECK( - tree::toString(mapping.resultTree) - == "16R * [ 2R * [ 1R * Pos[ 8R * X(double) , 8R * Y(double) , 8R * Z(double) ] , 8R * Mass(float) , " - "1R * Vel[ 8R * X(double) , 8R * Y(double) , 8R * Z(double) ] , 8R * Flags[ 1C * (bool) , 1C * (bool) " - ", 1C * (bool) , 1C * (bool) ] ] ]"); - - STATIC_REQUIRE(mapping.blobCount == 1); - CHECK(mapping.blobSize(0) == 14336); - - using ArrayIndex = typename Mapping::ArrayExtents::Index; - { - const auto ai = ArrayIndex{0, 0}; - CHECK(mapping.blobNrAndOffset<0, 0>(ai).offset == 0); - CHECK(mapping.blobNrAndOffset<0, 1>(ai).offset == 64); - CHECK(mapping.blobNrAndOffset<0, 2>(ai).offset == 128); - CHECK(mapping.blobNrAndOffset<1>(ai).offset == 192); - CHECK(mapping.blobNrAndOffset<2, 0>(ai).offset == 224); - CHECK(mapping.blobNrAndOffset<2, 1>(ai).offset == 288); - CHECK(mapping.blobNrAndOffset<2, 2>(ai).offset == 352); - } - - { - const auto ai = ArrayIndex{0, 1}; - CHECK(mapping.blobNrAndOffset<0, 0>(ai).offset == 8); - CHECK(mapping.blobNrAndOffset<0, 1>(ai).offset == 72); - CHECK(mapping.blobNrAndOffset<0, 2>(ai).offset == 136); - CHECK(mapping.blobNrAndOffset<1>(ai).offset == 196); - CHECK(mapping.blobNrAndOffset<2, 0>(ai).offset == 232); - CHECK(mapping.blobNrAndOffset<2, 1>(ai).offset == 296); - CHECK(mapping.blobNrAndOffset<2, 2>(ai).offset == 360); - } - - { - const auto ai = ArrayIndex{1, 0}; - CHECK(mapping.blobNrAndOffset<0, 0>(ai).offset == 896); - CHECK(mapping.blobNrAndOffset<0, 1>(ai).offset == 960); - CHECK(mapping.blobNrAndOffset<0, 2>(ai).offset == 1024); - CHECK(mapping.blobNrAndOffset<1>(ai).offset == 1088); - CHECK(mapping.blobNrAndOffset<2, 0>(ai).offset == 1120); - CHECK(mapping.blobNrAndOffset<2, 1>(ai).offset == 1184); - CHECK(mapping.blobNrAndOffset<2, 2>(ai).offset == 1248); - } -} - -TEST_CASE("mapping.Tree.getNode") -{ - using ArrayExtents = llama::ArrayExtentsDynamic; - const ArrayExtents extents{16, 16}; - - auto treeOperationList = llama::Tuple{}; - using Mapping = tree::Mapping; - const Mapping mapping(extents, treeOperationList); - - using namespace tree; - using namespace tree::functor::internal; - - CHECK( - toString(getNode>(mapping.resultTree)) - == "16R * [ 16R * [ 1C * Pos[ 1C * X(double) , 1C * Y(double) , 1C * Z(double) ] , 1C * Mass(float) " - ", 1C * Vel[ 1C * X(double) , 1C * Y(double) , 1C * Z(double) ] , 1C * Flags[ 1C * (bool) , 1C * " - "(bool) , 1C * (bool) , 1C * (bool) ] ] ]"); - CHECK( - toString(getNode>(mapping.resultTree)) - == "16R * [ 1C * Pos[ 1C * X(double) , 1C * Y(double) , 1C * Z(double) ] , 1C * Mass(float) , 1C * " - "Vel[ 1C * X(double) , 1C * Y(double) , 1C * Z(double) ] , 1C * Flags[ 1C * (bool) , 1C * (bool) , 1C " - "* (bool) , 1C * (bool) ] ]"); - CHECK( - toString(getNode>(mapping.resultTree)) - == "1C * Pos[ 1C * X(double) , 1C * Y(double) , 1C * Z(double) ]"); - CHECK(toString(getNode>(mapping.resultTree)) == "1C * X(double)"); - CHECK(toString(getNode>(mapping.resultTree)) == "1C * Y(double)"); - CHECK(toString(getNode>(mapping.resultTree)) == "1C * Z(double)"); - CHECK(toString(getNode>(mapping.resultTree)) == "1C * Mass(float)"); - CHECK( - toString(getNode>(mapping.resultTree)) - == "1C * Vel[ 1C * X(double) , 1C * Y(double) , 1C * Z(double) ]"); - CHECK(toString(getNode>(mapping.resultTree)) == "1C * X(double)"); - CHECK(toString(getNode>(mapping.resultTree)) == "1C * Y(double)"); - CHECK(toString(getNode>(mapping.resultTree)) == "1C * Z(double)"); - CHECK( - toString(getNode>(mapping.resultTree)) - == "1C * Flags[ 1C * (bool) , 1C * (bool) , 1C * (bool) , 1C * (bool) ]"); - CHECK(toString(getNode>(mapping.resultTree)) == "1C * (bool)"); - CHECK(toString(getNode>(mapping.resultTree)) == "1C * (bool)"); - CHECK(toString(getNode>(mapping.resultTree)) == "1C * (bool)"); - CHECK(toString(getNode>(mapping.resultTree)) == "1C * (bool)"); -} - -TEST_CASE("mapping.Tree") -{ - using ArrayExtents = llama::ArrayExtents; - constexpr ArrayExtents extents{}; - - auto treeOperationList = llama::Tuple{tree::functor::Idem(), tree::functor::LeafOnlyRT{}, tree::functor::Idem{}}; - - using Mapping = tree::Mapping; - const Mapping mapping(extents, treeOperationList); - -# ifndef __NVCOMPILER - auto raw = prettyPrintType(mapping.basicTree); -# ifdef _WIN32 - tree::internal::replaceAll(raw, "__int64", "long"); -# endif -# ifdef _LIBCPP_VERSION - tree::internal::replaceAll(raw, "std::__1::", "std::"); -# endif - const auto* const ref = R"(llama::mapping::tree::Node< - llama::NoName, - llama::Tuple< - llama::mapping::tree::Node< - llama::NoName, - llama::Tuple< - llama::mapping::tree::Node< - tag::Pos, - llama::Tuple< - llama::mapping::tree::Leaf< - tag::X, - double, - std::integral_constant< - unsigned long, - 1 - > - >, - llama::mapping::tree::Leaf< - tag::Y, - double, - std::integral_constant< - unsigned long, - 1 - > - >, - llama::mapping::tree::Leaf< - tag::Z, - double, - std::integral_constant< - unsigned long, - 1 - > - > - >, - std::integral_constant< - unsigned long, - 1 - > - >, - llama::mapping::tree::Leaf< - tag::Mass, - float, - std::integral_constant< - unsigned long, - 1 - > - >, - llama::mapping::tree::Node< - tag::Vel, - llama::Tuple< - llama::mapping::tree::Leaf< - tag::X, - double, - std::integral_constant< - unsigned long, - 1 - > - >, - llama::mapping::tree::Leaf< - tag::Y, - double, - std::integral_constant< - unsigned long, - 1 - > - >, - llama::mapping::tree::Leaf< - tag::Z, - double, - std::integral_constant< - unsigned long, - 1 - > - > - >, - std::integral_constant< - unsigned long, - 1 - > - >, - llama::mapping::tree::Node< - tag::Flags, - llama::Tuple< - llama::mapping::tree::Leaf< - llama::RecordCoord< - 0 - >, - bool, - std::integral_constant< - unsigned long, - 1 - > - >, - llama::mapping::tree::Leaf< - llama::RecordCoord< - 1 - >, - bool, - std::integral_constant< - unsigned long, - 1 - > - >, - llama::mapping::tree::Leaf< - llama::RecordCoord< - 2 - >, - bool, - std::integral_constant< - unsigned long, - 1 - > - >, - llama::mapping::tree::Leaf< - llama::RecordCoord< - 3 - >, - bool, - std::integral_constant< - unsigned long, - 1 - > - > - >, - std::integral_constant< - unsigned long, - 1 - > - > - >, - unsigned long - > - >, - unsigned long ->)"; - CHECK(raw == ref); -# endif - - auto raw2 = prettyPrintType(mapping.resultTree); -# ifdef _WIN32 - tree::internal::replaceAll(raw2, "__int64", "long"); -# endif -# ifdef _LIBCPP_VERSION - tree::internal::replaceAll(raw2, "std::__1::", "std::"); -# endif - const auto* const ref2 = R"(llama::mapping::tree::Node< - llama::NoName, - llama::Tuple< - llama::mapping::tree::Node< - llama::NoName, - llama::Tuple< - llama::mapping::tree::Node< - tag::Pos, - llama::Tuple< - llama::mapping::tree::Leaf< - tag::X, - double, - unsigned long - >, - llama::mapping::tree::Leaf< - tag::Y, - double, - unsigned long - >, - llama::mapping::tree::Leaf< - tag::Z, - double, - unsigned long - > - >, - std::integral_constant< - unsigned long, - 1 - > - >, - llama::mapping::tree::Leaf< - tag::Mass, - float, - unsigned long - >, - llama::mapping::tree::Node< - tag::Vel, - llama::Tuple< - llama::mapping::tree::Leaf< - tag::X, - double, - unsigned long - >, - llama::mapping::tree::Leaf< - tag::Y, - double, - unsigned long - >, - llama::mapping::tree::Leaf< - tag::Z, - double, - unsigned long - > - >, - std::integral_constant< - unsigned long, - 1 - > - >, - llama::mapping::tree::Node< - tag::Flags, - llama::Tuple< - llama::mapping::tree::Leaf< - llama::RecordCoord< - 0 - >, - bool, - unsigned long - >, - llama::mapping::tree::Leaf< - llama::RecordCoord< - 1 - >, - bool, - unsigned long - >, - llama::mapping::tree::Leaf< - llama::RecordCoord< - 2 - >, - bool, - unsigned long - >, - llama::mapping::tree::Leaf< - llama::RecordCoord< - 3 - >, - bool, - unsigned long - > - >, - std::integral_constant< - unsigned long, - 1 - > - > - >, - std::integral_constant< - unsigned long, - 1 - > - > - >, - std::integral_constant< - unsigned long, - 1 - > ->)"; - CHECK(raw2 == ref2); - - CHECK( - tree::toString(mapping.basicTree) - == "12R * [ 12R * [ 1C * Pos[ 1C * X(double) , 1C * Y(double) , 1C * Z(double) ] , 1C * Mass(float) , 1C * " - "Vel[ 1C * X(double) , 1C * Y(double) , 1C * " - "Z(double) ] , 1C * Flags[ 1C * (bool) , 1C * (bool) , 1C * (bool) , 1C * (bool) ] ] ]"); - CHECK( - tree::toString(mapping.resultTree) - == "1C * [ 1C * [ 1C * Pos[ 144R * X(double) , 144R * Y(double) , 144R * Z(double) ] , 144R * Mass(float) , " - "1C * Vel[ 144R * X(double) , 144R * Y(double) , 144R * Z(double) ] , 1C * Flags[ 144R * (bool) , 144R " - "* (bool) , 144R * (bool) , 144R * (bool) ] ] ]"); - - STATIC_REQUIRE(mapping.blobCount == 1); - CHECK(mapping.blobSize(0) == 8064); - CHECK(mapping.blobNrAndOffset<2, 1>({50, 100}).offset == 10784); - CHECK(mapping.blobNrAndOffset<2, 1>({50, 101}).offset == 10792); - - auto view = llama::allocView(mapping); - for(size_t x = 0; x < extents[0]; ++x) - for(size_t y = 0; y < extents[1]; ++y) - { - auto record = view(x, y); - llama::forEachLeafCoord([&](auto ai) { record(ai) = 0; }, tag::Vel{}); - } - double sum = 0.0; - for(size_t x = 0; x < extents[0]; ++x) - for(size_t y = 0; y < extents[1]; ++y) - sum += view(x, y)(llama::RecordCoord<0, 1>{}); - CHECK(sum == 0); -} - -TEST_CASE("treeCoordToString") -{ - const auto ai = llama::ArrayIndex{6, 7, 8}; - CHECK( - tree::treeCoordToString(tree::createTreeCoord>(ai)) == "[ 6:0, 7:0, 8:0, 0:0, 0:0 ]"); - CHECK( - tree::treeCoordToString(tree::createTreeCoord>(ai)) == "[ 6:0, 7:0, 8:0, 0:1, 0:0 ]"); - CHECK( - tree::treeCoordToString(tree::createTreeCoord>(ai)) == "[ 6:0, 7:0, 8:0, 0:2, 0:0 ]"); - CHECK(tree::treeCoordToString(tree::createTreeCoord>(ai)) == "[ 6:0, 7:0, 8:1, 0:0 ]"); - CHECK( - tree::treeCoordToString(tree::createTreeCoord>(ai)) == "[ 6:0, 7:0, 8:2, 0:0, 0:0 ]"); - CHECK( - tree::treeCoordToString(tree::createTreeCoord>(ai)) == "[ 6:0, 7:0, 8:2, 0:1, 0:0 ]"); - CHECK( - tree::treeCoordToString(tree::createTreeCoord>(ai)) == "[ 6:0, 7:0, 8:2, 0:2, 0:0 ]"); - CHECK( - tree::treeCoordToString(tree::createTreeCoord>(ai)) == "[ 6:0, 7:0, 8:3, 0:0, 0:0 ]"); - CHECK( - tree::treeCoordToString(tree::createTreeCoord>(ai)) == "[ 6:0, 7:0, 8:3, 0:1, 0:0 ]"); -} - -#endif diff --git a/tests/view.cpp b/tests/view.cpp index e3804a435c..79de0c2db9 100644 --- a/tests/view.cpp +++ b/tests/view.cpp @@ -39,9 +39,6 @@ TEST_CASE("view.default-ctor") [[maybe_unused]] const llama::View, std::byte*> view5{}; [[maybe_unused]] const llama::View, std::byte*> view6{}; - [[maybe_unused]] const llama:: - View>, std::byte*> - view7{}; } TEST_CASE("view.observers")