File: btl_ofi_frag.c

package info (click to toggle)
openmpi 4.1.0-10
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 126,560 kB
  • sloc: ansic: 685,465; makefile: 42,952; f90: 19,220; sh: 7,002; java: 6,360; perl: 3,524; cpp: 2,227; python: 1,350; lex: 989; fortran: 61; tcl: 12
file content (198 lines) | stat: -rw-r--r-- 6,716 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */
/*
 * $COPYRIGHT$
 * Copyright (c) 2018      Los Alamos National Security, LLC. All rights
 *                         reserved.
 * Copyright (c) 2018      Intel Inc. All rights reserved
 * $COPYRIGHT$
 *
 * Additional copyrights may follow
 *
 * $HEADER$
 */

#include "btl_ofi.h"
#include "btl_ofi_frag.h"
#include "btl_ofi_rdma.h"
#include "btl_ofi_endpoint.h"

static void mca_btl_ofi_base_frag_constructor (mca_btl_ofi_base_frag_t *frag)
{
    /* zero everything out */
    memset ((char *) frag + sizeof (frag->base), 0, sizeof (*frag) - sizeof (frag->base));

    frag->base.des_segments = frag->segments;
    frag->base.des_segment_count = 1;
}

static void mca_btl_ofi_base_frag_destructor (mca_btl_ofi_base_frag_t *frag)
{

}

OBJ_CLASS_INSTANCE(mca_btl_ofi_base_frag_t,
                   mca_btl_base_descriptor_t,
                   mca_btl_ofi_base_frag_constructor,
                   mca_btl_ofi_base_frag_destructor);

OBJ_CLASS_INSTANCE(mca_btl_ofi_frag_completion_t,
                   opal_free_list_item_t,
                   NULL,
                   NULL);

mca_btl_ofi_frag_completion_t *mca_btl_ofi_frag_completion_alloc
                                        (mca_btl_base_module_t *btl,
                                         mca_btl_ofi_context_t *context,
                                         mca_btl_ofi_base_frag_t *frag,
                                         int type)
{
    mca_btl_ofi_frag_completion_t *comp;

    comp = (mca_btl_ofi_frag_completion_t*) opal_free_list_get(&context->frag_comp_list);
    comp->base.btl = btl;
    comp->base.my_context = context;
    comp->base.my_list = &context->frag_comp_list;
    comp->base.type = type;

    comp->frag = frag;
    comp->comp_ctx.comp = comp;

    return comp;
}


mca_btl_base_descriptor_t *mca_btl_ofi_alloc(
                                mca_btl_base_module_t *btl,
                                mca_btl_base_endpoint_t *endpoint,
                                uint64_t order, size_t size, uint32_t flags)
{
    mca_btl_ofi_module_t *ofi_btl = (mca_btl_ofi_module_t*) btl;
    mca_btl_ofi_base_frag_t *frag = NULL;
    mca_btl_ofi_context_t *context = get_ofi_context(ofi_btl);

    frag = mca_btl_ofi_frag_alloc(ofi_btl, &context->frag_list, endpoint);

    if (OPAL_LIKELY(frag)) {
        frag->segments[0].seg_addr.pval = frag + 1;
        frag->segments[0].seg_len = size;

        frag->base.des_segment_count = 1;
        frag->base.des_segments = &frag->segments[0];
        frag->base.des_flags = flags;
        frag->base.order     = order;
        frag->hdr.len        = size;
    }

    return (mca_btl_base_descriptor_t*) frag;
}

int mca_btl_ofi_free (mca_btl_base_module_t *btl, mca_btl_base_descriptor_t *des)
{
    /* return the frag to the free list. */
    mca_btl_ofi_frag_return ((mca_btl_ofi_base_frag_t*) des);
    return OPAL_SUCCESS;
}

