//@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 KOKKOSBLAS1_NRM2_TPL_SPEC_DECL_HPP_ #define KOKKOSBLAS1_NRM2_TPL_SPEC_DECL_HPP_ namespace KokkosBlas { namespace Impl { namespace { template inline void nrm2_print_specialization() { #ifdef KOKKOSKERNELS_ENABLE_CHECK_SPECIALIZATION printf("KokkosBlas1::nrm2<> TPL Blas specialization for < %s , %s >\n", typeid(RV).name(), typeid(XV).name()); #endif } } // namespace } // namespace Impl } // namespace KokkosBlas // Generic Host side BLAS (could be MKL or whatever) #ifdef KOKKOSKERNELS_ENABLE_TPL_BLAS #include "KokkosBlas_Host_tpl.hpp" namespace KokkosBlas { namespace Impl { #define KOKKOSBLAS1_DNRM2_TPL_SPEC_DECL_BLAS(LAYOUT, MEMSPACE, ETI_SPEC_AVAIL) \ template \ struct Nrm2 >, \ Kokkos::View, \ Kokkos::MemoryTraits >, \ 1, true, ETI_SPEC_AVAIL> { \ typedef Kokkos::View > RV; \ typedef Kokkos::View, \ Kokkos::MemoryTraits > \ XV; \ typedef typename XV::size_type size_type; \ \ static void nrm2(const ExecSpace& space, RV& R, const XV& X, const bool& take_sqrt) { \ Kokkos::Profiling::pushRegion("KokkosBlas::nrm2[TPL_BLAS,double]"); \ const size_type numElems = X.extent(0); \ if (numElems < static_cast(INT_MAX)) { \ nrm2_print_specialization(); \ int N = numElems; \ int int_one = 1; \ R() = HostBlas::nrm2(N, X.data(), int_one); \ if (!take_sqrt) R() = R() * R(); \ } else { \ Nrm2::nrm2(space, R, X, take_sqrt); \ } \ Kokkos::Profiling::popRegion(); \ } \ }; #define KOKKOSBLAS1_SNRM2_TPL_SPEC_DECL_BLAS(LAYOUT, MEMSPACE, ETI_SPEC_AVAIL) \ template \ struct Nrm2 >, \ Kokkos::View, \ Kokkos::MemoryTraits >, \ 1, true, ETI_SPEC_AVAIL> { \ typedef Kokkos::View > RV; \ typedef Kokkos::View, \ Kokkos::MemoryTraits > \ XV; \ typedef typename XV::size_type size_type; \ \ static void nrm2(const ExecSpace& space, RV& R, const XV& X, const bool& take_sqrt) { \ Kokkos::Profiling::pushRegion("KokkosBlas::nrm2[TPL_BLAS,float]"); \ const size_type numElems = X.extent(0); \ if (numElems < static_cast(INT_MAX)) { \ nrm2_print_specialization(); \ int N = numElems; \ int int_one = 1; \ R() = HostBlas::nrm2(N, X.data(), int_one); \ if (!take_sqrt) R() = R() * R(); \ } else { \ Nrm2::nrm2(space, R, X, take_sqrt); \ } \ Kokkos::Profiling::popRegion(); \ } \ }; #define KOKKOSBLAS1_ZNRM2_TPL_SPEC_DECL_BLAS(LAYOUT, MEMSPACE, ETI_SPEC_AVAIL) \ template \ struct Nrm2 >, \ Kokkos::View*, LAYOUT, Kokkos::Device, \ Kokkos::MemoryTraits >, \ 1, true, ETI_SPEC_AVAIL> { \ typedef Kokkos::View > RV; \ typedef Kokkos::View*, LAYOUT, Kokkos::Device, \ Kokkos::MemoryTraits > \ XV; \ typedef typename XV::size_type size_type; \ \ static void nrm2(const ExecSpace& space, RV& R, const XV& X, const bool& take_sqrt) { \ Kokkos::Profiling::pushRegion("KokkosBlas::nrm2[TPL_BLAS,complex]"); \ const size_type numElems = X.extent(0); \ if (numElems < static_cast(INT_MAX)) { \ nrm2_print_specialization(); \ int N = numElems; \ int int_one = 1; \ R() = HostBlas >::nrm2(N, reinterpret_cast*>(X.data()), \ int_one); \ if (!take_sqrt) R() = R() * R(); \ } else { \ Nrm2::nrm2(space, R, X, take_sqrt); \ } \ Kokkos::Profiling::popRegion(); \ } \ }; #define KOKKOSBLAS1_CNRM2_TPL_SPEC_DECL_BLAS(LAYOUT, MEMSPACE, ETI_SPEC_AVAIL) \ template \ struct Nrm2 >, \ Kokkos::View*, LAYOUT, Kokkos::Device, \ Kokkos::MemoryTraits >, \ 1, true, ETI_SPEC_AVAIL> { \ typedef Kokkos::View > RV; \ typedef Kokkos::View*, LAYOUT, Kokkos::Device, \ Kokkos::MemoryTraits > \ XV; \ typedef typename XV::size_type size_type; \ \ static void nrm2(const ExecSpace& space, RV& R, const XV& X, const bool& take_sqrt) { \ Kokkos::Profiling::pushRegion("KokkosBlas::nrm2[TPL_BLAS,complex]"); \ const size_type numElems = X.extent(0); \ if (numElems < static_cast(INT_MAX)) { \ nrm2_print_specialization(); \ int N = numElems; \ int int_one = 1; \ R() = \ HostBlas >::nrm2(N, reinterpret_cast*>(X.data()), int_one); \ if (!take_sqrt) R() = R() * R(); \ } else { \ Nrm2::nrm2(space, R, X, take_sqrt); \ } \ Kokkos::Profiling::popRegion(); \ } \ }; KOKKOSBLAS1_DNRM2_TPL_SPEC_DECL_BLAS(Kokkos::LayoutLeft, Kokkos::HostSpace, true) KOKKOSBLAS1_DNRM2_TPL_SPEC_DECL_BLAS(Kokkos::LayoutLeft, Kokkos::HostSpace, false) KOKKOSBLAS1_SNRM2_TPL_SPEC_DECL_BLAS(Kokkos::LayoutLeft, Kokkos::HostSpace, true) KOKKOSBLAS1_SNRM2_TPL_SPEC_DECL_BLAS(Kokkos::LayoutLeft, Kokkos::HostSpace, false) KOKKOSBLAS1_ZNRM2_TPL_SPEC_DECL_BLAS(Kokkos::LayoutLeft, Kokkos::HostSpace, true) KOKKOSBLAS1_ZNRM2_TPL_SPEC_DECL_BLAS(Kokkos::LayoutLeft, Kokkos::HostSpace, false) KOKKOSBLAS1_CNRM2_TPL_SPEC_DECL_BLAS(Kokkos::LayoutLeft, Kokkos::HostSpace, true) KOKKOSBLAS1_CNRM2_TPL_SPEC_DECL_BLAS(Kokkos::LayoutLeft, Kokkos::HostSpace, false) } // namespace Impl } // namespace KokkosBlas #endif #ifdef KOKKOSKERNELS_ENABLE_TPL_CUBLAS #include namespace KokkosBlas { namespace Impl { #define KOKKOSBLAS1_NRM2_TPL_SPEC_DECL_CUBLAS(LAYOUT, KOKKOS_TYPE, TPL_TYPE, EXECSPACE, MEMSPACE, TPL_NRM2, \ ETI_SPEC_AVAIL) \ template <> \ struct Nrm2::mag_type, LAYOUT, Kokkos::HostSpace, \ Kokkos::MemoryTraits >, \ Kokkos::View, \ Kokkos::MemoryTraits >, \ 1, true, ETI_SPEC_AVAIL> { \ using RT = Kokkos::ArithTraits::mag_type; \ using RV = Kokkos::View >; \ using XV = Kokkos::View, \ Kokkos::MemoryTraits >; \ using size_type = typename XV::size_type; \ \ static void nrm2(const EXECSPACE& space, RV& R, const XV& X, const bool& take_sqrt) { \ Kokkos::Profiling::pushRegion("KokkosBlas::nrm2[TPL_CUBLAS," + Kokkos::ArithTraits::name() + "]"); \ const size_type numElems = X.extent(0); \ if (numElems <= static_cast(std::numeric_limits::max())) { \ nrm2_print_specialization(); \ const int N = static_cast(numElems); \ KokkosBlas::Impl::CudaBlasSingleton& s = KokkosBlas::Impl::CudaBlasSingleton::singleton(); \ KOKKOSBLAS_IMPL_CUBLAS_SAFE_CALL(cublasSetStream(s.handle, space.cuda_stream())); \ KOKKOSBLAS_IMPL_CUBLAS_SAFE_CALL(TPL_NRM2(s.handle, N, reinterpret_cast(X.data()), 1, &R())); \ KOKKOSBLAS_IMPL_CUBLAS_SAFE_CALL(cublasSetStream(s.handle, NULL)); \ if (!take_sqrt) R() = R() * R(); \ } else { \ Nrm2::nrm2(space, R, X, take_sqrt); \ } \ Kokkos::Profiling::popRegion(); \ } \ }; #define KOKKOSBLAS1_NRM2_TPL_SPEC_DECL_CUBLAS_EXT(ETI_SPEC_AVAIL) \ KOKKOSBLAS1_NRM2_TPL_SPEC_DECL_CUBLAS(Kokkos::LayoutLeft, float, float, Kokkos::Cuda, Kokkos::CudaSpace, \ cublasSnrm2, ETI_SPEC_AVAIL) \ KOKKOSBLAS1_NRM2_TPL_SPEC_DECL_CUBLAS(Kokkos::LayoutLeft, double, double, Kokkos::Cuda, Kokkos::CudaSpace, \ cublasDnrm2, ETI_SPEC_AVAIL) \ KOKKOSBLAS1_NRM2_TPL_SPEC_DECL_CUBLAS(Kokkos::LayoutLeft, Kokkos::complex, cuComplex, Kokkos::Cuda, \ Kokkos::CudaSpace, cublasScnrm2, ETI_SPEC_AVAIL) \ KOKKOSBLAS1_NRM2_TPL_SPEC_DECL_CUBLAS(Kokkos::LayoutLeft, Kokkos::complex, cuDoubleComplex, Kokkos::Cuda, \ Kokkos::CudaSpace, cublasDznrm2, ETI_SPEC_AVAIL) KOKKOSBLAS1_NRM2_TPL_SPEC_DECL_CUBLAS_EXT(true) KOKKOSBLAS1_NRM2_TPL_SPEC_DECL_CUBLAS_EXT(false) } // namespace Impl } // namespace KokkosBlas #endif #ifdef KOKKOSKERNELS_ENABLE_TPL_ROCBLAS #include namespace KokkosBlas { namespace Impl { #define KOKKOSBLAS1_NRM2_TPL_SPEC_DECL_ROCBLAS(LAYOUT, KOKKOS_TYPE, TPL_TYPE, EXECSPACE, MEMSPACE, TPL_NRM2, \ ETI_SPEC_AVAIL) \ template <> \ struct Nrm2::mag_type, LAYOUT, Kokkos::HostSpace, \ Kokkos::MemoryTraits >, \ Kokkos::View, \ Kokkos::MemoryTraits >, \ 1, true, ETI_SPEC_AVAIL> { \ using RT = Kokkos::ArithTraits::mag_type; \ using RV = Kokkos::View >; \ using XV = Kokkos::View, \ Kokkos::MemoryTraits >; \ using size_type = typename XV::size_type; \ \ static void nrm2(const EXECSPACE& space, RV& R, const XV& X, const bool& take_sqrt) { \ Kokkos::Profiling::pushRegion("KokkosBlas::nrm2[TPL_ROCBLAS," + Kokkos::ArithTraits::name() + "]"); \ const size_type numElems = X.extent(0); \ if (numElems <= static_cast(std::numeric_limits::max())) { \ nrm2_print_specialization(); \ const rocblas_int N = static_cast(numElems); \ 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( \ TPL_NRM2(s.handle, N, reinterpret_cast(X.data()), 1, &R())); \ KOKKOSBLAS_IMPL_ROCBLAS_SAFE_CALL(rocblas_set_stream(s.handle, NULL)); \ if (!take_sqrt) R() = R() * R(); \ } else { \ Nrm2::nrm2(space, R, X, take_sqrt); \ } \ Kokkos::Profiling::popRegion(); \ } \ }; #define KOKKOSBLAS1_NRM2_TPL_SPEC_DECL_ROCBLAS_EXT(ETI_SPEC_AVAIL) \ KOKKOSBLAS1_NRM2_TPL_SPEC_DECL_ROCBLAS(Kokkos::LayoutLeft, float, float, Kokkos::HIP, Kokkos::HIPSpace, \ rocblas_snrm2, ETI_SPEC_AVAIL) \ KOKKOSBLAS1_NRM2_TPL_SPEC_DECL_ROCBLAS(Kokkos::LayoutLeft, double, double, Kokkos::HIP, Kokkos::HIPSpace, \ rocblas_dnrm2, ETI_SPEC_AVAIL) \ KOKKOSBLAS1_NRM2_TPL_SPEC_DECL_ROCBLAS(Kokkos::LayoutLeft, Kokkos::complex, rocblas_float_complex, \ Kokkos::HIP, Kokkos::HIPSpace, rocblas_scnrm2, ETI_SPEC_AVAIL) \ KOKKOSBLAS1_NRM2_TPL_SPEC_DECL_ROCBLAS(Kokkos::LayoutLeft, Kokkos::complex, rocblas_double_complex, \ Kokkos::HIP, Kokkos::HIPSpace, rocblas_dznrm2, ETI_SPEC_AVAIL) KOKKOSBLAS1_NRM2_TPL_SPEC_DECL_ROCBLAS_EXT(true) KOKKOSBLAS1_NRM2_TPL_SPEC_DECL_ROCBLAS_EXT(false) } // namespace Impl } // namespace KokkosBlas #endif #if defined(KOKKOSKERNELS_ENABLE_TPL_MKL) && defined(KOKKOS_ENABLE_SYCL) #include #include #include namespace KokkosBlas { namespace Impl { #define KOKKOSBLAS1_NRM2_TPL_SPEC_DECL_ONEMKL(LAYOUT, KOKKOS_TYPE, TPL_TYPE, EXECSPACE, MEMSPACE, TPL_NRM2, \ ETI_SPEC_AVAIL) \ template <> \ struct Nrm2::mag_type, LAYOUT, Kokkos::HostSpace, \ Kokkos::MemoryTraits >, \ Kokkos::View, \ Kokkos::MemoryTraits >, \ 1, true, ETI_SPEC_AVAIL> { \ using RT = Kokkos::ArithTraits::mag_type; \ using RV = Kokkos::View >; \ using XV = Kokkos::View, \ Kokkos::MemoryTraits >; \ using size_type = typename XV::size_type; \ \ static void nrm2(const EXECSPACE& space, RV& R, const XV& X, const bool& take_sqrt) { \ Kokkos::Profiling::pushRegion("KokkosBlas::nrm2[TPL_ONEMKL," + Kokkos::ArithTraits::name() + "]"); \ const size_type numElems = X.extent(0); \ if (numElems <= static_cast(std::numeric_limits::max())) { \ nrm2_print_specialization(); \ const std::int64_t N = static_cast(numElems); \ TPL_NRM2(space.sycl_queue(), N, reinterpret_cast(X.data()), 1, &R()); \ if (!take_sqrt) R() = R() * R(); \ } else { \ Nrm2::nrm2(space, R, X, take_sqrt); \ } \ Kokkos::Profiling::popRegion(); \ } \ }; #define KOKKOSBLAS1_NRM2_TPL_SPEC_DECL_ONEMKL_EXT(ETI_SPEC_AVAIL) \ KOKKOSBLAS1_NRM2_TPL_SPEC_DECL_ONEMKL(Kokkos::LayoutLeft, float, float, Kokkos::Experimental::SYCL, \ Kokkos::Experimental::SYCLDeviceUSMSpace, oneapi::mkl::blas::row_major::nrm2, \ ETI_SPEC_AVAIL) \ KOKKOSBLAS1_NRM2_TPL_SPEC_DECL_ONEMKL(Kokkos::LayoutLeft, double, double, Kokkos::Experimental::SYCL, \ Kokkos::Experimental::SYCLDeviceUSMSpace, oneapi::mkl::blas::row_major::nrm2, \ ETI_SPEC_AVAIL) \ KOKKOSBLAS1_NRM2_TPL_SPEC_DECL_ONEMKL(Kokkos::LayoutLeft, Kokkos::complex, std::complex, \ Kokkos::Experimental::SYCL, Kokkos::Experimental::SYCLDeviceUSMSpace, \ oneapi::mkl::blas::row_major::nrm2, ETI_SPEC_AVAIL) \ KOKKOSBLAS1_NRM2_TPL_SPEC_DECL_ONEMKL(Kokkos::LayoutLeft, Kokkos::complex, std::complex, \ Kokkos::Experimental::SYCL, Kokkos::Experimental::SYCLDeviceUSMSpace, \ oneapi::mkl::blas::row_major::nrm2, ETI_SPEC_AVAIL) KOKKOSBLAS1_NRM2_TPL_SPEC_DECL_ONEMKL_EXT(true) KOKKOSBLAS1_NRM2_TPL_SPEC_DECL_ONEMKL_EXT(false) } // namespace Impl } // namespace KokkosBlas #endif // KOKKOSKERNELS_ENABLE_TPL_MKL && KOKKOS_ENABLE_SYCL #endif