13 #include <source_location>
15 #include <type_traits>
19 #include <cuda_runtime_api.h>
28 #define RAPIDSMPF_CUDA_VERSION_AT_LEAST(version) (CUDART_VERSION >= version)
31 using Clock = std::chrono::high_resolution_clock;
33 using Duration = std::chrono::duration<double>;
35 using TimePoint = std::chrono::time_point<Clock, Duration>;
49 template <
typename MapType>
50 std::pair<typename MapType::key_type, typename MapType::mapped_type>
extract_item(
51 MapType& map,
typename MapType::const_iterator position
53 auto node = map.extract(position);
55 throw std::out_of_range(
"Invalid iterator passed to extract");
57 return {std::move(node.key()), std::move(node.mapped())};
70 template <
typename MapType>
71 std::pair<typename MapType::key_type, typename MapType::mapped_type>
extract_item(
72 MapType& map,
typename MapType::key_type
const& key
74 auto node = map.extract(key);
76 throw std::out_of_range(
"Invalid key passed to extract");
78 return {std::move(node.key()), std::move(node.mapped())};
92 template <
typename MapType>
94 MapType& map,
typename MapType::key_type
const& key
112 template <
typename MapType>
114 MapType& map,
typename MapType::const_iterator position
129 template <
typename MapType>
131 MapType& map,
typename MapType::key_type
const& key
148 template <
typename MapType>
150 MapType& map,
typename MapType::const_iterator position
165 template <
typename MapType>
167 using ValueType =
typename std::remove_reference_t<MapType>::mapped_type;
168 std::vector<ValueType> vec;
169 vec.reserve(map.size());
170 for (
auto&& [key, value] : map) {
171 vec.push_back(std::move(value));
191 template <
typename T>
193 return (y == 0) ? 0 : x / y;
197 #define RAPIDSMPF_CONCAT_DETAIL_(x, y) x##y
198 #define RAPIDSMPF_CONCAT(x, y) RAPIDSMPF_CONCAT_DETAIL_(x, y)
201 #define RAPIDSMPF_STRINGIFY_DETAIL_(x) #x
202 #define RAPIDSMPF_STRINGIFY(x) RAPIDSMPF_STRINGIFY_DETAIL_(x)
220 #define RAPIDSMPF_OVERLOAD_BY_ARG_COUNT(_1, _2, NAME, ...) NAME
233 template <
typename T>
239 template <
typename T>
241 return std::addressof(ptr);
245 template <
typename T>
251 template <
typename T>
259 template <
class... Ts>
261 using Ts::operator()...;
280 template <std::ranges::input_range R,
typename T,
typename Proj = std::
identity>
281 [[nodiscard]] constexpr
bool contains(R&& range, T
const& value, Proj proj = {}) {
282 for (
auto const& elem : range) {
283 if (std::invoke(proj, elem) == value) {
309 template <
typename To,
typename From>
310 requires std::is_arithmetic_v<To> && std::is_arithmetic_v<From>
312 From value, std::source_location
const& loc = std::source_location::current()
314 if constexpr (std::is_same_v<From, To>) {
317 }
else if constexpr (std::is_integral_v<From> && std::is_integral_v<To>) {
319 if (!std::in_range<To>(value)) {
320 throw std::overflow_error(
321 "RapidsMPF cast error at: " + std::string(loc.file_name()) +
":"
322 + std::to_string(loc.line()) +
", value out of range"
325 return static_cast<To
>(value);
328 return static_cast<To
>(value);
constexpr T * to_pointer(T *ptr) noexcept
Returns the raw pointer from a pointer, reference, or smart pointer.
RAPIDS Multi-Processor interfaces.
std::chrono::duration< double > Duration
Alias for a duration type representing time in seconds as a double.
std::chrono::time_point< Clock, Duration > TimePoint
Alias for a time point with double precision in seconds.
MapType::mapped_type extract_value(MapType &map, typename MapType::key_type const &key)
Extracts the value associated with a specific key from a map, removing the key-value pair.
MapType::key_type extract_key(MapType &map, typename MapType::key_type const &key)
Extracts a key from a map, removing the key-value pair.
bool is_running_under_valgrind()
Checks whether the application is running under Valgrind.
std::pair< typename MapType::key_type, typename MapType::mapped_type > extract_item(MapType &map, typename MapType::const_iterator position)
Extracts a key-value pair from a map, removing it from the map.
constexpr T safe_div(T x, T y)
Performs safe division, returning 0 if the denominator is zero.
std::chrono::high_resolution_clock Clock
Alias for high-resolution clock from the chrono library.
constexpr bool contains(R &&range, T const &value, Proj proj={})
Backport of std::ranges::contains from C++23 for C++20.
requires std::is_arithmetic_v< To > &&constexpr std::is_arithmetic_v< From > To safe_cast(From value, std::source_location const &loc=std::source_location::current())
Safely casts a numeric value to another type with overflow checking.
auto to_vector(MapType &&map)
Converts a map-like associative container to a vector by moving the values and discarding the keys.
Helper for overloaded lambdas using std::visit.