bake-rpc.h 4.84 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 <margo.h>
11
#include <mercury_proc_string.h>
12
#include <bake.h>
Philip Carns's avatar
Philip Carns committed
13

14
/* encoders for BAKE-specific types */
15
static inline hg_return_t hg_proc_bake_target_id_t(hg_proc_t proc, bake_target_id_t *bti);
16
static inline hg_return_t hg_proc_bake_region_id_t(hg_proc_t proc, bake_region_id_t *rid);
Philip Carns's avatar
Philip Carns committed
17

18 19 20 21 22
/* BAKE shutdown */
DECLARE_MARGO_RPC_HANDLER(bake_shutdown_ult)

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

30 31
/* BAKE write */
MERCURY_GEN_PROC(bake_write_in_t,
Philip Carns's avatar
Philip Carns committed
32
    ((bake_target_id_t)(bti))\
33
    ((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 46
typedef struct 
{
    bake_target_id_t bti;
47
    bake_region_id_t rid;
Philip Carns's avatar
Philip Carns committed
48 49 50
    uint64_t region_offset;
    uint32_t size;
    char * buffer;
51 52 53
} 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
54
    ((int32_t)(ret)))
55
DECLARE_MARGO_RPC_HANDLER(bake_eager_write_ult)
Philip Carns's avatar
Philip Carns committed
56

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

65 66
/* BAKE get size */
MERCURY_GEN_PROC(bake_get_size_in_t,
67
    ((bake_target_id_t)(bti))\
68 69
    ((bake_region_id_t)(rid)))
MERCURY_GEN_PROC(bake_get_size_out_t,
70 71
    ((int32_t)(ret))\
    ((uint64_t)(size)))
72
DECLARE_MARGO_RPC_HANDLER(bake_get_size_ult)
73

74 75
/* BAKE read */
MERCURY_GEN_PROC(bake_read_in_t,
76
    ((bake_target_id_t)(bti))\
77
    ((bake_region_id_t)(rid))\
78
    ((uint64_t)(region_offset))\
79 80 81 82
    ((hg_bulk_t)(bulk_handle))\
    ((uint64_t)(bulk_offset))\
    ((uint64_t)(bulk_size))\
    ((hg_string_t)(remote_addr_str)))
83
MERCURY_GEN_PROC(bake_read_out_t,
84
    ((int32_t)(ret)))
85
DECLARE_MARGO_RPC_HANDLER(bake_read_ult)
86

87 88
/* BAKE eager read */
MERCURY_GEN_PROC(bake_eager_read_in_t,
Philip Carns's avatar
Philip Carns committed
89
    ((bake_target_id_t)(bti))\
90
    ((bake_region_id_t)(rid))\
Philip Carns's avatar
Philip Carns committed
91 92 93 94 95 96 97
    ((uint64_t)(region_offset))\
    ((uint32_t)(size)))
typedef struct 
{
    int32_t ret;
    uint32_t size;
    char * buffer;
98 99 100
} 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
101

102 103
/* BAKE probe */
MERCURY_GEN_PROC(bake_probe_out_t,
104 105
    ((int32_t)(ret))\
    ((bake_target_id_t)(bti)))
106
DECLARE_MARGO_RPC_HANDLER(bake_probe_ult)
107

108 109
/* BAKE noop */
DECLARE_MARGO_RPC_HANDLER(bake_noop_ult)
Philip Carns's avatar
Philip Carns committed
110

Philip Carns's avatar
Philip Carns committed
111

112
static inline hg_return_t hg_proc_bake_region_id_t(hg_proc_t proc, bake_region_id_t *rid)
113 114
{
    /* TODO: update later depending on final region_id_t type */
Philip Carns's avatar
Philip Carns committed
115
    /* TODO: need separate encoders for different backend types */
116 117 118
    int i;
    hg_return_t ret;

Philip Carns's avatar
Philip Carns committed
119
    hg_proc_hg_uint32_t(proc, &rid->type);
120
    for(i=0; i<BAKE_REGION_ID_DATA_SIZE; i++)
121 122 123 124 125 126 127 128 129 130
    {
        ret = hg_proc_hg_uint8_t(proc, (uint8_t*)&rid->data[i]);
        if(ret != HG_SUCCESS)
            return(ret);
    }
    return(HG_SUCCESS);
}

static inline hg_return_t hg_proc_bake_target_id_t(hg_proc_t proc, bake_target_id_t *bti)
{
131 132
    /* TODO: make this portable */
    return(hg_proc_memcpy(proc, bti->id, sizeof(bti->id)));
133 134
}

135
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
136
{
Philip Carns's avatar
Philip Carns committed
137
    /* TODO: error checking */
138
    bake_eager_write_in_t *in = v_out_p;
139
    void *buf = NULL;
Philip Carns's avatar
Philip Carns committed
140 141

    hg_proc_bake_target_id_t(proc, &in->bti);
142
    hg_proc_bake_region_id_t(proc, &in->rid);
Philip Carns's avatar
Philip Carns committed
143 144
    hg_proc_uint64_t(proc, &in->region_offset);
    hg_proc_uint32_t(proc, &in->size);
145 146 147 148 149 150 151 152 153
    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);
    }
Philip Carns's avatar
Philip Carns committed
154

Philip Carns's avatar
Philip Carns committed
155 156 157
    return(HG_SUCCESS);
}

Philip Carns's avatar
Philip Carns committed
158

159
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
160 161
{
    /* TODO: error checking */
162
    bake_eager_read_out_t *out = v_out_p;
163
    void *buf = NULL;
Philip Carns's avatar
Philip Carns committed
164 165 166

    hg_proc_int32_t(proc, &out->ret);
    hg_proc_uint32_t(proc, &out->size);
167 168 169 170 171 172 173 174 175
    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
176 177 178 179

    return(HG_SUCCESS);
}

180
#endif /* __BAKE_RPC */