SimiLie
Loading...
Searching...
No Matches
full_tensor.hpp
1// SPDX-FileCopyrightText: 2024 Baptiste Legouix
2// SPDX-License-Identifier: AGPL-3.0-or-later
3
4#pragma once
5
6#include <ddc/ddc.hpp>
7
8#include <similie/misc/stride.hpp>
9#include <similie/tensor/tensor_impl.hpp>
10
11namespace sil {
12
13namespace tensor {
14
15// struct representing an abstract unique index sweeping on all possible combination of natural indices, for a full tensor (dense with no particular structure).
16template <TensorNatIndex... TensorIndex>
18{
19 static constexpr bool is_tensor_index = true;
20 static constexpr bool is_explicitely_stored_tensor = true;
21
22 using subindices_domain_t = ddc::DiscreteDomain<TensorIndex...>;
23
24 KOKKOS_FUNCTION static constexpr subindices_domain_t subindices_domain()
25 {
26 return ddc::DiscreteDomain<TensorIndex...>(
27 ddc::DiscreteElement<TensorIndex...>(ddc::DiscreteElement<TensorIndex>(0)...),
28 ddc::DiscreteVector<TensorIndex...>(
29 ddc::DiscreteVector<TensorIndex>(TensorIndex::size())...));
30 }
31
32 static constexpr std::size_t rank()
33 {
34 if constexpr (sizeof...(TensorIndex) == 0) {
35 return 0;
36 } else {
37 return (TensorIndex::rank() + ...);
38 }
39 }
40
41 static constexpr std::size_t size()
42 {
43 if constexpr (rank() == 0) {
44 return 1;
45 } else {
46 return (TensorIndex::size() * ...);
47 }
48 }
49
50 static constexpr std::size_t mem_size()
51 {
52 if constexpr (rank() == 0) {
53 return 1;
54 } else {
55 return (TensorIndex::mem_size() * ...);
56 }
57 }
58
59 static constexpr std::size_t access_size()
60 {
61 return (1 * ... * TensorIndex::access_size());
62 }
63
64 KOKKOS_FUNCTION static constexpr std::size_t mem_id(
65 std::array<std::size_t, sizeof...(TensorIndex)> const& natural_ids)
66 {
67 return access_id(natural_ids);
68 }
69
70 KOKKOS_FUNCTION static constexpr std::size_t access_id(
71 std::array<std::size_t, sizeof...(TensorIndex)> const& natural_ids)
72 {
73 if constexpr (rank() == 0) {
74 return 0;
75 } else {
76 return ((misc::detail::stride<TensorIndex, TensorIndex...>()
77 * natural_ids[ddc::type_seq_rank_v<TensorIndex, ddc::TypeSeq<TensorIndex...>>])
78 + ...);
79 }
80 }
81
82 KOKKOS_FUNCTION static constexpr std::size_t access_id_to_mem_id(std::size_t access_id)
83 {
84 return access_id;
85 }
86
87 template <class Tensor, class Elem, class Id, class FunctorType>
88 KOKKOS_FUNCTION static constexpr Tensor::element_type process_access(
89 const FunctorType& access,
90 Tensor const& tensor,
91 Elem const& elem)
92 {
93 return access(tensor, elem);
94 }
95
96 KOKKOS_FUNCTION static constexpr std::array<std::size_t, rank()>
98 {
99 assert(mem_id < mem_size());
100 if constexpr (rank() == 0) {
101 return std::array<std::size_t, rank()> {};
102 } else {
103 return std::array<std::size_t, rank()> {
104 (mem_id % misc::detail::next_stride<TensorIndex, TensorIndex...>())
105 / misc::detail::stride<TensorIndex, TensorIndex...>()...};
106 }
107 }
108};
109
110static_assert(TensorIndexConcept<TensorFullIndex<TensorNaturalIndex<detail::DimensionConcept>>>);
111
112} // namespace tensor
113
114} // namespace sil
The top-level namespace of SimiLie.
Definition csr.hpp:15
static KOKKOS_FUNCTION constexpr std::size_t mem_id(std::array< std::size_t, sizeof...(TensorIndex)> const &natural_ids)
static KOKKOS_FUNCTION constexpr subindices_domain_t subindices_domain()
static constexpr std::size_t size()
ddc::DiscreteDomain< TensorIndex... > subindices_domain_t
static constexpr std::size_t rank()
static KOKKOS_FUNCTION constexpr std::size_t access_id(std::array< std::size_t, sizeof...(TensorIndex)> const &natural_ids)
static KOKKOS_FUNCTION constexpr std::array< std::size_t, rank()> mem_id_to_canonical_natural_ids(std::size_t mem_id)
static constexpr std::size_t access_size()
static constexpr bool is_tensor_index
static constexpr bool is_explicitely_stored_tensor
static KOKKOS_FUNCTION constexpr std::size_t access_id_to_mem_id(std::size_t access_id)
static KOKKOS_FUNCTION constexpr Tensor::element_type process_access(const FunctorType &access, Tensor const &tensor, Elem const &elem)
static constexpr std::size_t mem_size()