| 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 |
/// \author Kyungjoo Kim ([email protected]) |
| 17 |
|
| 18 |
// Note: Luc Berger-Vergiat 04/14/21 |
| 19 |
// This test does not run on cuda or HIP |
| 20 |
// backends so the whole file is guarded |
| 21 |
// to ensure it is not included in these |
| 22 |
// backends unit-test |
| 23 |
|
| 24 |
#if !defined(TEST_CUDA_BATCHED_DENSE_CPP) && !defined(TEST_HIP_BATCHED_DENSE_CPP) && \ |
| 25 |
!defined(TEST_SYCL_BATCHED_DENSE_CPP) && !defined(TEST_OPENMPTARGET_BATCHED_DENSE_CPP) |
| 26 |
|
| 27 |
#include "gtest/gtest.h" |
| 28 |
#include "Kokkos_Core.hpp" |
| 29 |
#include "Kokkos_Random.hpp" |
| 30 |
|
| 31 |
#include "KokkosBatched_Vector.hpp" |
| 32 |
|
| 33 |
#include "KokkosKernels_TestUtils.hpp" |
| 34 |
|
| 35 |
using namespace KokkosBatched; |
| 36 |
|
| 37 |
namespace Test { |
| 38 |
|
| 39 |
template <typename VectorViewType> |
| 40 |
void impl_init_vector_view(const VectorViewType& a) { |
| 41 |
int cnt = 0; |
| 42 |
for (int i0 = 0, i0end = a.extent(0); i0 < i0end; ++i0) |
| 43 |
for (int i1 = 0, i1end = a.extent(1); i1 < i1end; ++i1) |
| 44 |
for (int i2 = 0, i2end = a.extent(2); i2 < i2end; ++i2) |
| 45 |
for (int i3 = 0, i3end = a.extent(3); i3 < i3end; ++i3) |
| 46 |
for (int i4 = 0, i4end = a.extent(4); i4 < i4end; ++i4) |
| 47 |
for (int i5 = 0, i5end = a.extent(5); i5 < i5end; ++i5) |
| 48 |
for (int i6 = 0, i6end = a.extent(6); i6 < i6end; ++i6) |
| 49 |
for (int i7 = 0, i7end = a.extent(7); i7 < i7end; ++i7) |
| 50 |
a.access(i0, i1, i2, i3, i4, i5, i6, i7) = cnt++; |
| 51 |
} |
| 52 |
#define TEST_LOOP \ |
| 53 |
for (int i0 = 0, i0end = b.extent(0); i0 < i0end; ++i0) \ |
| 54 |
for (int i1 = 0, i1end = b.extent(1); i1 < i1end; ++i1) \ |
| 55 |
for (int i2 = 0, i2end = b.extent(2); i2 < i2end; ++i2) \ |
| 56 |
for (int i3 = 0, i3end = b.extent(3); i3 < i3end; ++i3) \ |
| 57 |
for (int i4 = 0, i4end = b.extent(4); i4 < i4end; ++i4) \ |
| 58 |
for (int i5 = 0, i5end = b.extent(5); i5 < i5end; ++i5) \ |
| 59 |
for (int i6 = 0, i6end = b.extent(6); i6 < i6end; ++i6) \ |
| 60 |
for (int i7 = 0, i7end = b.extent(7); i7 < i7end; ++i7) |
| 61 |
|
| 62 |
template <typename VectorViewType> |
| 63 |
void impl_verify_vector_view(const VectorViewType& a, const SimdViewAccess<VectorViewType, PackDim<0> >& b) { |
| 64 |
typedef typename VectorViewType::value_type vector_type; |
| 65 |
constexpr int vl = vector_type::vector_length; |
| 66 |
typedef Kokkos::ArithTraits<typename vector_type::value_type> ats; |
| 67 |
const typename ats::mag_type eps = 1.0e3 * ats::epsilon(); |
| 68 |
TEST_LOOP |
| 69 |
EXPECT_NEAR_KK(a.access(i0 / vl, i1, i2, i3, i4, i5, i6, i7)[i0 % vl], b(i0, i1, i2, i3, i4, i5, i6, i7), eps); |
| 70 |
} |
| 71 |
template <typename VectorViewType> |
| 72 |
void impl_verify_vector_view(const VectorViewType& a, const SimdViewAccess<VectorViewType, PackDim<1> >& b) { |
| 73 |
typedef typename VectorViewType::value_type vector_type; |
| 74 |
constexpr int vl = vector_type::vector_length; |
| 75 |
typedef Kokkos::ArithTraits<typename vector_type::value_type> ats; |
| 76 |
const typename ats::mag_type eps = 1.0e3 * ats::epsilon(); |
| 77 |
TEST_LOOP |
| 78 |
EXPECT_NEAR_KK(a.access(i0, i1 / vl, i2, i3, i4, i5, i6, i7)[i1 % vl], b(i0, i1, i2, i3, i4, i5, i6, i7), eps); |
| 79 |
} |
| 80 |
template <typename VectorViewType> |
| 81 |
void impl_verify_vector_view(const VectorViewType& a, const SimdViewAccess<VectorViewType, PackDim<2> >& b) { |
| 82 |
typedef typename VectorViewType::value_type vector_type; |
| 83 |
constexpr int vl = vector_type::vector_length; |
| 84 |
typedef Kokkos::ArithTraits<typename vector_type::value_type> ats; |
| 85 |
const typename ats::mag_type eps = 1.0e3 * ats::epsilon(); |
| 86 |
TEST_LOOP |
| 87 |
EXPECT_NEAR_KK(a.access(i0, i1, i2 / vl, i3, i4, i5, i6, i7)[i2 % vl], b(i0, i1, i2, i3, i4, i5, i6, i7), eps); |
| 88 |
} |
| 89 |
template <typename VectorViewType> |
| 90 |
void impl_verify_vector_view(const VectorViewType& a, const SimdViewAccess<VectorViewType, PackDim<3> >& b) { |
| 91 |
typedef typename VectorViewType::value_type vector_type; |
| 92 |
constexpr int vl = vector_type::vector_length; |
| 93 |
typedef Kokkos::ArithTraits<typename vector_type::value_type> ats; |
| 94 |
const typename ats::mag_type eps = 1.0e3 * ats::epsilon(); |
| 95 |
TEST_LOOP |
| 96 |
EXPECT_NEAR_KK(a.access(i0, i1, i2, i3 / vl, i4, i5, i6, i7)[i3 % vl], b(i0, i1, i2, i3, i4, i5, i6, i7), eps); |
| 97 |
} |
| 98 |
template <typename VectorViewType> |
| 99 |
void impl_verify_vector_view(const VectorViewType& a, const SimdViewAccess<VectorViewType, PackDim<4> >& b) { |
| 100 |
typedef typename VectorViewType::value_type vector_type; |
| 101 |
constexpr int vl = vector_type::vector_length; |
| 102 |
typedef Kokkos::ArithTraits<typename vector_type::value_type> ats; |
| 103 |
const typename ats::mag_type eps = 1.0e3 * ats::epsilon(); |
| 104 |
TEST_LOOP |
| 105 |
EXPECT_NEAR_KK(a.access(i0, i1, i2, i3, i4 / vl, i5, i6, i7)[i4 % vl], b(i0, i1, i2, i3, i4, i5, i6, i7), eps); |
| 106 |
} |
| 107 |
template <typename VectorViewType> |
| 108 |
void impl_verify_vector_view(const VectorViewType& a, const SimdViewAccess<VectorViewType, PackDim<5> >& b) { |
| 109 |
typedef typename VectorViewType::value_type vector_type; |
| 110 |
constexpr int vl = vector_type::vector_length; |
| 111 |
typedef Kokkos::ArithTraits<typename vector_type::value_type> ats; |
| 112 |
const typename ats::mag_type eps = 1.0e3 * ats::epsilon(); |
| 113 |
TEST_LOOP |
| 114 |
EXPECT_NEAR_KK(a.access(i0, i1, i2, i3, i4, i5 / vl, i6, i7)[i5 % vl], b(i0, i1, i2, i3, i4, i5, i6, i7), eps); |
| 115 |
} |
| 116 |
template <typename VectorViewType> |
| 117 |
void impl_verify_vector_view(const VectorViewType& a, const SimdViewAccess<VectorViewType, PackDim<6> >& b) { |
| 118 |
typedef typename VectorViewType::value_type vector_type; |
| 119 |
constexpr int vl = vector_type::vector_length; |
| 120 |
typedef Kokkos::ArithTraits<typename vector_type::value_type> ats; |
| 121 |
const typename ats::mag_type eps = 1.0e3 * ats::epsilon(); |
| 122 |
TEST_LOOP |
| 123 |
EXPECT_NEAR_KK(a.access(i0, i1, i2, i3, i4, i5, i6 / vl, i7)[i6 % vl], b(i0, i1, i2, i3, i4, i5, i6, i7), eps); |
| 124 |
} |
| 125 |
template <typename VectorViewType> |
| 126 |
void impl_verify_vector_view(const VectorViewType& a, const SimdViewAccess<VectorViewType, PackDim<7> >& b) { |
| 127 |
typedef typename VectorViewType::value_type vector_type; |
| 128 |
constexpr int vl = vector_type::vector_length; |
| 129 |
typedef Kokkos::ArithTraits<typename vector_type::value_type> ats; |
| 130 |
const typename ats::mag_type eps = 1.0e3 * ats::epsilon(); |
| 131 |
TEST_LOOP |
| 132 |
EXPECT_NEAR_KK(a.access(i0, i1, i2, i3, i4, i5, i6, i7 / vl)[i7 % vl], b(i0, i1, i2, i3, i4, i5, i6, i7), eps); |
| 133 |
} |
| 134 |
|
| 135 |
template <typename DeviceType, typename VectorTagType, int VectorLength> |
| 136 |
void impl_test_batched_vector_view() { |
| 137 |
/// random data initialization |
| 138 |
typedef Vector<VectorTagType, VectorLength> vector_type; |
| 139 |
|
| 140 |
// typedef typename vector_type::value_type value_type; |
| 141 |
// const int vector_length = vector_type::vector_length; |
| 142 |
const int test_view_size = 4; |
| 143 |
{ /// rank 1 array |
| 144 |
Kokkos::View<vector_type*, DeviceType> a("a", test_view_size); |
| 145 |
impl_init_vector_view(a); |
| 146 |
impl_verify_vector_view(a, SimdViewAccess<Kokkos::View<vector_type*, DeviceType>, PackDim<0> >(a)); |
| 147 |
} |
| 148 |
{ /// rank 2 array |
| 149 |
Kokkos::View<vector_type**, DeviceType> a("a", test_view_size, test_view_size); |
| 150 |
impl_init_vector_view(a); |
| 151 |
|
| 152 |
impl_verify_vector_view(a, SimdViewAccess<Kokkos::View<vector_type**, DeviceType>, PackDim<0> >(a)); |
| 153 |
impl_verify_vector_view(a, SimdViewAccess<Kokkos::View<vector_type**, DeviceType>, PackDim<1> >(a)); |
| 154 |
} |
| 155 |
{ /// rank 3 array |
| 156 |
Kokkos::View<vector_type***, DeviceType> a("a", test_view_size, test_view_size, test_view_size); |
| 157 |
impl_init_vector_view(a); |
| 158 |
|
| 159 |
impl_verify_vector_view(a, SimdViewAccess<Kokkos::View<vector_type***, DeviceType>, PackDim<0> >(a)); |
| 160 |
impl_verify_vector_view(a, SimdViewAccess<Kokkos::View<vector_type***, DeviceType>, PackDim<1> >(a)); |
| 161 |
impl_verify_vector_view(a, SimdViewAccess<Kokkos::View<vector_type***, DeviceType>, PackDim<2> >(a)); |
| 162 |
} |
| 163 |
{ /// rank 4 array |
| 164 |
Kokkos::View<vector_type****, DeviceType> a("a", test_view_size, test_view_size, test_view_size, test_view_size); |
| 165 |
impl_init_vector_view(a); |
| 166 |
|
| 167 |
impl_verify_vector_view(a, SimdViewAccess<Kokkos::View<vector_type****, DeviceType>, PackDim<0> >(a)); |
| 168 |
impl_verify_vector_view(a, SimdViewAccess<Kokkos::View<vector_type****, DeviceType>, PackDim<1> >(a)); |
| 169 |
impl_verify_vector_view(a, SimdViewAccess<Kokkos::View<vector_type****, DeviceType>, PackDim<2> >(a)); |
| 170 |
impl_verify_vector_view(a, SimdViewAccess<Kokkos::View<vector_type****, DeviceType>, PackDim<3> >(a)); |
| 171 |
} |
| 172 |
{ /// rank 5 array |
| 173 |
Kokkos::View<vector_type*****, DeviceType> a("a", test_view_size, test_view_size, test_view_size, test_view_size, |
| 174 |
test_view_size); |
| 175 |
impl_init_vector_view(a); |
| 176 |
|
| 177 |
impl_verify_vector_view(a, SimdViewAccess<Kokkos::View<vector_type*****, DeviceType>, PackDim<0> >(a)); |
| 178 |
impl_verify_vector_view(a, SimdViewAccess<Kokkos::View<vector_type*****, DeviceType>, PackDim<1> >(a)); |
| 179 |
impl_verify_vector_view(a, SimdViewAccess<Kokkos::View<vector_type*****, DeviceType>, PackDim<2> >(a)); |
| 180 |
impl_verify_vector_view(a, SimdViewAccess<Kokkos::View<vector_type*****, DeviceType>, PackDim<3> >(a)); |
| 181 |
impl_verify_vector_view(a, SimdViewAccess<Kokkos::View<vector_type*****, DeviceType>, PackDim<4> >(a)); |
| 182 |
} |
| 183 |
{ /// rank 6 array |
| 184 |
Kokkos::View<vector_type******, DeviceType> a("a", test_view_size, test_view_size, test_view_size, test_view_size, |
| 185 |
test_view_size, test_view_size); |
| 186 |
impl_init_vector_view(a); |
| 187 |
|
| 188 |
impl_verify_vector_view(a, SimdViewAccess<Kokkos::View<vector_type******, DeviceType>, PackDim<0> >(a)); |
| 189 |
impl_verify_vector_view(a, SimdViewAccess<Kokkos::View<vector_type******, DeviceType>, PackDim<1> >(a)); |
| 190 |
impl_verify_vector_view(a, SimdViewAccess<Kokkos::View<vector_type******, DeviceType>, PackDim<2> >(a)); |
| 191 |
impl_verify_vector_view(a, SimdViewAccess<Kokkos::View<vector_type******, DeviceType>, PackDim<3> >(a)); |
| 192 |
impl_verify_vector_view(a, SimdViewAccess<Kokkos::View<vector_type******, DeviceType>, PackDim<4> >(a)); |
| 193 |
impl_verify_vector_view(a, SimdViewAccess<Kokkos::View<vector_type******, DeviceType>, PackDim<5> >(a)); |
| 194 |
} |
| 195 |
{ /// rank 7 array |
| 196 |
Kokkos::View<vector_type*******, DeviceType> a("a", test_view_size, test_view_size, test_view_size, test_view_size, |
| 197 |
test_view_size, test_view_size, test_view_size); |
| 198 |
impl_init_vector_view(a); |
| 199 |
|
| 200 |
impl_verify_vector_view(a, SimdViewAccess<Kokkos::View<vector_type*******, DeviceType>, PackDim<0> >(a)); |
| 201 |
impl_verify_vector_view(a, SimdViewAccess<Kokkos::View<vector_type*******, DeviceType>, PackDim<1> >(a)); |
| 202 |
impl_verify_vector_view(a, SimdViewAccess<Kokkos::View<vector_type*******, DeviceType>, PackDim<2> >(a)); |
| 203 |
impl_verify_vector_view(a, SimdViewAccess<Kokkos::View<vector_type*******, DeviceType>, PackDim<3> >(a)); |
| 204 |
impl_verify_vector_view(a, SimdViewAccess<Kokkos::View<vector_type*******, DeviceType>, PackDim<4> >(a)); |
| 205 |
impl_verify_vector_view(a, SimdViewAccess<Kokkos::View<vector_type*******, DeviceType>, PackDim<5> >(a)); |
| 206 |
impl_verify_vector_view(a, SimdViewAccess<Kokkos::View<vector_type*******, DeviceType>, PackDim<6> >(a)); |
| 207 |
} |
| 208 |
{ /// rank 8 array |
| 209 |
Kokkos::View<vector_type********, DeviceType> a("a", test_view_size, test_view_size, test_view_size, test_view_size, |
| 210 |
test_view_size, test_view_size, test_view_size, test_view_size); |
| 211 |
impl_init_vector_view(a); |
| 212 |
|
| 213 |
impl_verify_vector_view(a, SimdViewAccess<Kokkos::View<vector_type********, DeviceType>, PackDim<0> >(a)); |
| 214 |
impl_verify_vector_view(a, SimdViewAccess<Kokkos::View<vector_type********, DeviceType>, PackDim<1> >(a)); |
| 215 |
impl_verify_vector_view(a, SimdViewAccess<Kokkos::View<vector_type********, DeviceType>, PackDim<2> >(a)); |
| 216 |
impl_verify_vector_view(a, SimdViewAccess<Kokkos::View<vector_type********, DeviceType>, PackDim<3> >(a)); |
| 217 |
impl_verify_vector_view(a, SimdViewAccess<Kokkos::View<vector_type********, DeviceType>, PackDim<4> >(a)); |
| 218 |
impl_verify_vector_view(a, SimdViewAccess<Kokkos::View<vector_type********, DeviceType>, PackDim<5> >(a)); |
| 219 |
impl_verify_vector_view(a, SimdViewAccess<Kokkos::View<vector_type********, DeviceType>, PackDim<6> >(a)); |
| 220 |
impl_verify_vector_view(a, SimdViewAccess<Kokkos::View<vector_type********, DeviceType>, PackDim<7> >(a)); |
| 221 |
} |
| 222 |
} |
| 223 |
} // namespace Test |
| 224 |
|
| 225 |
template <typename DeviceType, typename VectorTagType, int VectorLength> |
| 226 |
int test_batched_vector_view() { |
| 227 |
static_assert(Kokkos::SpaceAccessibility<DeviceType, Kokkos::HostSpace>::accessible, |
| 228 |
"vector datatype is only tested on host space"); |
| 229 |
Test::impl_test_batched_vector_view<DeviceType, VectorTagType, VectorLength>(); |
| 230 |
|
| 231 |
return 0; |
| 232 |
} |
| 233 |
|
| 234 |
/// |
| 235 |
/// SIMD |
| 236 |
/// |
| 237 |
|
| 238 |
#if defined(KOKKOSKERNELS_INST_FLOAT) |
| 239 |
TEST_F(TestCategory, batched_vector_view_simd_float8) { test_batched_vector_view<TestDevice, SIMD<float>, 8>(); } |
| 240 |
#endif |
| 241 |
|
| 242 |
#if defined(KOKKOSKERNELS_INST_DOUBLE) |
| 243 |
TEST_F(TestCategory, batched_vector_view_simd_double4) { test_batched_vector_view<TestDevice, SIMD<double>, 4>(); } |
| 244 |
TEST_F(TestCategory, batched_vector_view_simd_double8) { test_batched_vector_view<TestDevice, SIMD<double>, 8>(); } |
| 245 |
#endif |
| 246 |
|
| 247 |
#if defined(KOKKOSKERNELS_INST_COMPLEX_FLOAT) |
| 248 |
TEST_F(TestCategory, batched_vector_view_simd_scomplex4) { |
| 249 |
test_batched_vector_view<TestDevice, SIMD<Kokkos::complex<float> >, 4>(); |
| 250 |
} |
| 251 |
TEST_F(TestCategory, batched_vector_view_simd_scomplex8) { |
| 252 |
test_batched_vector_view<TestDevice, SIMD<Kokkos::complex<float> >, 8>(); |
| 253 |
} |
| 254 |
#endif |
| 255 |
|
| 256 |
#if defined(KOKKOSKERNELS_INST_COMPLEX_DOUBLE) |
| 257 |
TEST_F(TestCategory, batched_vector_view_simd_dcomplex2) { |
| 258 |
test_batched_vector_view<TestDevice, SIMD<Kokkos::complex<double> >, 2>(); |
| 259 |
} |
| 260 |
|
| 261 |
#if defined(KOKKOS_COMPILER_INTEL) && ((KOKKOS_COMPILER_INTEL > 1900) && (KOKKOS_COMPILER_INTEL <= 2021)) |
| 262 |
TEST_F(TestCategory, batched_vector_view_simd_dcomplex4) { |
| 263 |
printf( |
| 264 |
"Skipped: intel compiler version > 19.0.05 && <= 2021\n" |
| 265 |
"See https://github.com/kokkos/kokkos-kernels/issues/1673."); |
| 266 |
} |
| 267 |
#else |
| 268 |
TEST_F(TestCategory, batched_vector_view_simd_dcomplex4) { |
| 269 |
test_batched_vector_view<TestDevice, SIMD<Kokkos::complex<double> >, 4>(); |
| 270 |
} |
| 271 |
#endif // KOKKOS_COMPILER_INTEL |
| 272 |
#endif // KOKKOSKERNELS_INST_COMPLEX_DOUBLE |
| 273 |
|
| 274 |
#endif // check to not include this in a device test |