Tpetra parallel linear algebra  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Tpetra_Details_ExecutionSpacesUser.hpp
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 #ifndef TPETRA_DETAILS_EXECUTIONSPACESUSER_HPP
11 #define TPETRA_DETAILS_EXECUTIONSPACESUSER_HPP
12 
13 #include <iostream>
14 #include <sstream>
15 #include <vector>
16 
17 #include <Kokkos_Core.hpp>
18 
19 #include "Teuchos_RCP.hpp"
20 
21 #include "Tpetra_Details_ExecutionSpacesSlot.hpp"
22 
23 namespace Tpetra {
24 namespace Details {
25 namespace Spaces {
26 
34 class User {
35 public:
36 #ifdef KOKKOS_ENABLE_CUDA
37 
46  template <typename ExecSpace,
47  Spaces::Priority priority = Spaces::Priority::medium,
48  Spaces::IsCuda<ExecSpace> = true>
49  Teuchos::RCP<const ExecSpace> space_instance() const {
50  return cudaSlot.space_instance<priority>();
51  }
52 
62  template <typename ExecSpace, Spaces::IsCuda<ExecSpace> = true>
63  Teuchos::RCP<const ExecSpace>
64  space_instance(const Spaces::Priority &priority) const {
65  return cudaSlot.space_instance(priority);
66  }
67 #endif // KOKKOS_ENABLE_CUDA
68 
69 #ifdef KOKKOS_ENABLE_SERIAL
70  template <typename ExecSpace,
71  Spaces::Priority priority = Spaces::Priority::medium,
72  Spaces::IsSerial<ExecSpace> = true>
73  Teuchos::RCP<const ExecSpace> space_instance() const {
74  return serialSlot.space_instance<priority>();
75  }
76  template <typename ExecSpace, Spaces::IsSerial<ExecSpace> = true>
77  Teuchos::RCP<const ExecSpace>
78  space_instance(const Spaces::Priority &priority) const {
79  return serialSlot.space_instance(priority);
80  }
81 #endif // KOKKOS_ENABLE_SERIAL
82 
83 #ifdef KOKKOS_ENABLE_OPENMP
84  template <typename ExecSpace,
85  Spaces::Priority priority = Spaces::Priority::medium,
86  Spaces::IsOpenMP<ExecSpace> = true>
87  Teuchos::RCP<const ExecSpace> space_instance() const {
88  return openMPSlot.space_instance<priority>();
89  }
90  template <typename ExecSpace, Spaces::IsOpenMP<ExecSpace> = true>
91  Teuchos::RCP<const ExecSpace>
92  space_instance(const Spaces::Priority &priority) const {
93  return openMPSlot.space_instance(priority);
94  }
95 #endif // KOKKOS_ENABLE_OPENMP
96 
97 #ifdef KOKKOS_ENABLE_HIP
98  template <typename ExecSpace,
99  Spaces::Priority priority = Spaces::Priority::medium,
100  Spaces::IsHIP<ExecSpace> = true>
101  Teuchos::RCP<const ExecSpace> space_instance() const {
102  return HIPSlot.space_instance<priority>();
103  }
104  template <typename ExecSpace, Spaces::IsHIP<ExecSpace> = true>
105  Teuchos::RCP<const ExecSpace>
106  space_instance(const Spaces::Priority &priority) const {
107  return HIPSlot.space_instance(priority);
108  }
109 #endif // KOKKOS_ENABLE_HIP
110 
111 #ifdef KOKKOS_ENABLE_SYCL
112  template <typename ExecSpace,
113  Spaces::Priority priority = Spaces::Priority::medium,
114  Spaces::IsSYCL<ExecSpace> = true>
115  Teuchos::RCP<const ExecSpace> space_instance() const {
116  return SYCLSlot.space_instance<priority>();
117  }
118  template <typename ExecSpace, Spaces::IsSYCL<ExecSpace> = true>
119  Teuchos::RCP<const ExecSpace>
120  space_instance(const Spaces::Priority &priority) const {
121  return SYCLSlot.space_instance(priority);
122  }
123 #endif // KOKKOS_ENABLE_SYCL
124 
125 #ifdef KOKKOS_ENABLE_SERIAL
126  Slot<Kokkos::Serial> serialSlot;
127 #endif
128 #ifdef KOKKOS_ENABLE_OPENMP
129  Slot<Kokkos::OpenMP> openMPSlot;
130 #endif
131 #ifdef KOKKOS_ENABLE_CUDA
132  Slot<Kokkos::Cuda> cudaSlot;
133 #endif
134 #ifdef KOKKOS_ENABLE_HIP
135  Slot<Kokkos::HIP> HIPSlot;
136 #endif
137 #ifdef KOKKOS_ENABLE_SYCL
139 #endif
140 
141 }; // User
142 } // namespace Spaces
143 } // namespace Details
144 } // namespace Tpetra
145 
146 #endif // TPETRA_DETAILS_EXECUTIONSPACESUSER_HPP
A class can inherit from this if it wants to use Tpetra managed spaces.
Lazily acquires and stores Kokkos Execution Spaces.