| 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 KOKKOSBLAS1_DOT_TPL_SPEC_AVAIL_HPP_ |
| 18 |
#define KOKKOSBLAS1_DOT_TPL_SPEC_AVAIL_HPP_ |
| 19 |
|
| 20 |
namespace KokkosBlas { |
| 21 |
namespace Impl { |
| 22 |
// Specialization struct which defines whether a specialization exists |
| 23 |
template <class execution_space, class AV, class XMV, class YMV, int Xrank = XMV::rank, int Yrank = YMV::rank> |
| 24 |
struct dot_tpl_spec_avail { |
| 25 |
enum : bool { value = false }; |
| 26 |
}; |
| 27 |
} // namespace Impl |
| 28 |
} // namespace KokkosBlas |
| 29 |
|
| 30 |
namespace KokkosBlas { |
| 31 |
namespace Impl { |
| 32 |
|
| 33 |
// Generic Host side BLAS (could be MKL or whatever) |
| 34 |
#ifdef KOKKOSKERNELS_ENABLE_TPL_BLAS |
| 35 |
// double |
| 36 |
#define KOKKOSBLAS1_DOT_TPL_SPEC_AVAIL_BLAS(SCALAR, LAYOUT, MEMSPACE) \ |
| 37 |
template <class ExecSpace> \ |
| 38 |
struct dot_tpl_spec_avail<ExecSpace, \ |
| 39 |
Kokkos::View<SCALAR, LAYOUT, Kokkos::HostSpace, Kokkos::MemoryTraits<Kokkos::Unmanaged> >, \ |
| 40 |
Kokkos::View<const SCALAR*, LAYOUT, Kokkos::Device<ExecSpace, MEMSPACE>, \ |
| 41 |
Kokkos::MemoryTraits<Kokkos::Unmanaged> >, \ |
| 42 |
Kokkos::View<const SCALAR*, LAYOUT, Kokkos::Device<ExecSpace, MEMSPACE>, \ |
| 43 |
Kokkos::MemoryTraits<Kokkos::Unmanaged> >, \ |
| 44 |
1, 1> { \ |
| 45 |
enum : bool { value = true }; \ |
| 46 |
}; |
| 47 |
|
| 48 |
KOKKOSBLAS1_DOT_TPL_SPEC_AVAIL_BLAS(double, Kokkos::LayoutLeft, Kokkos::HostSpace) |
| 49 |
KOKKOSBLAS1_DOT_TPL_SPEC_AVAIL_BLAS(float, Kokkos::LayoutLeft, Kokkos::HostSpace) |
| 50 |
|
| 51 |
// TODO: we met difficuties in FindTPLMKL.cmake to set the BLAS library properly |
| 52 |
// such that the test in CheckHostBlasReturnComplex.cmake could not be |
| 53 |
// compiled and run to give a correct answer on KK_BLAS_RESULT_AS_POINTER_ARG. |
| 54 |
// This resulted in segfault in dot() with MKL and complex. |
| 55 |
// So we just temporarily disable it until FindTPLMKL.cmake is fixed. |
| 56 |
#if !defined(KOKKOSKERNELS_ENABLE_TPL_MKL) |
| 57 |
KOKKOSBLAS1_DOT_TPL_SPEC_AVAIL_BLAS(Kokkos::complex<double>, Kokkos::LayoutLeft, Kokkos::HostSpace) |
| 58 |
KOKKOSBLAS1_DOT_TPL_SPEC_AVAIL_BLAS(Kokkos::complex<float>, Kokkos::LayoutLeft, Kokkos::HostSpace) |
| 59 |
#endif |
| 60 |
|
| 61 |
#endif |
| 62 |
|
| 63 |
#define KOKKOSBLAS1_DOT_TPL_SPEC(SCALAR, LAYOUT, EXECSPACE, MEMSPACE) \ |
| 64 |
template <> \ |
| 65 |
struct dot_tpl_spec_avail<EXECSPACE, \ |
| 66 |
Kokkos::View<SCALAR, LAYOUT, Kokkos::HostSpace, Kokkos::MemoryTraits<Kokkos::Unmanaged> >, \ |
| 67 |
Kokkos::View<const SCALAR*, LAYOUT, Kokkos::Device<EXECSPACE, MEMSPACE>, \ |
| 68 |
Kokkos::MemoryTraits<Kokkos::Unmanaged> >, \ |
| 69 |
Kokkos::View<const SCALAR*, LAYOUT, Kokkos::Device<EXECSPACE, MEMSPACE>, \ |
| 70 |
Kokkos::MemoryTraits<Kokkos::Unmanaged> >, \ |
| 71 |
1, 1> { \ |
| 72 |
enum : bool { value = true }; \ |
| 73 |
}; |
| 74 |
|
| 75 |
#define KOKKOSBLAS1_DOT_TPL_SPEC_AVAIL(LAYOUT, EXECSPACE, MEMSPACE) \ |
| 76 |
KOKKOSBLAS1_DOT_TPL_SPEC(float, LAYOUT, EXECSPACE, MEMSPACE) \ |
| 77 |
KOKKOSBLAS1_DOT_TPL_SPEC(double, LAYOUT, EXECSPACE, MEMSPACE) \ |
| 78 |
KOKKOSBLAS1_DOT_TPL_SPEC(Kokkos::complex<float>, LAYOUT, EXECSPACE, MEMSPACE) \ |
| 79 |
KOKKOSBLAS1_DOT_TPL_SPEC(Kokkos::complex<double>, LAYOUT, EXECSPACE, MEMSPACE) |
| 80 |
|
| 81 |
#ifdef KOKKOSKERNELS_ENABLE_TPL_CUBLAS |
| 82 |
// Note BMK: CUBLAS dot is consistently slower than our native dot |
| 83 |
// (measured 11.2, 11.8, 12.0 using perf test, and all are similar) |
| 84 |
// If a future version improves performance, re-enable it here and |
| 85 |
// in the tpl_spec_decl file. |
| 86 |
#if 0 |
| 87 |
KOKKOSBLAS1_DOT_TPL_SPEC_AVAIL(Kokkos::LayoutLeft, Kokkos::Cuda, |
| 88 |
Kokkos::CudaSpace) |
| 89 |
#endif |
| 90 |
#endif |
| 91 |
|
| 92 |
#ifdef KOKKOSKERNELS_ENABLE_TPL_ROCBLAS |
| 93 |
KOKKOSBLAS1_DOT_TPL_SPEC_AVAIL(Kokkos::LayoutLeft, Kokkos::HIP, Kokkos::HIPSpace) |
| 94 |
#endif |
| 95 |
|
| 96 |
#if defined(KOKKOSKERNELS_ENABLE_TPL_MKL) && defined(KOKKOS_ENABLE_SYCL) |
| 97 |
KOKKOSBLAS1_DOT_TPL_SPEC_AVAIL(Kokkos::LayoutLeft, Kokkos::Experimental::SYCL, Kokkos::Experimental::SYCLDeviceUSMSpace) |
| 98 |
#endif |
| 99 |
} // namespace Impl |
| 100 |
} // namespace KokkosBlas |
| 101 |
#endif |