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 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274
|
//@HEADER
// ************************************************************************
//
// Kokkos v. 4.0
// Copyright (2022) National Technology & Engineering
// Solutions of Sandia, LLC (NTESS).
//
// Under the terms of Contract DE-NA0003525 with NTESS,
// the U.S. Government retains certain rights in this software.
//
// Part of Kokkos, under the Apache License v2.0 with LLVM Exceptions.
// See https://kokkos.org/LICENSE for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//@HEADER
#include <Kokkos_Core.hpp>
#include <Kokkos_DynRankView.hpp>
namespace {
// clang-format off
template<class DataType>
struct data_analysis {
using data_type = DataType;
using const_data_type = const DataType;
using runtime_data_type = DataType;
using runtime_const_data_type = const DataType;
using non_const_data_type = std::remove_const_t<DataType>;
};
template<class DataType>
struct data_analysis<DataType*> {
using data_type = typename data_analysis<DataType>::data_type*;
using const_data_type = typename data_analysis<DataType>::const_data_type*;
using runtime_data_type = typename data_analysis<DataType>::runtime_data_type*;
using runtime_const_data_type = typename data_analysis<DataType>::runtime_const_data_type*;
using non_const_data_type = typename data_analysis<DataType>::non_const_data_type*;
};
template<class DataType, size_t N>
struct data_analysis<DataType[N]> {
using data_type = typename data_analysis<DataType>::data_type[N];
using const_data_type = typename data_analysis<DataType>::const_data_type[N];
using runtime_data_type = typename data_analysis<DataType>::runtime_data_type*;
using runtime_const_data_type = typename data_analysis<DataType>::runtime_const_data_type*;
using non_const_data_type = typename data_analysis<DataType>::non_const_data_type[N];
};
template<class ViewType, class ViewTraitsType, class DataType, class Layout, class Space, class MemoryTraitsType,
class HostMirrorSpace, class ValueType, class ReferenceType>
constexpr bool test_view_typedefs_impl() {
// ========================
// inherited from ViewTraits
// ========================
static_assert(std::is_same_v<typename ViewType::data_type, DataType>);
static_assert(std::is_same_v<typename ViewType::const_data_type, typename data_analysis<DataType>::const_data_type>);
static_assert(std::is_same_v<typename ViewType::non_const_data_type, typename data_analysis<DataType>::non_const_data_type>);
// FIXME: these should be deprecated and for proper testing (I.e. where this is different from data_type)
// we would need ensemble types which use the hidden View dimension facility of View (i.e. which make
// "specialize" not void)
static_assert(std::is_same_v<typename ViewType::scalar_array_type, DataType>);
static_assert(std::is_same_v<typename ViewType::const_scalar_array_type, typename data_analysis<DataType>::const_data_type>);
static_assert(std::is_same_v<typename ViewType::non_const_scalar_array_type, typename data_analysis<DataType>::non_const_data_type>);
#ifdef KOKKOS_ENABLE_DEPRECATED_CODE_4
static_assert(std::is_same_v<typename ViewType::specialize, void>);
#endif
// FIXME: value_type definition conflicts with mdspan value_type
static_assert(std::is_same_v<typename ViewType::value_type, ValueType>);
static_assert(std::is_same_v<typename ViewType::const_value_type, const ValueType>);
static_assert(std::is_same_v<typename ViewType::non_const_value_type, std::remove_const_t<ValueType>>);
// FIXME: should maybe be deprecated
static_assert(std::is_same_v<typename ViewType::array_layout, Layout>);
// FIXME: should be deprecated and is some complicated impl type
// static_assert(!std::is_void_v<typename ViewType::dimension>);
static_assert(std::is_same_v<typename ViewType::execution_space, typename Space::execution_space>);
static_assert(std::is_same_v<typename ViewType::memory_space, typename Space::memory_space>);
static_assert(std::is_same_v<typename ViewType::device_type, Kokkos::Device<typename ViewType::execution_space, typename ViewType::memory_space>>);
static_assert(std::is_same_v<typename ViewType::memory_traits, MemoryTraitsType>);
static_assert(std::is_same_v<typename ViewType::host_mirror_space, HostMirrorSpace>);
static_assert(std::is_same_v<typename ViewType::size_type, typename ViewType::memory_space::size_type>);
// FIXME: should be deprecated in favor of reference
static_assert(std::is_same_v<typename ViewType::reference_type, ReferenceType>);
// FIXME: should be deprecated in favor of data_handle_type
static_assert(std::is_same_v<typename ViewType::pointer_type, ValueType*>);
// =========================================
// in Legacy View: some helper View variants
// =========================================
// FIXME: in contrast to View, hooks_policy is not propagated
static_assert(std::is_same_v<typename ViewType::traits, ViewTraitsType>);
static_assert(std::is_same_v<typename ViewType::array_type,
Kokkos::DynRankView<typename ViewType::data_type, typename ViewType::array_layout,
typename ViewType::device_type, //typename ViewTraitsType::hooks_policy,
typename ViewType::memory_traits>>);
static_assert(std::is_same_v<typename ViewType::const_type,
Kokkos::DynRankView<typename ViewType::const_data_type, typename ViewType::array_layout,
typename ViewType::device_type, //typename ViewTraitsType::hooks_policy,
typename ViewType::memory_traits>>);
static_assert(std::is_same_v<typename ViewType::non_const_type,
Kokkos::DynRankView<typename ViewType::non_const_data_type, typename ViewType::array_layout,
typename ViewType::device_type, //typename ViewTraitsType::hooks_policy,
typename ViewType::memory_traits>>);
static_assert(std::is_same_v<typename ViewType::HostMirror,
Kokkos::DynRankView<typename ViewType::non_const_data_type, typename ViewType::array_layout,
HostMirrorSpace
/*, typename ViewTraitsType::hooks_policy*/>>);
/* FIXME: these don't exist in DynRankView, should they?
using uniform_layout_type = std::conditional_t<ViewType::rank()==0 || (ViewType::rank()==0 &&
std::is_same_v<Layout, Kokkos::LayoutRight>),
Kokkos::LayoutLeft, Layout>;
// Uhm uniformtype removes all memorytraits?
static_assert(std::is_same_v<typename ViewType::uniform_type,
Kokkos::DynRankView<typename ViewType::data_type, uniform_layout_type,
typename ViewType::device_type, Kokkos::MemoryTraits<>>>);
static_assert(std::is_same_v<typename ViewType::uniform_const_type,
Kokkos::DynRankView<typename ViewType::const_data_type, uniform_layout_type,
typename ViewType::device_type, Kokkos::MemoryTraits<>>>);
static_assert(std::is_same_v<typename ViewType::uniform_runtime_type,
Kokkos::DynRankView<typename data_analysis<DataType>::runtime_data_type, uniform_layout_type,
typename ViewType::device_type, Kokkos::MemoryTraits<>>>);
static_assert(std::is_same_v<typename ViewType::uniform_runtime_const_type,
Kokkos::DynRankView<typename data_analysis<DataType>::runtime_const_data_type, uniform_layout_type,
typename ViewType::device_type, Kokkos::MemoryTraits<>>>);
using anonymous_device_type = Kokkos::Device<typename ViewType::execution_space, Kokkos::AnonymousSpace>;
static_assert(std::is_same_v<typename ViewType::uniform_nomemspace_type,
Kokkos::DynRankView<typename ViewType::data_type, uniform_layout_type,
anonymous_device_type, Kokkos::MemoryTraits<>>>);
static_assert(std::is_same_v<typename ViewType::uniform_const_nomemspace_type,
Kokkos::DynRankView<typename ViewType::const_data_type, uniform_layout_type,
anonymous_device_type, Kokkos::MemoryTraits<>>>);
static_assert(std::is_same_v<typename ViewType::uniform_runtime_nomemspace_type,
Kokkos::DynRankView<typename data_analysis<DataType>::runtime_data_type, uniform_layout_type,
anonymous_device_type, Kokkos::MemoryTraits<>>>);
static_assert(std::is_same_v<typename ViewType::uniform_runtime_const_nomemspace_type,
Kokkos::DynRankView<typename data_analysis<DataType>::runtime_const_data_type, uniform_layout_type,
anonymous_device_type, Kokkos::MemoryTraits<>>>);
*/
// ==================================
// mdspan compatibility
// ==================================
// FIXME: This typedef caused some weird issue with MSVC+NVCC
// static_assert(std::is_same_v<typename ViewType::layout_type, Layout>);
// FIXME: Not supported yet
// static_assert(std::is_same_v<typename ViewType::extents_type, >);
// static_assert(std::is_same_v<typename ViewType::mapping_type, >);
// static_assert(std::is_same_v<typename ViewType::accessor_type, >);
static_assert(std::is_same_v<typename ViewType::element_type, ValueType>);
// FIXME: should be remove_const_t<element_type>
static_assert(std::is_same_v<typename ViewType::value_type, ValueType>);
static_assert(std::is_same_v<typename ViewType::size_type, typename Space::memory_space::size_type>);
// FIXME: we need to evaluate how we want to proceed with this, as with
// extents index_type also determines the stride, while LegacyView uses size_t strides
// So we are doing this now to avoid breakage but it means we may use 64 bit indices on the GPU
#ifndef KOKKOS_ENABLE_IMPL_VIEW_LEGACY
static_assert(std::is_same_v<typename ViewType::index_type, size_t>);
#endif
static_assert(std::is_same_v<typename ViewType::rank_type, size_t>);
// FIXME: should come from accessor_type
static_assert(std::is_same_v<typename ViewType::data_handle_type, typename ViewType::pointer_type>);
static_assert(std::is_same_v<typename ViewType::reference, typename ViewType::reference_type>);
return true;
}
// Helper function to unpack data type and other args from the View, and pass them on
template<class T, class ... ViewArgs>
struct ViewParams {};
template<class L, class S, class M, class HostMirrorSpace, class ValueType, class ReferenceType, class T, class ... ViewArgs>
constexpr bool test_view_typedefs(ViewParams<T, ViewArgs...>) {
return test_view_typedefs_impl<Kokkos::DynRankView<T, ViewArgs...>, Kokkos::ViewTraits<T*******, ViewArgs...>,
T, L, S, M, HostMirrorSpace, ValueType, ReferenceType>();
}
constexpr bool is_host_exec = std::is_same_v<Kokkos::DefaultExecutionSpace, Kokkos::DefaultHostExecutionSpace>;
#if defined(KOKKOS_ENABLE_CUDA_UVM) || defined(KOKKOS_ENABLE_IMPL_CUDA_UNIFIED_MEMORY) || defined(KOKKOS_IMPL_HIP_UNIFIED_MEMORY)
constexpr bool has_unified_mem_space = true;
#else
constexpr bool has_unified_mem_space = false;
#endif
// The test take explicit template arguments for: LayoutType, Space, MemoryTraits, HostMirrorSpace, ValueType, ReferenceType
// The ViewParams is just a type pack for the View template arguments
// Kokkos::View<int>
namespace TestInt {
using layout_type = Kokkos::DefaultExecutionSpace::array_layout;
using space = Kokkos::DefaultExecutionSpace;
using memory_traits = Kokkos::MemoryTraits<>;
// HostMirrorSpace is a mess so: if the default exec is a host exec, that is it
using host_mirror_space = std::conditional_t<is_host_exec, Kokkos::DefaultExecutionSpace,
// otherwise if unified memory is not on its HostSpace
std::conditional_t<!has_unified_mem_space, Kokkos::HostSpace,
// otherwise its the following Device type
Kokkos::Device<Kokkos::DefaultHostExecutionSpace, typename Kokkos::DefaultExecutionSpace::memory_space>>>;
static_assert(test_view_typedefs<layout_type, space, memory_traits, host_mirror_space, int, int&>(
ViewParams<int>{}));
}
// Kokkos::View<int, DefaultExecutionSpace>
namespace TestIntDefaultExecutionSpace {
using layout_type = Kokkos::DefaultExecutionSpace::array_layout;
using space = Kokkos::DefaultExecutionSpace;
using memory_traits = Kokkos::MemoryTraits<>;
// HostMirrorSpace is a mess so: if the default exec is a host exec, it is HostSpace (note difference from View<int> ...)
using host_mirror_space = std::conditional_t<is_host_exec, Kokkos::HostSpace,
// otherwise if unified memory is not on its also HostSpace!
std::conditional_t<!has_unified_mem_space, Kokkos::HostSpace,
// otherwise its the following memory space ...
Kokkos::DefaultExecutionSpace::memory_space>>;
static_assert(test_view_typedefs<layout_type, space, memory_traits, host_mirror_space, int, int&>(
ViewParams<int, Kokkos::DefaultExecutionSpace>{}));
}
// Kokkos::View<const float, Kokkos::HostSpace>
namespace TestFloatPPHostSpace {
using layout_type = Kokkos::LayoutRight;
using space = Kokkos::HostSpace;
using memory_traits = Kokkos::MemoryTraits<>;
using host_mirror_space = Kokkos::HostSpace;
static_assert(test_view_typedefs<layout_type, space, memory_traits, host_mirror_space, const float, const float&>(
ViewParams<const float, Kokkos::HostSpace>{}));
}
// Kokkos::View<float, Kokkos::Device<Kokkos::DefaultHostExecutionSpace, Kokkos::HostSpace>>
namespace TestFloatPPDeviceDefaultHostExecHostSpace {
using layout_type = Kokkos::LayoutRight;
using space = Kokkos::Device<Kokkos::DefaultHostExecutionSpace, Kokkos::HostSpace>;
using memory_traits = Kokkos::MemoryTraits<>;
using host_mirror_space = Kokkos::HostSpace;
static_assert(test_view_typedefs<layout_type, space, memory_traits, host_mirror_space, float, float&>(
ViewParams<float, Kokkos::LayoutRight, Kokkos::Device<Kokkos::DefaultHostExecutionSpace, Kokkos::HostSpace>>{}));
}
// Kokkos::View<int, Kokkos::MemoryTraits<Kokkos::Atomic>>
namespace TestIntAtomic {
using layout_type = Kokkos::DefaultExecutionSpace::array_layout;
using space = Kokkos::DefaultExecutionSpace;
using memory_traits = Kokkos::MemoryTraits<Kokkos::Atomic>;
// HostMirrorSpace is a mess so: if the default exec is a host exec, that is it
using host_mirror_space = std::conditional_t<is_host_exec, Kokkos::DefaultExecutionSpace,
// otherwise if unified memory is not on its HostSpace
std::conditional_t<!has_unified_mem_space, Kokkos::HostSpace,
// otherwise its the following Device type
Kokkos::Device<Kokkos::DefaultHostExecutionSpace, typename Kokkos::DefaultExecutionSpace::memory_space>>>;
#ifdef KOKKOS_ENABLE_IMPL_VIEW_LEGACY
using expected_ref_type = Kokkos::Impl::AtomicDataElement<Kokkos::ViewTraits<int*******, Kokkos::MemoryTraits<Kokkos::Atomic>>>;
#else
using expected_ref_type = desul::AtomicRef<int, desul::MemoryOrderRelaxed, desul::MemoryScopeDevice>;
#endif
// clang-format on
static_assert(test_view_typedefs<layout_type, space, memory_traits,
host_mirror_space, int, expected_ref_type>(
ViewParams<int, Kokkos::MemoryTraits<Kokkos::Atomic>>{}));
} // namespace TestIntAtomic
} // namespace
|