18#ifndef LIBMESH_KOKKOS_STORAGE_POLICY_H
19#define LIBMESH_KOKKOS_STORAGE_POLICY_H
30#include "libmesh/libmesh_common.h"
32#define PETSC_SKIP_CXX_COMPLEX_FIX 1
33#include "libmesh/ignore_warnings.h"
34#include <Kokkos_Core.hpp>
35#include "libmesh/restore_warnings.h"
54template <
typename Scalar,
typename Layout>
64 using vector_view = ::Kokkos::View<scalar_type * [LIBMESH_DIM], layout_type>;
71 using tensor_view = ::Kokkos::View<scalar_type * [LIBMESH_DIM][LIBMESH_DIM], layout_type>;
77 static constexpr const char *
80 return std::is_same<layout_type, ::Kokkos::LayoutLeft>::value ?
"layoutleft" :
81 std::is_same<layout_type, ::Kokkos::LayoutRight>::value ?
"layoutright" :
108template <
typename StoragePolicy>
109constexpr const char *
112 return StoragePolicy::name();
120template <
typename StoragePolicy>
121inline typename StoragePolicy::vector_view
124 return typename StoragePolicy::vector_view(std::string(label), n);
134 return make_vector_storage<default_storage_policy>(label, n);
142template <
typename StoragePolicy>
143inline typename StoragePolicy::tensor_view
146 return typename StoragePolicy::tensor_view(std::string(label), n);
156 return make_tensor_storage<default_storage_policy>(label, n);
171template <
typename StoragePolicy,
typename VectorType>
172inline typename StoragePolicy::vector_view
175 auto d = make_vector_storage<StoragePolicy>(label, values.size());
176 auto h = ::Kokkos::create_mirror_view(d);
178 for (std::size_t i = 0; i < values.size(); ++i)
179 for (
unsigned int component = 0; component < LIBMESH_DIM; ++component)
180 h(i, component) = values[i](component);
182 ::Kokkos::deep_copy(d, h);
190template <
typename VectorType>
194 return upload_vector_storage<default_storage_policy>(values, label);
209template <
typename StoragePolicy,
typename TensorType>
210inline typename StoragePolicy::tensor_view
213 auto d = make_tensor_storage<StoragePolicy>(label, values.size());
214 auto h = ::Kokkos::create_mirror_view(d);
216 for (std::size_t i = 0; i < values.size(); ++i)
217 for (
unsigned int row = 0;
row < LIBMESH_DIM; ++
row)
218 for (
unsigned int col = 0; col < LIBMESH_DIM; ++col)
219 h(i,
row, col) = values[i](
row, col);
221 ::Kokkos::deep_copy(d, h);
229template <
typename TensorType>
233 return upload_tensor_storage<default_storage_policy>(values, label);
constexpr const char * storage_policy_name()
StoragePolicy::tensor_view upload_tensor_storage(const std::vector< TensorType > &values, const char *label)
Allocates a device view sized for values, copies each tensor's components into a host mirror,...
StoragePolicy::tensor_view make_tensor_storage(const char *label, const std::size_t n)
LIBMESH_DEVICE_INLINE auto row(const TensorLike &T_in, const unsigned int i) -> std::enable_if_t< is_tensor_like_v< TensorLike >, std::conditional_t< std::is_void< ResultVector >::value, libMesh::TypeVector< typename TensorLike::value_type >, ResultVector > >
StoragePolicy::vector_view upload_vector_storage(const std::vector< VectorType > &values, const char *label)
Allocates a device view sized for values, copies each vector's components into a host mirror,...
static_dim_storage_policy< libMesh::Real, ::Kokkos::LayoutRight > layout_right_storage_policy
StoragePolicy::vector_view make_vector_storage(const char *label, const std::size_t n)
Storage policy describing Kokkos views that hold runtime-many vectors or tensors whose per-entry dime...
static constexpr const char * name()
::Kokkos::View< scalar_type *[LIBMESH_DIM][LIBMESH_DIM], layout_type > tensor_view
View type holding n tensors: the runtime extent indexes the entry, the static LIBMESH_DIM x LIBMESH_D...
::Kokkos::View< scalar_type *[LIBMESH_DIM], layout_type > vector_view
View type holding n vectors: the runtime extent indexes the entry, the static LIBMESH_DIM extent inde...