| 1 |
// @HEADER |
| 2 |
// ***************************************************************************** |
| 3 |
// Tpetra: Templated Linear Algebra Services Package |
| 4 |
// |
| 5 |
// Copyright 2008 NTESS and the Tpetra contributors. |
| 6 |
// SPDX-License-Identifier: BSD-3-Clause |
| 7 |
// ***************************************************************************** |
| 8 |
// @HEADER |
| 9 |
|
| 10 |
#include <Teuchos_UnitTestHarness.hpp> |
| 11 |
|
| 12 |
#include <Tpetra_Core.hpp> |
| 13 |
#include <Tpetra_Details_ExecutionSpaces.hpp> |
| 14 |
|
| 15 |
/*! \file Spaces.cpp |
| 16 |
\brief Make sure Tpetra::Details::Spaces interfaces compile and don't crash |
| 17 |
*/ |
| 18 |
|
| 19 |
namespace { // (anonymous) |
| 20 |
|
| 21 |
template <typename ExecutionSpace> |
| 22 |
void test_exec_space_wait(bool &success, Teuchos::FancyOStream &out) { |
| 23 |
ExecutionSpace e1, e2; |
| 24 |
Tpetra::Details::Spaces::exec_space_wait(e1, e2); |
| 25 |
Tpetra::Details::Spaces::exec_space_wait("test_exec_space_wait", e1, e2); |
| 26 |
|
| 27 |
success = true; |
| 28 |
} |
| 29 |
|
| 30 |
template <typename ExecutionSpace> |
| 31 |
void test_make_instance(bool &success, Teuchos::FancyOStream &out) { |
| 32 |
|
| 33 |
using Priority = Tpetra::Details::Spaces::Priority; |
| 34 |
{ |
| 35 |
ExecutionSpace e1 = |
| 36 |
Tpetra::Details::Spaces::make_instance<ExecutionSpace>(); |
| 37 |
ExecutionSpace e2 = |
| 38 |
Tpetra::Details::Spaces::make_instance<ExecutionSpace, Priority::low>(); |
| 39 |
ExecutionSpace e3 = |
| 40 |
Tpetra::Details::Spaces::make_instance<ExecutionSpace, |
| 41 |
Priority::medium>(); |
| 42 |
ExecutionSpace e4 = |
| 43 |
Tpetra::Details::Spaces::make_instance<ExecutionSpace, |
| 44 |
Priority::high>(); |
| 45 |
} |
| 46 |
{ |
| 47 |
ExecutionSpace e1 = |
| 48 |
Tpetra::Details::Spaces::make_instance<ExecutionSpace>(Priority::low); |
| 49 |
ExecutionSpace e2 = Tpetra::Details::Spaces::make_instance<ExecutionSpace>( |
| 50 |
Priority::medium); |
| 51 |
ExecutionSpace e3 = |
| 52 |
Tpetra::Details::Spaces::make_instance<ExecutionSpace>(Priority::high); |
| 53 |
} |
| 54 |
|
| 55 |
success = true; |
| 56 |
} |
| 57 |
|
| 58 |
template <typename ExecutionSpace> |
| 59 |
void test_space_instance(bool &success, Teuchos::FancyOStream &out) { |
| 60 |
using Priority = Tpetra::Details::Spaces::Priority; |
| 61 |
|
| 62 |
// unnumbered spaces are the same |
| 63 |
{ |
| 64 |
Teuchos::RCP<const ExecutionSpace> e1 = |
| 65 |
Tpetra::Details::Spaces::space_instance<ExecutionSpace>(); |
| 66 |
Teuchos::RCP<const ExecutionSpace> e2 = |
| 67 |
Tpetra::Details::Spaces::space_instance<ExecutionSpace>(); |
| 68 |
TEUCHOS_TEST_EQUALITY(e1, e2, out, success); |
| 69 |
} |
| 70 |
|
| 71 |
// unnumbered space is the same as 0 |
| 72 |
{ |
| 73 |
Teuchos::RCP<const ExecutionSpace> e1 = |
| 74 |
Tpetra::Details::Spaces::space_instance<ExecutionSpace>(); |
| 75 |
Teuchos::RCP<const ExecutionSpace> e2 = |
| 76 |
Tpetra::Details::Spaces::space_instance<ExecutionSpace>(0); |
| 77 |
TEUCHOS_TEST_EQUALITY(e1, e2, out, success); |
| 78 |
} |
| 79 |
|
| 80 |
// construct priorities (no relationship with each other defined yet) |
| 81 |
{ |
| 82 |
Teuchos::RCP<const ExecutionSpace> e1 = |
| 83 |
Tpetra::Details::Spaces::space_instance<ExecutionSpace, |
| 84 |
Priority::low>(); |
| 85 |
Teuchos::RCP<const ExecutionSpace> e2 = |
| 86 |
Tpetra::Details::Spaces::space_instance<ExecutionSpace, |
| 87 |
Priority::medium>(); |
| 88 |
Teuchos::RCP<const ExecutionSpace> e3 = |
| 89 |
Tpetra::Details::Spaces::space_instance<ExecutionSpace, |
| 90 |
Priority::high>(); |
| 91 |
} |
| 92 |
{ |
| 93 |
Teuchos::RCP<const ExecutionSpace> e1 = |
| 94 |
Tpetra::Details::Spaces::space_instance<ExecutionSpace, Priority::low>( |
| 95 |
0); |
| 96 |
Teuchos::RCP<const ExecutionSpace> e2 = |
| 97 |
Tpetra::Details::Spaces::space_instance<ExecutionSpace, |
| 98 |
Priority::medium>(2); |
| 99 |
Teuchos::RCP<const ExecutionSpace> e3 = |
| 100 |
Tpetra::Details::Spaces::space_instance<ExecutionSpace, Priority::high>( |
| 101 |
10); |
| 102 |
} |
| 103 |
|
| 104 |
{ |
| 105 |
Teuchos::RCP<const ExecutionSpace> e1 = |
| 106 |
Tpetra::Details::Spaces::space_instance<ExecutionSpace>(Priority::low); |
| 107 |
Teuchos::RCP<const ExecutionSpace> e2 = |
| 108 |
Tpetra::Details::Spaces::space_instance<ExecutionSpace>( |
| 109 |
Priority::medium); |
| 110 |
Teuchos::RCP<const ExecutionSpace> e3 = |
| 111 |
Tpetra::Details::Spaces::space_instance<ExecutionSpace>(Priority::high); |
| 112 |
} |
| 113 |
|
| 114 |
{ |
| 115 |
Teuchos::RCP<const ExecutionSpace> e1 = |
| 116 |
Tpetra::Details::Spaces::space_instance<ExecutionSpace>(Priority::low, |
| 117 |
0); |
| 118 |
Teuchos::RCP<const ExecutionSpace> e2 = |
| 119 |
Tpetra::Details::Spaces::space_instance<ExecutionSpace>( |
| 120 |
Priority::medium, 2); |
| 121 |
Teuchos::RCP<const ExecutionSpace> e3 = |
| 122 |
Tpetra::Details::Spaces::space_instance<ExecutionSpace>(Priority::high, |
| 123 |
10); |
| 124 |
} |
| 125 |
|
| 126 |
success = true; |
| 127 |
} |
| 128 |
|
| 129 |
template <typename ExecutionSpace, bool expected> |
| 130 |
void test_is_gpu_exec_space(bool &success, Teuchos::FancyOStream &out) { |
| 131 |
TEUCHOS_TEST_EQUALITY( |
| 132 |
expected, Tpetra::Details::Spaces::is_gpu_exec_space<ExecutionSpace>(), |
| 133 |
out, success); |
| 134 |
} |
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
} // namespace |
| 139 |
|
| 140 |
int main(int argc, char **argv) { |
| 141 |
Tpetra::ScopeGuard sg(&argc, &argv); |
| 142 |
|
| 143 |
bool success = false; |
| 144 |
auto out = Teuchos::fancyOStream (Teuchos::rcpFromRef (std::cout)); |
| 145 |
*out << "Test spaces" << std::endl; |
| 146 |
|
| 147 |
#if defined(KOKKOS_ENABLE_SERIAL) |
| 148 |
test_exec_space_wait<Kokkos::Serial>(success, *out); |
| 149 |
test_make_instance<Kokkos::Serial>(success, *out); |
| 150 |
test_space_instance<Kokkos::Serial>(success, *out); |
| 151 |
test_is_gpu_exec_space<Kokkos::Serial, false>(success, *out); |
| 152 |
#endif |
| 153 |
|
| 154 |
#if defined(KOKKOS_ENABLE_OPENMP) |
| 155 |
test_exec_space_wait<Kokkos::OpenMP>(success, *out); |
| 156 |
test_make_instance<Kokkos::OpenMP>(success, *out); |
| 157 |
test_space_instance<Kokkos::OpenMP>(success, *out); |
| 158 |
test_is_gpu_exec_space<Kokkos::OpenMP, false>(success, *out); |
| 159 |
#endif |
| 160 |
|
| 161 |
#if defined(KOKKOS_ENABLE_THREADS) |
| 162 |
test_exec_space_wait<Kokkos::Threads>(success, *out); |
| 163 |
test_make_instance<Kokkos::Threads>(success, *out); |
| 164 |
test_space_instance<Kokkos::Threads>(success, *out); |
| 165 |
test_is_gpu_exec_space<Kokkos::Threads, false>(success, *out); |
| 166 |
#endif |
| 167 |
|
| 168 |
#if defined(KOKKOS_ENABLE_CUDA) |
| 169 |
test_exec_space_wait<Kokkos::Cuda>(success, *out); |
| 170 |
test_make_instance<Kokkos::Cuda>(success, *out); |
| 171 |
test_space_instance<Kokkos::Cuda>(success, *out); |
| 172 |
test_is_gpu_exec_space<Kokkos::Cuda, true>(success, *out); |
| 173 |
#endif |
| 174 |
|
| 175 |
#if defined(KOKKOS_ENABLE_HIP) |
| 176 |
test_exec_space_wait<Kokkos::HIP>(success, *out); |
| 177 |
test_make_instance<Kokkos::HIP>(success, *out); |
| 178 |
test_space_instance<Kokkos::HIP>(success, *out); |
| 179 |
test_is_gpu_exec_space<Kokkos::HIP, true>(success, *out); |
| 180 |
#endif |
| 181 |
|
| 182 |
#if defined(KOKKOS_ENABLE_SYCL) |
| 183 |
test_exec_space_wait<Kokkos::Experimental::SYCL>(success, *out); |
| 184 |
test_make_instance<Kokkos::Experimental::SYCL>(success, *out); |
| 185 |
test_space_instance<Kokkos::Experimental::SYCL>(success, *out); |
| 186 |
test_is_gpu_exec_space<Kokkos::Experimental::SYCL, true>(success, *out); |
| 187 |
#endif |
| 188 |
|
| 189 |
if (success) { |
| 190 |
std::cout << std::endl << "End Result: TEST PASSED" << std::endl; |
| 191 |
} else { |
| 192 |
std::cout << std::endl << "End Result: TEST FAILED" << std::endl; |
| 193 |
} |
| 194 |
|
| 195 |
Teuchos::OSTab tab1(out); |
| 196 |
return 0; |
| 197 |
} |