int mca_btl_ofi_send (mca_btl_base_module_t *btl,
                      mca_btl_base_endpoint_t *endpoint,
                      mca_btl_base_descriptor_t *descriptor,
                      mca_btl_base_tag_t tag)
{
    int rc = 0;
    mca_btl_ofi_context_t *context;
    mca_btl_ofi_module_t *ofi_btl = (mca_btl_ofi_module_t*) btl;
    mca_btl_ofi_endpoint_t *ofi_ep = (mca_btl_ofi_endpoint_t*) endpoint;
    mca_btl_ofi_base_frag_t *frag = (mca_btl_ofi_base_frag_t*) descriptor;
    mca_btl_ofi_frag_completion_t *comp;

    frag->base.des_flags |= MCA_BTL_DES_SEND_ALWAYS_CALLBACK;

    /* This tag is the active message tag for the remote side */
    frag->hdr.tag = tag;

    /* create completion context */
    context = get_ofi_context(ofi_btl);
    comp = mca_btl_ofi_frag_completion_alloc(btl, context, frag,
                                             MCA_BTL_OFI_TYPE_SEND);

    /* send the frag. Note that we start sending from BTL header + payload
     * because we need the other side to have this header information. */
    rc = fi_send(context->tx_ctx,
                 &frag->hdr,
                 sizeof(mca_btl_ofi_header_t) +  frag->hdr.len,
                 NULL,
                 ofi_ep->peer_addr,
                 &comp->comp_ctx);

    if (OPAL_UNLIKELY(FI_SUCCESS != rc)) {
        return OPAL_ERR_OUT_OF_RESOURCE;
    }

    MCA_BTL_OFI_NUM_SEND_INC(ofi_btl);
    return OPAL_SUCCESS;
}

int mca_btl_ofi_recv_frag (mca_btl_ofi_module_t *ofi_btl,
                           mca_btl_base_endpoint_t *endpoint,
                           mca_btl_ofi_context_t *context,
                           mca_btl_ofi_base_frag_t *frag)
{
    int rc;
    mca_btl_active_message_callback_t *reg;

    /* Tell PML where the payload is */
    frag->base.des_segments = frag->segments;
    frag->segments[0].seg_addr.pval = frag+1;
    frag->segments[0].seg_len = frag->hdr.len;
    frag->base.des_segment_count = 1;

    /* call the callback */
    reg = mca_btl_base_active_message_trigger + frag->hdr.tag;
    reg->cbfunc (&ofi_btl->super, frag->hdr.tag, &frag->base, reg->cbdata);
    mca_btl_ofi_frag_complete(frag, OPAL_SUCCESS);

    /* repost the recv */
    rc = mca_btl_ofi_post_recvs((mca_btl_base_module_t*) ofi_btl, context, 1);
    if (OPAL_SUCCESS != rc) {
        /* might not be that bad but let's just fail here. */
        BTL_ERROR(("failed reposting receive."));
        MCA_BTL_OFI_ABORT();
    }

    return OPAL_SUCCESS;
}

struct mca_btl_base_descriptor_t *mca_btl_ofi_prepare_src (
                                                mca_btl_base_module_t *btl,
                                                mca_btl_base_endpoint_t *endpoint,
                                                opal_convertor_t *convertor,
                                                uint8_t order, size_t reserve,
                                                size_t *size, uint32_t flags)
{
    struct iovec iov;
    size_t length;
    uint32_t iov_count = 1;
    mca_btl_ofi_base_frag_t *frag;

    /* allocate the frag with reserve. */
    frag = (mca_btl_ofi_base_frag_t*) mca_btl_ofi_alloc(btl, endpoint,
                                                        order, reserve, flags);
    if (OPAL_UNLIKELY(NULL == frag)) {
        return NULL;
    }

    /* pack the data after the reserve */
    iov.iov_len = *size;
    iov.iov_base = (IOVBASE_TYPE*)(((unsigned char*)(frag->segments[0].seg_addr.pval)) + reserve);
    opal_convertor_pack(convertor, &iov, &iov_count, &length);

    /* pass on frag information */
    frag->base.des_segments = frag->segments;
    frag->base.des_flags = flags;
    frag->base.order = MCA_BTL_NO_ORDER;
    frag->segments[0].seg_len += length;
    frag->hdr.len += length;
    *size = length;

    return &frag->base;
}