File: TestViewCustomization.cpp

package info (click to toggle)
kokkos 5.0.1-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 15,140 kB
  • sloc: cpp: 225,293; sh: 1,250; python: 78; makefile: 16; fortran: 4; ansic: 2
file content (71 lines) | stat: -rw-r--r-- 2,777 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
// SPDX-FileCopyrightText: Copyright Contributors to the Kokkos project

#include <Kokkos_Macros.hpp>
#ifdef KOKKOS_ENABLE_EXPERIMENTAL_CXX20_MODULES
import kokkos.core;
import kokkos.core_impl;
#else
#include <Kokkos_Core.hpp>
#endif
#include <cstddef>
#include <type_traits>

namespace Foo {

struct FooVal {
  int value;
};

struct BarVal {
  int value;
};
// Customization point to control mdspan arguments from view arguments
// Default implementation returns void to indicate no customization
template <class LayoutType, class DeviceType, class MemoryTraits>
constexpr auto customize_view_arguments(
    Kokkos::Impl::ViewArguments<BarVal, LayoutType, DeviceType, MemoryTraits>) {
  using mem_space_t = typename DeviceType::memory_space;
  return Kokkos::Impl::ViewCustomArguments<
      int, Kokkos::Impl::SpaceAwareAccessor<
               mem_space_t, Kokkos::default_accessor<BarVal>>>{};
}
template <class LayoutType, class DeviceType, class MemoryTraits>
constexpr auto customize_view_arguments(
    Kokkos::Impl::ViewArguments<const BarVal, LayoutType, DeviceType,
                                MemoryTraits>) {
  using mem_space_t = typename DeviceType::memory_space;
  return Kokkos::Impl::ViewCustomArguments<
      unsigned, Kokkos::Impl::SpaceAwareAccessor<
                    mem_space_t, Kokkos::default_accessor<const BarVal>>>{};
}

}  // namespace Foo

using view_fooval_t  = Kokkos::View<Foo::FooVal*>;
using view_barval_t  = Kokkos::View<Foo::BarVal*>;
using view_cbarval_t = Kokkos::View<const Foo::BarVal*>;

static_assert(!view_fooval_t::traits::impl_is_customized);
static_assert(view_barval_t::traits::impl_is_customized);
static_assert(view_cbarval_t::traits::impl_is_customized);

static_assert(
    std::is_same_v<typename view_fooval_t::extents_type::index_type, size_t>);
static_assert(
    std::is_same_v<typename view_barval_t::extents_type::index_type, int>);
static_assert(std::is_same_v<typename view_cbarval_t::extents_type::index_type,
                             unsigned>);

using mem_space_t = typename Kokkos::DefaultExecutionSpace::memory_space;
static_assert(std::is_same_v<typename view_fooval_t::accessor_type,
                             Kokkos::Impl::CheckedReferenceCountedAccessor<
                                 Foo::FooVal, mem_space_t>>);
static_assert(
    std::is_same_v<typename view_barval_t::accessor_type,
                   Kokkos::Impl::SpaceAwareAccessor<
                       mem_space_t, Kokkos::default_accessor<Foo::BarVal>>>);
static_assert(std::is_same_v<
              typename view_cbarval_t::accessor_type,
              Kokkos::Impl::SpaceAwareAccessor<
                  mem_space_t, Kokkos::default_accessor<const Foo::BarVal>>>);