Tpetra parallel linear algebra  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Tpetra_Details_Blas.hpp
Go to the documentation of this file.
1 // @HEADER
2 // *****************************************************************************
3 // Tpetra: Templated Linear Algebra Services Package
4 //
5 // Copyright 2008 NTESS and the Tpetra contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
10 #ifndef TPETRA_DETAILS_BLAS_HPP
11 #define TPETRA_DETAILS_BLAS_HPP
12 
20 
21 #include "TpetraCore_config.h"
22 #include "Kokkos_Core.hpp"
23 #include "Kokkos_Complex.hpp"
24 #include <type_traits>
25 
26 namespace Tpetra {
27 namespace Details {
28 namespace Blas {
29 
35 template<class ScalarType>
37  static constexpr bool value =
38  std::is_same<ScalarType, float>::value ||
39  std::is_same<ScalarType, double>::value ||
40  std::is_same<ScalarType, ::Kokkos::complex<float> >::value ||
41  std::is_same<ScalarType, ::Kokkos::complex<double> >::value;
42 };
43 
49 template<class LayoutType>
51  static constexpr bool value =
52  std::is_same<LayoutType, ::Kokkos::LayoutLeft>::value;
53 };
54 
56 template<class ViewType,
57  class IndexType = int>
58 IndexType
59 getStride2DView (const ViewType& A)
60 {
61  static_assert (ViewType::rank == 2, "A must be a rank-2 Kokkos::View.");
62  static_assert (std::is_same<typename ViewType::array_layout, Kokkos::LayoutLeft>::value ||
63  std::is_same<typename ViewType::array_layout, Kokkos::LayoutRight>::value ||
64  std::is_same<typename ViewType::array_layout, Kokkos::LayoutStride>::value,
65  "A's layout must be either LayoutLeft, LayoutRight, or LayoutStride.");
66  static_assert (std::is_integral<IndexType>::value,
67  "IndexType must be a built-in integer type.");
68  IndexType stride[8];
69  A.stride (stride);
70  // BLAS implementations do not like zero LDA, even if (e.g.,) the
71  // number of rows is actually zero. See e.g., GitHub Issue #3235.
72  const auto LDA = (A.extent (1) > 1) ? stride[1] : A.extent (0);
73  return LDA == 0 ? IndexType (1) : LDA;
74 }
75 
76 namespace Impl {
77 
78 template<class ViewType,
79  class ArrayLayout,
80  class IndexType>
81 struct GetStride1DView {
82  typedef ArrayLayout array_layout;
83 
84  static IndexType getStride (const ViewType& x)
85  {
86  static_assert (ViewType::rank == 1, "x must be a rank-1 Kokkos::View.");
87  static_assert (std::is_same<typename ViewType::array_layout, Kokkos::LayoutLeft>::value ||
88  std::is_same<typename ViewType::array_layout, Kokkos::LayoutRight>::value ||
89  std::is_same<typename ViewType::array_layout, Kokkos::LayoutStride>::value,
90  "x's layout must be either LayoutLeft, LayoutRight, or LayoutStride.");
91  static_assert (std::is_same<typename ViewType::array_layout, array_layout>::value,
92  "ViewType::array_layout must be the same as array_layout.");
93  static_assert (std::is_integral<IndexType>::value,
94  "IndexType must be a built-in integer type.");
95  IndexType stride[8];
96  x.stride (stride);
97  return stride[0];
98  }
99 };
100 
101 template<class ViewType,
102  class IndexType>
103 struct GetStride1DView<ViewType, Kokkos::LayoutLeft, IndexType> {
104  typedef Kokkos::LayoutLeft array_layout;
105 
106  static IndexType getStride (const ViewType&)
107  {
108  static_assert (ViewType::rank == 1, "x must be a rank-1 Kokkos::View.");
109  static_assert (std::is_same<typename ViewType::array_layout, array_layout>::value,
110  "ViewType::array_layout must be the same as array_layout.");
111  static_assert (std::is_integral<IndexType>::value,
112  "IndexType must be a built-in integer type.");
113  return static_cast<IndexType> (1);
114  }
115 };
116 
117 template<class ViewType,
118  class IndexType>
119 struct GetStride1DView<ViewType, Kokkos::LayoutRight, IndexType> {
120  typedef Kokkos::LayoutRight array_layout;
121 
122  static IndexType getStride (const ViewType&)
123  {
124  static_assert (ViewType::rank == 1, "x must be a rank-1 Kokkos::View.");
125  static_assert (std::is_same<typename ViewType::array_layout, array_layout>::value,
126  "ViewType::array_layout must be the same as array_layout.");
127  static_assert (std::is_integral<IndexType>::value,
128  "IndexType must be a built-in integer type.");
129  return static_cast<IndexType> (1);
130  }
131 };
132 
133 } // namespace Impl
134 
136 template<class ViewType,
137  class IndexType = int>
138 IndexType
139 getStride1DView (const ViewType& x)
140 {
141  typedef Impl::GetStride1DView<ViewType, typename ViewType::array_layout, IndexType> impl_type;
142  return impl_type::getStride (x);
143 }
144 
145 } // namespace Blas
146 } // namespace Details
147 } // namespace Tpetra
148 
149 #endif // TPETRA_DETAILS_BLAS_HPP
Do BLAS libraries (all that are compliant with the BLAS Standard) support the given &quot;scalar&quot; (matrix ...
Do BLAS libraries (all that are compliant with the BLAS Standard) support the given Kokkos array layo...