Realm
A distributed, event-based tasking library
Loading...
Searching...
No Matches
memory.h
Go to the documentation of this file.
1/*
2 * Copyright 2025 Stanford University, NVIDIA Corporation
3 * SPDX-License-Identifier: Apache-2.0
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18// memorys for Realm
19
20#ifndef REALM_MEMORY_H
21#define REALM_MEMORY_H
22
23#include "realm/realm_c.h"
24
25#include <stddef.h>
26#include <iostream>
27#include <functional>
28
29namespace Realm {
30
32
34 public:
37
38 Memory() = default;
39 constexpr explicit Memory(id_t id)
40 : id(id)
41 {}
42
43 constexpr operator id_t() const { return id; }
44
45 bool operator<(const Memory &rhs) const { return id < rhs.id; }
46 bool operator==(const Memory &rhs) const { return id == rhs.id; }
47 bool operator!=(const Memory &rhs) const { return id != rhs.id; }
48
49 static const Memory NO_MEMORY;
50
51 bool exists(void) const { return id != 0; }
52
53 // Return the address space for this memory
55
56 // Different Memory types (defined in realm_c.h)
57 // can't just typedef the kind because of C/C++ enum scope rules
58 enum Kind
59 {
60#define C_ENUMS(name, desc) name,
62#undef C_ENUMS
63 };
64
65 // Return what kind of memory this is
66 Kind kind(void) const;
67 // Return the maximum capacity of this memory
68 size_t capacity(void) const;
69
70 // reports a problem with a memory in general (this is primarily for fault injection)
71 void report_memory_fault(int reason, const void *reason_data,
72 size_t reason_size) const;
73 };
74
75 inline std::ostream &operator<<(std::ostream &os, Memory m)
76 {
77 return os << std::hex << m.id << std::dec;
78 }
79
80 inline std::ostream &operator<<(std::ostream &os, Memory::Kind kind)
81 {
82#define STRING_KIND_CASE(kind, desc) \
83 case Memory::Kind::kind: \
84 return os << #kind;
85 switch(kind) {
87 }
88#undef STRING_KIND_CASE
89 return os << "UNKNOWN_KIND";
90 }
91
92}; // namespace Realm
93
94template <>
95struct std::hash<Realm::Memory> {
96 std::size_t operator()(const Realm::Memory &m) const noexcept
97 {
98 return std::hash<realm_id_t>()(m.id);
99 }
100};
101
102 // include "memory.inl"
103
104#endif // ifndef REALM_MEMORY_H
Definition memory.h:33
Kind kind(void) const
void report_memory_fault(int reason, const void *reason_data, size_t reason_size) const
bool operator<(const Memory &rhs) const
Definition memory.h:45
Kind
Definition memory.h:59
bool operator!=(const Memory &rhs) const
Definition memory.h:47
id_t id
Definition memory.h:36
static const Memory NO_MEMORY
Definition memory.h:49
AddressSpace address_space(void) const
bool exists(void) const
Definition memory.h:51
Memory()=default
constexpr Memory(id_t id)
Definition memory.h:39
::realm_id_t id_t
Definition memory.h:35
size_t capacity(void) const
bool operator==(const Memory &rhs) const
Definition memory.h:46
#define REALM_PUBLIC_API
Definition compiler_support.h:217
#define STRING_KIND_CASE(kind, desc)
#define C_ENUMS(name, desc)
Definition memory.h:60
Definition activemsg.h:38
::realm_address_space_t AddressSpace
Definition memory.h:31
std::ostream & operator<<(std::ostream &os, const DenseRectangleList< N, T > &drl)
#define REALM_MEMORY_KINDS(__op__)
Definition realm_c.h:248
unsigned long long realm_id_t
Definition realm_c.h:64
unsigned int realm_address_space_t
Definition realm_c.h:72
#define REALM_NO_MEM
Definition realm_c.h:166
std::size_t operator()(const Realm::Memory &m) const noexcept
Definition memory.h:96