| 1 |
/* SPDX-License-Identifier: BSD-2-Clause OR GPL-2.0-only */ |
| 2 |
/* SPDX-FileCopyrightText: Copyright Amazon.com, Inc. or its affiliates. All rights reserved. */ |
| 3 |
|
| 4 |
#include "efa_unit_tests.h" |
| 5 |
|
| 6 |
/** |
| 7 |
* @brief Test the runt size returned by efa_rdm_peer_get_runt_size |
| 8 |
* |
| 9 |
* @param resource efa_resource |
| 10 |
* @param iface hmem iface |
| 11 |
* @param peer_num_runt_bytes_in_flight how many runt bytes are in flight on the peer side |
| 12 |
* @param total_runt_size the total runt size |
| 13 |
* @param total_len the total length of the message to be sent |
| 14 |
* @param expected_runt_size the expected runt size |
| 15 |
*/ |
| 16 |
static |
| 17 |
void test_efa_rdm_peer_get_runt_size_impl( |
| 18 |
struct efa_resource *resource, |
| 19 |
enum fi_hmem_iface iface, size_t peer_num_runt_bytes_in_flight, |
| 20 |
size_t total_runt_size, size_t total_len, size_t expected_runt_size) |
| 21 |
{ |
| 22 |
struct efa_rdm_ep *efa_rdm_ep; |
| 23 |
struct efa_ep_addr raw_addr; |
| 24 |
size_t raw_addr_len = sizeof(raw_addr); |
| 25 |
struct efa_rdm_peer *peer; |
| 26 |
fi_addr_t addr; |
| 27 |
struct efa_mr mock_mr; |
| 28 |
struct efa_rdm_ope mock_txe; |
| 29 |
size_t runt_size; |
| 30 |
int ret; |
| 31 |
|
| 32 |
efa_rdm_ep = container_of(resource->ep, struct efa_rdm_ep, base_ep.util_ep.ep_fid); |
| 33 |
g_efa_hmem_info[iface].runt_size = total_runt_size; |
| 34 |
|
| 35 |
/* insert a fake peer */ |
| 36 |
ret = fi_getname(&resource->ep->fid, &raw_addr, &raw_addr_len); |
| 37 |
assert_int_equal(ret, 0); |
| 38 |
raw_addr.qpn = 1; |
| 39 |
raw_addr.qkey = 0x1234; |
| 40 |
ret = fi_av_insert(resource->av, &raw_addr, 1, &addr, 0 /* flags */, NULL /* context */); |
| 41 |
assert_int_equal(ret, 1); |
| 42 |
peer = efa_rdm_ep_get_peer(efa_rdm_ep, addr); |
| 43 |
peer->num_runt_bytes_in_flight = peer_num_runt_bytes_in_flight; |
| 44 |
|
| 45 |
mock_mr.peer.iface = iface; |
| 46 |
|
| 47 |
memset(&mock_txe, 0, sizeof(mock_txe)); |
| 48 |
mock_txe.total_len = total_len; |
| 49 |
mock_txe.addr = addr; |
| 50 |
mock_txe.desc[0] = &mock_mr; |
| 51 |
|
| 52 |
runt_size = efa_rdm_peer_get_runt_size(peer, efa_rdm_ep, &mock_txe); |
| 53 |
assert_true(runt_size == expected_runt_size); |
| 54 |
} |
| 55 |
|
| 56 |
void test_efa_rdm_peer_get_runt_size_no_enough_runt(struct efa_resource **state) |
| 57 |
{ |
| 58 |
struct efa_resource *resource = *state; |
| 59 |
size_t msg_length; |
| 60 |
size_t expected_runt_size; |
| 61 |
size_t peer_num_runt_bytes_in_flight; |
| 62 |
size_t total_runt_size; |
| 63 |
|
| 64 |
efa_unit_test_resource_construct(resource, FI_EP_RDM, EFA_FABRIC_NAME); |
| 65 |
|
| 66 |
msg_length = 12000; |
| 67 |
peer_num_runt_bytes_in_flight = 1001; |
| 68 |
total_runt_size = 1000; |
| 69 |
/* 1001 is exceeding 1000, cannot runt */ |
| 70 |
expected_runt_size = 0; |
| 71 |
test_efa_rdm_peer_get_runt_size_impl(resource, FI_HMEM_SYSTEM, peer_num_runt_bytes_in_flight, total_runt_size, msg_length, expected_runt_size); |
| 72 |
} |
| 73 |
|
| 74 |
void test_efa_rdm_peer_get_runt_size_cuda_memory_smaller_than_alignment(struct efa_resource **state) |
| 75 |
{ |
| 76 |
struct efa_resource *resource = *state; |
| 77 |
size_t msg_length; |
| 78 |
size_t expected_runt_size; |
| 79 |
size_t peer_num_runt_bytes_in_flight; |
| 80 |
size_t total_runt_size; |
| 81 |
|
| 82 |
efa_unit_test_resource_construct(resource, FI_EP_RDM, EFA_FABRIC_NAME); |
| 83 |
|
| 84 |
msg_length = 12000; |
| 85 |
peer_num_runt_bytes_in_flight = 1000; |
| 86 |
total_runt_size = 1048; |
| 87 |
/* 1048 - 1000 is smaller than cuda memory alignment (64), runt size must be 0 */ |
| 88 |
expected_runt_size = 0; |
| 89 |
test_efa_rdm_peer_get_runt_size_impl(resource, FI_HMEM_CUDA, peer_num_runt_bytes_in_flight, total_runt_size, msg_length, expected_runt_size); |
| 90 |
} |
| 91 |
|
| 92 |
void test_efa_rdm_peer_get_runt_size_cuda_memory_exceeding_total_len(struct efa_resource **state) |
| 93 |
{ |
| 94 |
struct efa_resource *resource = *state; |
| 95 |
size_t msg_length; |
| 96 |
size_t expected_runt_size; |
| 97 |
size_t peer_num_runt_bytes_in_flight; |
| 98 |
size_t total_runt_size; |
| 99 |
|
| 100 |
efa_unit_test_resource_construct(resource, FI_EP_RDM, EFA_FABRIC_NAME); |
| 101 |
|
| 102 |
msg_length = 12000; |
| 103 |
peer_num_runt_bytes_in_flight = 0; |
| 104 |
total_runt_size = 16384; |
| 105 |
/* 16384 - 0 is exceeding 12000 (total_len), runt size must be 12000 // 64 * 64 = 11968 */ |
| 106 |
expected_runt_size = 11968; |
| 107 |
test_efa_rdm_peer_get_runt_size_impl(resource, FI_HMEM_CUDA, peer_num_runt_bytes_in_flight, total_runt_size, msg_length, expected_runt_size); |
| 108 |
} |
| 109 |
|
| 110 |
void test_efa_rdm_peer_get_runt_size_cuda_memory_normal(struct efa_resource **state) |
| 111 |
{ |
| 112 |
struct efa_resource *resource = *state; |
| 113 |
size_t msg_length; |
| 114 |
size_t expected_runt_size; |
| 115 |
size_t peer_num_runt_bytes_in_flight; |
| 116 |
size_t total_runt_size; |
| 117 |
|
| 118 |
efa_unit_test_resource_construct(resource, FI_EP_RDM, EFA_FABRIC_NAME); |
| 119 |
|
| 120 |
msg_length = 12000; |
| 121 |
peer_num_runt_bytes_in_flight = 10000; |
| 122 |
total_runt_size = 16384; |
| 123 |
/* 16384 - 10000 is smaller than 12000 (total_len), runt size must be (16384 - 10000) // 64 * 64 = 6336 */ |
| 124 |
expected_runt_size = 6336; |
| 125 |
test_efa_rdm_peer_get_runt_size_impl(resource, FI_HMEM_CUDA, peer_num_runt_bytes_in_flight, total_runt_size, msg_length, expected_runt_size); |
| 126 |
} |
| 127 |
|
| 128 |
/* When using LL128 protocol, the segmented size of runting read must be 128 multiple. */ |
| 129 |
void test_efa_rdm_peer_get_runt_size_cuda_memory_128_multiple_alignment(struct efa_resource **state) |
| 130 |
{ |
| 131 |
struct efa_resource *resource = *state; |
| 132 |
struct efa_rdm_ep *efa_rdm_ep; |
| 133 |
size_t msg_length; |
| 134 |
size_t expected_runt_size; |
| 135 |
size_t peer_num_runt_bytes_in_flight; |
| 136 |
size_t total_runt_size; |
| 137 |
|
| 138 |
efa_unit_test_resource_construct(resource, FI_EP_RDM, EFA_FABRIC_NAME); |
| 139 |
efa_rdm_ep = container_of(resource->ep, struct efa_rdm_ep, base_ep.util_ep.ep_fid); |
| 140 |
efa_rdm_ep->sendrecv_in_order_aligned_128_bytes = 1; |
| 141 |
|
| 142 |
msg_length = 12000; |
| 143 |
peer_num_runt_bytes_in_flight = 10240; |
| 144 |
total_runt_size = 16384; |
| 145 |
/* 16384 - 10240 is smaller than 12000 (total_len), |
| 146 |
* runt size must be (16384 - 10240) // 128 * 128 = 6144 |
| 147 |
*/ |
| 148 |
expected_runt_size = 6144; |
| 149 |
test_efa_rdm_peer_get_runt_size_impl(resource, FI_HMEM_CUDA, peer_num_runt_bytes_in_flight, total_runt_size, msg_length, expected_runt_size); |
| 150 |
} |
| 151 |
|
| 152 |
void test_efa_rdm_peer_get_runt_size_cuda_memory_non_128_multiple_alignment(struct efa_resource **state) |
| 153 |
{ |
| 154 |
struct efa_resource *resource = *state; |
| 155 |
struct efa_rdm_ep *efa_rdm_ep; |
| 156 |
size_t msg_length; |
| 157 |
size_t expected_runt_size; |
| 158 |
size_t peer_num_runt_bytes_in_flight; |
| 159 |
size_t total_runt_size; |
| 160 |
|
| 161 |
efa_unit_test_resource_construct(resource, FI_EP_RDM, EFA_FABRIC_NAME); |
| 162 |
efa_rdm_ep = container_of(resource->ep, struct efa_rdm_ep, base_ep.util_ep.ep_fid); |
| 163 |
efa_rdm_ep->sendrecv_in_order_aligned_128_bytes = 1; |
| 164 |
|
| 165 |
msg_length = 12000; |
| 166 |
peer_num_runt_bytes_in_flight = 512; |
| 167 |
total_runt_size = 1004; |
| 168 |
/* 1004 - 512 is smaller than 12000 (total_len), |
| 169 |
* runt size must be (1004 - 512) // 128 * 128 = 384 |
| 170 |
*/ |
| 171 |
expected_runt_size = 384; |
| 172 |
test_efa_rdm_peer_get_runt_size_impl(resource, FI_HMEM_CUDA, peer_num_runt_bytes_in_flight, total_runt_size, msg_length, expected_runt_size); |
| 173 |
} |
| 174 |
|
| 175 |
void test_efa_rdm_peer_get_runt_size_cuda_memory_smaller_than_128_alignment(struct efa_resource **state) |
| 176 |
{ |
| 177 |
struct efa_resource *resource = *state; |
| 178 |
struct efa_rdm_ep *efa_rdm_ep; |
| 179 |
size_t msg_length; |
| 180 |
size_t expected_runt_size; |
| 181 |
size_t peer_num_runt_bytes_in_flight; |
| 182 |
size_t total_runt_size; |
| 183 |
|
| 184 |
efa_unit_test_resource_construct(resource, FI_EP_RDM, EFA_FABRIC_NAME); |
| 185 |
efa_rdm_ep = container_of(resource->ep, struct efa_rdm_ep, base_ep.util_ep.ep_fid); |
| 186 |
efa_rdm_ep->sendrecv_in_order_aligned_128_bytes = 1; |
| 187 |
|
| 188 |
msg_length = 12000; |
| 189 |
peer_num_runt_bytes_in_flight = 1000; |
| 190 |
total_runt_size = 1048; |
| 191 |
/* 1048 - 1000 is smaller than 128 memory alignment, runt size must be 0 */ |
| 192 |
expected_runt_size = 0; |
| 193 |
test_efa_rdm_peer_get_runt_size_impl(resource, FI_HMEM_CUDA, peer_num_runt_bytes_in_flight, total_runt_size, msg_length, expected_runt_size); |
| 194 |
} |
| 195 |
|
| 196 |
void test_efa_rdm_peer_get_runt_size_cuda_memory_exceeding_total_len_128_alignment(struct efa_resource **state) |
| 197 |
{ |
| 198 |
struct efa_resource *resource = *state; |
| 199 |
struct efa_rdm_ep *efa_rdm_ep; |
| 200 |
size_t msg_length; |
| 201 |
size_t expected_runt_size; |
| 202 |
size_t peer_num_runt_bytes_in_flight; |
| 203 |
size_t total_runt_size; |
| 204 |
|
| 205 |
efa_unit_test_resource_construct(resource, FI_EP_RDM, EFA_FABRIC_NAME); |
| 206 |
efa_rdm_ep = container_of(resource->ep, struct efa_rdm_ep, base_ep.util_ep.ep_fid); |
| 207 |
efa_rdm_ep->sendrecv_in_order_aligned_128_bytes = 1; |
| 208 |
|
| 209 |
msg_length = 12000; |
| 210 |
peer_num_runt_bytes_in_flight = 0; |
| 211 |
total_runt_size = 16384; |
| 212 |
/* 16384 - 0 is exceeding 12000 (total_len), runt size must be 12000 // 128 * 128 = 11904 */ |
| 213 |
expected_runt_size = 11904; |
| 214 |
test_efa_rdm_peer_get_runt_size_impl(resource, FI_HMEM_CUDA, peer_num_runt_bytes_in_flight, total_runt_size, msg_length, expected_runt_size); |
| 215 |
} |
| 216 |
|
| 217 |
void test_efa_rdm_peer_get_runt_size_host_memory_smaller_than_alignment(struct efa_resource **state) |
| 218 |
{ |
| 219 |
struct efa_resource *resource = *state; |
| 220 |
size_t msg_length; |
| 221 |
size_t expected_runt_size; |
| 222 |
size_t peer_num_runt_bytes_in_flight; |
| 223 |
size_t total_runt_size; |
| 224 |
|
| 225 |
efa_unit_test_resource_construct(resource, FI_EP_RDM, EFA_FABRIC_NAME); |
| 226 |
|
| 227 |
msg_length = 12000; |
| 228 |
peer_num_runt_bytes_in_flight = 1000; |
| 229 |
total_runt_size = 1004; |
| 230 |
/* 1004 - 1000 is smaller than host memory alignment (8), runt size must be 0 */ |
| 231 |
expected_runt_size = 0; |
| 232 |
test_efa_rdm_peer_get_runt_size_impl(resource, FI_HMEM_SYSTEM, peer_num_runt_bytes_in_flight, total_runt_size, msg_length, expected_runt_size); |
| 233 |
} |
| 234 |
|
| 235 |
void test_efa_rdm_peer_get_runt_size_host_memory_exceeding_total_len(struct efa_resource **state) |
| 236 |
{ |
| 237 |
struct efa_resource *resource = *state; |
| 238 |
size_t msg_length; |
| 239 |
size_t expected_runt_size; |
| 240 |
size_t peer_num_runt_bytes_in_flight; |
| 241 |
size_t total_runt_size; |
| 242 |
|
| 243 |
efa_unit_test_resource_construct(resource, FI_EP_RDM, EFA_FABRIC_NAME); |
| 244 |
|
| 245 |
msg_length = 1111; |
| 246 |
peer_num_runt_bytes_in_flight = 0; |
| 247 |
total_runt_size = 16384; |
| 248 |
/* 16384 - 0 is exceeding 1111 (total_len), runt size must be 1111 // 8 * 8 = 1104 */ |
| 249 |
expected_runt_size = 1104; |
| 250 |
test_efa_rdm_peer_get_runt_size_impl(resource, FI_HMEM_SYSTEM, peer_num_runt_bytes_in_flight, total_runt_size, msg_length, expected_runt_size); |
| 251 |
} |
| 252 |
|
| 253 |
void test_efa_rdm_peer_get_runt_size_host_memory_normal(struct efa_resource **state) |
| 254 |
{ |
| 255 |
struct efa_resource *resource = *state; |
| 256 |
size_t msg_length; |
| 257 |
size_t expected_runt_size; |
| 258 |
size_t peer_num_runt_bytes_in_flight; |
| 259 |
size_t total_runt_size; |
| 260 |
|
| 261 |
efa_unit_test_resource_construct(resource, FI_EP_RDM, EFA_FABRIC_NAME); |
| 262 |
|
| 263 |
msg_length = 12000; |
| 264 |
peer_num_runt_bytes_in_flight = 10000; |
| 265 |
total_runt_size = 11111; |
| 266 |
/* 11111 - 10000 is smaller than 12000 (total_len), runt size must be (11111 - 10000) // 8 * 8 = 1104 */ |
| 267 |
expected_runt_size = 1104; |
| 268 |
test_efa_rdm_peer_get_runt_size_impl(resource, FI_HMEM_SYSTEM, peer_num_runt_bytes_in_flight, total_runt_size, msg_length, expected_runt_size); |
| 269 |
} |
| 270 |
|
| 271 |
/** |
| 272 |
* @brief Test the protocol returned by efa_rdm_peer_select_readbase_rtm() |
| 273 |
* |
| 274 |
* @param resource efa test resources |
| 275 |
* @param iface hmem iface |
| 276 |
* @param peer_num_runt_bytes_in_flight how many runt bytes are in flight on the peer side |
| 277 |
* @param total_runt_size the total runt size |
| 278 |
* @param total_len the total length of the message to be sent |
| 279 |
* @param op the operational code (ofi_op_msg or ofi_op_tag) |
| 280 |
* @param fi_flags the op flags of the send operations |
| 281 |
* @param expected_protocol the expected protocol to be selected |
| 282 |
*/ |
| 283 |
static |
| 284 |
void test_efa_rdm_peer_select_readbase_rtm_impl( |
| 285 |
struct efa_resource *resource, |
| 286 |
enum fi_hmem_iface iface, size_t peer_num_runt_bytes_in_flight, |
| 287 |
size_t total_runt_size, size_t total_len, |
| 288 |
int op, uint64_t fi_flags, int expected_protocol) |
| 289 |
{ |
| 290 |
struct efa_rdm_ep *efa_rdm_ep; |
| 291 |
struct efa_ep_addr raw_addr; |
| 292 |
size_t raw_addr_len = sizeof(raw_addr); |
| 293 |
struct efa_rdm_peer *peer; |
| 294 |
fi_addr_t addr; |
| 295 |
struct efa_mr mock_mr; |
| 296 |
struct efa_rdm_ope mock_txe; |
| 297 |
int readbase_rtm; |
| 298 |
int ret; |
| 299 |
|
| 300 |
efa_rdm_ep = container_of(resource->ep, struct efa_rdm_ep, base_ep.util_ep.ep_fid); |
| 301 |
g_efa_hmem_info[iface].runt_size = total_runt_size; |
| 302 |
|
| 303 |
/* insert a fake peer */ |
| 304 |
ret = fi_getname(&resource->ep->fid, &raw_addr, &raw_addr_len); |
| 305 |
assert_int_equal(ret, 0); |
| 306 |
raw_addr.qpn = 1; |
| 307 |
raw_addr.qkey = 0x1234; |
| 308 |
ret = fi_av_insert(resource->av, &raw_addr, 1, &addr, 0 /* flags */, NULL /* context */); |
| 309 |
assert_int_equal(ret, 1); |
| 310 |
peer = efa_rdm_ep_get_peer(efa_rdm_ep, addr); |
| 311 |
peer->num_runt_bytes_in_flight = peer_num_runt_bytes_in_flight; |
| 312 |
|
| 313 |
mock_mr.peer.iface = iface; |
| 314 |
|
| 315 |
memset(&mock_txe, 0, sizeof(mock_txe)); |
| 316 |
mock_txe.total_len = total_len; |
| 317 |
mock_txe.addr = addr; |
| 318 |
mock_txe.desc[0] = &mock_mr; |
| 319 |
mock_txe.op = op; |
| 320 |
mock_txe.fi_flags = fi_flags; |
| 321 |
|
| 322 |
readbase_rtm = efa_rdm_peer_select_readbase_rtm(peer, efa_rdm_ep, &mock_txe); |
| 323 |
assert_true(readbase_rtm == expected_protocol); |
| 324 |
} |
| 325 |
|
| 326 |
void test_efa_rdm_peer_select_readbase_rtm_no_runt(struct efa_resource **state) |
| 327 |
{ |
| 328 |
struct efa_resource *resource = *state; |
| 329 |
size_t msg_length; |
| 330 |
size_t peer_num_runt_bytes_in_flight; |
| 331 |
size_t total_runt_size; |
| 332 |
|
| 333 |
efa_unit_test_resource_construct(resource, FI_EP_RDM, EFA_FABRIC_NAME); |
| 334 |
|
| 335 |
msg_length = 12000; |
| 336 |
peer_num_runt_bytes_in_flight = 1000; |
| 337 |
total_runt_size = 1048; |
| 338 |
/* 1048 - 1000 is smaller than cuda memory alignment, runt size must be 0, use long read protocol */ |
| 339 |
test_efa_rdm_peer_select_readbase_rtm_impl(resource, FI_HMEM_CUDA, peer_num_runt_bytes_in_flight, |
| 340 |
total_runt_size, msg_length, ofi_op_msg, 0, EFA_RDM_LONGREAD_MSGRTM_PKT); |
| 341 |
} |
| 342 |
|
| 343 |
void test_efa_rdm_peer_select_readbase_rtm_do_runt(struct efa_resource **state) |
| 344 |
{ |
| 345 |
struct efa_resource *resource = *state; |
| 346 |
size_t msg_length; |
| 347 |
size_t peer_num_runt_bytes_in_flight; |
| 348 |
size_t total_runt_size; |
| 349 |
|
| 350 |
efa_unit_test_resource_construct(resource, FI_EP_RDM, EFA_FABRIC_NAME); |
| 351 |
|
| 352 |
msg_length = 12000; |
| 353 |
peer_num_runt_bytes_in_flight = 1000; |
| 354 |
total_runt_size = 2000; |
| 355 |
/* 2000 - 1000 is larger than cuda memory alignment, should use runt read protocol */ |
| 356 |
test_efa_rdm_peer_select_readbase_rtm_impl(resource, FI_HMEM_CUDA, peer_num_runt_bytes_in_flight, |
| 357 |
total_runt_size, msg_length, ofi_op_msg, 0, EFA_RDM_RUNTREAD_MSGRTM_PKT); |
| 358 |
} |