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