Commit bad21a6d authored by Jonathan Jenkins's avatar Jonathan Jenkins

initial cut at mapping context functionality

parent 27aa3cf3
/*
* Copyright (C) 2015 University of Chicago.
* See COPYRIGHT notice in top-level directory.
*
*/
/* SUMMARY - data structure and utilities to direct LP mappings. As opposed to
* the codes-mapping API, this defines metadata necessary to allow implicit
* mappings based on LP type and configuration specification
* (see modelnet, LSM, etc)
* mctx stands for mapping context */
#ifndef CODES_MAPPING_CONTEXT_H
#define CODES_MAPPING_CONTEXT_H
#include <stdbool.h>
#include <ross.h>
/* types of map contexts */
enum codes_mctx_type {
// instructs those using the context to map directly to an LP
CODES_MCTX_GLOBAL_DIRECT,
// instructs those using the context to map into the same group/repetition
// and compute the callee offset as the modulus of the caller offset and
// the number of callees in the group, to provide simple wraparound
// behaviour
CODES_MCTX_GROUP_MODULO,
// instructs those using the context to map into the same group/repetition
// and directly to a callee offset
CODES_MCTX_GROUP_DIRECT
};
/* defines whether to specialize by destination annotation, and if so, which
* one.
*
* NOTE: this structure does not "own" the annotation, and makes no attempt to
* clean it up. */
struct codes_mctx_annotation {
char const * annotation;
bool ignore_annotations;
};
/* parameters for each mapping context type */
struct codes_mctx_global_direct {
tw_lpid lpid;
};
struct codes_mctx_group_modulo {
struct codes_mctx_annotation anno;
};
struct codes_mctx_group_direct {
struct codes_mctx_annotation anno;
int offset;
};
struct codes_mctx {
enum codes_mctx_type type;
union {
struct codes_mctx_global_direct global_direct;
struct codes_mctx_group_modulo group_modulo;
struct codes_mctx_group_direct group_direct;
} u;
};
/* simple setter functions */
struct codes_mctx codes_mctx_set_global_direct(tw_lpid lpid);
struct codes_mctx codes_mctx_set_group_modulo(
char const * annotation,
bool ignore_annotations);
struct codes_mctx codes_mctx_set_group_direct(
int offset,
char const * annotation,
bool ignore_annotations);
/* helper function to do a codes mapping - this function is subject to change
* based on what types of ctx exist */
tw_lpid codes_mctx_to_lpid(
struct codes_mctx const * ctx,
char const * dest_lp_name,
tw_lp const * sender);
#endif /* end of include guard: CODES_MAPPING_CONTEXT_H */
/*
* Local variables:
* c-indent-level: 4
* c-basic-offset: 4
* indent-tabs-mode: nil
* End:
*
* vim: ts=8 sts=4 sw=4 expandtab
*/
......@@ -59,7 +59,8 @@ nobase_include_HEADERS = \
codes/local-storage-model.h \
codes/rc-stack.h \
codes/codes-jobmap.h \
codes/codes-callback.h
codes/codes-callback.h \
codes/codes-mapping-context.h
#codes/codes-nw-workload.h
......@@ -102,6 +103,7 @@ src_libcodes_base_a_SOURCES = \
src/util/jobmap-impl/jobmap-dummy.c \
src/util/jobmap-impl/jobmap-list.c\
src/util/jobmap-impl/jobmap-identity.c\
src/util/codes-mapping-context.c \
src/workload/codes-workload.c \
src/workload/codes-workload-method.h \
src/workload/methods/codes-iolang-wrkld.c \
......
/*
* Copyright (C) 2015 University of Chicago.
* See COPYRIGHT notice in top-level directory.
*
*/
#include <codes/codes-mapping-context.h>
#include <codes/codes_mapping.h>
struct codes_mctx codes_mctx_set_global_direct(tw_lpid lpid)
{
struct codes_mctx rtn;
rtn.type = CODES_MCTX_GLOBAL_DIRECT;
rtn.u.global_direct.lpid = lpid;
return rtn;
}
struct codes_mctx codes_mctx_set_group_modulo(
char const * annotation,
bool ignore_annotations)
{
struct codes_mctx rtn;
rtn.type = CODES_MCTX_GROUP_MODULO;
rtn.u.group_modulo.anno.annotation = annotation;
rtn.u.group_modulo.anno.ignore_annotations = ignore_annotations;
return rtn;
}
struct codes_mctx codes_mctx_set_group_direct(
int offset,
char const * annotation,
bool ignore_annotations)
{
struct codes_mctx rtn;
rtn.type = CODES_MCTX_GROUP_DIRECT;
rtn.u.group_direct.offset = offset;
rtn.u.group_direct.anno.annotation = annotation;
rtn.u.group_direct.anno.ignore_annotations = ignore_annotations;
return rtn;
}
/* helper function to do a codes mapping - this function is subject to change
* based on what types of ctx exist */
tw_lpid codes_mctx_to_lpid(
struct codes_mctx const * ctx,
char const * dest_lp_name,
tw_lp const * sender)
{
struct codes_mctx_annotation const *anno;
// short circuit for direct mappings
switch (ctx->type) {
case CODES_MCTX_GLOBAL_DIRECT:
return ctx->u.global_direct.lpid;
case CODES_MCTX_GROUP_MODULO:
anno = &ctx->u.group_modulo.anno;
break;
case CODES_MCTX_GROUP_DIRECT:
anno = &ctx->u.group_direct.anno;
break;
default:
assert(0);
}
char sender_group[MAX_NAME_LENGTH];
int unused, rep_id, offset;
// get sender info
codes_mapping_get_lp_info(sender->gid, sender_group, &unused, NULL, &unused,
NULL, &rep_id, &offset);
int dest_offset;
if (ctx->type == CODES_MCTX_GROUP_MODULO) {
int num_dest_lps = codes_mapping_get_lp_count(sender_group, 1,
dest_lp_name, anno->annotation, anno->ignore_annotations);
if (num_dest_lps == 0)
tw_error(TW_LOC,
"ERROR: Found no LPs of type %s in group %s "
"(source lpid %lu) with annotation: %s\n",
dest_lp_name, sender_group, sender->gid,
anno->ignore_annotations ? "ignored" :
(anno->annotation ? anno->annotation : "none"));
dest_offset = offset % num_dest_lps;
}
else if (ctx->type == CODES_MCTX_GROUP_DIRECT) {
dest_offset = ctx->u.group_direct.offset;
}
else
assert(0);
tw_lpid rtn;
codes_mapping_get_lp_id(sender_group, dest_lp_name, anno->annotation,
anno->ignore_annotations, rep_id, dest_offset, &rtn);
return rtn;
}
/*
* Local variables:
* c-indent-level: 4
* c-basic-offset: 4
* indent-tabs-mode: nil
* End:
*
* vim: ts=8 sts=4 sw=4 expandtab
*/
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment