Realm
A distributed, event-based tasking library
Loading...
Searching...
No Matches
module.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// Realm modules
19
20#ifndef REALM_MODULE_H
21#define REALM_MODULE_H
22
23#include "realm/realm_config.h"
24#include "realm/module_config.h"
25
26// to provide Realm functionality via the module interface, you need to:
27//
28// 1) define a subclass of Realm::Module, implementing all the methods
29// 2) include the following in your .cc file:
30// REGISTER_REALM_MODULE(YourModuleClassName);
31// 3) add your module to REALM_MODULES in the Makefile
32
33#include <vector>
34#include <string>
35#include <map>
36
37namespace Realm {
38
39 class RuntimeImpl;
40 class NetworkModule;
41
43 protected:
44 // can only construct subclasses of Module
45 Module(const std::string &_name);
46
47 public:
48 virtual ~Module(void);
49
50 const std::string &get_name(void) const;
51
52 // all subclasses should define this (static) method - its responsibilities are:
53 // 1) parse command line arguments in 'cmdline', removing any recognized arguments
54 // 2) do any necessary system discovery
55 // 3) do NOT actually allocate any resources yet
56 // 4) register machine notification callbacks, if desired
57 // 5) create an instance of a Module subclass and return it
58 //
59 // if the module cannot possibly be used in the current run (e.g. the CUDA module when
60 // no GPUs are present), 'create_module' can just return a null pointer
61 //
62 // static Module *create_module(RuntimeImpl *runtime, std::vector<std::string>&
63 // cmdline);
64
65 // do any general initialization - this is called after all configuration is
66 // complete
67 virtual void initialize(RuntimeImpl *runtime);
68
69 // create any memories provided by this module (default == do nothing)
70 // (each new MemoryImpl should use a Memory from RuntimeImpl::next_local_memory_id)
71 virtual void create_memories(RuntimeImpl *runtime);
72
73 // create any processors provided by the module (default == do nothing)
74 // (each new ProcessorImpl should use a Processor from
75 // RuntimeImpl::next_local_processor_id)
76 virtual void create_processors(RuntimeImpl *runtime);
77
78 // create any DMA channels provided by the module (default == do nothing)
79 virtual void create_dma_channels(RuntimeImpl *runtime);
80
81 // create any code translators provided by the module (default == do nothing)
82 virtual void create_code_translators(RuntimeImpl *runtime);
83
84 // if a module has to do cleanup that involves sending messages to other
85 // nodes, this must be done in the pre-detach cleanup
86 virtual void pre_detach_cleanup(void);
87
88 // clean up any common resources created by the module - this will be called
89 // after all memories/processors/etc. have been shut down and destroyed
90 virtual void cleanup(void);
91
92 protected:
93 std::string name;
94 };
95
96 // module-specific information can be attached to processors/memories/etc.
97 // as a sort of "mix-in", providing module-specific data and/or methods
98 // finding module-specific info is based on knowing the type and finding it
99 // via dynamic casts
107
108 // helper class for module registration - supports modules compiled in statically
109 // and the other for dynamically-loaded modules
110
112 public:
114
115 // called by the runtime during init - these may change the command line!
116 void create_network_modules(std::vector<NetworkModule *> &modules, int *argc,
117 const char ***argv);
118
119 // called by the runtime during init
120 void create_static_modules(std::vector<Module *> &modules);
121
122 // called by the runtime during init
123 void create_dynamic_modules(std::vector<Module *> &modules);
124
125 // called by runtime after all modules have been cleaned up
127
128 // called by the runtime::create_configs
129 void
130 create_static_module_configs(std::map<std::string, ModuleConfig *> &module_configs);
131
132 // called by the runtime::create_configs
133 void
134 create_dynamic_module_configs(std::vector<std::string> &cmdline,
135 std::map<std::string, ModuleConfig *> &module_configs);
136
137 // TODO: consider some sort of "priority" scheme to order modules' inits?
147 template <typename T>
149 public:
151
153 {
154 return T::create_module(runtime);
155 }
156
158 {
159 return T::create_module_config(runtime);
160 }
161 };
162
163 // called by the module registration helpers
165
166 static bool check_symbol_visibility(void);
167
168 // similar constructs for network modules
170 public:
172 : next(0)
173 {}
175 const char ***argv) const = 0;
177 };
178 template <typename T>
180 public:
181 NetworkRegistration(const std::string &name, size_t order = 9999)
182 {
184 }
185
187 const char ***argv) const
188 {
189 return T::create_network_module(runtime, argc, argv);
190 }
191 };
192
193 // called by the module registration helpers
195 const std::string &name, size_t order = 9999);
196
197 protected:
198 // called by create_dynamic_module_configs to load sofiles
199 void load_module_sofiles(std::vector<std::string> &cmdline);
200
201 protected:
204 std::vector<void *> module_sofile_handles;
205 std::vector<void *> network_sofile_handles;
206 };
207
208 // macros used within a module when being built as a dynamic shared object
209#define REGISTER_REALM_MODULE_CONFIG_DYNAMIC(classname) \
210 extern "C" { \
211 REALM_INTERNAL_API_EXTERNAL_LINKAGE char realm_module_version[] = REALM_VERSION; \
212 REALM_INTERNAL_API_EXTERNAL_LINKAGE Realm::ModuleConfig * \
213 create_realm_module_config(Realm::RuntimeImpl *runtime) \
214 { \
215 return classname::create_module_config(runtime); \
216 } \
217 }
218#define REGISTER_REALM_MODULE_DYNAMIC(classname) \
219 extern "C" { \
220 REALM_INTERNAL_API_EXTERNAL_LINKAGE char realm_module_version[] = REALM_VERSION; \
221 REALM_INTERNAL_API_EXTERNAL_LINKAGE Realm::Module * \
222 create_realm_module(Realm::RuntimeImpl *runtime) \
223 { \
224 return classname::create_module(runtime); \
225 } \
226 }
227#define REGISTER_REALM_NETWORK_MODULE_DYNAMIC(classname) \
228 extern "C" { \
229 REALM_INTERNAL_API_EXTERNAL_LINKAGE char realm_module_version[] = REALM_VERSION; \
230 REALM_INTERNAL_API_EXTERNAL_LINKAGE Realm::NetworkModule * \
231 create_realm_network_module(Realm::RuntimeImpl *runtime, int *argc, \
232 const char ***argv) \
233 { \
234 return classname::create_network_module(runtime, argc, argv); \
235 } \
236 }
237
238}; // namespace Realm
239
240#endif // ifndef REALM_MODULE_H
Definition module_config.h:32
NetworkRegistrationBase * next
Definition module.h:176
virtual NetworkModule * create_network_module(RuntimeImpl *runtime, int *argc, const char ***argv) const =0
NetworkRegistrationBase()
Definition module.h:171
virtual NetworkModule * create_network_module(RuntimeImpl *runtime, int *argc, const char ***argv) const
Definition module.h:186
NetworkRegistration(const std::string &name, size_t order=9999)
Definition module.h:181
StaticRegistrationBase * next
Definition module.h:145
virtual ModuleConfig * create_module_config(RuntimeImpl *runtime) const =0
StaticRegistrationBase()
Definition module.h:140
virtual Module * create_module(RuntimeImpl *runtime) const =0
virtual ModuleConfig * create_module_config(RuntimeImpl *runtime) const
Definition module.h:157
StaticRegistration(void)
Definition module.h:150
virtual Module * create_module(RuntimeImpl *runtime) const
Definition module.h:152
Definition module.h:111
RuntimeImpl * runtime
Definition module.h:202
static bool check_symbol_visibility(void)
std::vector< void * > network_sofile_handles
Definition module.h:205
static void add_static_registration(StaticRegistrationBase *reg)
std::vector< void * > module_sofile_handles
Definition module.h:204
void create_dynamic_module_configs(std::vector< std::string > &cmdline, std::map< std::string, ModuleConfig * > &module_configs)
static void add_network_registration(NetworkRegistrationBase *reg, const std::string &name, size_t order=9999)
void load_module_sofiles(std::vector< std::string > &cmdline)
void create_network_modules(std::vector< NetworkModule * > &modules, int *argc, const char ***argv)
bool sofile_loaded
Definition module.h:203
void create_dynamic_modules(std::vector< Module * > &modules)
void create_static_modules(std::vector< Module * > &modules)
ModuleRegistrar(RuntimeImpl *_runtime)
void unload_module_sofiles(void)
void create_static_module_configs(std::map< std::string, ModuleConfig * > &module_configs)
Definition module.h:100
ModuleSpecificInfo * next
Definition module.h:105
Definition module.h:42
const std::string & get_name(void) const
virtual void cleanup(void)
virtual ~Module(void)
virtual void pre_detach_cleanup(void)
virtual void create_memories(RuntimeImpl *runtime)
virtual void create_dma_channels(RuntimeImpl *runtime)
virtual void create_processors(RuntimeImpl *runtime)
virtual void create_code_translators(RuntimeImpl *runtime)
Module(const std::string &_name)
virtual void initialize(RuntimeImpl *runtime)
std::string name
Definition module.h:93
Definition network.h:144
Definition runtime_impl.h:264
#define REALM_INTERNAL_API_EXTERNAL_LINKAGE
Definition compiler_support.h:218
Definition activemsg.h:38