Skip to content

Regent: How to add a custom mapper

Seshu Yamajala edited this page Mar 25, 2024 · 3 revisions

app.rg:

local cmd = "g++ -shared -fPIC -o libmymapper.so mymapper.cc"
assert(os.execute(cmd) == 0)
terralib.linklibrary("./libmymapper.so")
local MAPPER = terralib.includec("mymapper.h", {"-I", "./"})
...
regentlib.start(main_task, MAPPER.register_mappers)

mymapper.cc:

#include <legion.h>
#include <legion/legion_mapping.h>
#include "mymapper.h"

using namespace Legion;

class MyMapper : public Mapping::Mapper {
  ...
};

static void registration_callback(Machine machine,
				  Runtime* rt,
                                  const std::set<Processor>& local_procs) {
  for (Processor proc : local_procs) {
    if (proc.kind() == Processor::LOC_PROC) {
      rt->replace_default_mapper(new MyMapper(
        rt->get_mapper_runtime(), machine, proc, ...));
    }
  }
}

void register_mappers() {
  Runtime::add_registration_callback(registration_callback);
}

mymapper.h:

#ifdef __cplusplus
extern "C" {
#endif
void register_mappers();
#ifdef __cplusplus
}
#endif