Skip to content

Commit ea4037d

Browse files
committed
fix cython bindings
Signed-off-by: niranda perera <niranda.perera@gmail.com>
1 parent 20a2ae2 commit ea4037d

16 files changed

Lines changed: 118 additions & 37 deletions

File tree

python/rapidsmpf/rapidsmpf/benchmarks/streaming_benchmark.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,11 @@ def streaming_shuffle(
175175
consumer_thread.join(timeout=wait_timeout)
176176

177177

178-
def ucxx_mpi_setup(options: Options, progress_thread: ProgressThread) -> Communicator:
178+
def ucxx_mpi_setup(
179+
options: Options,
180+
progress_thread: ProgressThread,
181+
statistics: Statistics | None = None,
182+
) -> Communicator:
179183
"""
180184
Bootstrap UCXX cluster using MPI.
181185
@@ -185,6 +189,9 @@ def ucxx_mpi_setup(options: Options, progress_thread: ProgressThread) -> Communi
185189
Configuration options.
186190
progress_thread
187191
Progress thread for the communicator.
192+
statistics
193+
Statistics object for recording communication metrics. If ``None``
194+
(the default), statistics tracking is disabled.
188195
189196
Returns
190197
-------
@@ -201,7 +208,7 @@ def ucxx_mpi_setup(options: Options, progress_thread: ProgressThread) -> Communi
201208

202209
if MPI.COMM_WORLD.Get_rank() == 0:
203210
comm = new_communicator(
204-
MPI.COMM_WORLD.size, None, None, options, progress_thread
211+
MPI.COMM_WORLD.size, None, None, options, progress_thread, statistics
205212
)
206213
root_address_str = get_root_ucxx_address(comm)
207214
else:
@@ -212,7 +219,12 @@ def ucxx_mpi_setup(options: Options, progress_thread: ProgressThread) -> Communi
212219
if MPI.COMM_WORLD.Get_rank() != 0:
213220
root_address = ucx_api.UCXAddress.create_from_buffer(root_address_str)
214221
comm = new_communicator(
215-
MPI.COMM_WORLD.size, None, root_address, options, progress_thread
222+
MPI.COMM_WORLD.size,
223+
None,
224+
root_address,
225+
options,
226+
progress_thread,
227+
statistics,
216228
)
217229

218230
assert comm.nranks == MPI.COMM_WORLD.size
@@ -245,15 +257,15 @@ def setup_and_run(args: argparse.Namespace) -> None:
245257
progress_thread = ProgressThread(stats)
246258
if args.comm == "mpi":
247259
comm = rapidsmpf.communicator.mpi.new_communicator(
248-
MPI.COMM_WORLD, options, progress_thread
260+
MPI.COMM_WORLD, options, progress_thread, stats
249261
)
250262
elif args.comm == "ucxx":
251263
if rapidsmpf.bootstrap.is_running_with_rrun():
252264
raise ValueError(
253265
"UCXX communicator is not supported with rrun yet, due to missing allreduce support"
254266
)
255267
else:
256-
comm = ucxx_mpi_setup(options, progress_thread)
268+
comm = ucxx_mpi_setup(options, progress_thread, stats)
257269

258270
# Create a buffer resource that limits device memory if `--spill-device`
259271
# is not None.

python/rapidsmpf/rapidsmpf/coll/allgather.pxd

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ from rapidsmpf.memory.buffer_resource cimport (BufferResource,
1414
cpp_BufferResource)
1515
from rapidsmpf.memory.packed_data cimport cpp_PackedData
1616
from rapidsmpf.progress_thread cimport cpp_ProgressThread
17-
from rapidsmpf.statistics cimport cpp_Statistics
1817

1918

2019
cdef extern from "<rapidsmpf/coll/allgather.hpp>" namespace \
@@ -30,8 +29,7 @@ cdef extern from "<rapidsmpf/coll/allgather.hpp>" nogil:
3029
cpp_AllGather(
3130
shared_ptr[cpp_Communicator] comm,
3231
int32_t op_id,
33-
cpp_BufferResource *br,
34-
shared_ptr[cpp_Statistics] statistics
32+
cpp_BufferResource *br
3533
) except +ex_handler
3634
void insert(uint64_t sequence_number, cpp_PackedData packed_data) \
3735
except +ex_handler

python/rapidsmpf/rapidsmpf/coll/allgather.pyi

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,13 @@ from __future__ import annotations
55
from rapidsmpf.communicator.communicator import Communicator
66
from rapidsmpf.memory.buffer_resource import BufferResource
77
from rapidsmpf.memory.packed_data import PackedData
8-
from rapidsmpf.statistics import Statistics
98

109
class AllGather:
1110
def __init__(
1211
self,
1312
comm: Communicator,
1413
op_id: int,
1514
br: BufferResource,
16-
statistics: Statistics | None = None,
1715
) -> None: ...
1816
@property
1917
def comm(self) -> Communicator: ...

python/rapidsmpf/rapidsmpf/coll/allgather.pyx

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ from rapidsmpf.memory.buffer_resource cimport (BufferResource,
1414
cpp_BufferResource)
1515
from rapidsmpf.memory.packed_data cimport (PackedData, cpp_PackedData,
1616
packed_data_vector_to_list)
17-
from rapidsmpf.statistics cimport Statistics
1817

1918

2019
cdef class AllGather:
@@ -37,8 +36,6 @@ cdef class AllGather:
3736
between 0 and 2^20 - 1.
3837
br
3938
Buffer resource for memory allocation.
40-
statistics
41-
Statistics collection instance. If None, statistics is disabled.
4239
4340
Notes
4441
-----
@@ -52,19 +49,15 @@ cdef class AllGather:
5249
Communicator comm not None,
5350
int32_t op_id,
5451
BufferResource br not None,
55-
Statistics statistics = None,
5652
):
5753
self._br = br
5854
self._comm = comm
5955
cdef cpp_BufferResource* br_ = br.ptr()
60-
if statistics is None:
61-
statistics = Statistics(enable=False) # Disables statistics.
6256
with nogil:
6357
self._handle = make_unique[cpp_AllGather](
6458
comm._handle,
6559
op_id,
6660
br_,
67-
statistics._handle,
6861
)
6962

7063
def __dealloc__(self):

python/rapidsmpf/rapidsmpf/communicator/communicator.pxd

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ from libcpp.string cimport string
77

88
from rapidsmpf._detail.exception_handling cimport ex_handler
99
from rapidsmpf.progress_thread cimport cpp_ProgressThread
10+
from rapidsmpf.statistics cimport Statistics, cpp_Statistics
1011

1112

1213
cdef extern from "<rapidsmpf/communicator/communicator.hpp>" namespace \
@@ -37,6 +38,7 @@ cdef extern from "<rapidsmpf/communicator/communicator.hpp>" nogil:
3738
string str() except +ex_handler
3839
shared_ptr[cpp_ProgressThread] progress_thread() except +ex_handler
3940
shared_ptr[cpp_Logger] logger()
41+
shared_ptr[cpp_Statistics] statistics()
4042

4143
cdef class Communicator:
4244
cdef shared_ptr[cpp_Communicator] _handle

python/rapidsmpf/rapidsmpf/communicator/communicator.pyi

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from enum import IntEnum
44

55
from rapidsmpf.progress_thread import ProgressThread
6+
from rapidsmpf.statistics import Statistics
67

78
class LOG_LEVEL(IntEnum):
89
NONE = ...
@@ -30,6 +31,8 @@ class Communicator:
3031
def logger(self) -> Logger: ...
3132
@property
3233
def progress_thread(self) -> ProgressThread: ...
34+
@property
35+
def statistics(self) -> Statistics: ...
3336
def get_str(self) -> str: ...
3437

3538
def _available_communicators() -> tuple[str, ...]: ...

python/rapidsmpf/rapidsmpf/communicator/communicator.pyx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ from libcpp.string cimport string
66
from libcpp.utility cimport move
77

88
from rapidsmpf.progress_thread cimport ProgressThread
9+
from rapidsmpf.statistics cimport Statistics
910

1011

1112
cdef class Logger:
@@ -179,6 +180,21 @@ cdef class Communicator:
179180
pt._handle = deref(self._handle).progress_thread()
180181
return pt
181182

183+
@property
184+
def statistics(self):
185+
"""
186+
Get the statistics object associated with this communicator.
187+
188+
Returns
189+
-------
190+
Statistics
191+
The statistics instance. If no statistics object was provided at
192+
construction time, a disabled (no-op) instance is returned.
193+
"""
194+
cdef Statistics stats = Statistics.__new__(Statistics)
195+
stats._handle = deref(self._handle).statistics()
196+
return stats
197+
182198
def get_str(self):
183199
"""
184200
Get a string representation of the communicator.

python/rapidsmpf/rapidsmpf/communicator/mpi.pyi

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@ from mpi4py.MPI import Intracomm
55
from rapidsmpf.communicator.communicator import Communicator
66
from rapidsmpf.config import Options
77
from rapidsmpf.progress_thread import ProgressThread
8+
from rapidsmpf.statistics import Statistics
89

910
def new_communicator(
10-
comm: Intracomm, options: Options, progress_thread: ProgressThread
11+
comm: Intracomm,
12+
options: Options,
13+
progress_thread: ProgressThread,
14+
statistics: Statistics | None = None,
1115
) -> Communicator: ...

python/rapidsmpf/rapidsmpf/communicator/mpi.pyx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,24 @@ from rapidsmpf._detail.exception_handling cimport ex_handler
99
from rapidsmpf.communicator.communicator cimport Communicator
1010
from rapidsmpf.config cimport Options, cpp_Options
1111
from rapidsmpf.progress_thread cimport ProgressThread, cpp_ProgressThread
12+
from rapidsmpf.statistics cimport Statistics, cpp_Statistics
1213

1314

1415
cdef extern from "<rapidsmpf/communicator/mpi.hpp>" nogil:
1516
cdef cppclass cpp_MPI_Communicator "rapidsmpf::MPI":
1617
cpp_MPI_Communicator(
17-
libmpi.MPI_Comm comm, cpp_Options options, shared_ptr[cpp_ProgressThread]
18+
libmpi.MPI_Comm comm,
19+
cpp_Options options,
20+
shared_ptr[cpp_ProgressThread],
21+
shared_ptr[cpp_Statistics]
1822
) except +ex_handler
1923

2024

2125
def new_communicator(
2226
Intracomm comm not None,
2327
Options options not None,
2428
ProgressThread progress_thread not None,
29+
Statistics statistics=None,
2530
):
2631
"""
2732
Create a new RapidsMPF-MPI communicator based on an existing mpi4py communicator.
@@ -34,14 +39,19 @@ def new_communicator(
3439
Configuration options.
3540
progress_thread
3641
Progress thread for the communicator.
42+
statistics
43+
Statistics object for recording communication metrics. If ``None``
44+
(the default), statistics tracking is disabled.
3745
3846
Returns
3947
-------
4048
A new RapidsMPF-MPI communicator.
4149
"""
50+
if statistics is None:
51+
statistics = Statistics(enable=False)
4252
cdef Communicator ret = Communicator.__new__(Communicator)
4353
with nogil:
4454
ret._handle = make_shared[cpp_MPI_Communicator](
45-
comm.ob_mpi, options._handle, progress_thread._handle
55+
comm.ob_mpi, options._handle, progress_thread._handle, statistics._handle
4656
)
4757
return ret

python/rapidsmpf/rapidsmpf/communicator/testing.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from rapidsmpf.communicator.communicator import Communicator
1616
from rapidsmpf.config import Options
1717
from rapidsmpf.progress_thread import ProgressThread
18+
from rapidsmpf.statistics import Statistics
1819

1920

2021
def initialize_ucxx() -> ucx_api.UCXWorker:
@@ -36,7 +37,10 @@ def initialize_ucxx() -> ucx_api.UCXWorker:
3637

3738

3839
def ucxx_mpi_setup(
39-
ucxx_worker: ucx_api.UCXWorker, options: Options, progress_thread: ProgressThread
40+
ucxx_worker: ucx_api.UCXWorker,
41+
options: Options,
42+
progress_thread: ProgressThread,
43+
statistics: Statistics | None = None,
4044
) -> Communicator:
4145
"""
4246
Bootstrap a UCXX communicator within an MPI rank.
@@ -49,6 +53,9 @@ def ucxx_mpi_setup(
4953
Configuration options.
5054
progress_thread
5155
Progress thread for the initialized communicator.
56+
statistics
57+
Statistics object for recording communication metrics. If ``None``
58+
(the default), statistics tracking is disabled.
5259
5360
Returns
5461
-------
@@ -63,7 +70,7 @@ def ucxx_mpi_setup(
6370

6471
if MPI.COMM_WORLD.Get_rank() == 0:
6572
comm = new_communicator(
66-
MPI.COMM_WORLD.size, ucxx_worker, None, options, progress_thread
73+
MPI.COMM_WORLD.size, ucxx_worker, None, options, progress_thread, statistics
6774
)
6875
root_address_bytes = get_root_ucxx_address(comm)
6976
else:
@@ -74,7 +81,12 @@ def ucxx_mpi_setup(
7481
if MPI.COMM_WORLD.Get_rank() != 0:
7582
root_address = ucx_api.UCXAddress.create_from_buffer(root_address_bytes)
7683
comm = new_communicator(
77-
MPI.COMM_WORLD.size, ucxx_worker, root_address, options, progress_thread
84+
MPI.COMM_WORLD.size,
85+
ucxx_worker,
86+
root_address,
87+
options,
88+
progress_thread,
89+
statistics,
7890
)
7991

8092
assert comm.nranks == MPI.COMM_WORLD.size

0 commit comments

Comments
 (0)