DDC 0.11.0
Loading...
Searching...
No Matches
discrete_space.cpp
1// Copyright (C) The DDC development team, see COPYRIGHT.md file
2//
3// SPDX-License-Identifier: MIT
4
5#include <functional>
6#include <map>
7#include <optional>
8#include <ostream>
9#include <string>
10
11#include <Kokkos_Macros.hpp>
12
13#if defined(KOKKOS_ENABLE_CUDA)
14# include <sstream>
15
16# include <cuda.h>
17#elif defined(KOKKOS_ENABLE_HIP)
18# include <sstream>
19
20# include <hip/hip_runtime.h>
21#endif
22
23namespace ddc::detail {
24
25#if defined(KOKKOS_ENABLE_CUDA)
26void device_throw_on_error(
27 cudaError_t const err,
28 const char* const func,
29 const char* const file,
30 const int line)
31{
32 if (err != cudaSuccess) {
33 std::stringstream ss;
34 ss << "CUDA Runtime Error at: " << file << ":" << line << "\n";
35 ss << cudaGetErrorString(err) << " " << func << "\n";
36 throw std::runtime_error(ss.str());
37 }
38}
39#elif defined(KOKKOS_ENABLE_HIP)
40void device_throw_on_error(
41 hipError_t const err,
42 const char* const func,
43 const char* const file,
44 const int line)
45{
46 if (err != hipSuccess) {
47 std::stringstream ss;
48 ss << "HIP Runtime Error at: " << file << ":" << line << "\n";
49 ss << hipGetErrorString(err) << " " << func << "\n";
50 throw std::runtime_error(ss.str());
51 }
52}
53#endif
54
55// Global CPU variable storing resetters. Required to correctly free data.
56std::optional<std::map<std::string, std::function<void()>>> g_discretization_store;
57
58void display_discretization_store(std::ostream& os)
59{
60 if (g_discretization_store) {
61 os << "The host discretization store is initialized:\n";
62 for (auto const& [key, value] : *g_discretization_store) {
63 os << " - " << key << "\n";
64 }
65 } else {
66 os << "The host discretization store is not initialized:\n";
67 }
68}
69
70} // namespace ddc::detail
The top-level namespace of DDC.