codes-mapping-context.h 4.25 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
/*
 * 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

Jonathan Jenkins's avatar
Jonathan Jenkins committed
16 17 18 19
#ifdef __cplusplus
extern "C" {
#endif

20 21 22
#include <stdbool.h>
#include <ross.h>

23 24
/* for convenience - an annotation-ignoring "group_modulo" context,
 * matching previous mapping behavior in most interfaces (modelnet and such) */
25
extern struct codes_mctx const * const CODES_MCTX_DEFAULT;
26

27 28 29 30 31
/* 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
32 33 34 35 36 37 38
    // 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
39 40 41 42
    // 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,
43 44
    // similar to GROUP_MODULO, but maps to offsets in reverse order
    CODES_MCTX_GROUP_MODULO_REVERSE,
45 46
    // instructs those using the context to map into the same group/repetition
    // and directly to a callee offset
47 48 49
    CODES_MCTX_GROUP_DIRECT,
    // unknown/uninitialized context
    CODES_MCTX_UNKNOWN
50 51 52
};

/* defines whether to specialize by destination annotation, and if so, which
53
 * one */
54
struct codes_mctx_annotation {
55 56 57
    // see canonical name mapping api in codes_mapping.h. -1 is used for
    // ignoring annotations
    int cid;
58 59 60 61 62 63 64
};

/* parameters for each mapping context type */
struct codes_mctx_global_direct {
    tw_lpid lpid;
};

65 66 67 68
struct codes_mctx_group_ratio {
    struct codes_mctx_annotation anno;
};

69 70 71
struct codes_mctx_group_modulo {
    struct codes_mctx_annotation anno;
};
72
// NOTE: group_modulo_reverse shares the group_modulo representation
73 74 75 76 77 78 79 80 81 82

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;
83
        struct codes_mctx_group_ratio    group_ratio;
84 85 86 87 88 89 90 91
        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);

92 93 94 95 96 97 98 99
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);

100 101 102 103
struct codes_mctx codes_mctx_set_group_modulo(
        char const * annotation,
        bool ignore_annotations);

104 105 106 107
struct codes_mctx codes_mctx_set_group_modulo_reverse(
        char const * annotation,
        bool ignore_annotations);

108 109 110 111 112 113
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
114
 * based on what types of ctx exist
115
 * NOTE: in GLOBAL_DIRECT mode, dest_lp_name and sender_gid are ignored */
116 117 118
tw_lpid codes_mctx_to_lpid(
        struct codes_mctx const * ctx,
        char const * dest_lp_name,
119 120 121 122 123 124 125 126
        tw_lpid sender_gid);

/* helper function to extract which annotation a various map context maps to.
 * annotation is allocated or NULL if unused */
char const * codes_mctx_get_annotation(
        struct codes_mctx const *ctx,
        char const * dest_lp_name,
        tw_lpid sender_id);
127

Jonathan Jenkins's avatar
Jonathan Jenkins committed
128 129 130 131
#ifdef __cplusplus
}
#endif

132 133 134 135 136 137 138 139 140 141 142
#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
 */