Debian Codegraph @

packages/kokkos-kernels/blas/tpls/KokkosBlas3_trsm_tpl_spec_decl.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
17 #ifndef KOKKOSBLAS3_TRSM_TPL_SPEC_DECL_HPP_
18 #define KOKKOSBLAS3_TRSM_TPL_SPEC_DECL_HPP_
19
20 #ifdef KOKKOSKERNELS_ENABLE_TPL_BLAS
21 #include "KokkosBlas_Host_tpl.hpp"
22
23 namespace KokkosBlas {
24 namespace Impl {
25
26 #define KOKKOSBLAS3_DTRSM_BLAS(LAYOUTA, LAYOUTB, MEM_SPACE, ETI_SPEC_AVAIL) \
27 template <class ExecSpace> \
28 struct TRSM< \
29 ExecSpace, \
30 Kokkos::View<const double**, LAYOUTA, Kokkos::Device<ExecSpace, MEM_SPACE>, \
31 Kokkos::MemoryTraits<Kokkos::Unmanaged> >, \
32 Kokkos::View<double**, LAYOUTB, Kokkos::Device<ExecSpace, MEM_SPACE>, Kokkos::MemoryTraits<Kokkos::Unmanaged> >, \
33 true, ETI_SPEC_AVAIL> { \
34 typedef double SCALAR; \
35 typedef Kokkos::View<const SCALAR**, LAYOUTA, Kokkos::Device<ExecSpace, MEM_SPACE>, \
36 Kokkos::MemoryTraits<Kokkos::Unmanaged> > \
37 AViewType; \
38 typedef Kokkos::View<SCALAR**, LAYOUTB, Kokkos::Device<ExecSpace, MEM_SPACE>, \
39 Kokkos::MemoryTraits<Kokkos::Unmanaged> > \
40 BViewType; \
41 \
42 static void trsm(const ExecSpace& /*space*/, const char side[], const char uplo[], const char trans[], \
43 const char diag[], typename BViewType::const_value_type& alpha, const AViewType& A, \
44 const BViewType& B) { \
45 Kokkos::Profiling::pushRegion("KokkosBlas::trsm[TPL_BLAS,double]"); \
46 const int M = static_cast<int>(B.extent(0)); \
47 const int N = static_cast<int>(B.extent(1)); \
48 \
49 bool A_is_ll = std::is_same<Kokkos::LayoutLeft, LAYOUTA>::value; \
50 bool B_is_ll = std::is_same<Kokkos::LayoutLeft, LAYOUTB>::value; \
51 \
52 const int AST = A_is_ll ? A.stride(1) : A.stride(0), LDA = (AST == 0) ? 1 : AST; \
53 const int BST = B_is_ll ? B.stride(1) : B.stride(0), LDB = (BST == 0) ? 1 : BST; \
54 \
55 char side_; \
56 char uplo_; \
57 \
58 if (A_is_ll) { \
59 if ((side[0] == 'L') || (side[0] == 'l')) \
60 side_ = 'L'; \
61 else \
62 side_ = 'R'; \
63 if ((uplo[0] == 'L') || (uplo[0] == 'l')) \
64 uplo_ = 'L'; \
65 else \
66 uplo_ = 'U'; \
67 } else { \
68 if ((side[0] == 'L') || (side[0] == 'l')) \
69 side_ = 'R'; \
70 else \
71 side_ = 'L'; \
72 if ((uplo[0] == 'L') || (uplo[0] == 'l')) \
73 uplo_ = 'U'; \
74 else \
75 uplo_ = 'L'; \
76 } \
77 \
78 if (A_is_ll) \
79 HostBlas<double>::trsm(side_, uplo_, trans[0], diag[0], M, N, alpha, A.data(), LDA, B.data(), LDB); \
80 else \
81 HostBlas<double>::trsm(side_, uplo_, trans[0], diag[0], N, M, alpha, A.data(), LDA, B.data(), LDB); \
82 Kokkos::Profiling::popRegion(); \
83 } \
84 };
85
86 #define KOKKOSBLAS3_STRSM_BLAS(LAYOUTA, LAYOUTB, MEM_SPACE, ETI_SPEC_AVAIL) \
87 template <class ExecSpace> \
88 struct TRSM< \
89 ExecSpace, \
90 Kokkos::View<const float**, LAYOUTA, Kokkos::Device<ExecSpace, MEM_SPACE>, \
91 Kokkos::MemoryTraits<Kokkos::Unmanaged> >, \
92 Kokkos::View<float**, LAYOUTB, Kokkos::Device<ExecSpace, MEM_SPACE>, Kokkos::MemoryTraits<Kokkos::Unmanaged> >, \
93 true, ETI_SPEC_AVAIL> { \
94 typedef float SCALAR; \
95 typedef Kokkos::View<const SCALAR**, LAYOUTA, Kokkos::Device<ExecSpace, MEM_SPACE>, \
96 Kokkos::MemoryTraits<Kokkos::Unmanaged> > \
97 AViewType; \
98 typedef Kokkos::View<SCALAR**, LAYOUTB, Kokkos::Device<ExecSpace, MEM_SPACE>, \
99 Kokkos::MemoryTraits<Kokkos::Unmanaged> > \
100 BViewType; \
101 \
102 static void trsm(const ExecSpace& /*space*/, const char side[], const char uplo[], const char trans[], \
103 const char diag[], typename BViewType::const_value_type& alpha, const AViewType& A, \
104 const BViewType& B) { \
105 Kokkos::Profiling::pushRegion("KokkosBlas::trsm[TPL_BLAS,float]"); \
106 const int M = static_cast<int>(B.extent(0)); \
107 const int N = static_cast<int>(B.extent(1)); \
108 \
109 bool A_is_ll = std::is_same<Kokkos::LayoutLeft, LAYOUTA>::value; \
110 bool B_is_ll = std::is_same<Kokkos::LayoutLeft, LAYOUTB>::value; \
111 \
112 const int AST = A_is_ll ? A.stride(1) : A.stride(0), LDA = (AST == 0) ? 1 : AST; \
113 const int BST = B_is_ll ? B.stride(1) : B.stride(0), LDB = (BST == 0) ? 1 : BST; \
114 \
115 char side_; \
116 char uplo_; \
117 \
118 if (A_is_ll) { \
119 if ((side[0] == 'L') || (side[0] == 'l')) \
120 side_ = 'L'; \
121 else \
122 side_ = 'R'; \
123 if ((uplo[0] == 'L') || (uplo[0] == 'l')) \
124 uplo_ = 'L'; \
125 else \
126 uplo_ = 'U'; \
127 } else { \
128 if ((side[0] == 'L') || (side[0] == 'l')) \
129 side_ = 'R'; \
130 else \
131 side_ = 'L'; \
132 if ((uplo[0] == 'L') || (uplo[0] == 'l')) \
133 uplo_ = 'U'; \
134 else \
135 uplo_ = 'L'; \
136 } \
137 \
138 if (A_is_ll) \
139 HostBlas<float>::trsm(side_, uplo_, trans[0], diag[0], M, N, alpha, A.data(), LDA, B.data(), LDB); \
140 else \
141 HostBlas<float>::trsm(side_, uplo_, trans[0], diag[0], N, M, alpha, A.data(), LDA, B.data(), LDB); \
142 Kokkos::Profiling::popRegion(); \
143 } \
144 };
145
146 #define KOKKOSBLAS3_ZTRSM_BLAS(LAYOUTA, LAYOUTB, MEM_SPACE, ETI_SPEC_AVAIL) \
147 template <class ExecSpace> \
148 struct TRSM<ExecSpace, \
149 Kokkos::View<const Kokkos::complex<double>**, LAYOUTA, Kokkos::Device<ExecSpace, MEM_SPACE>, \
150 Kokkos::MemoryTraits<Kokkos::Unmanaged> >, \
151 Kokkos::View<Kokkos::complex<double>**, LAYOUTB, Kokkos::Device<ExecSpace, MEM_SPACE>, \
152 Kokkos::MemoryTraits<Kokkos::Unmanaged> >, \
153 true, ETI_SPEC_AVAIL> { \
154 typedef Kokkos::complex<double> SCALAR; \
155 typedef Kokkos::View<const SCALAR**, LAYOUTA, Kokkos::Device<ExecSpace, MEM_SPACE>, \
156 Kokkos::MemoryTraits<Kokkos::Unmanaged> > \
157 AViewType; \
158 typedef Kokkos::View<SCALAR**, LAYOUTB, Kokkos::Device<ExecSpace, MEM_SPACE>, \
159 Kokkos::MemoryTraits<Kokkos::Unmanaged> > \
160 BViewType; \
161 \
162 static void trsm(const ExecSpace& /*space*/, const char side[], const char uplo[], const char trans[], \
163 const char diag[], typename BViewType::const_value_type& alpha, const AViewType& A, \
164 const BViewType& B) { \
165 Kokkos::Profiling::pushRegion("KokkosBlas::trsm[TPL_BLAS,complex<double>]"); \
166 const int M = static_cast<int>(B.extent(0)); \
167 const int N = static_cast<int>(B.extent(1)); \
168 \
169 bool A_is_ll = std::is_same<Kokkos::LayoutLeft, LAYOUTA>::value; \
170 bool B_is_ll = std::is_same<Kokkos::LayoutLeft, LAYOUTB>::value; \
171 \
172 const int AST = A_is_ll ? A.stride(1) : A.stride(0), LDA = (AST == 0) ? 1 : AST; \
173 const int BST = B_is_ll ? B.stride(1) : B.stride(0), LDB = (BST == 0) ? 1 : BST; \
174 \
175 char side_; \
176 char uplo_; \
177 \
178 if (A_is_ll) { \
179 if ((side[0] == 'L') || (side[0] == 'l')) \
180 side_ = 'L'; \
181 else \
182 side_ = 'R'; \
183 if ((uplo[0] == 'L') || (uplo[0] == 'l')) \
184 uplo_ = 'L'; \
185 else \
186 uplo_ = 'U'; \
187 } else { \
188 if ((side[0] == 'L') || (side[0] == 'l')) \
189 side_ = 'R'; \
190 else \
191 side_ = 'L'; \
192 if ((uplo[0] == 'L') || (uplo[0] == 'l')) \
193 uplo_ = 'U'; \
194 else \
195 uplo_ = 'L'; \
196 } \
197 \
198 const std::complex<double> alpha_val = alpha; \
199 if (A_is_ll) \
200 HostBlas<std::complex<double> >::trsm(side_, uplo_, trans[0], diag[0], M, N, alpha_val, \
201 reinterpret_cast<const std::complex<double>*>(A.data()), LDA, \
202 reinterpret_cast<std::complex<double>*>(B.data()), LDB); \
203 else \
204 HostBlas<std::complex<double> >::trsm(side_, uplo_, trans[0], diag[0], N, M, alpha_val, \
205 reinterpret_cast<const std::complex<double>*>(A.data()), LDA, \
206 reinterpret_cast<std::complex<double>*>(B.data()), LDB); \
207 Kokkos::Profiling::popRegion(); \
208 } \
209 };
210
211 #define KOKKOSBLAS3_CTRSM_BLAS(LAYOUTA, LAYOUTB, MEM_SPACE, ETI_SPEC_AVAIL) \
212 template <class ExecSpace> \
213 struct TRSM<ExecSpace, \
214 Kokkos::View<const Kokkos::complex<float>**, LAYOUTA, Kokkos::Device<ExecSpace, MEM_SPACE>, \
215 Kokkos::MemoryTraits<Kokkos::Unmanaged> >, \
216 Kokkos::View<Kokkos::complex<float>**, LAYOUTB, Kokkos::Device<ExecSpace, MEM_SPACE>, \
217 Kokkos::MemoryTraits<Kokkos::Unmanaged> >, \
218 true, ETI_SPEC_AVAIL> { \
219 typedef Kokkos::complex<float> SCALAR; \
220 typedef Kokkos::View<const SCALAR**, LAYOUTA, Kokkos::Device<ExecSpace, MEM_SPACE>, \
221 Kokkos::MemoryTraits<Kokkos::Unmanaged> > \
222 AViewType; \
223 typedef Kokkos::View<SCALAR**, LAYOUTB, Kokkos::Device<ExecSpace, MEM_SPACE>, \
224 Kokkos::MemoryTraits<Kokkos::Unmanaged> > \
225 BViewType; \
226 \
227 static void trsm(const ExecSpace& /*space*/, const char side[], const char uplo[], const char trans[], \
228 const char diag[], typename BViewType::const_value_type& alpha, const AViewType& A, \
229 const BViewType& B) { \
230 Kokkos::Profiling::pushRegion("KokkosBlas::trsm[TPL_BLAS,complex<float>]"); \
231 const int M = static_cast<int>(B.extent(0)); \
232 const int N = static_cast<int>(B.extent(1)); \
233 \
234 bool A_is_ll = std::is_same<Kokkos::LayoutLeft, LAYOUTA>::value; \
235 bool B_is_ll = std::is_same<Kokkos::LayoutLeft, LAYOUTB>::value; \
236 \
237 const int AST = A_is_ll ? A.stride(1) : A.stride(0), LDA = (AST == 0) ? 1 : AST; \
238 const int BST = B_is_ll ? B.stride(1) : B.stride(0), LDB = (BST == 0) ? 1 : BST; \
239 \
240 char side_; \
241 char uplo_; \
242 \
243 if (A_is_ll) { \
244 if ((side[0] == 'L') || (side[0] == 'l')) \
245 side_ = 'L'; \
246 else \
247 side_ = 'R'; \
248 if ((uplo[0] == 'L') || (uplo[0] == 'l')) \
249 uplo_ = 'L'; \
250 else \
251 uplo_ = 'U'; \
252 } else { \
253 if ((side[0] == 'L') || (side[0] == 'l')) \
254 side_ = 'R'; \
255 else \
256 side_ = 'L'; \
257 if ((uplo[0] == 'L') || (uplo[0] == 'l')) \
258 uplo_ = 'U'; \
259 else \
260 uplo_ = 'L'; \
261 } \
262 \
263 const std::complex<float> alpha_val = alpha; \
264 if (A_is_ll) \
265 HostBlas<std::complex<float> >::trsm(side_, uplo_, trans[0], diag[0], M, N, alpha_val, \
266 reinterpret_cast<const std::complex<float>*>(A.data()), LDA, \
267 reinterpret_cast<std::complex<float>*>(B.data()), LDB); \
268 else \
269 HostBlas<std::complex<float> >::trsm(side_, uplo_, trans[0], diag[0], N, M, alpha_val, \
270 reinterpret_cast<const std::complex<float>*>(A.data()), LDA, \
271 reinterpret_cast<std::complex<float>*>(B.data()), LDB); \
272 Kokkos::Profiling::popRegion(); \
273 } \
274 };
275
276 KOKKOSBLAS3_DTRSM_BLAS(Kokkos::LayoutLeft, Kokkos::LayoutLeft, Kokkos::HostSpace, true)
277 KOKKOSBLAS3_DTRSM_BLAS(Kokkos::LayoutLeft, Kokkos::LayoutLeft, Kokkos::HostSpace, false)
278 KOKKOSBLAS3_DTRSM_BLAS(Kokkos::LayoutRight, Kokkos::LayoutRight, Kokkos::HostSpace, true)
279 KOKKOSBLAS3_DTRSM_BLAS(Kokkos::LayoutRight, Kokkos::LayoutRight, Kokkos::HostSpace, false)
280
281 KOKKOSBLAS3_STRSM_BLAS(Kokkos::LayoutLeft, Kokkos::LayoutLeft, Kokkos::HostSpace, true)
282 KOKKOSBLAS3_STRSM_BLAS(Kokkos::LayoutLeft, Kokkos::LayoutLeft, Kokkos::HostSpace, false)
283 KOKKOSBLAS3_STRSM_BLAS(Kokkos::LayoutRight, Kokkos::LayoutRight, Kokkos::HostSpace, true)
284 KOKKOSBLAS3_STRSM_BLAS(Kokkos::LayoutRight, Kokkos::LayoutRight, Kokkos::HostSpace, false)
285
286 KOKKOSBLAS3_ZTRSM_BLAS(Kokkos::LayoutLeft, Kokkos::LayoutLeft, Kokkos::HostSpace, true)
287 KOKKOSBLAS3_ZTRSM_BLAS(Kokkos::LayoutLeft, Kokkos::LayoutLeft, Kokkos::HostSpace, false)
288 KOKKOSBLAS3_ZTRSM_BLAS(Kokkos::LayoutRight, Kokkos::LayoutRight, Kokkos::HostSpace, true)
289 KOKKOSBLAS3_ZTRSM_BLAS(Kokkos::LayoutRight, Kokkos::LayoutRight, Kokkos::HostSpace, false)
290
291 KOKKOSBLAS3_CTRSM_BLAS(Kokkos::LayoutLeft, Kokkos::LayoutLeft, Kokkos::HostSpace, true)
292 KOKKOSBLAS3_CTRSM_BLAS(Kokkos::LayoutLeft, Kokkos::LayoutLeft, Kokkos::HostSpace, false)
293 KOKKOSBLAS3_CTRSM_BLAS(Kokkos::LayoutRight, Kokkos::LayoutRight, Kokkos::HostSpace, true)
294 KOKKOSBLAS3_CTRSM_BLAS(Kokkos::LayoutRight, Kokkos::LayoutRight, Kokkos::HostSpace, false)
295
296 } // namespace Impl
297 } // namespace KokkosBlas
298 #endif // KOKKOSKERNELS_ENABLE_TPL_BLAS
299
300 // cuBLAS
301 #ifdef KOKKOSKERNELS_ENABLE_TPL_CUBLAS
302 #include <KokkosBlas_tpl_spec.hpp>
303
304 namespace KokkosBlas {
305 namespace Impl {
306
307 #define KOKKOSBLAS3_DTRSM_CUBLAS(LAYOUTA, LAYOUTB, MEM_SPACE, ETI_SPEC_AVAIL) \
308 template <class ExecSpace> \
309 struct TRSM< \
310 ExecSpace, \
311 Kokkos::View<const double**, LAYOUTA, Kokkos::Device<ExecSpace, MEM_SPACE>, \
312 Kokkos::MemoryTraits<Kokkos::Unmanaged> >, \
313 Kokkos::View<double**, LAYOUTB, Kokkos::Device<ExecSpace, MEM_SPACE>, Kokkos::MemoryTraits<Kokkos::Unmanaged> >, \
314 true, ETI_SPEC_AVAIL> { \
315 typedef double SCALAR; \
316 typedef Kokkos::View<const SCALAR**, LAYOUTA, Kokkos::Device<ExecSpace, MEM_SPACE>, \
317 Kokkos::MemoryTraits<Kokkos::Unmanaged> > \
318 AViewType; \
319 typedef Kokkos::View<SCALAR**, LAYOUTB, Kokkos::Device<ExecSpace, MEM_SPACE>, \
320 Kokkos::MemoryTraits<Kokkos::Unmanaged> > \
321 BViewType; \
322 \
323 static void trsm(const ExecSpace& space, const char side[], const char uplo[], const char trans[], \
324 const char diag[], typename BViewType::const_value_type& alpha, const AViewType& A, \
325 const BViewType& B) { \
326 Kokkos::Profiling::pushRegion("KokkosBlas::trsm[TPL_CUBLAS,double]"); \
327 const int M = static_cast<int>(B.extent(0)); \
328 const int N = static_cast<int>(B.extent(1)); \
329 \
330 bool A_is_ll = std::is_same<Kokkos::LayoutLeft, LAYOUTA>::value; \
331 bool B_is_ll = std::is_same<Kokkos::LayoutLeft, LAYOUTB>::value; \
332 \
333 const int AST = A_is_ll ? A.stride(1) : A.stride(0), LDA = (AST == 0) ? 1 : AST; \
334 const int BST = B_is_ll ? B.stride(1) : B.stride(0), LDB = (BST == 0) ? 1 : BST; \
335 \
336 cublasSideMode_t side_; \
337 cublasFillMode_t uplo_; \
338 cublasOperation_t trans_; \
339 cublasDiagType_t diag_; \
340 \
341 if (A_is_ll) { \
342 if ((side[0] == 'L') || (side[0] == 'l')) \
343 side_ = CUBLAS_SIDE_LEFT; \
344 else \
345 side_ = CUBLAS_SIDE_RIGHT; \
346 if ((uplo[0] == 'L') || (uplo[0] == 'l')) \
347 uplo_ = CUBLAS_FILL_MODE_LOWER; \
348 else \
349 uplo_ = CUBLAS_FILL_MODE_UPPER; \
350 } else { \
351 if ((side[0] == 'L') || (side[0] == 'l')) \
352 side_ = CUBLAS_SIDE_RIGHT; \
353 else \
354 side_ = CUBLAS_SIDE_LEFT; \
355 if ((uplo[0] == 'L') || (uplo[0] == 'l')) \
356 uplo_ = CUBLAS_FILL_MODE_UPPER; \
357 else \
358 uplo_ = CUBLAS_FILL_MODE_LOWER; \
359 } \
360 \
361 if ((trans[0] == 'N') || (trans[0] == 'n')) \
362 trans_ = CUBLAS_OP_N; \
363 else if ((trans[0] == 'T') || (trans[0] == 't')) \
364 trans_ = CUBLAS_OP_T; \
365 else \
366 trans_ = CUBLAS_OP_C; \
367 if ((diag[0] == 'U') || (diag[0] == 'u')) \
368 diag_ = CUBLAS_DIAG_UNIT; \
369 else \
370 diag_ = CUBLAS_DIAG_NON_UNIT; \
371 \
372 KokkosBlas::Impl::CudaBlasSingleton& s = KokkosBlas::Impl::CudaBlasSingleton::singleton(); \
373 KOKKOSBLAS_IMPL_CUBLAS_SAFE_CALL(cublasSetStream(s.handle, space.cuda_stream())); \
374 if (A_is_ll) { \
375 KOKKOSBLAS_IMPL_CUBLAS_SAFE_CALL( \
376 cublasDtrsm(s.handle, side_, uplo_, trans_, diag_, M, N, &alpha, A.data(), LDA, B.data(), LDB)); \
377 } else { \
378 KOKKOSBLAS_IMPL_CUBLAS_SAFE_CALL( \
379 cublasDtrsm(s.handle, side_, uplo_, trans_, diag_, N, M, &alpha, A.data(), LDA, B.data(), LDB)); \
380 } \
381 KOKKOSBLAS_IMPL_CUBLAS_SAFE_CALL(cublasSetStream(s.handle, NULL)); \
382 Kokkos::Profiling::popRegion(); \
383 } \
384 };
385
386 #define KOKKOSBLAS3_STRSM_CUBLAS(LAYOUTA, LAYOUTB, MEM_SPACE, ETI_SPEC_AVAIL) \
387 template <class ExecSpace> \
388 struct TRSM< \
389 ExecSpace, \
390 Kokkos::View<const float**, LAYOUTA, Kokkos::Device<ExecSpace, MEM_SPACE>, \
391 Kokkos::MemoryTraits<Kokkos::Unmanaged> >, \
392 Kokkos::View<float**, LAYOUTB, Kokkos::Device<ExecSpace, MEM_SPACE>, Kokkos::MemoryTraits<Kokkos::Unmanaged> >, \
393 true, ETI_SPEC_AVAIL> { \
394 typedef float SCALAR; \
395 typedef Kokkos::View<const SCALAR**, LAYOUTA, Kokkos::Device<ExecSpace, MEM_SPACE>, \
396 Kokkos::MemoryTraits<Kokkos::Unmanaged> > \
397 AViewType; \
398 typedef Kokkos::View<SCALAR**, LAYOUTB, Kokkos::Device<ExecSpace, MEM_SPACE>, \
399 Kokkos::MemoryTraits<Kokkos::Unmanaged> > \
400 BViewType; \
401 \
402 static void trsm(const ExecSpace& space, const char side[], const char uplo[], const char trans[], \
403 const char diag[], typename BViewType::const_value_type& alpha, const AViewType& A, \
404 const BViewType& B) { \
405 Kokkos::Profiling::pushRegion("KokkosBlas::trsm[TPL_CUBLAS,float]"); \
406 const int M = static_cast<int>(B.extent(0)); \
407 const int N = static_cast<int>(B.extent(1)); \
408 \
409 bool A_is_ll = std::is_same<Kokkos::LayoutLeft, LAYOUTA>::value; \
410 bool B_is_ll = std::is_same<Kokkos::LayoutLeft, LAYOUTB>::value; \
411 \
412 const int AST = A_is_ll ? A.stride(1) : A.stride(0), LDA = (AST == 0) ? 1 : AST; \
413 const int BST = B_is_ll ? B.stride(1) : B.stride(0), LDB = (BST == 0) ? 1 : BST; \
414 \
415 cublasSideMode_t side_; \
416 cublasFillMode_t uplo_; \
417 cublasOperation_t trans_; \
418 cublasDiagType_t diag_; \
419 \
420 if (A_is_ll) { \
421 if ((side[0] == 'L') || (side[0] == 'l')) \
422 side_ = CUBLAS_SIDE_LEFT; \
423 else \
424 side_ = CUBLAS_SIDE_RIGHT; \
425 if ((uplo[0] == 'L') || (uplo[0] == 'l')) \
426 uplo_ = CUBLAS_FILL_MODE_LOWER; \
427 else \
428 uplo_ = CUBLAS_FILL_MODE_UPPER; \
429 } else { \
430 if ((side[0] == 'L') || (side[0] == 'l')) \
431 side_ = CUBLAS_SIDE_RIGHT; \
432 else \
433 side_ = CUBLAS_SIDE_LEFT; \
434 if ((uplo[0] == 'L') || (uplo[0] == 'l')) \
435 uplo_ = CUBLAS_FILL_MODE_UPPER; \
436 else \
437 uplo_ = CUBLAS_FILL_MODE_LOWER; \
438 } \
439 \
440 if ((trans[0] == 'N') || (trans[0] == 'n')) \
441 trans_ = CUBLAS_OP_N; \
442 else if ((trans[0] == 'T') || (trans[0] == 't')) \
443 trans_ = CUBLAS_OP_T; \
444 else \
445 trans_ = CUBLAS_OP_C; \
446 if ((diag[0] == 'U') || (diag[0] == 'u')) \
447 diag_ = CUBLAS_DIAG_UNIT; \
448 else \
449 diag_ = CUBLAS_DIAG_NON_UNIT; \
450 \
451 KokkosBlas::Impl::CudaBlasSingleton& s = KokkosBlas::Impl::CudaBlasSingleton::singleton(); \
452 KOKKOSBLAS_IMPL_CUBLAS_SAFE_CALL(cublasSetStream(s.handle, space.cuda_stream())); \
453 if (A_is_ll) { \
454 KOKKOSBLAS_IMPL_CUBLAS_SAFE_CALL( \
455 cublasStrsm(s.handle, side_, uplo_, trans_, diag_, M, N, &alpha, A.data(), LDA, B.data(), LDB)); \
456 } else { \
457 KOKKOSBLAS_IMPL_CUBLAS_SAFE_CALL( \
458 cublasStrsm(s.handle, side_, uplo_, trans_, diag_, N, M, &alpha, A.data(), LDA, B.data(), LDB)); \
459 } \
460 KOKKOSBLAS_IMPL_CUBLAS_SAFE_CALL(cublasSetStream(s.handle, NULL)); \
461 \
462 Kokkos::Profiling::popRegion(); \
463 } \
464 };
465
466 #define KOKKOSBLAS3_ZTRSM_CUBLAS(LAYOUTA, LAYOUTB, MEM_SPACE, ETI_SPEC_AVAIL) \
467 template <class ExecSpace> \
468 struct TRSM<ExecSpace, \
469 Kokkos::View<const Kokkos::complex<double>**, LAYOUTA, Kokkos::Device<ExecSpace, MEM_SPACE>, \
470 Kokkos::MemoryTraits<Kokkos::Unmanaged> >, \
471 Kokkos::View<Kokkos::complex<double>**, LAYOUTB, Kokkos::Device<ExecSpace, MEM_SPACE>, \
472 Kokkos::MemoryTraits<Kokkos::Unmanaged> >, \
473 true, ETI_SPEC_AVAIL> { \
474 typedef Kokkos::complex<double> SCALAR; \
475 typedef Kokkos::View<const SCALAR**, LAYOUTA, Kokkos::Device<ExecSpace, MEM_SPACE>, \
476 Kokkos::MemoryTraits<Kokkos::Unmanaged> > \
477 AViewType; \
478 typedef Kokkos::View<SCALAR**, LAYOUTB, Kokkos::Device<ExecSpace, MEM_SPACE>, \
479 Kokkos::MemoryTraits<Kokkos::Unmanaged> > \
480 BViewType; \
481 \
482 static void trsm(const ExecSpace& space, const char side[], const char uplo[], const char trans[], \
483 const char diag[], typename BViewType::const_value_type& alpha, const AViewType& A, \
484 const BViewType& B) { \
485 Kokkos::Profiling::pushRegion("KokkosBlas::trsm[TPL_CUBLAS,complex<double>]"); \
486 const int M = static_cast<int>(B.extent(0)); \
487 const int N = static_cast<int>(B.extent(1)); \
488 \
489 bool A_is_ll = std::is_same<Kokkos::LayoutLeft, LAYOUTA>::value; \
490 bool B_is_ll = std::is_same<Kokkos::LayoutLeft, LAYOUTB>::value; \
491 \
492 const int AST = A_is_ll ? A.stride(1) : A.stride(0), LDA = (AST == 0) ? 1 : AST; \
493 const int BST = B_is_ll ? B.stride(1) : B.stride(0), LDB = (BST == 0) ? 1 : BST; \
494 \
495 cublasSideMode_t side_; \
496 cublasFillMode_t uplo_; \
497 cublasOperation_t trans_; \
498 cublasDiagType_t diag_; \
499 \
500 if (A_is_ll) { \
501 if ((side[0] == 'L') || (side[0] == 'l')) \
502 side_ = CUBLAS_SIDE_LEFT; \
503 else \
504 side_ = CUBLAS_SIDE_RIGHT; \
505 if ((uplo[0] == 'L') || (uplo[0] == 'l')) \
506 uplo_ = CUBLAS_FILL_MODE_LOWER; \
507 else \
508 uplo_ = CUBLAS_FILL_MODE_UPPER; \
509 } else { \
510 if ((side[0] == 'L') || (side[0] == 'l')) \
511 side_ = CUBLAS_SIDE_RIGHT; \
512 else \
513 side_ = CUBLAS_SIDE_LEFT; \
514 if ((uplo[0] == 'L') || (uplo[0] == 'l')) \
515 uplo_ = CUBLAS_FILL_MODE_UPPER; \
516 else \
517 uplo_ = CUBLAS_FILL_MODE_LOWER; \
518 } \
519 \
520 if ((trans[0] == 'N') || (trans[0] == 'n')) \
521 trans_ = CUBLAS_OP_N; \
522 else if ((trans[0] == 'T') || (trans[0] == 't')) \
523 trans_ = CUBLAS_OP_T; \
524 else \
525 trans_ = CUBLAS_OP_C; \
526 if ((diag[0] == 'U') || (diag[0] == 'u')) \
527 diag_ = CUBLAS_DIAG_UNIT; \
528 else \
529 diag_ = CUBLAS_DIAG_NON_UNIT; \
530 \
531 KokkosBlas::Impl::CudaBlasSingleton& s = KokkosBlas::Impl::CudaBlasSingleton::singleton(); \
532 KOKKOSBLAS_IMPL_CUBLAS_SAFE_CALL(cublasSetStream(s.handle, space.cuda_stream())); \
533 if (A_is_ll) { \
534 KOKKOSBLAS_IMPL_CUBLAS_SAFE_CALL(cublasZtrsm(s.handle, side_, uplo_, trans_, diag_, M, N, \
535 reinterpret_cast<const cuDoubleComplex*>(&alpha), \
536 reinterpret_cast<const cuDoubleComplex*>(A.data()), LDA, \
537 reinterpret_cast<cuDoubleComplex*>(B.data()), LDB)); \
538 } else { \
539 KOKKOSBLAS_IMPL_CUBLAS_SAFE_CALL(cublasZtrsm(s.handle, side_, uplo_, trans_, diag_, N, M, \
540 reinterpret_cast<const cuDoubleComplex*>(&alpha), \
541 reinterpret_cast<const cuDoubleComplex*>(A.data()), LDA, \
542 reinterpret_cast<cuDoubleComplex*>(B.data()), LDB)); \
543 } \
544 KOKKOSBLAS_IMPL_CUBLAS_SAFE_CALL(cublasSetStream(s.handle, NULL)); \
545 \
546 Kokkos::Profiling::popRegion(); \
547 } \
548 };
549
550 #define KOKKOSBLAS3_CTRSM_CUBLAS(LAYOUTA, LAYOUTB, MEM_SPACE, ETI_SPEC_AVAIL) \
551 template <class ExecSpace> \
552 struct TRSM<ExecSpace, \
553 Kokkos::View<const Kokkos::complex<float>**, LAYOUTA, Kokkos::Device<ExecSpace, MEM_SPACE>, \
554 Kokkos::MemoryTraits<Kokkos::Unmanaged> >, \
555 Kokkos::View<Kokkos::complex<float>**, LAYOUTB, Kokkos::Device<ExecSpace, MEM_SPACE>, \
556 Kokkos::MemoryTraits<Kokkos::Unmanaged> >, \
557 true, ETI_SPEC_AVAIL> { \
558 typedef Kokkos::complex<float> SCALAR; \
559 typedef Kokkos::View<const SCALAR**, LAYOUTA, Kokkos::Device<ExecSpace, MEM_SPACE>, \
560 Kokkos::MemoryTraits<Kokkos::Unmanaged> > \
561 AViewType; \
562 typedef Kokkos::View<SCALAR**, LAYOUTB, Kokkos::Device<ExecSpace, MEM_SPACE>, \
563 Kokkos::MemoryTraits<Kokkos::Unmanaged> > \
564 BViewType; \
565 \
566 static void trsm(const ExecSpace& space, const char side[], const char uplo[], const char trans[], \
567 const char diag[], typename BViewType::const_value_type& alpha, const AViewType& A, \
568 const BViewType& B) { \
569 Kokkos::Profiling::pushRegion("KokkosBlas::trsm[TPL_CUBLAS,complex<float>]"); \
570 const int M = static_cast<int>(B.extent(0)); \
571 const int N = static_cast<int>(B.extent(1)); \
572 \
573 bool A_is_ll = std::is_same<Kokkos::LayoutLeft, LAYOUTA>::value; \
574 bool B_is_ll = std::is_same<Kokkos::LayoutLeft, LAYOUTB>::value; \
575 \
576 const int AST = A_is_ll ? A.stride(1) : A.stride(0), LDA = (AST == 0) ? 1 : AST; \
577 const int BST = B_is_ll ? B.stride(1) : B.stride(0), LDB = (BST == 0) ? 1 : BST; \
578 \
579 cublasSideMode_t side_; \
580 cublasFillMode_t uplo_; \
581 cublasOperation_t trans_; \
582 cublasDiagType_t diag_; \
583 \
584 if (A_is_ll) { \
585 if ((side[0] == 'L') || (side[0] == 'l')) \
586 side_ = CUBLAS_SIDE_LEFT; \
587 else \
588 side_ = CUBLAS_SIDE_RIGHT; \
589 if ((uplo[0] == 'L') || (uplo[0] == 'l')) \
590 uplo_ = CUBLAS_FILL_MODE_LOWER; \
591 else \
592 uplo_ = CUBLAS_FILL_MODE_UPPER; \
593 } else { \
594 if ((side[0] == 'L') || (side[0] == 'l')) \
595 side_ = CUBLAS_SIDE_RIGHT; \
596 else \
597 side_ = CUBLAS_SIDE_LEFT; \
598 if ((uplo[0] == 'L') || (uplo[0] == 'l')) \
599 uplo_ = CUBLAS_FILL_MODE_UPPER; \
600 else \
601 uplo_ = CUBLAS_FILL_MODE_LOWER; \
602 } \
603 \
604 if ((trans[0] == 'N') || (trans[0] == 'n')) \
605 trans_ = CUBLAS_OP_N; \
606 else if ((trans[0] == 'T') || (trans[0] == 't')) \
607 trans_ = CUBLAS_OP_T; \
608 else \
609 trans_ = CUBLAS_OP_C; \
610 if ((diag[0] == 'U') || (diag[0] == 'u')) \
611 diag_ = CUBLAS_DIAG_UNIT; \
612 else \
613 diag_ = CUBLAS_DIAG_NON_UNIT; \
614 \
615 KokkosBlas::Impl::CudaBlasSingleton& s = KokkosBlas::Impl::CudaBlasSingleton::singleton(); \
616 KOKKOSBLAS_IMPL_CUBLAS_SAFE_CALL(cublasSetStream(s.handle, space.cuda_stream())); \
617 if (A_is_ll) { \
618 KOKKOSBLAS_IMPL_CUBLAS_SAFE_CALL(cublasCtrsm( \
619 s.handle, side_, uplo_, trans_, diag_, M, N, reinterpret_cast<const cuComplex*>(&alpha), \
620 reinterpret_cast<const cuComplex*>(A.data()), LDA, reinterpret_cast<cuComplex*>(B.data()), LDB)); \
621 } else { \
622 KOKKOSBLAS_IMPL_CUBLAS_SAFE_CALL(cublasCtrsm( \
623 s.handle, side_, uplo_, trans_, diag_, N, M, reinterpret_cast<const cuComplex*>(&alpha), \
624 reinterpret_cast<const cuComplex*>(A.data()), LDA, reinterpret_cast<cuComplex*>(B.data()), LDB)); \
625 } \
626 KOKKOSBLAS_IMPL_CUBLAS_SAFE_CALL(cublasSetStream(s.handle, NULL)); \
627 \
628 Kokkos::Profiling::popRegion(); \
629 } \
630 };
631
632 KOKKOSBLAS3_DTRSM_CUBLAS(Kokkos::LayoutLeft, Kokkos::LayoutLeft, Kokkos::CudaSpace, true)
633 KOKKOSBLAS3_DTRSM_CUBLAS(Kokkos::LayoutLeft, Kokkos::LayoutLeft, Kokkos::CudaSpace, false)
634 KOKKOSBLAS3_DTRSM_CUBLAS(Kokkos::LayoutRight, Kokkos::LayoutRight, Kokkos::CudaSpace, true)
635 KOKKOSBLAS3_DTRSM_CUBLAS(Kokkos::LayoutRight, Kokkos::LayoutRight, Kokkos::CudaSpace, false)
636
637 KOKKOSBLAS3_DTRSM_CUBLAS(Kokkos::LayoutLeft, Kokkos::LayoutLeft, Kokkos::CudaUVMSpace, true)
638 KOKKOSBLAS3_DTRSM_CUBLAS(Kokkos::LayoutLeft, Kokkos::LayoutLeft, Kokkos::CudaUVMSpace, false)
639 KOKKOSBLAS3_DTRSM_CUBLAS(Kokkos::LayoutRight, Kokkos::LayoutRight, Kokkos::CudaUVMSpace, true)
640 KOKKOSBLAS3_DTRSM_CUBLAS(Kokkos::LayoutRight, Kokkos::LayoutRight, Kokkos::CudaUVMSpace, false)
641
642 KOKKOSBLAS3_STRSM_CUBLAS(Kokkos::LayoutLeft, Kokkos::LayoutLeft, Kokkos::CudaSpace, true)
643 KOKKOSBLAS3_STRSM_CUBLAS(Kokkos::LayoutLeft, Kokkos::LayoutLeft, Kokkos::CudaSpace, false)
644 KOKKOSBLAS3_STRSM_CUBLAS(Kokkos::LayoutRight, Kokkos::LayoutRight, Kokkos::CudaSpace, true)
645 KOKKOSBLAS3_STRSM_CUBLAS(Kokkos::LayoutRight, Kokkos::LayoutRight, Kokkos::CudaSpace, false)
646
647 KOKKOSBLAS3_STRSM_CUBLAS(Kokkos::LayoutLeft, Kokkos::LayoutLeft, Kokkos::CudaUVMSpace, true)
648 KOKKOSBLAS3_STRSM_CUBLAS(Kokkos::LayoutLeft, Kokkos::LayoutLeft, Kokkos::CudaUVMSpace, false)
649 KOKKOSBLAS3_STRSM_CUBLAS(Kokkos::LayoutRight, Kokkos::LayoutRight, Kokkos::CudaUVMSpace, true)
650 KOKKOSBLAS3_STRSM_CUBLAS(Kokkos::LayoutRight, Kokkos::LayoutRight, Kokkos::CudaUVMSpace, false)
651
652 KOKKOSBLAS3_ZTRSM_CUBLAS(Kokkos::LayoutLeft, Kokkos::LayoutLeft, Kokkos::CudaSpace, true)
653 KOKKOSBLAS3_ZTRSM_CUBLAS(Kokkos::LayoutLeft, Kokkos::LayoutLeft, Kokkos::CudaSpace, false)
654 KOKKOSBLAS3_ZTRSM_CUBLAS(Kokkos::LayoutRight, Kokkos::LayoutRight, Kokkos::CudaSpace, true)
655 KOKKOSBLAS3_ZTRSM_CUBLAS(Kokkos::LayoutRight, Kokkos::LayoutRight, Kokkos::CudaSpace, false)
656
657 KOKKOSBLAS3_ZTRSM_CUBLAS(Kokkos::LayoutLeft, Kokkos::LayoutLeft, Kokkos::CudaUVMSpace, true)
658 KOKKOSBLAS3_ZTRSM_CUBLAS(Kokkos::LayoutLeft, Kokkos::LayoutLeft, Kokkos::CudaUVMSpace, false)
659 KOKKOSBLAS3_ZTRSM_CUBLAS(Kokkos::LayoutRight, Kokkos::LayoutRight, Kokkos::CudaUVMSpace, true)
660 KOKKOSBLAS3_ZTRSM_CUBLAS(Kokkos::LayoutRight, Kokkos::LayoutRight, Kokkos::CudaUVMSpace, false)
661
662 KOKKOSBLAS3_CTRSM_CUBLAS(Kokkos::LayoutLeft, Kokkos::LayoutLeft, Kokkos::CudaSpace, true)
663 KOKKOSBLAS3_CTRSM_CUBLAS(Kokkos::LayoutLeft, Kokkos::LayoutLeft, Kokkos::CudaSpace, false)
664 KOKKOSBLAS3_CTRSM_CUBLAS(Kokkos::LayoutRight, Kokkos::LayoutRight, Kokkos::CudaSpace, true)
665 KOKKOSBLAS3_CTRSM_CUBLAS(Kokkos::LayoutRight, Kokkos::LayoutRight, Kokkos::CudaSpace, false)
666
667 KOKKOSBLAS3_CTRSM_CUBLAS(Kokkos::LayoutLeft, Kokkos::LayoutLeft, Kokkos::CudaUVMSpace, true)
668 KOKKOSBLAS3_CTRSM_CUBLAS(Kokkos::LayoutLeft, Kokkos::LayoutLeft, Kokkos::CudaUVMSpace, false)
669 KOKKOSBLAS3_CTRSM_CUBLAS(Kokkos::LayoutRight, Kokkos::LayoutRight, Kokkos::CudaUVMSpace, true)
670 KOKKOSBLAS3_CTRSM_CUBLAS(Kokkos::LayoutRight, Kokkos::LayoutRight, Kokkos::CudaUVMSpace, false)
671
672 } // namespace Impl
673 } // namespace KokkosBlas
674 #endif // KOKKOSKERNELS_ENABLE_TPL_CUBLAS
675
676 #endif