Debian Codegraph @

packages/tpetra/core/test/Spaces/SpaceUser.cpp

raw
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_ExecutionSpacesUser.hpp>
14
15 /*! \file SpaceUser.cpp
16 \brief Make sure SpaceUser compiles and doesn't crash
17 */
18
19 namespace { // (anonymous)
20
21 template <typename ExecSpace> struct S : public Tpetra::Details::Spaces::User {
22
23 static constexpr size_t B = size_t(1024) * size_t(1024) * size_t(1024);
24
25 void priority() const {
26 auto e1 =
27 space_instance<ExecSpace, Tpetra::Details::Spaces::Priority::low>();
28 auto e2 =
29 space_instance<ExecSpace, Tpetra::Details::Spaces::Priority::medium>();
30 auto e3 =
31 space_instance<ExecSpace, Tpetra::Details::Spaces::Priority::high>();
32 auto e4 = space_instance<ExecSpace>(Tpetra::Details::Spaces::Priority::low);
33 auto e5 =
34 space_instance<ExecSpace>(Tpetra::Details::Spaces::Priority::medium);
35 auto e6 =
36 space_instance<ExecSpace>(Tpetra::Details::Spaces::Priority::high);
37 }
38
39 // request the same instance 1B times should be pretty quick
40 void reuse() const {
41 for (size_t i = 0; i < B; ++i) {
42 auto e1 =
43 space_instance<ExecSpace, Tpetra::Details::Spaces::Priority::low>();
44 }
45 }
46
47 }; // S
48
49 template <typename ExecutionSpace>
50 void test_priority(bool &success, Teuchos::FancyOStream &out) {
51 S<ExecutionSpace>().priority();
52 success = true;
53 }
54
55 template <typename ExecutionSpace>
56 void test_reuse(bool &success, Teuchos::FancyOStream &out) {
57 S<ExecutionSpace>().reuse();
58 success = true;
59 }
60
61 } // namespace
62
63 int main(int argc, char **argv) {
64 Tpetra::ScopeGuard sg(&argc, &argv);
65
66 bool success = false;
67 auto out = Teuchos::fancyOStream (Teuchos::rcpFromRef (std::cout));
68 *out << "Test SpaceUser" << std::endl;
69
70 #if defined(KOKKOS_ENABLE_SERIAL)
71 test_priority<Kokkos::Serial>(success, *out);
72 test_reuse<Kokkos::Serial>(success, *out);
73 #endif
74
75 #if defined(KOKKOS_ENABLE_OPENMP)
76 test_priority<Kokkos::OpenMP>(success, *out);
77 test_reuse<Kokkos::OpenMP>(success, *out);
78 #endif
79
80 #if defined(KOKKOS_ENABLE_THREADS)
81 test_priority<Kokkos::Threads>(success, *out);
82 test_reuse<Kokkos::Threads>(success, *out);
83 #endif
84
85 #if defined(KOKKOS_ENABLE_CUDA)
86 test_priority<Kokkos::Cuda>(success, *out);
87 test_reuse<Kokkos::Cuda>(success, *out);
88 #endif
89
90 #if defined(KOKKOS_ENABLE_HIP)
91 test_priority<Kokkos::HIP>(success, *out);
92 test_reuse<Kokkos::HIP>(success, *out);
93 #endif
94
95 #if defined(KOKKOS_ENABLE_SYCL)
96 test_priority<Kokkos::Experimental::SYCL>(success, *out);
97 test_reuse<Kokkos::Experimental::SYCL>(success, *out);
98 #endif
99
100 if (success) {
101 std::cout << std::endl << "End Result: TEST PASSED" << std::endl;
102 } else {
103 std::cout << std::endl << "End Result: TEST FAILED" << std::endl;
104 }
105
106 Teuchos::OSTab tab1(out);
107 return 0;
108 }