This source file includes following definitions.
- to_fi_op
- mca_btl_ofi_afop
- mca_btl_ofi_aop
- mca_btl_ofi_acswap
1
2
3
4
5
6
7
8
9
10
11
12
13
14 #include <rdma/fi_atomic.h>
15 #include "btl_ofi_rdma.h"
16
17 static inline int to_fi_op(mca_btl_base_atomic_op_t op)
18 {
19 switch (op) {
20 case MCA_BTL_ATOMIC_ADD:
21 return FI_SUM;
22 case MCA_BTL_ATOMIC_SWAP:
23 return FI_ATOMIC_WRITE;
24 default:
25 BTL_ERROR(("Unknown or unsupported atomic op."));
26 MCA_BTL_OFI_ABORT();
27
28
29 return OPAL_ERROR;
30 }
31 }
32
33 int mca_btl_ofi_afop (struct mca_btl_base_module_t *btl, struct mca_btl_base_endpoint_t *endpoint,
34 void *local_address, uint64_t remote_address, mca_btl_base_registration_handle_t *local_handle,
35 mca_btl_base_registration_handle_t *remote_handle, mca_btl_base_atomic_op_t op,
36 uint64_t operand, int flags, int order, mca_btl_base_rdma_completion_fn_t cbfunc,
37 void *cbcontext, void *cbdata)
38 {
39 int rc;
40 int fi_datatype = FI_UINT64;
41 int fi_op;
42
43 mca_btl_ofi_module_t *ofi_btl = (mca_btl_ofi_module_t *) btl;
44 mca_btl_ofi_endpoint_t *btl_endpoint = (mca_btl_ofi_endpoint_t*) endpoint;
45 mca_btl_ofi_rdma_completion_t *comp = NULL;
46 mca_btl_ofi_context_t *ofi_context;
47
48 ofi_context = get_ofi_context(ofi_btl);
49
50 if (flags & MCA_BTL_ATOMIC_FLAG_32BIT) {
51 fi_datatype = FI_UINT32;
52 }
53
54 fi_op = to_fi_op(op);
55
56 comp = mca_btl_ofi_rdma_completion_alloc(btl, endpoint,
57 ofi_context,
58 local_address,
59 local_handle,
60 cbfunc, cbcontext, cbdata,
61 MCA_BTL_OFI_TYPE_AFOP);
62
63
64 comp->operand = (uint64_t) operand;
65
66 remote_address = (remote_address - (uint64_t) remote_handle->base_addr);
67
68 rc = fi_fetch_atomic(ofi_context->tx_ctx,
69 (void*) &comp->operand, 1, NULL,
70 local_address, local_handle->desc,
71 btl_endpoint->peer_addr,
72 remote_address, remote_handle->rkey,
73 fi_datatype, fi_op, &comp->comp_ctx);
74
75 if (rc == -FI_EAGAIN) {
76 return OPAL_ERR_OUT_OF_RESOURCE;
77 } else if (rc < 0) {
78 BTL_ERROR(("fi_fetch_atomic failed with rc=%d (%s)", rc, fi_strerror(-rc)));
79 MCA_BTL_OFI_ABORT();
80 }
81
82 MCA_BTL_OFI_NUM_RDMA_INC(ofi_btl);
83
84 return OPAL_SUCCESS;
85 }
86
87 int mca_btl_ofi_aop (struct mca_btl_base_module_t *btl, mca_btl_base_endpoint_t *endpoint,
88 uint64_t remote_address, mca_btl_base_registration_handle_t *remote_handle,
89 mca_btl_base_atomic_op_t op, uint64_t operand, int flags, int order,
90 mca_btl_base_rdma_completion_fn_t cbfunc, void *cbcontext, void *cbdata)
91 {
92 int rc;
93 int fi_datatype = FI_UINT64;
94 int fi_op;
95
96 mca_btl_ofi_module_t *ofi_btl = (mca_btl_ofi_module_t *) btl;
97 mca_btl_ofi_endpoint_t *btl_endpoint = (mca_btl_ofi_endpoint_t*) endpoint;
98 mca_btl_ofi_rdma_completion_t *comp = NULL;
99 mca_btl_ofi_context_t *ofi_context;
100
101 ofi_context = get_ofi_context(ofi_btl);
102
103 if (flags & MCA_BTL_ATOMIC_FLAG_32BIT) {
104 fi_datatype = FI_UINT32;
105 }
106
107 fi_op = to_fi_op(op);
108
109 comp = mca_btl_ofi_rdma_completion_alloc(btl, endpoint,
110 ofi_context,
111 NULL,
112 NULL,
113 cbfunc, cbcontext, cbdata,
114 MCA_BTL_OFI_TYPE_AOP);
115
116
117 comp->operand = (uint64_t) operand;
118
119 remote_address = (remote_address - (uint64_t) remote_handle->base_addr);
120
121 rc = fi_atomic(ofi_context->tx_ctx,
122 (void*) &comp->operand, 1, NULL,
123 btl_endpoint->peer_addr,
124 remote_address, remote_handle->rkey,
125 fi_datatype, fi_op, &comp->comp_ctx);
126
127 if (rc == -FI_EAGAIN) {
128 return OPAL_ERR_OUT_OF_RESOURCE;
129 } else if (rc < 0) {
130 BTL_ERROR(("fi_atomic failed with rc=%d (%s)", rc, fi_strerror(-rc)));
131 MCA_BTL_OFI_ABORT();
132 }
133
134 MCA_BTL_OFI_NUM_RDMA_INC(ofi_btl);
135
136 return OPAL_SUCCESS;
137 }
138
139 int mca_btl_ofi_acswap (struct mca_btl_base_module_t *btl, struct mca_btl_base_endpoint_t *endpoint,
140 void *local_address, uint64_t remote_address, mca_btl_base_registration_handle_t *local_handle,
141 mca_btl_base_registration_handle_t *remote_handle, uint64_t compare, uint64_t value, int flags,
142 int order, mca_btl_base_rdma_completion_fn_t cbfunc, void *cbcontext, void *cbdata)
143 {
144 int rc;
145 int fi_datatype = FI_UINT64;
146
147 mca_btl_ofi_rdma_completion_t *comp = NULL;
148
149 mca_btl_ofi_module_t *ofi_btl = (mca_btl_ofi_module_t *) btl;
150 mca_btl_ofi_endpoint_t *btl_endpoint = (mca_btl_ofi_endpoint_t*) endpoint;
151 mca_btl_ofi_context_t *ofi_context;
152
153 ofi_context = get_ofi_context(ofi_btl);
154
155 if (flags & MCA_BTL_ATOMIC_FLAG_32BIT) {
156 fi_datatype = FI_UINT32;
157 }
158
159 comp = mca_btl_ofi_rdma_completion_alloc(btl, endpoint,
160 ofi_context,
161 local_address,
162 local_handle,
163 cbfunc, cbcontext, cbdata,
164 MCA_BTL_OFI_TYPE_CSWAP);
165
166
167 comp->operand = (uint64_t) value;
168 comp->compare = (uint64_t) compare;
169
170 remote_address = (remote_address - (uint64_t) remote_handle->base_addr);
171
172
173 rc = fi_compare_atomic(ofi_context->tx_ctx,
174 (void*) &comp->operand, 1, NULL,
175 (void*) &comp->compare, NULL,
176 local_address, local_handle->desc,
177 btl_endpoint->peer_addr,
178 remote_address, remote_handle->rkey,
179 fi_datatype,
180 FI_CSWAP,
181 &comp->comp_ctx);
182
183 if (rc == -FI_EAGAIN) {
184 return OPAL_ERR_OUT_OF_RESOURCE;
185 } else if (rc < 0) {
186 BTL_ERROR(("fi_compare_atomic failed with rc=%d (%s)", rc, fi_strerror(-rc)));
187 MCA_BTL_OFI_ABORT();
188 }
189
190 MCA_BTL_OFI_NUM_RDMA_INC(ofi_btl);
191
192 return OPAL_SUCCESS;
193 }