Kokkos Core Kernels Package Version of the Day
Loading...
Searching...
No Matches
KokkosExp_InterOp.hpp
1//@HEADER
2// ************************************************************************
3//
4// Kokkos v. 4.0
5// Copyright (2022) National Technology & Engineering
6// Solutions of Sandia, LLC (NTESS).
7//
8// Under the terms of Contract DE-NA0003525 with NTESS,
9// the U.S. Government retains certain rights in this software.
10//
11// Part of Kokkos, under the Apache License v2.0 with LLVM Exceptions.
12// See https://kokkos.org/LICENSE for license information.
13// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
14//
15//@HEADER
16
17#ifndef KOKKOS_CORE_EXP_INTEROP_HPP
18#define KOKKOS_CORE_EXP_INTEROP_HPP
19#ifndef KOKKOS_IMPL_PUBLIC_INCLUDE
20#define KOKKOS_IMPL_PUBLIC_INCLUDE
21#define KOKKOS_IMPL_PUBLIC_INCLUDE_NOTDEFINED_INTEROP
22#endif
23
24#include <Kokkos_Core_fwd.hpp>
25#include <Kokkos_Layout.hpp>
26#include <Kokkos_MemoryTraits.hpp>
27#include <Kokkos_View.hpp>
28#include <impl/Kokkos_Utilities.hpp>
29#include <type_traits>
30
31namespace Kokkos {
32namespace Impl {
33
34// ------------------------------------------------------------------ //
35// this is used to convert
36// Kokkos::Device<ExecSpace, MemSpace> to MemSpace
37//
38template <typename Tp>
39struct device_memory_space {
40 using type = Tp;
41};
42
43template <typename ExecT, typename MemT>
44struct device_memory_space<Kokkos::Device<ExecT, MemT>> {
45 using type = MemT;
46};
47
48template <typename Tp>
49using device_memory_space_t = typename device_memory_space<Tp>::type;
50
51// ------------------------------------------------------------------ //
52// this is the impl version which takes a view and converts to python
53// view type
54//
55template <typename, typename...>
56struct python_view_type_impl;
57
58template <template <typename...> class ViewT, typename ValueT,
59 typename... Types>
60struct python_view_type_impl<ViewT<ValueT>, type_list<Types...>> {
61 using type = ViewT<ValueT, device_memory_space_t<Types>...>;
62};
63
64template <template <typename...> class ViewT, typename ValueT,
65 typename... Types>
66struct python_view_type_impl<ViewT<ValueT, Types...>>
67 : python_view_type_impl<ViewT<ValueT>,
68 filter_type_list_t<is_default_memory_trait,
69 type_list<Types...>, false>> {};
70
71template <typename... T>
72using python_view_type_impl_t = typename python_view_type_impl<T...>::type;
73
74} // namespace Impl
75} // namespace Kokkos
76
77namespace Kokkos {
78
79template <typename DataType, class... Properties>
80class DynRankView;
81
82namespace Impl {
83
84// Duplicate from the header file for DynRankView to avoid core depending on
85// containers.
86template <class>
87struct is_dyn_rank_view_dup : public std::false_type {};
88
89template <class D, class... P>
90struct is_dyn_rank_view_dup<Kokkos::DynRankView<D, P...>>
91 : public std::true_type {};
92
93} // namespace Impl
94
95namespace Experimental {
96
97// ------------------------------------------------------------------ //
98// this is used to extract the uniform type of a view
99//
100template <typename ViewT>
101struct python_view_type {
102 static_assert(
104 Kokkos::Impl::is_dyn_rank_view_dup<std::decay_t<ViewT>>::value,
105 "Error! python_view_type only supports Kokkos::View and "
106 "Kokkos::DynRankView");
107
108 using type =
109 Kokkos::Impl::python_view_type_impl_t<typename ViewT::array_type>;
110};
111
112template <typename ViewT>
113using python_view_type_t = typename python_view_type<ViewT>::type;
114
115template <typename Tp>
116auto as_python_type(Tp&& _v) {
117 using cast_type = python_view_type_t<Tp>;
118 return static_cast<cast_type>(std::forward<Tp>(_v));
119}
120} // namespace Experimental
121} // namespace Kokkos
122
123#ifdef KOKKOS_IMPL_PUBLIC_INCLUDE_NOTDEFINED_INTEROP
124#undef KOKKOS_IMPL_PUBLIC_INCLUDE
125#undef KOKKOS_IMPL_PUBLIC_INCLUDE_NOTDEFINED_INTEROP
126#endif
127#endif
Declaration of various MemoryLayout options.
A thread safe view to a bitset.