Tpetra parallel linear algebra Version of the Day
Loading...
Searching...
No Matches
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
26namespace Tpetra {
27namespace Details {
28namespace Blas {
29
35template <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
49template <class LayoutType>
51 static constexpr bool value =
52 std::is_same<LayoutType, ::Kokkos::LayoutLeft>::value;
53};
54
56template <class ViewType,
57 class IndexType = int>
60 static_assert(ViewType::rank == 2, "A must be a rank-2 Kokkos::View.");
61 static_assert(std::is_same<typename ViewType::array_layout, Kokkos::LayoutLeft>::value ||
62 std::is_same<typename ViewType::array_layout, Kokkos::LayoutRight>::value ||
63 std::is_same<typename ViewType::array_layout, Kokkos::LayoutStride>::value,
64 "A's layout must be either LayoutLeft, LayoutRight, or LayoutStride.");
65 static_assert(std::is_integral<IndexType>::value,
66 "IndexType must be a built-in integer type.");
67 IndexType stride[8];
68 A.stride(stride);
69 // BLAS implementations do not like zero LDA, even if (e.g.,) the
70 // number of rows is actually zero. See e.g., GitHub Issue #3235.
71 const auto LDA = (A.extent(1) > 1) ? stride[1] : A.extent(0);
72 return LDA == 0 ? IndexType(1) : LDA;
73}
74
75namespace Impl {
76
77template <class ViewType,
78 class ArrayLayout,
79 class IndexType>
80struct GetStride1DView {
81 typedef ArrayLayout array_layout;
82
83 static IndexType getStride(const ViewType& x) {
84 static_assert(ViewType::rank == 1, "x must be a rank-1 Kokkos::View.");
85 static_assert(std::is_same<typename ViewType::array_layout, Kokkos::LayoutLeft>::value ||
86 std::is_same<typename ViewType::array_layout, Kokkos::LayoutRight>::value ||
87 std::is_same<typename ViewType::array_layout, Kokkos::LayoutStride>::value,
88 "x's layout must be either LayoutLeft, LayoutRight, or LayoutStride.");
89 static_assert(std::is_same<typename ViewType::array_layout, array_layout>::value,
90 "ViewType::array_layout must be the same as array_layout.");
91 static_assert(std::is_integral<IndexType>::value,
92 "IndexType must be a built-in integer type.");
93 IndexType stride[8];
94 x.stride(stride);
95 return stride[0];
96 }
97};
98
99template <class ViewType,
100 class IndexType>
101struct GetStride1DView<ViewType, Kokkos::LayoutLeft, IndexType> {
102 typedef Kokkos::LayoutLeft array_layout;
103
104 static IndexType getStride(const ViewType&) {
105 static_assert(ViewType::rank == 1, "x must be a rank-1 Kokkos::View.");
106 static_assert(std::is_same<typename ViewType::array_layout, array_layout>::value,
107 "ViewType::array_layout must be the same as array_layout.");
108 static_assert(std::is_integral<IndexType>::value,
109 "IndexType must be a built-in integer type.");
110 return static_cast<IndexType>(1);
111 }
112};
113
114template <class ViewType,
115 class IndexType>
116struct GetStride1DView<ViewType, Kokkos::LayoutRight, IndexType> {
117 typedef Kokkos::LayoutRight array_layout;
118
119 static IndexType getStride(const ViewType&) {
120 static_assert(ViewType::rank == 1, "x must be a rank-1 Kokkos::View.");
121 static_assert(std::is_same<typename ViewType::array_layout, array_layout>::value,
122 "ViewType::array_layout must be the same as array_layout.");
123 static_assert(std::is_integral<IndexType>::value,
124 "IndexType must be a built-in integer type.");
125 return static_cast<IndexType>(1);
126 }
127};
128
129} // namespace Impl
130
132template <class ViewType,
133 class IndexType = int>
134IndexType
136 typedef Impl::GetStride1DView<ViewType, typename ViewType::array_layout, IndexType> impl_type;
137 return impl_type::getStride(x);
138}
139
140} // namespace Blas
141} // namespace Details
142} // namespace Tpetra
143
144#endif // TPETRA_DETAILS_BLAS_HPP
IndexType getStride1DView(const ViewType &x)
Get the stride ("INCX" in BLAS terms) of the 1-D Kokkos::View x.
IndexType getStride2DView(const ViewType &A)
Get the stride (leading dimension) of the 2-D Kokkos::View A.
Struct that holds views of the contents of a CrsMatrix.
Implementation details of Tpetra.
Namespace Tpetra contains the class and methods constituting the Tpetra library.
Do BLAS libraries (all that are compliant with the BLAS Standard) support the given Kokkos array layo...
Do BLAS libraries (all that are compliant with the BLAS Standard) support the given "scalar" (matrix ...