forked from kokkos/kokkos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Kokkos_Error.hpp
133 lines (107 loc) · 3.68 KB
/
Kokkos_Error.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
//@HEADER
// ************************************************************************
//
// Kokkos v. 4.0
// Copyright (2022) National Technology & Engineering
// Solutions of Sandia, LLC (NTESS).
//
// Under the terms of Contract DE-NA0003525 with NTESS,
// the U.S. Government retains certain rights in this software.
//
// Part of Kokkos, under the Apache License v2.0 with LLVM Exceptions.
// See https://kokkos.org/LICENSE for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//@HEADER
#ifndef KOKKOS_IMPL_ERROR_HPP
#define KOKKOS_IMPL_ERROR_HPP
#include <string>
#include <iosfwd>
#include <Kokkos_Macros.hpp>
#include <Kokkos_Abort.hpp>
#include <Kokkos_Assert.hpp>
namespace Kokkos {
namespace Impl {
[[noreturn]] void throw_runtime_exception(const std::string &msg);
void log_warning(const std::string &msg);
std::string human_memory_size(size_t arg_bytes);
} // namespace Impl
namespace Experimental {
class RawMemoryAllocationFailure : public std::bad_alloc {
public:
enum class FailureMode {
OutOfMemoryError,
AllocationNotAligned,
InvalidAllocationSize,
MaximumCudaUVMAllocationsExceeded,
Unknown
};
enum class AllocationMechanism {
StdMalloc,
#ifdef KOKKOS_ENABLE_DEPRECATED_CODE_4
PosixMemAlign KOKKOS_DEPRECATED,
PosixMMap KOKKOS_DEPRECATED,
IntelMMAlloc KOKKOS_DEPRECATED,
#endif
CudaMalloc,
CudaMallocManaged,
CudaHostAlloc,
HIPMalloc,
HIPHostMalloc,
HIPMallocManaged,
SYCLMallocDevice,
SYCLMallocShared,
SYCLMallocHost,
OpenACCMalloc,
};
private:
size_t m_attempted_size;
size_t m_attempted_alignment;
FailureMode m_failure_mode;
AllocationMechanism m_mechanism;
public:
RawMemoryAllocationFailure(
size_t arg_attempted_size, size_t arg_attempted_alignment,
FailureMode arg_failure_mode = FailureMode::OutOfMemoryError,
AllocationMechanism arg_mechanism =
AllocationMechanism::StdMalloc) noexcept
: m_attempted_size(arg_attempted_size),
m_attempted_alignment(arg_attempted_alignment),
m_failure_mode(arg_failure_mode),
m_mechanism(arg_mechanism) {}
RawMemoryAllocationFailure() noexcept = delete;
RawMemoryAllocationFailure(RawMemoryAllocationFailure const &) noexcept =
default;
RawMemoryAllocationFailure(RawMemoryAllocationFailure &&) noexcept = default;
RawMemoryAllocationFailure &operator =(
RawMemoryAllocationFailure const &) noexcept = default;
RawMemoryAllocationFailure &operator =(
RawMemoryAllocationFailure &&) noexcept = default;
~RawMemoryAllocationFailure() noexcept override = default;
[[nodiscard]] const char *what() const noexcept override {
if (m_failure_mode == FailureMode::OutOfMemoryError) {
return "Memory allocation error: out of memory";
} else if (m_failure_mode == FailureMode::AllocationNotAligned) {
return "Memory allocation error: allocation result was under-aligned";
}
return nullptr; // unreachable
}
[[nodiscard]] size_t attempted_size() const noexcept {
return m_attempted_size;
}
[[nodiscard]] size_t attempted_alignment() const noexcept {
return m_attempted_alignment;
}
[[nodiscard]] AllocationMechanism allocation_mechanism() const noexcept {
return m_mechanism;
}
[[nodiscard]] FailureMode failure_mode() const noexcept {
return m_failure_mode;
}
void print_error_message(std::ostream &o) const;
[[nodiscard]] std::string get_error_message() const;
virtual void append_additional_error_information(std::ostream &) const {}
};
} // end namespace Experimental
} // namespace Kokkos
#endif /* #ifndef KOKKOS_IMPL_ERROR_HPP */