Debian Codegraph @

packages/kokkos-kernels/batched/dense/impl/KokkosBatched_InverseLU_Serial_Impl.hpp

raw
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 #ifndef KOKKOSBATCHED_INVERSELU_SERIAL_IMPL_HPP
17 #define KOKKOSBATCHED_INVERSELU_SERIAL_IMPL_HPP
18
19 /// \author Vinh Dang ([email protected])
20
21 #include "KokkosBatched_Util.hpp"
22 #include "KokkosBatched_SolveLU_Decl.hpp"
23 #include "KokkosBatched_SolveLU_Serial_Impl.hpp"
24
25 namespace KokkosBatched {
26
27 ///
28 /// Serial Impl
29 /// =========
30
31 ///
32 /// InverseLU no piv
33 ///
34
35 #if defined(KOKKOSBATCHED_IMPL_ENABLE_INTEL_MKL) && defined(KOKKOSBATCHED_IMPL_ENABLE_INTEL_MKL_BATCHED) && \
36 defined(__KOKKOSBATCHED_ENABLE_INTEL_MKL_COMPACT_BATCHED__)
37 template <>
38 template <typename AViewType, typename WViewType>
39 KOKKOS_INLINE_FUNCTION int SerialInverseLU<Algo::InverseLU::CompactMKL>::invoke(const AViewType &A,
40 const WViewType &W) {
41 typedef typename AViewType::value_type vector_type;
42 // typedef typename vector_type::value_type value_type;
43
44 const int m = A.extent(0), n = A.extent(1);
45
46 static_assert(is_vector<vector_type>::value, "value type is not vector type");
47 static_assert(vector_type::vector_length == 4 || vector_type::vector_length == 8,
48 "AVX, AVX2 and AVX512 is supported");
49 static_assert(AViewType::rank == 2, "A should have two dimensions");
50 static_assert(WViewType::rank == 1, "W should have one dimension");
51 static_assert(std::is_same<typename AViewType::memory_space, typename WViewType::memory_space>::value,
52 "A and W should be on the same memory space");
53 static_assert(!std::is_same<typename WViewType::array_layout, Kokkos::LayoutStride>::value,
54 "W should be an contiguous 1D array");
55 assert(A.extent(0) * A.extent(1) * sizeof(typename AViewType::value_type) <=
56 W.span() * sizeof(typename WViewType::value_type));
57 assert(m == n);
58
59 const MKL_COMPACT_PACK format = vector_type::vector_length == 8 ? MKL_COMPACT_AVX512 : MKL_COMPACT_AVX;
60
61 int r_val = 0;
62 if (A.stride(0) == 1) {
63 mkl_dgetrinp_compact(MKL_COL_MAJOR, n, (double *)A.data(), A.stride(1), (double *)W.data(),
64 (MKL_INT)(n * n * vector_type::vector_length), (MKL_INT *)&r_val, format,
65 (MKL_INT)vector_type::vector_length);
66
67 } else if (A.stride(1) == 1) {
68 mkl_dgetrinp_compact(MKL_ROW_MAJOR, n, (double *)A.data(), A.stride(0), (double *)W.data(),
69 (MKL_INT)(n * n * vector_type::vector_length), (MKL_INT *)&r_val, format,
70 (MKL_INT)vector_type::vector_length);
71 } else {
72 r_val = -1;
73 }
74 return r_val;
75 }
76 #endif
77
78 } // namespace KokkosBatched
79
80 #endif