<T>LAPACK 0.1.1
C++ Template Linear Algebra PACKage
Loading...
Searching...
No Matches
utils.hpp
Go to the documentation of this file.
1
3//
4// Copyright (c) 2021-2023, University of Colorado Denver. All rights reserved.
5//
6// This file is part of <T>LAPACK.
7// <T>LAPACK is free software: you can redistribute it and/or modify it under
8// the terms of the BSD 3-Clause license. See the accompanying LICENSE file.
9
10#ifndef TLAPACK_CUDA_UTILS_HH
11#define TLAPACK_CUDA_UTILS_HH
12
13#include <starpu.h>
14
16
17namespace tlapack {
18
19// C++ standard utils:
20using std::enable_if_t;
21using std::is_same_v;
22
23namespace starpu {
24 namespace cuda {
25
27 template <class... Ts>
28 struct is_cublas {
29 static constexpr bool value = false;
30 };
31
33 template <class... Ts>
34 constexpr bool is_cublas_v = is_cublas<Ts..., int>::value;
35
37 template <class... Ts>
38 constexpr bool is_cusolver_v =
39#ifdef STARPU_HAVE_LIBCUSOLVER
40 is_cublas_v<Ts...>;
41#else
42 false;
43#endif
44
45#ifdef STARPU_USE_CUDA
46 template <class T>
47 struct is_cublas<T,
48 enable_if_t<(is_same_v<real_type<T>, float> ||
49 is_same_v<real_type<T>, double>),
50 int>> {
51 static constexpr bool value = true;
52 };
53
54 template <>
55 struct is_cublas<StrongZero, int> {
56 static constexpr bool value = true;
57 };
58
59 template <class T1, class T2, class... Ts>
60 struct is_cublas<T1, T2, Ts...> {
61 using T = scalar_type<T1, T2, Ts...>;
62 static constexpr bool value = is_cublas<T1, int>::value &&
63 is_cublas<T2, Ts...>::value &&
64 std::is_constructible_v<T, T1>;
65 };
66
67 inline cublasOperation_t op2cublas(Op op) noexcept
68 {
69 switch (op) {
70 case Op::NoTrans:
71 return CUBLAS_OP_N;
72 case Op::Trans:
73 return CUBLAS_OP_T;
74 case Op::ConjTrans:
75 return CUBLAS_OP_C;
76 case Op::Conj:
77 return CUBLAS_OP_CONJG;
78 default:
79 return cublasOperation_t(-1);
80 }
81 }
82
83 inline cublasFillMode_t uplo2cublas(Uplo uplo) noexcept
84 {
85 switch (uplo) {
86 case Uplo::Upper:
87 return CUBLAS_FILL_MODE_UPPER;
88 case Uplo::Lower:
89 return CUBLAS_FILL_MODE_LOWER;
90 default:
91 return cublasFillMode_t(-1);
92 }
93 }
94
95 inline cublasDiagType_t diag2cublas(Diag diag) noexcept
96 {
97 switch (diag) {
98 case Diag::NonUnit:
99 return CUBLAS_DIAG_NON_UNIT;
100 case Diag::Unit:
101 return CUBLAS_DIAG_UNIT;
102 default:
103 return cublasDiagType_t(-1);
104 }
105 }
106
107 inline cublasSideMode_t side2cublas(Side side) noexcept
108 {
109 switch (side) {
110 case Side::Left:
111 return CUBLAS_SIDE_LEFT;
112 case Side::Right:
113 return CUBLAS_SIDE_RIGHT;
114 default:
115 return cublasSideMode_t(-1);
116 }
117 }
118#endif
119 } // namespace cuda
120} // namespace starpu
121} // namespace tlapack
122
123#endif // TLAPACK_CUDA_UTILS_HH
Concept for types that represent tlapack::Diag.
Concept for types that represent tlapack::Op.
Concept for types that represent tlapack::Side.
Concept for types that represent tlapack::Uplo.
typename traits::real_type_traits< Types..., int >::type real_type
The common real type of the list of types.
Definition scalar_type_traits.hpp:113
typename traits::scalar_type_traits< Types..., int >::type scalar_type
The common scalar type of the list of types.
Definition scalar_type_traits.hpp:250
constexpr bool is_cublas_v
Alias for is_cublas<>::value.
Definition utils.hpp:34
constexpr bool is_cusolver_v
True if a type is supported by cuSOLVER.
Definition utils.hpp:38
Strong zero type.
Definition StrongZero.hpp:43
Check if a type is supported by cuBLAS.
Definition utils.hpp:28