Realm
A distributed, event-based tasking library
Loading...
Searching...
No Matches
runtime.h
Go to the documentation of this file.
1/*
2 * Copyright 2026 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// Realm runtime object
19
20#ifndef REALM_RUNTIME_H
21#define REALM_RUNTIME_H
22
23#include "realm/processor.h"
24#include "realm/redop.h"
25#include "realm/custom_serdez.h"
26#include "realm/module_config.h"
27
28namespace Realm {
29
30 class Module;
31
33 protected:
34 void *impl; // hidden internal implementation - this is NOT a transferrable handle
35
36 public:
37 Runtime(void);
38 Runtime(const Runtime &r)
39 : impl(r.impl)
40 {}
42 {
43 impl = r.impl;
44 return *this;
45 }
46
47 ~Runtime(void) {}
48
49 static Runtime get_runtime(void);
50
51 // returns a valid (but possibly empty) string pointer describing the
52 // version of the Realm library - this can be compared against
53 // REALM_VERSION in application code to detect a header/library mismatch
54 static const char *get_library_version();
55
56 // performs any network initialization and, critically, makes sure
57 // *argc and *argv contain the application's real command line
58 // (instead of e.g. mpi spawner information)
59 bool network_init(int *argc, char ***argv);
82 const void *vtable_data;
85 // REQUIRED FUNCTIONS //
87
97 bool (*put)(const void *key, size_t key_size, const void *value, size_t value_sizem,
98 const void *vtable_data, size_t vtable_data_size) = nullptr;
118 bool (*get)(const void *key, size_t key_size, void *value, size_t *value_size,
119 const void *vtable_data, size_t vtable_data_size) = nullptr;
121 // SYNCRONIZATION FUNCTIONS //
122 // (PROVIDE ONE OR BOTH) //
124 // For the synchronization callbacks you can provide one or both
125 // functions. All three combinations correspond to different use cases.
126 // * Providing only "bar": this is an inelastic job with a fixed
127 // universe of processes that will never change.
128 // * Providing only "cas": this is an elastic job with processes
129 // that will come and go one at a time.
130 // * Providing both: this is an elastic job with processes that
131 // will come and go as groups. Groups of processes must both
132 // join and leave together.
160 inline static constexpr std::string_view group_key = "realm_group";
161 inline static constexpr std::string_view rank_key = "realm_rank";
162 inline static constexpr std::string_view ranks_key = "realm_ranks";
163 bool (*bar)(const void *vtable_data, size_t vtable_data_size) = nullptr;
182 bool (*cas)(const void *key, size_t key_size, void *expected, size_t *expected_size,
183 const void *desired, size_t desired_size, const void *vtable_data,
184 size_t vtable_data_size) = nullptr;
185 };
187
188 void parse_command_line(int argc, char **argv);
189 void parse_command_line(std::vector<std::string> &cmdline,
190 bool remove_realm_args = false);
191
193
194 // configures the runtime from the provided command line - after this
195 // call it is possible to create user events/reservations/etc,
196 // perform registrations and query the machine model, but not spawn
197 // tasks or create instances
198 bool configure_from_command_line(int argc, char **argv);
199 bool configure_from_command_line(std::vector<std::string> &cmdline,
200 bool remove_realm_args = false);
201
202 // starts up the runtime, allowing task/instance creation
203 void start(void);
204
205 // single-call version of the above three calls
206 bool init(int *argc, char ***argv);
207
208 // this is now just a wrapper around Processor::register_task - consider switching to
209 // that
210 bool register_task(Processor::TaskFuncID taskid, Processor::TaskFuncPtr taskptr);
211
213 const ReductionOpUntyped *redop);
215 {
216 Event event = Event::NO_EVENT;
217 if(register_reduction(event, redop_id, redop)) {
218 event.wait();
219 return true;
220 }
221 return false;
222 }
223 template <typename REDOP>
225 {
226 const ReductionOp<REDOP> redop;
227 return register_reduction(redop_id, &redop);
228 }
229 template <typename REDOP>
231 {
232 const ReductionOp<REDOP> redop;
233 return register_reduction(redop_id, &redop);
234 }
235
237 const CustomSerdezUntyped *serdez);
238 template <typename SERDEZ>
240 {
241 const CustomSerdezWrapper<SERDEZ> serdez;
242 return register_custom_serdez(serdez_id, &serdez);
243 }
244
246 const void *args, size_t arglen,
247 Event wait_on = Event::NO_EVENT, int priority = 0);
248
250 Processor::TaskFuncID task_id, const void *args,
251 size_t arglen, bool one_per_node = false,
252 Event wait_on = Event::NO_EVENT, int priority = 0);
253
254 // there are three potentially interesting ways to start the initial
255 // tasks:
257 {
258 ONE_TASK_ONLY, // a single task on a single node of the machine
259 ONE_TASK_PER_NODE, // one task running on one proc of each node
260 ONE_TASK_PER_PROC, // a task for every processor in the machine
261 };
262
263 REALM_ATTR_DEPRECATED("use collective_spawn calls instead",
264 void run(Processor::TaskFuncID task_id = 0,
265 RunStyle style = ONE_TASK_ONLY, const void *args = 0,
266 size_t arglen = 0, bool background = false));
267
268 // requests a shutdown of the runtime
269 void shutdown(Event wait_on = Event::NO_EVENT, int result_code = 0);
270
271 // returns the result_code passed to shutdown()
273
274 // called before runtime::init to create module configs for users to configure realm
275 bool create_configs(int argc, char **argv);
276
277 // return the configuration of a specific module
278 ModuleConfig *get_module_config(const std::string &name) const;
279 // modules in Realm may offer extra capabilities specific to certain kinds
280 // of hardware or software - to get access, you'll want to know the name
281 // of the module and it's C++ type (both should be found in the module's
282 // header file - this function will return a null pointer if the module
283 // isn't present or if the expected and actual types mismatch
284 template <typename T>
285 T *get_module(const char *name)
286 {
287 Module *mod = get_module_untyped(name);
288 if(mod)
289 return dynamic_cast<T *>(mod);
290 else
291 return 0;
292 }
293
294 protected:
295 Module *get_module_untyped(const char *name);
296 };
297
298}; // namespace Realm
299
300 // include "runtime.inl"
301
302#endif // ifndef REALM_RUNTIME_H
Definition custom_serdez.h:150
Definition custom_serdez.h:192
Definition event.h:50
void wait(void) const
Definition module_config.h:32
Definition module.h:42
Definition processor.h:37
Kind
Definition processor.h:65
::realm_task_func_id_t TaskFuncID
Definition processor.h:58
Definition runtime.h:32
RunStyle
Definition runtime.h:257
@ ONE_TASK_PER_NODE
Definition runtime.h:259
@ ONE_TASK_ONLY
Definition runtime.h:258
@ ONE_TASK_PER_PROC
Definition runtime.h:260
bool configure_from_command_line(std::vector< std::string > &cmdline, bool remove_realm_args=false)
bool register_reduction(Event &event, ReductionOpID redop_id, const ReductionOpUntyped *redop)
void * impl
Definition runtime.h:34
bool register_reduction(ReductionOpID redop_id, const ReductionOpUntyped *redop)
Definition runtime.h:214
void parse_command_line(std::vector< std::string > &cmdline, bool remove_realm_args=false)
static Runtime get_runtime(void)
bool init(int *argc, char ***argv)
bool register_task(Processor::TaskFuncID taskid, Processor::TaskFuncPtr taskptr)
static const char * get_library_version()
Module * get_module_untyped(const char *name)
~Runtime(void)
Definition runtime.h:47
void shutdown(Event wait_on=Event::NO_EVENT, int result_code=0)
bool register_custom_serdez(CustomSerdezID serdez_id)
Definition runtime.h:239
void parse_command_line(int argc, char **argv)
Runtime(const Runtime &r)
Definition runtime.h:38
bool register_custom_serdez(CustomSerdezID serdez_id, const CustomSerdezUntyped *serdez)
int wait_for_shutdown(void)
bool register_reduction(ReductionOpID redop_id)
Definition runtime.h:224
bool create_configs(int argc, char **argv)
T * get_module(const char *name)
Definition runtime.h:285
Runtime & operator=(const Runtime &r)
Definition runtime.h:41
bool configure_from_command_line(int argc, char **argv)
bool network_init(const KeyValueStoreVtable &vtable)
Event collective_spawn_by_kind(Processor::Kind target_kind, Processor::TaskFuncID task_id, const void *args, size_t arglen, bool one_per_node=false, Event wait_on=Event::NO_EVENT, int priority=0)
REALM_ATTR_DEPRECATED("use collective_spawn calls instead", void run(Processor::TaskFuncID task_id=0, RunStyle style=ONE_TASK_ONLY, const void *args=0, size_t arglen=0, bool background=false))
void start(void)
Event collective_spawn(Processor target_proc, Processor::TaskFuncID task_id, const void *args, size_t arglen, Event wait_on=Event::NO_EVENT, int priority=0)
bool register_reduction(Event &event, ReductionOpID redop_id)
Definition runtime.h:230
void finish_configure(void)
bool network_init(int *argc, char ***argv)
ModuleConfig * get_module_config(const std::string &name) const
#define REALM_PUBLIC_API
Definition compiler_support.h:217
Definition activemsg.h:38
int CustomSerdezID
Definition custom_serdez.h:148
::realm_reduction_op_id_t ReductionOpID
Definition event.h:38
Definition redop.h:56
Definition redop.h:274
const void * vtable_data
Definition runtime.h:82
size_t vtable_data_size
Definition runtime.h:83