//@HEADER // ************************************************************************ // // Kokkos v. 4.0 // Copyright (2022) National Technology & Engineering // Solutions of Sandia, LLC (NTESS). // // Under the terms of Contract DE-NA0003525 with NTESS, // the U.S. Government retains certain rights in this software. // // Part of Kokkos, under the Apache License v2.0 with LLVM Exceptions. // See https://kokkos.org/LICENSE for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //@HEADER #ifndef KOKKOSBLAS2_GEMV_TPL_SPEC_DECL_HPP_ #define KOKKOSBLAS2_GEMV_TPL_SPEC_DECL_HPP_ #ifdef KOKKOSKERNELS_ENABLE_TPL_BLAS #include "KokkosBlas_Host_tpl.hpp" namespace KokkosBlas { namespace Impl { #define KOKKOSBLAS2_GEMV_DETERMINE_ARGS(LAYOUTA) \ bool A_is_lr = std::is_same::value; \ const int M = static_cast(A_is_lr ? A.extent(1) : A.extent(0)); \ const int N = static_cast(A_is_lr ? A.extent(0) : A.extent(1)); \ constexpr int one = 1; \ const int LDA = A_is_lr ? A.stride(0) : A.stride(1); \ \ char transa; \ if ((trans[0] == 'N') || (trans[0] == 'n')) \ transa = A_is_lr ? 'T' : 'N'; \ else if ((trans[0] == 'T') || (trans[0] == 't')) \ transa = A_is_lr ? 'N' : 'T'; \ else { \ if (A_is_lr) \ throw std::runtime_error( \ "Error: HostBlas::gemv conjugate transpose requires LayoutLeft " \ "views."); \ transa = 'C'; \ } #define KOKKOSBLAS2_DGEMV_BLAS(LAYOUTA, LAYOUTX, LAYOUTY, MEM_SPACE, ETI_SPEC_AVAIL) \ template \ struct GEMV< \ ExecSpace, \ Kokkos::View, \ Kokkos::MemoryTraits >, \ Kokkos::View, \ Kokkos::MemoryTraits >, \ Kokkos::View, Kokkos::MemoryTraits >, \ true, ETI_SPEC_AVAIL> { \ typedef double SCALAR; \ typedef Kokkos::View, \ Kokkos::MemoryTraits > \ AViewType; \ typedef Kokkos::View, \ Kokkos::MemoryTraits > \ XViewType; \ typedef Kokkos::View, \ Kokkos::MemoryTraits > \ YViewType; \ \ static void gemv(const ExecSpace& /* space */, const char trans[], typename AViewType::const_value_type& alpha, \ const AViewType& A, const XViewType& X, typename YViewType::const_value_type& beta, \ const YViewType& Y) { \ Kokkos::Profiling::pushRegion("KokkosBlas::gemv[TPL_BLAS,double]"); \ KOKKOSBLAS2_GEMV_DETERMINE_ARGS(LAYOUTA); \ HostBlas::gemv(transa, M, N, alpha, A.data(), LDA, X.data(), one, beta, Y.data(), one); \ Kokkos::Profiling::popRegion(); \ } \ }; #define KOKKOSBLAS2_SGEMV_BLAS(LAYOUTA, LAYOUTX, LAYOUTY, MEM_SPACE, ETI_SPEC_AVAIL) \ template \ struct GEMV< \ ExecSpace, \ Kokkos::View, \ Kokkos::MemoryTraits >, \ Kokkos::View, \ Kokkos::MemoryTraits >, \ Kokkos::View, Kokkos::MemoryTraits >, \ true, ETI_SPEC_AVAIL> { \ typedef float SCALAR; \ typedef Kokkos::View, \ Kokkos::MemoryTraits > \ AViewType; \ typedef Kokkos::View, \ Kokkos::MemoryTraits > \ XViewType; \ typedef Kokkos::View, \ Kokkos::MemoryTraits > \ YViewType; \ \ static void gemv(const ExecSpace& /* space */, const char trans[], typename AViewType::const_value_type& alpha, \ const AViewType& A, const XViewType& X, typename YViewType::const_value_type& beta, \ const YViewType& Y) { \ Kokkos::Profiling::pushRegion("KokkosBlas::gemv[TPL_BLAS,float]"); \ KOKKOSBLAS2_GEMV_DETERMINE_ARGS(LAYOUTA); \ HostBlas::gemv(transa, M, N, alpha, A.data(), LDA, X.data(), one, beta, Y.data(), one); \ Kokkos::Profiling::popRegion(); \ } \ }; #define KOKKOSBLAS2_ZGEMV_BLAS(LAYOUTA, LAYOUTX, LAYOUTY, MEM_SPACE, ETI_SPEC_AVAIL) \ template \ struct GEMV**, LAYOUTA, Kokkos::Device, \ Kokkos::MemoryTraits >, \ Kokkos::View*, LAYOUTX, Kokkos::Device, \ Kokkos::MemoryTraits >, \ Kokkos::View*, LAYOUTY, Kokkos::Device, \ Kokkos::MemoryTraits >, \ true, ETI_SPEC_AVAIL> { \ typedef Kokkos::complex SCALAR; \ typedef Kokkos::View, \ Kokkos::MemoryTraits > \ AViewType; \ typedef Kokkos::View, \ Kokkos::MemoryTraits > \ XViewType; \ typedef Kokkos::View, \ Kokkos::MemoryTraits > \ YViewType; \ \ static void gemv(const ExecSpace& /* space */, const char trans[], typename AViewType::const_value_type& alpha, \ const AViewType& A, const XViewType& X, typename YViewType::const_value_type& beta, \ const YViewType& Y) { \ Kokkos::Profiling::pushRegion("KokkosBlas::gemv[TPL_BLAS,complex]"); \ KOKKOSBLAS2_GEMV_DETERMINE_ARGS(LAYOUTA); \ const std::complex alpha_val = alpha, beta_val = beta; \ HostBlas >::gemv(transa, M, N, alpha_val, \ reinterpret_cast*>(A.data()), LDA, \ reinterpret_cast*>(X.data()), one, beta_val, \ reinterpret_cast*>(Y.data()), one); \ Kokkos::Profiling::popRegion(); \ } \ }; #define KOKKOSBLAS2_CGEMV_BLAS(LAYOUTA, LAYOUTX, LAYOUTY, MEM_SPACE, ETI_SPEC_AVAIL) \ template \ struct GEMV**, LAYOUTA, Kokkos::Device, \ Kokkos::MemoryTraits >, \ Kokkos::View*, LAYOUTX, Kokkos::Device, \ Kokkos::MemoryTraits >, \ Kokkos::View*, LAYOUTY, Kokkos::Device, \ Kokkos::MemoryTraits >, \ true, ETI_SPEC_AVAIL> { \ typedef Kokkos::complex SCALAR; \ typedef Kokkos::View, \ Kokkos::MemoryTraits > \ AViewType; \ typedef Kokkos::View, \ Kokkos::MemoryTraits > \ XViewType; \ typedef Kokkos::View, \ Kokkos::MemoryTraits > \ YViewType; \ \ static void gemv(const ExecSpace& /* space */, const char trans[], typename AViewType::const_value_type& alpha, \ const AViewType& A, const XViewType& X, typename YViewType::const_value_type& beta, \ const YViewType& Y) { \ Kokkos::Profiling::pushRegion("KokkosBlas::gemv[TPL_BLAS,complex]"); \ KOKKOSBLAS2_GEMV_DETERMINE_ARGS(LAYOUTA); \ const std::complex alpha_val = alpha, beta_val = beta; \ HostBlas >::gemv(transa, M, N, alpha_val, \ reinterpret_cast*>(A.data()), LDA, \ reinterpret_cast*>(X.data()), one, beta_val, \ reinterpret_cast*>(Y.data()), one); \ Kokkos::Profiling::popRegion(); \ } \ }; KOKKOSBLAS2_DGEMV_BLAS(Kokkos::LayoutLeft, Kokkos::LayoutLeft, Kokkos::LayoutLeft, Kokkos::HostSpace, true) KOKKOSBLAS2_DGEMV_BLAS(Kokkos::LayoutLeft, Kokkos::LayoutLeft, Kokkos::LayoutLeft, Kokkos::HostSpace, false) KOKKOSBLAS2_DGEMV_BLAS(Kokkos::LayoutRight, Kokkos::LayoutRight, Kokkos::LayoutRight, Kokkos::HostSpace, true) KOKKOSBLAS2_DGEMV_BLAS(Kokkos::LayoutRight, Kokkos::LayoutRight, Kokkos::LayoutRight, Kokkos::HostSpace, false) KOKKOSBLAS2_SGEMV_BLAS(Kokkos::LayoutLeft, Kokkos::LayoutLeft, Kokkos::LayoutLeft, Kokkos::HostSpace, true) KOKKOSBLAS2_SGEMV_BLAS(Kokkos::LayoutLeft, Kokkos::LayoutLeft, Kokkos::LayoutLeft, Kokkos::HostSpace, false) KOKKOSBLAS2_SGEMV_BLAS(Kokkos::LayoutRight, Kokkos::LayoutRight, Kokkos::LayoutRight, Kokkos::HostSpace, true) KOKKOSBLAS2_SGEMV_BLAS(Kokkos::LayoutRight, Kokkos::LayoutRight, Kokkos::LayoutRight, Kokkos::HostSpace, false) KOKKOSBLAS2_ZGEMV_BLAS(Kokkos::LayoutLeft, Kokkos::LayoutLeft, Kokkos::LayoutLeft, Kokkos::HostSpace, true) KOKKOSBLAS2_ZGEMV_BLAS(Kokkos::LayoutLeft, Kokkos::LayoutLeft, Kokkos::LayoutLeft, Kokkos::HostSpace, false) KOKKOSBLAS2_ZGEMV_BLAS(Kokkos::LayoutRight, Kokkos::LayoutRight, Kokkos::LayoutRight, Kokkos::HostSpace, true) KOKKOSBLAS2_ZGEMV_BLAS(Kokkos::LayoutRight, Kokkos::LayoutRight, Kokkos::LayoutRight, Kokkos::HostSpace, false) KOKKOSBLAS2_CGEMV_BLAS(Kokkos::LayoutLeft, Kokkos::LayoutLeft, Kokkos::LayoutLeft, Kokkos::HostSpace, true) KOKKOSBLAS2_CGEMV_BLAS(Kokkos::LayoutLeft, Kokkos::LayoutLeft, Kokkos::LayoutLeft, Kokkos::HostSpace, false) KOKKOSBLAS2_CGEMV_BLAS(Kokkos::LayoutRight, Kokkos::LayoutRight, Kokkos::LayoutRight, Kokkos::HostSpace, true) KOKKOSBLAS2_CGEMV_BLAS(Kokkos::LayoutRight, Kokkos::LayoutRight, Kokkos::LayoutRight, Kokkos::HostSpace, false) } // namespace Impl } // namespace KokkosBlas #endif // KOKKOSKERNELS_ENABLE_TPL_BLAS // cuBLAS #ifdef KOKKOSKERNELS_ENABLE_TPL_CUBLAS #include namespace KokkosBlas { namespace Impl { #define KOKKOSBLAS2_GEMV_CUBLAS_DETERMINE_ARGS(LAYOUTA) \ bool A_is_lr = std::is_same::value; \ const int M = static_cast(A_is_lr ? A.extent(1) : A.extent(0)); \ const int N = static_cast(A_is_lr ? A.extent(0) : A.extent(1)); \ constexpr int one = 1; \ const int LDA = A_is_lr ? A.stride(0) : A.stride(1); \ \ cublasOperation_t transa; \ if ((trans[0] == 'N') || (trans[0] == 'n')) \ transa = A_is_lr ? CUBLAS_OP_T : CUBLAS_OP_N; \ else if ((trans[0] == 'T') || (trans[0] == 't')) \ transa = A_is_lr ? CUBLAS_OP_N : CUBLAS_OP_T; \ else { \ if (A_is_lr) \ throw std::runtime_error( \ "Error: cublas gemv conjugate transpose requires LayoutLeft " \ "views."); \ transa = CUBLAS_OP_C; \ } #define KOKKOSBLAS2_DGEMV_CUBLAS(LAYOUTA, LAYOUTX, LAYOUTY, MEM_SPACE, ETI_SPEC_AVAIL) \ template \ struct GEMV< \ ExecSpace, \ Kokkos::View, \ Kokkos::MemoryTraits >, \ Kokkos::View, \ Kokkos::MemoryTraits >, \ Kokkos::View, Kokkos::MemoryTraits >, \ true, ETI_SPEC_AVAIL> { \ typedef double SCALAR; \ typedef Kokkos::View, \ Kokkos::MemoryTraits > \ AViewType; \ typedef Kokkos::View, \ Kokkos::MemoryTraits > \ XViewType; \ typedef Kokkos::View, \ Kokkos::MemoryTraits > \ YViewType; \ \ static void gemv(const ExecSpace& space, const char trans[], typename AViewType::const_value_type& alpha, \ const AViewType& A, const XViewType& X, typename YViewType::const_value_type& beta, \ const YViewType& Y) { \ Kokkos::Profiling::pushRegion("KokkosBlas::gemv[TPL_CUBLAS,double]"); \ KOKKOSBLAS2_GEMV_CUBLAS_DETERMINE_ARGS(LAYOUTA); \ KokkosBlas::Impl::CudaBlasSingleton& s = KokkosBlas::Impl::CudaBlasSingleton::singleton(); \ KOKKOSBLAS_IMPL_CUBLAS_SAFE_CALL(cublasSetStream(s.handle, space.cuda_stream())); \ KOKKOSBLAS_IMPL_CUBLAS_SAFE_CALL( \ cublasDgemv(s.handle, transa, M, N, &alpha, A.data(), LDA, X.data(), one, &beta, Y.data(), one)); \ KOKKOSBLAS_IMPL_CUBLAS_SAFE_CALL(cublasSetStream(s.handle, NULL)); \ Kokkos::Profiling::popRegion(); \ } \ }; #define KOKKOSBLAS2_SGEMV_CUBLAS(LAYOUTA, LAYOUTX, LAYOUTY, MEM_SPACE, ETI_SPEC_AVAIL) \ template \ struct GEMV< \ ExecSpace, \ Kokkos::View, \ Kokkos::MemoryTraits >, \ Kokkos::View, \ Kokkos::MemoryTraits >, \ Kokkos::View, Kokkos::MemoryTraits >, \ true, ETI_SPEC_AVAIL> { \ typedef float SCALAR; \ typedef Kokkos::View, \ Kokkos::MemoryTraits > \ AViewType; \ typedef Kokkos::View, \ Kokkos::MemoryTraits > \ XViewType; \ typedef Kokkos::View, \ Kokkos::MemoryTraits > \ YViewType; \ \ static void gemv(const ExecSpace& space, const char trans[], typename AViewType::const_value_type& alpha, \ const AViewType& A, const XViewType& X, typename YViewType::const_value_type& beta, \ const YViewType& Y) { \ Kokkos::Profiling::pushRegion("KokkosBlas::gemv[TPL_CUBLAS,float]"); \ KOKKOSBLAS2_GEMV_CUBLAS_DETERMINE_ARGS(LAYOUTA); \ KokkosBlas::Impl::CudaBlasSingleton& s = KokkosBlas::Impl::CudaBlasSingleton::singleton(); \ KOKKOSBLAS_IMPL_CUBLAS_SAFE_CALL(cublasSetStream(s.handle, space.cuda_stream())); \ KOKKOSBLAS_IMPL_CUBLAS_SAFE_CALL( \ cublasSgemv(s.handle, transa, M, N, &alpha, A.data(), LDA, X.data(), one, &beta, Y.data(), one)); \ KOKKOSBLAS_IMPL_CUBLAS_SAFE_CALL(cublasSetStream(s.handle, NULL)); \ Kokkos::Profiling::popRegion(); \ } \ }; #define KOKKOSBLAS2_ZGEMV_CUBLAS(LAYOUTA, LAYOUTX, LAYOUTY, MEM_SPACE, ETI_SPEC_AVAIL) \ template \ struct GEMV**, LAYOUTA, Kokkos::Device, \ Kokkos::MemoryTraits >, \ Kokkos::View*, LAYOUTX, Kokkos::Device, \ Kokkos::MemoryTraits >, \ Kokkos::View*, LAYOUTY, Kokkos::Device, \ Kokkos::MemoryTraits >, \ true, ETI_SPEC_AVAIL> { \ typedef Kokkos::complex SCALAR; \ typedef Kokkos::View, \ Kokkos::MemoryTraits > \ AViewType; \ typedef Kokkos::View, \ Kokkos::MemoryTraits > \ XViewType; \ typedef Kokkos::View, \ Kokkos::MemoryTraits > \ YViewType; \ \ static void gemv(const ExecSpace& space, const char trans[], typename AViewType::const_value_type& alpha, \ const AViewType& A, const XViewType& X, typename YViewType::const_value_type& beta, \ const YViewType& Y) { \ Kokkos::Profiling::pushRegion("KokkosBlas::gemv[TPL_CUBLAS,complex]"); \ KOKKOSBLAS2_GEMV_CUBLAS_DETERMINE_ARGS(LAYOUTA); \ KokkosBlas::Impl::CudaBlasSingleton& s = KokkosBlas::Impl::CudaBlasSingleton::singleton(); \ KOKKOSBLAS_IMPL_CUBLAS_SAFE_CALL(cublasSetStream(s.handle, space.cuda_stream())); \ KOKKOSBLAS_IMPL_CUBLAS_SAFE_CALL(cublasZgemv( \ s.handle, transa, M, N, reinterpret_cast(&alpha), \ reinterpret_cast(A.data()), LDA, reinterpret_cast(X.data()), \ one, reinterpret_cast(&beta), reinterpret_cast(Y.data()), one)); \ KOKKOSBLAS_IMPL_CUBLAS_SAFE_CALL(cublasSetStream(s.handle, NULL)); \ Kokkos::Profiling::popRegion(); \ } \ }; #define KOKKOSBLAS2_CGEMV_CUBLAS(LAYOUTA, LAYOUTX, LAYOUTY, MEM_SPACE, ETI_SPEC_AVAIL) \ template \ struct GEMV**, LAYOUTA, Kokkos::Device, \ Kokkos::MemoryTraits >, \ Kokkos::View*, LAYOUTX, Kokkos::Device, \ Kokkos::MemoryTraits >, \ Kokkos::View*, LAYOUTY, Kokkos::Device, \ Kokkos::MemoryTraits >, \ true, ETI_SPEC_AVAIL> { \ typedef Kokkos::complex SCALAR; \ typedef Kokkos::View, \ Kokkos::MemoryTraits > \ AViewType; \ typedef Kokkos::View, \ Kokkos::MemoryTraits > \ XViewType; \ typedef Kokkos::View, \ Kokkos::MemoryTraits > \ YViewType; \ \ static void gemv(const ExecSpace& space, const char trans[], typename AViewType::const_value_type& alpha, \ const AViewType& A, const XViewType& X, typename YViewType::const_value_type& beta, \ const YViewType& Y) { \ Kokkos::Profiling::pushRegion("KokkosBlas::gemv[TPL_CUBLAS,complex]"); \ KOKKOSBLAS2_GEMV_CUBLAS_DETERMINE_ARGS(LAYOUTA); \ KokkosBlas::Impl::CudaBlasSingleton& s = KokkosBlas::Impl::CudaBlasSingleton::singleton(); \ KOKKOSBLAS_IMPL_CUBLAS_SAFE_CALL(cublasSetStream(s.handle, space.cuda_stream())); \ KOKKOSBLAS_IMPL_CUBLAS_SAFE_CALL( \ cublasCgemv(s.handle, transa, M, N, reinterpret_cast(&alpha), \ reinterpret_cast(A.data()), LDA, reinterpret_cast(X.data()), \ one, reinterpret_cast(&beta), reinterpret_cast(Y.data()), one)); \ KOKKOSBLAS_IMPL_CUBLAS_SAFE_CALL(cublasSetStream(s.handle, NULL)); \ Kokkos::Profiling::popRegion(); \ } \ }; KOKKOSBLAS2_DGEMV_CUBLAS(Kokkos::LayoutLeft, Kokkos::LayoutLeft, Kokkos::LayoutLeft, Kokkos::CudaSpace, true) KOKKOSBLAS2_DGEMV_CUBLAS(Kokkos::LayoutLeft, Kokkos::LayoutLeft, Kokkos::LayoutLeft, Kokkos::CudaSpace, false) KOKKOSBLAS2_DGEMV_CUBLAS(Kokkos::LayoutRight, Kokkos::LayoutRight, Kokkos::LayoutRight, Kokkos::CudaSpace, true) KOKKOSBLAS2_DGEMV_CUBLAS(Kokkos::LayoutRight, Kokkos::LayoutRight, Kokkos::LayoutRight, Kokkos::CudaSpace, false) KOKKOSBLAS2_SGEMV_CUBLAS(Kokkos::LayoutLeft, Kokkos::LayoutLeft, Kokkos::LayoutLeft, Kokkos::CudaSpace, true) KOKKOSBLAS2_SGEMV_CUBLAS(Kokkos::LayoutLeft, Kokkos::LayoutLeft, Kokkos::LayoutLeft, Kokkos::CudaSpace, false) KOKKOSBLAS2_SGEMV_CUBLAS(Kokkos::LayoutRight, Kokkos::LayoutRight, Kokkos::LayoutRight, Kokkos::CudaSpace, true) KOKKOSBLAS2_SGEMV_CUBLAS(Kokkos::LayoutRight, Kokkos::LayoutRight, Kokkos::LayoutRight, Kokkos::CudaSpace, false) KOKKOSBLAS2_ZGEMV_CUBLAS(Kokkos::LayoutLeft, Kokkos::LayoutLeft, Kokkos::LayoutLeft, Kokkos::CudaSpace, true) KOKKOSBLAS2_ZGEMV_CUBLAS(Kokkos::LayoutLeft, Kokkos::LayoutLeft, Kokkos::LayoutLeft, Kokkos::CudaSpace, false) KOKKOSBLAS2_ZGEMV_CUBLAS(Kokkos::LayoutRight, Kokkos::LayoutRight, Kokkos::LayoutRight, Kokkos::CudaSpace, true) KOKKOSBLAS2_ZGEMV_CUBLAS(Kokkos::LayoutRight, Kokkos::LayoutRight, Kokkos::LayoutRight, Kokkos::CudaSpace, false) KOKKOSBLAS2_CGEMV_CUBLAS(Kokkos::LayoutLeft, Kokkos::LayoutLeft, Kokkos::LayoutLeft, Kokkos::CudaSpace, true) KOKKOSBLAS2_CGEMV_CUBLAS(Kokkos::LayoutLeft, Kokkos::LayoutLeft, Kokkos::LayoutLeft, Kokkos::CudaSpace, false) KOKKOSBLAS2_CGEMV_CUBLAS(Kokkos::LayoutRight, Kokkos::LayoutRight, Kokkos::LayoutRight, Kokkos::CudaSpace, true) KOKKOSBLAS2_CGEMV_CUBLAS(Kokkos::LayoutRight, Kokkos::LayoutRight, Kokkos::LayoutRight, Kokkos::CudaSpace, false) } // namespace Impl } // namespace KokkosBlas #endif // KOKKOSKERNELS_ENABLE_TPL_CUBLAS // rocBLAS #ifdef KOKKOSKERNELS_ENABLE_TPL_ROCBLAS #include namespace KokkosBlas { namespace Impl { #define KOKKOSBLAS2_GEMV_ROCBLAS_DETERMINE_ARGS(LAYOUT) \ bool A_is_lr = std::is_same::value; \ const int M = static_cast(A_is_lr ? A.extent(1) : A.extent(0)); \ const int N = static_cast(A_is_lr ? A.extent(0) : A.extent(1)); \ constexpr int one = 1; \ const int LDA = A_is_lr ? A.stride(0) : A.stride(1); \ \ rocblas_operation transa; \ if ((trans[0] == 'N') || (trans[0] == 'n')) \ transa = A_is_lr ? rocblas_operation_transpose : rocblas_operation_none; \ else if ((trans[0] == 'T') || (trans[0] == 't')) \ transa = A_is_lr ? rocblas_operation_none : rocblas_operation_transpose; \ else { \ if (A_is_lr) \ throw std::runtime_error( \ "Error: rocBLAS Xgemv conjugate transpose requires LayoutLeft " \ "matrix."); \ transa = rocblas_operation_conjugate_transpose; \ } #define KOKKOSBLAS2_DGEMV_ROCBLAS(LAYOUT, MEM_SPACE, ETI_SPEC_AVAIL) \ template \ struct GEMV< \ ExecSpace, \ Kokkos::View, \ Kokkos::MemoryTraits >, \ Kokkos::View, \ Kokkos::MemoryTraits >, \ Kokkos::View, Kokkos::MemoryTraits >, \ true, ETI_SPEC_AVAIL> { \ typedef double SCALAR; \ typedef Kokkos::View, \ Kokkos::MemoryTraits > \ AViewType; \ typedef Kokkos::View, \ Kokkos::MemoryTraits > \ XViewType; \ typedef Kokkos::View, \ Kokkos::MemoryTraits > \ YViewType; \ \ static void gemv(const ExecSpace& space, const char trans[], typename AViewType::const_value_type& alpha, \ const AViewType& A, const XViewType& X, typename YViewType::const_value_type& beta, \ const YViewType& Y) { \ Kokkos::Profiling::pushRegion("KokkosBlas::gemv[TPL_ROCBLAS,double]"); \ KOKKOSBLAS2_GEMV_ROCBLAS_DETERMINE_ARGS(LAYOUT); \ KokkosBlas::Impl::RocBlasSingleton& s = KokkosBlas::Impl::RocBlasSingleton::singleton(); \ KOKKOSBLAS_IMPL_ROCBLAS_SAFE_CALL(rocblas_set_stream(s.handle, space.hip_stream())); \ KOKKOSBLAS_IMPL_ROCBLAS_SAFE_CALL( \ rocblas_dgemv(s.handle, transa, M, N, &alpha, A.data(), LDA, X.data(), one, &beta, Y.data(), one)); \ KOKKOSBLAS_IMPL_ROCBLAS_SAFE_CALL(rocblas_set_stream(s.handle, NULL)); \ Kokkos::Profiling::popRegion(); \ } \ }; #define KOKKOSBLAS2_SGEMV_ROCBLAS(LAYOUT, MEM_SPACE, ETI_SPEC_AVAIL) \ template \ struct GEMV< \ ExecSpace, \ Kokkos::View, \ Kokkos::MemoryTraits >, \ Kokkos::View, \ Kokkos::MemoryTraits >, \ Kokkos::View, Kokkos::MemoryTraits >, \ true, ETI_SPEC_AVAIL> { \ typedef float SCALAR; \ typedef Kokkos::View, \ Kokkos::MemoryTraits > \ AViewType; \ typedef Kokkos::View, \ Kokkos::MemoryTraits > \ XViewType; \ typedef Kokkos::View, \ Kokkos::MemoryTraits > \ YViewType; \ \ static void gemv(const ExecSpace& space, const char trans[], typename AViewType::const_value_type& alpha, \ const AViewType& A, const XViewType& X, typename YViewType::const_value_type& beta, \ const YViewType& Y) { \ Kokkos::Profiling::pushRegion("KokkosBlas::gemv[TPL_ROCBLAS,float]"); \ KOKKOSBLAS2_GEMV_ROCBLAS_DETERMINE_ARGS(LAYOUT); \ KokkosBlas::Impl::RocBlasSingleton& s = KokkosBlas::Impl::RocBlasSingleton::singleton(); \ KOKKOSBLAS_IMPL_ROCBLAS_SAFE_CALL(rocblas_set_stream(s.handle, space.hip_stream())); \ KOKKOSBLAS_IMPL_ROCBLAS_SAFE_CALL( \ rocblas_sgemv(s.handle, transa, M, N, &alpha, A.data(), LDA, X.data(), one, &beta, Y.data(), one)); \ KOKKOSBLAS_IMPL_ROCBLAS_SAFE_CALL(rocblas_set_stream(s.handle, NULL)); \ Kokkos::Profiling::popRegion(); \ } \ }; #define KOKKOSBLAS2_ZGEMV_ROCBLAS(LAYOUT, MEM_SPACE, ETI_SPEC_AVAIL) \ template \ struct GEMV**, LAYOUT, Kokkos::Device, \ Kokkos::MemoryTraits >, \ Kokkos::View*, LAYOUT, Kokkos::Device, \ Kokkos::MemoryTraits >, \ Kokkos::View*, LAYOUT, Kokkos::Device, \ Kokkos::MemoryTraits >, \ true, ETI_SPEC_AVAIL> { \ typedef Kokkos::complex SCALAR; \ typedef Kokkos::View, \ Kokkos::MemoryTraits > \ AViewType; \ typedef Kokkos::View, \ Kokkos::MemoryTraits > \ XViewType; \ typedef Kokkos::View, \ Kokkos::MemoryTraits > \ YViewType; \ \ static void gemv(const ExecSpace& space, const char trans[], typename AViewType::const_value_type& alpha, \ const AViewType& A, const XViewType& X, typename YViewType::const_value_type& beta, \ const YViewType& Y) { \ Kokkos::Profiling::pushRegion("KokkosBlas::gemv[TPL_ROCBLAS,complex]"); \ KOKKOSBLAS2_GEMV_ROCBLAS_DETERMINE_ARGS(LAYOUT); \ KokkosBlas::Impl::RocBlasSingleton& s = KokkosBlas::Impl::RocBlasSingleton::singleton(); \ KOKKOSBLAS_IMPL_ROCBLAS_SAFE_CALL(rocblas_set_stream(s.handle, space.hip_stream())); \ KOKKOSBLAS_IMPL_ROCBLAS_SAFE_CALL(rocblas_zgemv(s.handle, transa, M, N, \ reinterpret_cast(&alpha), \ reinterpret_cast(A.data()), LDA, \ reinterpret_cast(X.data()), one, \ reinterpret_cast(&beta), \ reinterpret_cast(Y.data()), one)); \ KOKKOSBLAS_IMPL_ROCBLAS_SAFE_CALL(rocblas_set_stream(s.handle, NULL)); \ Kokkos::Profiling::popRegion(); \ } \ }; #define KOKKOSBLAS2_CGEMV_ROCBLAS(LAYOUT, MEM_SPACE, ETI_SPEC_AVAIL) \ template \ struct GEMV**, LAYOUT, Kokkos::Device, \ Kokkos::MemoryTraits >, \ Kokkos::View*, LAYOUT, Kokkos::Device, \ Kokkos::MemoryTraits >, \ Kokkos::View*, LAYOUT, Kokkos::Device, \ Kokkos::MemoryTraits >, \ true, ETI_SPEC_AVAIL> { \ typedef Kokkos::complex SCALAR; \ typedef Kokkos::View, \ Kokkos::MemoryTraits > \ AViewType; \ typedef Kokkos::View, \ Kokkos::MemoryTraits > \ XViewType; \ typedef Kokkos::View, \ Kokkos::MemoryTraits > \ YViewType; \ \ static void gemv(const ExecSpace& space, const char trans[], typename AViewType::const_value_type& alpha, \ const AViewType& A, const XViewType& X, typename YViewType::const_value_type& beta, \ const YViewType& Y) { \ Kokkos::Profiling::pushRegion("KokkosBlas::gemv[TPL_ROCBLAS,complex]"); \ KOKKOSBLAS2_GEMV_ROCBLAS_DETERMINE_ARGS(LAYOUT); \ KokkosBlas::Impl::RocBlasSingleton& s = KokkosBlas::Impl::RocBlasSingleton::singleton(); \ KOKKOSBLAS_IMPL_ROCBLAS_SAFE_CALL(rocblas_set_stream(s.handle, space.hip_stream())); \ KOKKOSBLAS_IMPL_ROCBLAS_SAFE_CALL(rocblas_cgemv(s.handle, transa, M, N, \ reinterpret_cast(&alpha), \ reinterpret_cast(A.data()), LDA, \ reinterpret_cast(X.data()), one, \ reinterpret_cast(&beta), \ reinterpret_cast(Y.data()), one)); \ KOKKOSBLAS_IMPL_ROCBLAS_SAFE_CALL(rocblas_set_stream(s.handle, NULL)); \ Kokkos::Profiling::popRegion(); \ } \ }; KOKKOSBLAS2_DGEMV_ROCBLAS(Kokkos::LayoutLeft, Kokkos::HIPSpace, true) KOKKOSBLAS2_DGEMV_ROCBLAS(Kokkos::LayoutLeft, Kokkos::HIPSpace, false) KOKKOSBLAS2_DGEMV_ROCBLAS(Kokkos::LayoutRight, Kokkos::HIPSpace, true) KOKKOSBLAS2_DGEMV_ROCBLAS(Kokkos::LayoutRight, Kokkos::HIPSpace, false) KOKKOSBLAS2_SGEMV_ROCBLAS(Kokkos::LayoutLeft, Kokkos::HIPSpace, true) KOKKOSBLAS2_SGEMV_ROCBLAS(Kokkos::LayoutLeft, Kokkos::HIPSpace, false) KOKKOSBLAS2_SGEMV_ROCBLAS(Kokkos::LayoutRight, Kokkos::HIPSpace, true) KOKKOSBLAS2_SGEMV_ROCBLAS(Kokkos::LayoutRight, Kokkos::HIPSpace, false) KOKKOSBLAS2_ZGEMV_ROCBLAS(Kokkos::LayoutLeft, Kokkos::HIPSpace, true) KOKKOSBLAS2_ZGEMV_ROCBLAS(Kokkos::LayoutLeft, Kokkos::HIPSpace, false) KOKKOSBLAS2_ZGEMV_ROCBLAS(Kokkos::LayoutRight, Kokkos::HIPSpace, true) KOKKOSBLAS2_ZGEMV_ROCBLAS(Kokkos::LayoutRight, Kokkos::HIPSpace, false) KOKKOSBLAS2_CGEMV_ROCBLAS(Kokkos::LayoutLeft, Kokkos::HIPSpace, true) KOKKOSBLAS2_CGEMV_ROCBLAS(Kokkos::LayoutLeft, Kokkos::HIPSpace, false) KOKKOSBLAS2_CGEMV_ROCBLAS(Kokkos::LayoutRight, Kokkos::HIPSpace, true) KOKKOSBLAS2_CGEMV_ROCBLAS(Kokkos::LayoutRight, Kokkos::HIPSpace, false) } // namespace Impl } // namespace KokkosBlas #endif // KOKKOSKERNELS_ENABLE_TPL_ROCBLAS // ONEMKL #if defined(KOKKOSKERNELS_ENABLE_TPL_MKL) && defined(KOKKOS_ENABLE_SYCL) #include #include #include namespace KokkosBlas { namespace Impl { inline oneapi::mkl::transpose mode_kk_to_onemkl(char mode_kk) { switch (toupper(mode_kk)) { case 'N': return oneapi::mkl::transpose::nontrans; case 'T': return oneapi::mkl::transpose::trans; case 'C': return oneapi::mkl::transpose::conjtrans; default:; } throw std::invalid_argument("Invalid mode for oneMKL (should be one of N, T, C)"); } template struct kokkos_to_std_type_map { using type = T; }; // e.g., map Kokkos::complex to std::complex template struct kokkos_to_std_type_map { using type = std::complex::mag_type>; }; #define KOKKOSBLAS2_GEMV_ONEMKL(SCALAR, LAYOUT, MEM_SPACE, ETI_SPEC_AVAIL) \ template \ struct GEMV, \ Kokkos::MemoryTraits >, \ Kokkos::View, \ Kokkos::MemoryTraits >, \ Kokkos::View, \ Kokkos::MemoryTraits >, \ true, ETI_SPEC_AVAIL> { \ using device_type = Kokkos::Device; \ using mem_traits = Kokkos::MemoryTraits; \ using AViewType = Kokkos::View; \ using XViewType = Kokkos::View; \ using YViewType = Kokkos::View; \ \ static void gemv(const ExecSpace& exec, const char kk_trans[], typename AViewType::const_value_type& alpha, \ const AViewType& A, const XViewType& X, typename YViewType::const_value_type& beta, \ const YViewType& Y) { \ if (beta == Kokkos::ArithTraits::zero()) { \ Kokkos::deep_copy(Y, Kokkos::ArithTraits::zero()); \ } \ \ bool row_major = std::is_same::value; \ const std::int64_t M = A.extent(0); \ const std::int64_t N = A.extent(1); \ oneapi::mkl::transpose trans = mode_kk_to_onemkl(kk_trans[0]); \ const std::int64_t LDA = row_major ? A.stride(0) : A.stride(1); \ std::string label = "KokkosBlas::gemv[TPL_ONEMKL," + Kokkos::ArithTraits::name() + "]"; \ \ Kokkos::Profiling::pushRegion(label); \ using mag_type = kokkos_to_std_type_map::is_complex>::type; \ const mag_type* a = reinterpret_cast(A.data()); \ const mag_type* x = reinterpret_cast(X.data()); \ mag_type* y = reinterpret_cast(Y.data()); \ if (row_major) { \ oneapi::mkl::blas::row_major::gemv(exec.sycl_queue(), trans, M, N, alpha, a, LDA, x, 1, beta, y, 1); \ } else { \ oneapi::mkl::blas::column_major::gemv(exec.sycl_queue(), trans, M, N, alpha, a, LDA, x, 1, beta, y, 1); \ } \ Kokkos::Profiling::popRegion(); \ } \ }; KOKKOSBLAS2_GEMV_ONEMKL(float, Kokkos::LayoutLeft, Kokkos::Experimental::SYCLDeviceUSMSpace, true) KOKKOSBLAS2_GEMV_ONEMKL(float, Kokkos::LayoutRight, Kokkos::Experimental::SYCLDeviceUSMSpace, true) KOKKOSBLAS2_GEMV_ONEMKL(double, Kokkos::LayoutLeft, Kokkos::Experimental::SYCLDeviceUSMSpace, true) KOKKOSBLAS2_GEMV_ONEMKL(double, Kokkos::LayoutRight, Kokkos::Experimental::SYCLDeviceUSMSpace, true) KOKKOSBLAS2_GEMV_ONEMKL(Kokkos::complex, Kokkos::LayoutLeft, Kokkos::Experimental::SYCLDeviceUSMSpace, true) KOKKOSBLAS2_GEMV_ONEMKL(Kokkos::complex, Kokkos::LayoutRight, Kokkos::Experimental::SYCLDeviceUSMSpace, true) KOKKOSBLAS2_GEMV_ONEMKL(Kokkos::complex, Kokkos::LayoutLeft, Kokkos::Experimental::SYCLDeviceUSMSpace, true) KOKKOSBLAS2_GEMV_ONEMKL(Kokkos::complex, Kokkos::LayoutRight, Kokkos::Experimental::SYCLDeviceUSMSpace, true) } // namespace Impl } // namespace KokkosBlas #endif #endif