Ginkgo Generated from branch based on main. Ginkgo version 1.9.0
A numerical linear algebra library targeting many-core architectures
Loading...
Searching...
No Matches
scoped_device_id_guard.hpp
1// SPDX-FileCopyrightText: 2017 - 2024 The Ginkgo authors
2//
3// SPDX-License-Identifier: BSD-3-Clause
4
5#ifndef GKO_PUBLIC_CORE_BASE_SCOPED_DEVICE_ID_GUARD_HPP_
6#define GKO_PUBLIC_CORE_BASE_SCOPED_DEVICE_ID_GUARD_HPP_
7
8
9#include <memory>
10
11
12namespace gko {
13
14
15class OmpExecutor;
16class ReferenceExecutor;
17class CudaExecutor;
18class HipExecutor;
19class DpcppExecutor;
20
21
22namespace detail {
23
24
29class generic_scoped_device_id_guard {
30public:
31 generic_scoped_device_id_guard() = default;
32
33 // TODO: this should be a purely virtual function, but somehow that leads to
34 // linker errors
35 virtual ~generic_scoped_device_id_guard() = default;
36
37 // Prohibit copy construction
38 generic_scoped_device_id_guard(
39 const generic_scoped_device_id_guard& other) = delete;
40
41 // Prohibit copy assignment
42 generic_scoped_device_id_guard& operator=(
43 const generic_scoped_device_id_guard& other) = delete;
44};
45
46
47} // namespace detail
48
49
77public:
86 scoped_device_id_guard(const ReferenceExecutor* exec, int device_id);
87
96 scoped_device_id_guard(const OmpExecutor* exec, int device_id);
97
106 scoped_device_id_guard(const CudaExecutor* exec, int device_id);
107
116 scoped_device_id_guard(const HipExecutor* exec, int device_id);
117
126 scoped_device_id_guard(const DpcppExecutor* exec, int device_id);
127
128 scoped_device_id_guard() = default;
129
130 // Prohibit copy construction.
132
133 // Allow move construction.
134 // These are needed, since C++14 does not guarantee copy elision.
136
137 // Prohibit copy assignment.
138 scoped_device_id_guard& operator=(const scoped_device_id_guard&) = delete;
139
140 // Allow move construction.
141 // These are needed, since C++14 does not guarantee copy elision.
142 scoped_device_id_guard& operator=(scoped_device_id_guard&&) = default;
143
144 ~scoped_device_id_guard() = default;
145
146private:
147 std::unique_ptr<detail::generic_scoped_device_id_guard> scope_;
148};
149
150
151} // namespace gko
152
153#endif // GKO_PUBLIC_CORE_BASE_SCOPED_DEVICE_ID_GUARD_HPP_
This is the Executor subclass which represents the CUDA device.
Definition executor.hpp:1542
This is the Executor subclass which represents a DPC++ enhanced device.
Definition executor.hpp:1996
This is the Executor subclass which represents the HIP enhanced device.
Definition executor.hpp:1779
This is the Executor subclass which represents the OpenMP device (typically CPU).
Definition executor.hpp:1387
This is a specialization of the OmpExecutor, which runs the reference implementations of the kernels ...
Definition executor.hpp:1468
This move-only class uses RAII to set the device id within a scoped block, if necessary.
Definition scoped_device_id_guard.hpp:76
scoped_device_id_guard(const DpcppExecutor *exec, int device_id)
Create a scoped device id from an DpcppExecutor.
scoped_device_id_guard(const OmpExecutor *exec, int device_id)
Create a scoped device id from an OmpExecutor.
scoped_device_id_guard(const HipExecutor *exec, int device_id)
Create a scoped device id from an HipExecutor.
scoped_device_id_guard(const CudaExecutor *exec, int device_id)
Create a scoped device id from an CudaExecutor.
scoped_device_id_guard(const ReferenceExecutor *exec, int device_id)
Create a scoped device id from an Reference.
The Ginkgo namespace.
Definition abstract_factory.hpp:20