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