GitLab maintenance scheduled for Today, 2019-12-05, from 17:00 to 18:00 CT - Services will be unavailable during this time.

Commit 78745f23 authored by Jonathan Jenkins's avatar Jonathan Jenkins

add anotehr mapping context

parent 2d2065cd
......@@ -29,6 +29,13 @@ 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 taking into account the ratio of source LP
// type count and destination LP type count. Currently doesn't respect
// annotations from the source LP.
CODES_MCTX_GROUP_RATIO,
// similar to GROUP_RATIO, but maps to offsets in reverse order
CODES_MCTX_GROUP_RATIO_REVERSE,
// 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
......@@ -55,6 +62,10 @@ struct codes_mctx_global_direct {
tw_lpid lpid;
};
struct codes_mctx_group_ratio {
struct codes_mctx_annotation anno;
};
struct codes_mctx_group_modulo {
struct codes_mctx_annotation anno;
};
......@@ -69,6 +80,7 @@ struct codes_mctx {
enum codes_mctx_type type;
union {
struct codes_mctx_global_direct global_direct;
struct codes_mctx_group_ratio group_ratio;
struct codes_mctx_group_modulo group_modulo;
struct codes_mctx_group_direct group_direct;
} u;
......@@ -77,6 +89,14 @@ struct codes_mctx {
/* simple setter functions */
struct codes_mctx codes_mctx_set_global_direct(tw_lpid lpid);
struct codes_mctx codes_mctx_set_group_ratio(
char const * annotation,
bool ignore_annotations);
struct codes_mctx codes_mctx_set_group_ratio_reverse(
char const * annotation,
bool ignore_annotations);
struct codes_mctx codes_mctx_set_group_modulo(
char const * annotation,
bool ignore_annotations);
......
......@@ -42,6 +42,7 @@ static struct codes_mctx set_group_modulo_common(
codes_mapping_get_anno_cid_by_name(annotation);
return rtn;
}
struct codes_mctx codes_mctx_set_group_modulo(
char const * annotation,
bool ignore_annotations)
......@@ -58,6 +59,37 @@ struct codes_mctx codes_mctx_set_group_modulo_reverse(
ignore_annotations);
}
static struct codes_mctx set_group_ratio_common(
enum codes_mctx_type type,
char const * annotation,
bool ignore_annotations)
{
struct codes_mctx rtn;
rtn.type = type;
if (ignore_annotations)
rtn.u.group_ratio.anno.cid = -1;
else
rtn.u.group_ratio.anno.cid =
codes_mapping_get_anno_cid_by_name(annotation);
return rtn;
}
struct codes_mctx codes_mctx_set_group_ratio(
char const * annotation,
bool ignore_annotations)
{
return set_group_ratio_common(CODES_MCTX_GROUP_RATIO, annotation,
ignore_annotations);
}
struct codes_mctx codes_mctx_set_group_ratio_reverse(
char const * annotation,
bool ignore_annotations)
{
return set_group_ratio_common(CODES_MCTX_GROUP_RATIO_REVERSE, annotation,
ignore_annotations);
}
struct codes_mctx codes_mctx_set_group_direct(
int offset,
char const * annotation,
......@@ -86,6 +118,10 @@ tw_lpid codes_mctx_to_lpid(
switch (ctx->type) {
case CODES_MCTX_GLOBAL_DIRECT:
return ctx->u.global_direct.lpid;
case CODES_MCTX_GROUP_RATIO:
case CODES_MCTX_GROUP_RATIO_REVERSE:
anno = &ctx->u.group_ratio.anno;
break;
case CODES_MCTX_GROUP_MODULO:
case CODES_MCTX_GROUP_MODULO_REVERSE:
anno = &ctx->u.group_modulo.anno;
......@@ -97,12 +133,13 @@ tw_lpid codes_mctx_to_lpid(
assert(0);
}
char sender_group[MAX_NAME_LENGTH];
int unused, rep_id, offset;
char const *sender_group;
char const *sender_lpname;
int rep_id, offset;
// get sender info
codes_mapping_get_lp_info(sender_gid, sender_group, &unused, NULL, &unused,
NULL, &rep_id, &offset);
codes_mapping_get_lp_info2(sender_gid, &sender_group, &sender_lpname, NULL,
&rep_id, &offset);
char const * anno_str;
if (anno->cid < 0)
......@@ -111,8 +148,14 @@ tw_lpid codes_mctx_to_lpid(
anno_str = codes_mapping_get_anno_name_by_cid(anno->cid);
int dest_offset;
if (ctx->type == CODES_MCTX_GROUP_MODULO ||
ctx->type == CODES_MCTX_GROUP_MODULO_REVERSE) {
int is_group_modulo = (ctx->type == CODES_MCTX_GROUP_MODULO ||
ctx->type == CODES_MCTX_GROUP_MODULO_REVERSE);
int is_group_ratio = (ctx->type == CODES_MCTX_GROUP_RATIO ||
ctx->type == CODES_MCTX_GROUP_RATIO_REVERSE);
int is_group_reverse = (ctx->type == CODES_MCTX_GROUP_MODULO_REVERSE ||
ctx->type == CODES_MCTX_GROUP_RATIO_REVERSE);
if (is_group_modulo || is_group_ratio) {
int num_dest_lps = codes_mapping_get_lp_count(sender_group, 1,
dest_lp_name, anno_str, anno->cid == -1);
if (num_dest_lps == 0)
......@@ -123,8 +166,20 @@ tw_lpid codes_mctx_to_lpid(
anno->cid == -1 ? "ignored" :
codes_mapping_get_anno_name_by_cid(anno->cid));
dest_offset = offset % num_dest_lps;
if (ctx->type == CODES_MCTX_GROUP_MODULO_REVERSE)
if (is_group_modulo)
dest_offset = offset % num_dest_lps;
else {
int num_src_lps = codes_mapping_get_lp_count(sender_group, 1,
sender_lpname, NULL, 1);
if (num_src_lps <= num_dest_lps)
dest_offset = offset;
else {
dest_offset = offset * num_dest_lps / num_src_lps;
if (dest_offset >= num_dest_lps)
dest_offset = num_dest_lps-1;
}
}
if (is_group_reverse)
dest_offset = num_dest_lps - 1 - dest_offset;
}
else if (ctx->type == CODES_MCTX_GROUP_DIRECT) {
......@@ -147,6 +202,14 @@ char const * codes_mctx_get_annotation(
switch(ctx->type) {
case CODES_MCTX_GLOBAL_DIRECT:
return codes_mapping_get_annotation_by_lpid(sender_id);
case CODES_MCTX_GROUP_RATIO:
case CODES_MCTX_GROUP_RATIO_REVERSE:
// if not ignoring the annotation, just return what's in the
// context
if (ctx->u.group_modulo.anno.cid >= 0)
return codes_mapping_get_anno_name_by_cid(
ctx->u.group_modulo.anno.cid);
break;
case CODES_MCTX_GROUP_MODULO:
case CODES_MCTX_GROUP_MODULO_REVERSE:
// if not ignoring the annotation, just return what's in the
......
......@@ -13,4 +13,16 @@ LPGROUPS
bar="2";
bar@baz="2";
}
BAZ
{
repetitions="5";
foo="4";
bar="2";
}
BAT
{
repetitions="5";
foo="5";
bar="3";
}
}
......@@ -25,10 +25,13 @@ int main(int argc, char *argv[])
if (rc != 0)
ERR("unable to load configuration file %s", argv[1]);
struct codes_mctx direct, group_modulo, group_rmodulo, group_direct,
group_modulo_anno, group_rmodulo_anno, group_direct_anno;
struct codes_mctx direct, group_ratio, group_rratio, group_modulo,
group_rmodulo, group_direct, group_modulo_anno,
group_rmodulo_anno, group_direct_anno;
direct = codes_mctx_set_global_direct(12ul);
group_ratio = codes_mctx_set_group_ratio(NULL, true);
group_rratio = codes_mctx_set_group_ratio_reverse(NULL, true);
group_modulo = codes_mctx_set_group_modulo(NULL, true);
group_rmodulo = codes_mctx_set_group_modulo_reverse(NULL, true);
group_direct = codes_mctx_set_group_direct(1, NULL, true);
......@@ -36,92 +39,127 @@ int main(int argc, char *argv[])
group_rmodulo_anno = codes_mctx_set_group_modulo_reverse("baz", false);
group_direct_anno = codes_mctx_set_group_direct(1, "baz", false);
tw_lpid in;
tw_lpid in, out;
tw_lpid rtn_id;
char const * out_anno;
char const * rtn_anno;
#define CHECK(_type_str) \
do { \
if (rtn_id != out) { \
ERR("%s mapping failed: in:%llu, expected:%llu, out:%llu", \
_type_str, LLU(in), LLU(rtn_id), LLU(out)); \
} \
} while(0)
#define CHECK_ANNO(_type_str) \
do { \
if (!((out_anno && rtn_anno && strcmp(out_anno, rtn_anno) == 0) || \
(!out_anno && !rtn_anno))) { \
ERR("%s anno mapping failed: in:%llu, expected:%s, out:%s", \
_type_str, LLU(in), rtn_anno, out_anno); \
} \
} while (0)
in = 0ul;
out = 12ul;
out_anno = NULL;
rtn_id = codes_mctx_to_lpid(&direct, NULL, 0);
if (12ul != rtn_id)
ERR("global_direct mapping: expected %llu, got %llu",
12ull, LLU(rtn_id));
rtn_anno = codes_mctx_get_annotation(&direct, NULL, 0);
if (rtn_anno)
ERR("global_direct mapping: expected NULL anno, got %s", rtn_anno);
CHECK("global_direct");
CHECK_ANNO("global_direct");
/* test BAZ group (evenly divide foo, bar) */
in = 47ul;
out = 50ul;
out_anno = NULL;
rtn_id = codes_mctx_to_lpid(&group_ratio, "bar", in);
rtn_anno = codes_mctx_get_annotation(&group_ratio, "bar", in);
CHECK("global_ratio");
CHECK_ANNO("global_ratio");
out = 49ul;
rtn_id = codes_mctx_to_lpid(&group_rratio, "bar", in);
rtn_anno = codes_mctx_get_annotation(&group_rratio, "bar", in);
CHECK("global_rratio");
CHECK_ANNO("global_rratio");
/* test BAT group (non-even foo/bar division) */
in = 79ul;
out = 82ul;
out_anno = NULL;
rtn_id = codes_mctx_to_lpid(&group_ratio, "bar", in);
rtn_anno = codes_mctx_get_annotation(&group_ratio, "bar", in);
CHECK("global_ratio");
CHECK_ANNO("global_ratio");
out = 80ul;
rtn_id = codes_mctx_to_lpid(&group_rratio, "bar", in);
rtn_anno = codes_mctx_get_annotation(&group_rratio, "bar", in);
CHECK("global_ratio");
CHECK_ANNO("global_ratio");
in = 8ul;
out = 9ul;
out_anno = NULL;
rtn_id = codes_mctx_to_lpid(&group_modulo, "bar", in);
if (rtn_id != 9ul)
ERR("group_modulo mapping: expected %llu, got %llu",
9ull, LLU(rtn_id));
rtn_anno = codes_mctx_get_annotation(&group_modulo, "bar", in);
if (rtn_anno)
ERR("group_modulo mapping: expected NULL anno, got %s", rtn_anno);
CHECK("group_modulo");
CHECK_ANNO("group_modulo");
rtn_id = codes_mctx_to_lpid(&group_rmodulo, "bar", in);
if (rtn_id != 9ul)
ERR("group_rmodulo mapping: expected %llu, got %llu",
9ull, LLU(rtn_id));
rtn_anno = codes_mctx_get_annotation(&group_rmodulo, "bar", in);
if (rtn_anno)
ERR("group_rmodulo mapping: expected NULL anno, got %s", rtn_anno);
CHECK("group_rmodulo");
CHECK_ANNO("group_rmodulo");
in = 12ul;
out = 13ul;
out_anno = NULL;
rtn_id = codes_mctx_to_lpid(&group_modulo, "bar", in);
if (rtn_id != 13ul)
ERR("group_modulo mapping: expected %llu, got %llu",
13ull, LLU(rtn_id));
rtn_anno = codes_mctx_get_annotation(&group_modulo, "bar", in);
if (rtn_anno)
ERR("group_modulo mapping: expected NULL anno, got %s", rtn_anno);
CHECK("group_modulo");
CHECK_ANNO("group_modulo");
out = 14ul;
rtn_id = codes_mctx_to_lpid(&group_rmodulo, "bar", in);
if (rtn_id != 14ul)
ERR("group_rmodulo mapping: expected %llu, got %llu",
14ull, LLU(rtn_id));
rtn_anno = codes_mctx_get_annotation(&group_rmodulo, "bar", in);
if (rtn_anno)
ERR("group_rmodulo mapping: expected NULL anno, got %s", rtn_anno);
CHECK("group_rmodulo");
CHECK_ANNO("group_rmodulo");
out = 13ul;
rtn_id = codes_mctx_to_lpid(CODES_MCTX_DEFAULT, "bar", in);
if (rtn_id != 13ul)
ERR("group_modulo mapping (default): expected %llu, got %llu",
13ull, LLU(rtn_id));
rtn_anno = codes_mctx_get_annotation(CODES_MCTX_DEFAULT, "bar", in);
if (rtn_anno)
ERR("group_modulo mapping: expected NULL anno, got %s", rtn_anno);
CHECK("CODES_MCTX_DEFAULT");
CHECK_ANNO("CODES_MCTX_DEFAULT");
out = 15ul;
out_anno = "baz";
rtn_id = codes_mctx_to_lpid(&group_modulo_anno, "bar", in);
if (rtn_id != 15ul)
ERR("group_modulo annotated mapping: expected %llu, got %llu",
15ull, LLU(rtn_id));
rtn_anno = codes_mctx_get_annotation(&group_modulo_anno, "bar", in);
if (strcmp(rtn_anno,"baz") != 0)
ERR("group_modulo mapping: expected anno \"baz\", got %s", rtn_anno);
CHECK("group_modulo_anno");
CHECK_ANNO("group_modulo_anno");
out = 16ul;
rtn_id = codes_mctx_to_lpid(&group_rmodulo_anno, "bar", in);
if (rtn_id != 16ul)
ERR("group_rmodulo annotated mapping: expected %llu, got %llu",
16ull, LLU(rtn_id));
rtn_anno = codes_mctx_get_annotation(&group_rmodulo_anno, "bar", in);
if (strcmp(rtn_anno,"baz") != 0)
ERR("group_rmodulo mapping: expected anno \"baz\", got %s", rtn_anno);
CHECK("group_rmodulo_anno");
CHECK_ANNO("group_rmodulo_anno");
in = 10ul;
out = 14ul;
out_anno = NULL;
rtn_id = codes_mctx_to_lpid(&group_direct, "bar", in);
if (rtn_id != 14ul)
ERR("group_direct mapping (default): expected %llu, got %llu",
14ull, LLU(rtn_id));
rtn_anno = codes_mctx_get_annotation(&group_direct, "bar", in);
if (rtn_anno)
ERR("group_modulo mapping: expected NULL anno, got %s", rtn_anno);
CHECK("group_direct");
CHECK_ANNO("group_direct");
out = 16ul;
out_anno = "baz";
rtn_id = codes_mctx_to_lpid(&group_direct_anno, "bar", in);
if (rtn_id != 16ul)
ERR("group_direct mapping (default): expected %llu, got %llu",
16ull, LLU(rtn_id));
rtn_anno = codes_mctx_get_annotation(&group_direct_anno, "bar", in);
if (strcmp(rtn_anno,"baz") != 0)
ERR("group_modulo mapping: expected anno \"baz\", got %s", rtn_anno);
CHECK("group_direct_anno");
CHECK("group_direct_anno");
return 0;
}
......
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