| 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 |
/* |
| 19 |
#include "gtest/gtest.h" |
| 20 |
#include "Kokkos_Core.hpp" |
| 21 |
#include "Kokkos_Random.hpp" |
| 22 |
|
| 23 |
#include "KokkosBatched_Eigendecomposition_Decl.hpp" |
| 24 |
#include "KokkosBatched_Eigendecomposition_Serial_Impl.hpp" |
| 25 |
|
| 26 |
#include "KokkosKernels_TestUtils.hpp" |
| 27 |
|
| 28 |
using namespace KokkosBatched; |
| 29 |
|
| 30 |
namespace Test { |
| 31 |
|
| 32 |
template<typename DeviceType, |
| 33 |
typename ViewRank3Type, |
| 34 |
typename ViewRank2Type, |
| 35 |
typename WorkViewType> |
| 36 |
struct Functor_TestBatchedSerialEigendecomposition { |
| 37 |
using execution_space = typename DeviceType::execution_space; |
| 38 |
ViewRank3Type _A; |
| 39 |
ViewRank2Type _Er, _Ei; |
| 40 |
ViewRank3Type _UL, _UR; |
| 41 |
WorkViewType _W; |
| 42 |
|
| 43 |
KOKKOS_INLINE_FUNCTION |
| 44 |
Functor_TestBatchedSerialEigendecomposition(const ViewRank3Type A, |
| 45 |
const ViewRank2Type Er, |
| 46 |
const ViewRank2Type Ei, |
| 47 |
const ViewRank3Type UL, |
| 48 |
const ViewRank3Type UR, |
| 49 |
const WorkViewType W) |
| 50 |
: _A(A), _Er(Er), _Ei(Ei), _UL(UL), _UR(UR), _W(W) |
| 51 |
{} |
| 52 |
|
| 53 |
KOKKOS_INLINE_FUNCTION |
| 54 |
void operator()(const int k) const { |
| 55 |
auto A = Kokkos::subview(_A, k, Kokkos::ALL(), Kokkos::ALL()); |
| 56 |
auto er = Kokkos::subview(_Er, k, Kokkos::ALL()); |
| 57 |
auto ei = Kokkos::subview(_Ei, k, Kokkos::ALL()); |
| 58 |
auto UL = Kokkos::subview(_UL, k, Kokkos::ALL(), Kokkos::ALL()); |
| 59 |
auto UR = Kokkos::subview(_UR, k, Kokkos::ALL(), Kokkos::ALL()); |
| 60 |
auto W = Kokkos::subview(_W, k, Kokkos::ALL()); |
| 61 |
SerialEigendecomposition::invoke(A, er, ei, UL, UR, W); |
| 62 |
} |
| 63 |
|
| 64 |
inline |
| 65 |
void run() { |
| 66 |
typedef typename ViewRank3Type::value_type value_type; |
| 67 |
std::string name_region("KokkosBatched::Test::SerialEigendecomposition"); |
| 68 |
std::string name_value_type = ( std::is_same<value_type,float>::value ? |
| 69 |
"::Float" : std::is_same<value_type,double>::value ? "::Double" : |
| 70 |
std::is_same<value_type,Kokkos::complex<float> |
| 71 |
>::value ? "::ComplexFloat" : std::is_same<value_type,Kokkos::complex<double> |
| 72 |
>::value ? "::ComplexDouble" : "::UnknownValueType" ); std::string name = |
| 73 |
name_region + name_value_type; Kokkos::Profiling::pushRegion( name.c_str() ); |
| 74 |
Kokkos::RangePolicy<execution_space> policy(0, _A.extent(0)); |
| 75 |
Kokkos::parallel_for(name.c_str(), policy, *this); |
| 76 |
Kokkos::Profiling::popRegion(); |
| 77 |
} |
| 78 |
}; |
| 79 |
|
| 80 |
template<typename DeviceType, |
| 81 |
typename ValueType, |
| 82 |
typename LayoutType> |
| 83 |
void impl_test_batched_serial_eigendecomposition(const int N, const int m) { |
| 84 |
typedef ValueType value_type; |
| 85 |
typedef Kokkos::View<value_type***,LayoutType,DeviceType> ViewRank3Type; |
| 86 |
typedef Kokkos::View<value_type**,LayoutType,DeviceType> ViewRank2Type; |
| 87 |
typedef Kokkos::View<value_type**,Kokkos::LayoutRight,DeviceType> |
| 88 |
WorkViewType; |
| 89 |
|
| 90 |
/// input |
| 91 |
ViewRank3Type A("A", N, m, m); |
| 92 |
WorkViewType W("W", N, 2*m*m+m*5); |
| 93 |
|
| 94 |
/// output |
| 95 |
ViewRank2Type Er("Er", N, m); |
| 96 |
ViewRank2Type Ei("Ei", N, m); |
| 97 |
ViewRank3Type UL("UL", N, m, m); |
| 98 |
ViewRank3Type UR("UR", N, m, m); |
| 99 |
|
| 100 |
|
| 101 |
Kokkos::Random_XorShift64_Pool<typename DeviceType::execution_space> |
| 102 |
random(13718); Kokkos::fill_random(A, random, value_type(1.0)); Kokkos::fence(); |
| 103 |
|
| 104 |
/// test body |
| 105 |
Functor_TestBatchedSerialEigendecomposition |
| 106 |
<DeviceType,ViewRank3Type,ViewRank2Type,WorkViewType>(A, Er, Ei, UL, UR, |
| 107 |
W).run(); Kokkos::fence(); |
| 108 |
} |
| 109 |
} |
| 110 |
|
| 111 |
template<typename DeviceType, |
| 112 |
typename ValueType> |
| 113 |
int test_batched_serial_eigendecomposition() { |
| 114 |
// #if defined(KOKKOSKERNELS_INST_LAYOUTLEFT) |
| 115 |
// { |
| 116 |
// |
| 117 |
Test::impl_test_batched_serial_eigendecomposition<DeviceType,ValueType,Kokkos::LayoutLeft>(10, |
| 118 |
10); |
| 119 |
// for (int i=0;i<10;++i) |
| 120 |
// |
| 121 |
Test::impl_test_batched_serial_eigendecomposition<DeviceType,ValueType,Kokkos::LayoutLeft>(10, |
| 122 |
1); |
| 123 |
// } |
| 124 |
// #endif |
| 125 |
#if defined(KOKKOSKERNELS_INST_LAYOUTRIGHT) |
| 126 |
{ |
| 127 |
Test::impl_test_batched_serial_eigendecomposition<DeviceType,ValueType,Kokkos::LayoutRight>(10, |
| 128 |
10); for (int i=0;i<10;++i) |
| 129 |
Test::impl_test_batched_serial_eigendecomposition<DeviceType,ValueType,Kokkos::LayoutRight>(10, |
| 130 |
1); |
| 131 |
} |
| 132 |
#endif |
| 133 |
|
| 134 |
return 0; |
| 135 |
} |
| 136 |
*/ |