Ginkgo: ginkgo/core/base/scoped_device_id_guard.hpp Source File

| Ginkgo Generated from branch based on main. Ginkgo version 1.11.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
76 class scoped_device_id_guard {
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.
131 scoped_device_id_guard(const scoped_device_id_guard&) = delete;
132
133 // Allow move construction.
134 // These are needed, since C++14 does not guarantee copy elision.
135 scoped_device_id_guard(scoped_device_id_guard&&) = default;
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_
gko::CudaExecutor
This is the Executor subclass which represents the CUDA device.
Definition executor.hpp:1542
gko::DpcppExecutor
This is the Executor subclass which represents a DPC++ enhanced device.
Definition executor.hpp:2004
gko::HipExecutor
This is the Executor subclass which represents the HIP enhanced device.
Definition executor.hpp:1787
gko::OmpExecutor
This is the Executor subclass which represents the OpenMP device (typically CPU).
Definition executor.hpp:1387
gko::ReferenceExecutor
This is a specialization of the OmpExecutor, which runs the reference implementations of the kernels ...
Definition executor.hpp:1468
gko::scoped_device_id_guard::scoped_device_id_guard
scoped_device_id_guard(const DpcppExecutor *exec, int device_id)
Create a scoped device id from an DpcppExecutor.
gko::scoped_device_id_guard::scoped_device_id_guard
scoped_device_id_guard(const OmpExecutor *exec, int device_id)
Create a scoped device id from an OmpExecutor.
gko::scoped_device_id_guard::scoped_device_id_guard
scoped_device_id_guard(const HipExecutor *exec, int device_id)
Create a scoped device id from an HipExecutor.
gko::scoped_device_id_guard::scoped_device_id_guard
scoped_device_id_guard(const CudaExecutor *exec, int device_id)
Create a scoped device id from an CudaExecutor.
gko::scoped_device_id_guard::scoped_device_id_guard
scoped_device_id_guard(const ReferenceExecutor *exec, int device_id)
Create a scoped device id from an Reference.
gko
The Ginkgo namespace.
Definition abstract_factory.hpp:20