bake-rpc.h 6.35 KB
Newer Older
Philip Carns's avatar
Philip Carns committed
1 2 3 4 5 6
/*
 * (C) 2015 The University of Chicago
 * 
 * See COPYRIGHT in top-level directory.
 */

7 8
#ifndef __BAKE_RPC
#define __BAKE_RPC
Philip Carns's avatar
Philip Carns committed
9

10
#include <uuid/uuid.h>
Philip Carns's avatar
Philip Carns committed
11
#include <margo.h>
12
#include <mercury_proc_string.h>
13
#include <bake.h>
Philip Carns's avatar
Philip Carns committed
14

15
/* encoders for BAKE-specific types */
16
static inline hg_return_t hg_proc_bake_target_id_t(hg_proc_t proc, bake_target_id_t *bti);
17
static inline hg_return_t hg_proc_bake_region_id_t(hg_proc_t proc, bake_region_id_t *rid);
18
static inline hg_return_t hg_proc_bake_probe_out_t(hg_proc_t proc, void* out);
19 20 21 22 23
/* BAKE shutdown */
DECLARE_MARGO_RPC_HANDLER(bake_shutdown_ult)

/* BAKE create */
MERCURY_GEN_PROC(bake_create_in_t,
24
    ((bake_target_id_t)(bti))\
25
    ((uint64_t)(region_size)))
26
MERCURY_GEN_PROC(bake_create_out_t,
27
    ((int32_t)(ret))\
28 29
    ((bake_region_id_t)(rid)))
DECLARE_MARGO_RPC_HANDLER(bake_create_ult)
30

31 32 33
/* BAKE write */
MERCURY_GEN_PROC(bake_write_in_t,
    ((bake_region_id_t)(rid))\
Philip Carns's avatar
Philip Carns committed
34
    ((uint64_t)(region_offset))\
35 36 37 38
    ((hg_bulk_t)(bulk_handle))\
    ((uint64_t)(bulk_offset))\
    ((uint64_t)(bulk_size))\
    ((hg_string_t)(remote_addr_str)))
39
MERCURY_GEN_PROC(bake_write_out_t,
Philip Carns's avatar
Philip Carns committed
40
    ((int32_t)(ret)))
41
DECLARE_MARGO_RPC_HANDLER(bake_write_ult)
42

43
/* BAKE eager write */
Philip Carns's avatar
Philip Carns committed
44 45
typedef struct 
{
46
    bake_region_id_t rid;
Philip Carns's avatar
Philip Carns committed
47 48 49
    uint64_t region_offset;
    uint32_t size;
    char * buffer;
50 51 52
} bake_eager_write_in_t;
static inline hg_return_t hg_proc_bake_eager_write_in_t(hg_proc_t proc, void *v_out_p);
MERCURY_GEN_PROC(bake_eager_write_out_t,
Philip Carns's avatar
Philip Carns committed
53
    ((int32_t)(ret)))
54
DECLARE_MARGO_RPC_HANDLER(bake_eager_write_ult)
Philip Carns's avatar
Philip Carns committed
55

56 57 58 59
/* BAKE persist */
MERCURY_GEN_PROC(bake_persist_in_t,
    ((bake_region_id_t)(rid)))
MERCURY_GEN_PROC(bake_persist_out_t,
Philip Carns's avatar
Philip Carns committed
60
    ((int32_t)(ret)))
61
DECLARE_MARGO_RPC_HANDLER(bake_persist_ult)
Philip Carns's avatar
Philip Carns committed
62

63 64
/* BAKE create/write/persist */
MERCURY_GEN_PROC(bake_create_write_persist_in_t,
65
    ((bake_target_id_t)(bti))\
66 67 68 69 70 71 72 73 74 75 76
    ((uint64_t)(region_size))\
    ((uint64_t)(region_offset))\
    ((hg_bulk_t)(bulk_handle))\
    ((uint64_t)(bulk_offset))\
    ((uint64_t)(bulk_size))\
    ((hg_string_t)(remote_addr_str)))
MERCURY_GEN_PROC(bake_create_write_persist_out_t,
    ((int32_t)(ret))\
    ((bake_region_id_t)(rid)))
DECLARE_MARGO_RPC_HANDLER(bake_create_write_persist_ult)

77 78 79 80
/* BAKE get size */
MERCURY_GEN_PROC(bake_get_size_in_t,
    ((bake_region_id_t)(rid)))
MERCURY_GEN_PROC(bake_get_size_out_t,
81 82
    ((int32_t)(ret))\
    ((uint64_t)(size)))
83
DECLARE_MARGO_RPC_HANDLER(bake_get_size_ult)
84

85 86 87 88 89 90 91 92
/* BAKE get data */
MERCURY_GEN_PROC(bake_get_data_in_t,
    ((bake_region_id_t)(rid)))
MERCURY_GEN_PROC(bake_get_data_out_t,
    ((int32_t)(ret))\
    ((uint64_t)(ptr)))
DECLARE_MARGO_RPC_HANDLER(bake_get_data_ult)

93 94 95
/* BAKE read */
MERCURY_GEN_PROC(bake_read_in_t,
    ((bake_region_id_t)(rid))\
96
    ((uint64_t)(region_offset))\
97 98 99 100
    ((hg_bulk_t)(bulk_handle))\
    ((uint64_t)(bulk_offset))\
    ((uint64_t)(bulk_size))\
    ((hg_string_t)(remote_addr_str)))
101
MERCURY_GEN_PROC(bake_read_out_t,
102
    ((hg_size_t)(size))\
103
    ((int32_t)(ret)))
104
DECLARE_MARGO_RPC_HANDLER(bake_read_ult)
105

