rexlib 0.1.0
Device-agnostic array computing library for CryoEM and CryoET image processing, with a pluggable backend architecture
Loading...
Searching...
No Matches
device_index.hpp
1// SPDX-License-Identifier: GPL-3.0-only
2
3#pragma once
4
5#include "../platform/constexpr.hpp"
6#include "../platform/dynamic_shared_object.h"
7
8#include <string>
9#include <ostream>
10
11namespace rexlib
12{
13
25{
26public:
36 REXLIB_API
37 device_index(const std::string &backend_name, std::size_t device_id);
38
48 REXLIB_API
49 device_index(std::string &&backend_name, std::size_t device_id);
50
51 REXLIB_API
52 device_index() noexcept;
53 REXLIB_API
54 device_index(const device_index &other);
55 REXLIB_API
56 device_index(device_index &&other) noexcept;
57 REXLIB_API
58 ~device_index();
59
60 REXLIB_API
61 device_index& operator=(const device_index &other);
62 REXLIB_API
63 device_index& operator=(device_index &&other) noexcept;
64
72 REXLIB_API
73 const std::string& get_backend_name() const noexcept;
74
82 REXLIB_API
83 std::size_t get_device_id() const noexcept;
84
85 friend bool
86 operator==(const device_index &lhs, const device_index &rhs) noexcept
87 {
88 return lhs.get_device_id() == rhs.get_device_id() &&
89 lhs.get_backend_name() == rhs.get_backend_name();
90 }
91
92 friend bool
93 operator!=(const device_index &lhs, const device_index &rhs) noexcept
94 {
95 return lhs.get_device_id() != rhs.get_device_id() ||
96 lhs.get_backend_name() != rhs.get_backend_name();
97 }
98
99 friend bool
100 operator<(const device_index &lhs, const device_index &rhs) noexcept
101 {
102 if (lhs.get_backend_name() < rhs.get_backend_name())
103 {
104 return true;
105 }
106 else if(lhs.get_backend_name() == rhs.get_backend_name())
107 {
108 return lhs.get_device_id() < rhs.get_device_id();
109 }
110 return false;
111 }
112
113 friend bool
114 operator<=(const device_index &lhs, const device_index &rhs) noexcept
115 {
116 if (lhs.get_backend_name() < rhs.get_backend_name())
117 {
118 return true;
119 }
120 else if(lhs.get_backend_name() == rhs.get_backend_name())
121 {
122 return lhs.get_device_id() <= rhs.get_device_id();
123 }
124 return false;
125 }
126
127 friend bool
128 operator>(const device_index &lhs, const device_index &rhs) noexcept
129 {
130 return rhs < lhs;
131 }
132
133 friend bool
134 operator>=(const device_index &lhs, const device_index &rhs) noexcept
135 {
136 return rhs <= lhs;
137 }
138
139 friend std::ostream&
140 operator<<(std::ostream &os, const device_index &index)
141 {
142 return os << index.get_backend_name() << ':' << index.get_device_id();
143 }
144
145private:
146 std::string m_backend_name;
147 std::size_t m_device_id;
148};
149
162REXLIB_API
163bool parse_device_index(const std::string &text, device_index &result);
164
165} // namespace rexlib
Location of a device as a (backend, id) tuple.
Definition device_index.hpp:25
device_index(const std::string &backend_name, std::size_t device_id)
Construct a new device index from its components.
const std::string & get_backend_name() const noexcept
Get the name of the device backend.
device_index(std::string &&backend_name, std::size_t device_id)
Construct a new device index from its components.
std::size_t get_device_id() const noexcept
Get the ID of the device within the backend.
Arrays, the operations on them and the devices that run those operations.
Definition cpu_device.hpp:10
bool parse_device_index(const std::string &text, device_index &result)
Parse the device ID from a string.