-
Notifications
You must be signed in to change notification settings - Fork 60
/
test_rma.py
210 lines (178 loc) · 6.03 KB
/
test_rma.py
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
199
200
201
202
203
204
205
206
207
208
209
210
import array
import io
import mmap
import os
import pytest
from ucp._libs import ucx_api
from ucp._libs.utils_test import blocking_flush
builtin_buffers = [
b"",
b"abcd",
array.array("i", []),
array.array("i", [0, 1, 2, 3]),
array.array("I", [0, 1, 2, 3]),
array.array("f", []),
array.array("f", [0, 1, 2, 3]),
array.array("d", [0, 1, 2, 3]),
memoryview(array.array("B", [0, 1, 2, 3, 4, 5])).cast("B", (3, 2)),
memoryview(b"abcd"),
memoryview(bytearray(b"abcd")),
io.BytesIO(b"abcd").getbuffer(),
mmap.mmap(-1, 5),
]
def _(*args, **kwargs):
pass
def test_flush():
ctx = ucx_api.UCXContext({})
worker = ucx_api.UCXWorker(ctx)
ep = ucx_api.UCXEndpoint.create_from_worker_address(
worker,
worker.get_address(),
endpoint_error_handling=True,
)
req = ep.flush(_)
if req is None:
info = req.info
while info["status"] == "pending":
worker.progress()
assert info["status"] == "finished"
@pytest.mark.parametrize("msg_size", [10, 2**24])
def test_implicit(msg_size):
ctx = ucx_api.UCXContext({})
mem = ucx_api.UCXMemoryHandle.alloc(ctx, msg_size)
packed_rkey = mem.pack_rkey()
worker = ucx_api.UCXWorker(ctx)
ep = ucx_api.UCXEndpoint.create_from_worker_address(
worker,
worker.get_address(),
endpoint_error_handling=True,
)
rkey = ep.unpack_rkey(packed_rkey)
self_mem = ucx_api.RemoteMemory(rkey, mem.address, msg_size)
send_msg = bytes(os.urandom(msg_size))
if not self_mem.put_nbi(send_msg):
blocking_flush(ep)
recv_msg = bytearray(len(send_msg))
if not self_mem.get_nbi(recv_msg):
blocking_flush(ep)
assert send_msg == recv_msg
@pytest.mark.parametrize("msg_size", [10, 2**24])
def test_explicit(msg_size):
ctx = ucx_api.UCXContext({})
mem = ucx_api.UCXMemoryHandle.alloc(ctx, msg_size)
packed_rkey = mem.pack_rkey()
worker = ucx_api.UCXWorker(ctx)
ep = ucx_api.UCXEndpoint.create_from_worker_address(
worker,
worker.get_address(),
endpoint_error_handling=True,
)
rkey = ep.unpack_rkey(packed_rkey)
self_mem = ucx_api.RemoteMemory(rkey, mem.address, msg_size)
send_msg = bytes(os.urandom(msg_size))
put_req = self_mem.put_nb(send_msg, _)
if put_req is not None:
blocking_flush(ep)
recv_msg = bytearray(len(send_msg))
recv_req = self_mem.get_nb(recv_msg, _)
if recv_req is not None:
blocking_flush(ep)
assert send_msg == recv_msg
@pytest.mark.parametrize("msg_size", [10, 2**24])
def test_ucxio(msg_size):
ctx = ucx_api.UCXContext({})
mem = ucx_api.UCXMemoryHandle.alloc(ctx, msg_size)
packed_rkey = mem.pack_rkey()
worker = ucx_api.UCXWorker(ctx)
ep = ucx_api.UCXEndpoint.create_from_worker_address(
worker,
worker.get_address(),
endpoint_error_handling=True,
)
rkey = ep.unpack_rkey(packed_rkey)
uio = ucx_api.UCXIO(mem.address, msg_size, rkey)
send_msg = bytes(os.urandom(msg_size))
uio.write(send_msg)
uio.seek(0)
recv_msg = uio.read(msg_size)
assert send_msg == recv_msg
# The alloc function may return more memory than requested based on OS page
# size. So this test for insane seek values uses 2GB seeks to make sure we
# always run into trouble
max_possible = 2 * 1024 * 1024 * 1024
@pytest.mark.parametrize("seek_loc", [-max_possible, max_possible])
@pytest.mark.parametrize("seek_flag", [io.SEEK_CUR, io.SEEK_SET, io.SEEK_END])
def test_ucxio_seek_bad(seek_loc, seek_flag):
msg_size = 1024
ctx = ucx_api.UCXContext({})
mem = ucx_api.UCXMemoryHandle.alloc(ctx, msg_size)
packed_rkey = mem.pack_rkey()
worker = ucx_api.UCXWorker(ctx)
ep = ucx_api.UCXEndpoint.create_from_worker_address(
worker,
worker.get_address(),
endpoint_error_handling=True,
)
rkey = ep.unpack_rkey(packed_rkey)
uio = ucx_api.UCXIO(mem.address, msg_size, rkey)
send_msg = bytes(os.urandom(msg_size))
uio.write(send_msg)
uio.seek(seek_loc, seek_flag)
recv_msg = uio.read(len(send_msg))
if seek_loc > 0:
expected = b""
else:
expected = send_msg
assert recv_msg == expected
@pytest.mark.parametrize(
"seek_data", [(io.SEEK_CUR, -25), (io.SEEK_SET, 4), (io.SEEK_END, -8)]
)
def test_ucxio_seek_good(seek_data):
seek_flag, seek_dest = seek_data
ctx = ucx_api.UCXContext({})
mem = ucx_api.UCXMemoryHandle.alloc(ctx, 1024)
msg_size = mem.length
packed_rkey = mem.pack_rkey()
worker = ucx_api.UCXWorker(ctx)
ep = ucx_api.UCXEndpoint.create_from_worker_address(
worker,
worker.get_address(),
endpoint_error_handling=True,
)
rkey = ep.unpack_rkey(packed_rkey)
uio = ucx_api.UCXIO(mem.address, msg_size, rkey)
send_msg = bytes(os.urandom(msg_size))
uio.write(send_msg)
uio.seek(seek_dest, seek_flag)
recv_msg = uio.read(4)
assert recv_msg == send_msg[seek_dest : seek_dest + 4]
def test_force_requests():
msg_size = 1024
ctx = ucx_api.UCXContext({})
mem = ucx_api.UCXMemoryHandle.alloc(ctx, msg_size)
packed_rkey = mem.pack_rkey()
worker = ucx_api.UCXWorker(ctx)
ep = ucx_api.UCXEndpoint.create_from_worker_address(
worker,
worker.get_address(),
endpoint_error_handling=True,
)
rkey = ep.unpack_rkey(packed_rkey)
self_mem = ucx_api.RemoteMemory(rkey, mem.address, msg_size)
counter = 0
send_msg = bytes(os.urandom(msg_size))
req = self_mem.put_nb(send_msg, _)
while req is None:
counter = counter + 1
req = self_mem.put_nb(send_msg, _)
# This `if` is here because some combinations of transports, such as
# normal desktop PCs, will never have their transports exhausted. So
# we have a break to make sure this test still completes
if counter > 10000:
pytest.xfail("Could not generate a request")
blocking_flush(worker)
while worker.progress():
pass
while self_mem.put_nb(send_msg, _):
pass
blocking_flush(worker)