106 107 108
/* BAKE eager read */
MERCURY_GEN_PROC(bake_eager_read_in_t,
    ((bake_region_id_t)(rid))\
Philip Carns's avatar
Philip Carns committed
109 110 111 112 113 114 115
    ((uint64_t)(region_offset))\
    ((uint32_t)(size)))
typedef struct 
{
    int32_t ret;
    uint32_t size;
    char * buffer;
116 117 118
} bake_eager_read_out_t;
static inline hg_return_t hg_proc_bake_eager_read_out_t(hg_proc_t proc, void *v_out_p);
DECLARE_MARGO_RPC_HANDLER(bake_eager_read_ult)
Philip Carns's avatar
Philip Carns committed
119

120
/* BAKE probe */
121 122 123 124 125 126 127 128
MERCURY_GEN_PROC(bake_probe_in_t,
                ((uint64_t)(max_targets)))
typedef struct
{
    int32_t ret;
    uint64_t num_targets;
    bake_target_id_t* targets;
} bake_probe_out_t;
129
DECLARE_MARGO_RPC_HANDLER(bake_probe_ult)
130

131 132
/* BAKE noop */
DECLARE_MARGO_RPC_HANDLER(bake_noop_ult)
Philip Carns's avatar
Philip Carns committed
133

Shane Snyder's avatar
Shane Snyder committed
134 135 136 137 138 139
/* BAKE remove */
MERCURY_GEN_PROC(bake_remove_in_t,
    ((bake_region_id_t)(rid)))
MERCURY_GEN_PROC(bake_remove_out_t,
    ((int32_t)(ret)))
DECLARE_MARGO_RPC_HANDLER(bake_remove_ult)
Philip Carns's avatar
Philip Carns committed
140

141
static inline hg_return_t hg_proc_bake_region_id_t(hg_proc_t proc, bake_region_id_t *rid)
142 143
{
    /* TODO: update later depending on final region_id_t type */
Philip Carns's avatar
Philip Carns committed
144
    /* TODO: need separate encoders for different backend types */
145 146 147
    int i;
    hg_return_t ret;

Philip Carns's avatar
Philip Carns committed
148
    hg_proc_hg_uint32_t(proc, &rid->type);
149
    for(i=0; i<BAKE_REGION_ID_DATA_SIZE; i++)
150 151 152 153 154 155 156 157
    {
        ret = hg_proc_hg_uint8_t(proc, (uint8_t*)&rid->data[i]);
        if(ret != HG_SUCCESS)
            return(ret);
    }
    return(HG_SUCCESS);
}

158
static inline hg_return_t hg_proc_bake_target_id_t(hg_proc_t proc, bake_target_id_t *bti)
159
{
160
    /* TODO: make this portable */
161
    return(hg_proc_memcpy(proc, bti, sizeof(*bti)));
162 163
}

164
static inline hg_return_t hg_proc_bake_eager_write_in_t(hg_proc_t proc, void *v_out_p)
Philip Carns's avatar
Philip Carns committed
165
{
166
    /* TODO: error checking */
167
    bake_eager_write_in_t *in = v_out_p;
168
    void *buf = NULL;
169

170
    hg_proc_bake_region_id_t(proc, &in->rid);
171 172
    hg_proc_uint64_t(proc, &in->region_offset);
    hg_proc_uint32_t(proc, &in->size);
173 174 175 176 177 178 179 180 181
    if(in->size)
    {
        buf = hg_proc_save_ptr(proc, in->size);
        if(hg_proc_get_op(proc) == HG_ENCODE)
            memcpy(buf, in->buffer, in->size);
        if(hg_proc_get_op(proc) == HG_DECODE)
            in->buffer = buf;
        hg_proc_restore_ptr(proc, buf, in->size);
    }
182

Philip Carns's avatar
Philip Carns committed
183 184 185
    return(HG_SUCCESS);
}

Philip Carns's avatar
Philip Carns committed
186

187
static inline hg_return_t hg_proc_bake_eager_read_out_t(hg_proc_t proc, void *v_out_p)
Philip Carns's avatar
Philip Carns committed
188 189
{
    /* TODO: error checking */
190
    bake_eager_read_out_t *out = v_out_p;
191
    void *buf = NULL;
Philip Carns's avatar
Philip Carns committed
192 193 194

    hg_proc_int32_t(proc, &out->ret);
    hg_proc_uint32_t(proc, &out->size);
195 196 197 198 199 200 201 202 203
    if(out->size)
    {
        buf = hg_proc_save_ptr(proc, out->size);
        if(hg_proc_get_op(proc) == HG_ENCODE)
            memcpy(buf, out->buffer, out->size);
        if(hg_proc_get_op(proc) == HG_DECODE)
            out->buffer = buf;
        hg_proc_restore_ptr(proc, buf, out->size);
    }
Philip Carns's avatar
Philip Carns committed
204 205 206 207

    return(HG_SUCCESS);
}

208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226
static inline hg_return_t hg_proc_bake_probe_out_t(hg_proc_t proc, void* data)
{
    bake_probe_out_t* out = (bake_probe_out_t*)data;
    void* buf = NULL;

    hg_proc_int32_t(proc, &out->ret);
    hg_proc_uint64_t(proc, &out->num_targets);
    if(out->num_targets)
    {
        buf = hg_proc_save_ptr(proc, out->num_targets * sizeof(bake_target_id_t));
        if(hg_proc_get_op(proc) == HG_ENCODE)
            memcpy(buf, out->targets, out->num_targets * sizeof(bake_target_id_t));
        if(hg_proc_get_op(proc) == HG_DECODE)
            out->targets = buf;
        hg_proc_restore_ptr(proc, buf, out->num_targets * sizeof(bake_target_id_t));
    }
    return HG_SUCCESS;
}

227
#endif /* __BAKE_RPC */