Skip to content

Commit bc5bcf5

Browse files
committed
complement missing docs
Signed-off-by: Runji Wang <[email protected]>
1 parent 8a374a9 commit bc5bcf5

File tree

7 files changed

+36
-0
lines changed

7 files changed

+36
-0
lines changed

src/lib.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1+
//! Asynchronous Rust bindings to UCX.
2+
13
#![deny(warnings)]
4+
#![deny(missing_docs)]
25

36
use ucx1_sys::ucs_status_ptr_t;
47
use ucx1_sys::ucs_status_t;
@@ -25,6 +28,8 @@ macro_rules! spawn_thread {
2528

2629
pub mod ucp;
2730

31+
/// UCX error code.
32+
#[allow(missing_docs)]
2833
#[repr(i8)]
2934
#[derive(thiserror::Error, Debug, PartialEq, Eq)]
3035
pub enum Error {

src/ucp/endpoint/mod.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ impl EndpointInner {
7373
}
7474
}
7575

76+
/// Communication endpoint.
7677
#[derive(Debug, Clone)]
7778
pub struct Endpoint {
7879
handle: ucp_ep_h,
@@ -189,10 +190,12 @@ impl Endpoint {
189190
Ok(endpoint)
190191
}
191192

193+
/// Whether the endpoint is closed.
192194
pub fn is_closed(&self) -> bool {
193195
self.inner.is_closed()
194196
}
195197

198+
/// Get the endpoint status.
196199
pub fn get_status(&self) -> Result<(), Error> {
197200
self.inner.check()
198201
}
@@ -203,6 +206,7 @@ impl Endpoint {
203206
Ok(self.handle)
204207
}
205208

209+
/// Print endpoint information to stderr.
206210
pub fn print_to_stderr(&self) {
207211
if !self.inner.is_closed() {
208212
unsafe { ucp_ep_print_info(self.handle, stderr) };
@@ -274,6 +278,7 @@ impl Endpoint {
274278
}
275279
}
276280

281+
/// Get the worker of the endpoint.
277282
pub fn worker(&self) -> &Rc<Worker> {
278283
&self.inner.worker
279284
}

src/ucp/endpoint/rma.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
use super::*;
22

3+
/// A memory region allocated through UCP library,
4+
/// which is optimized for remote memory access operations.
35
#[derive(Debug)]
46
pub struct MemoryHandle {
57
handle: ucp_mem_h,
68
context: Arc<Context>,
79
}
810

911
impl MemoryHandle {
12+
/// Register memory region.
1013
pub fn register(context: &Arc<Context>, region: &mut [u8]) -> Self {
1114
#[allow(invalid_value)]
1215
#[allow(clippy::uninit_assumed_init)]
@@ -53,6 +56,7 @@ impl Drop for MemoryHandle {
5356
}
5457
}
5558

59+
/// An owned buffer containing remote access key.
5660
#[derive(Debug)]
5761
pub struct RKeyBuffer {
5862
buf: *mut c_void,
@@ -71,6 +75,7 @@ impl Drop for RKeyBuffer {
7175
}
7276
}
7377

78+
/// Remote access key.
7479
#[derive(Debug)]
7580
pub struct RKey {
7681
handle: ucp_rkey_h,
@@ -80,6 +85,7 @@ unsafe impl Send for RKey {}
8085
unsafe impl Sync for RKey {}
8186

8287
impl RKey {
88+
/// Create remote access key from packed buffer.
8389
pub fn unpack(endpoint: &Endpoint, rkey_buffer: &[u8]) -> Self {
8490
let mut handle = MaybeUninit::uninit();
8591
let status = unsafe {
@@ -103,6 +109,7 @@ impl Drop for RKey {
103109
}
104110

105111
impl Endpoint {
112+
/// Stores a contiguous block of data into remote memory.
106113
pub async fn put(&self, buf: &[u8], remote_addr: u64, rkey: &RKey) -> Result<(), Error> {
107114
trace!("put: endpoint={:?} len={}", self.handle, buf.len());
108115
unsafe extern "C" fn callback(request: *mut c_void, status: ucs_status_t) {
@@ -134,6 +141,7 @@ impl Endpoint {
134141
}
135142
}
136143

144+
/// Loads a contiguous block of data from remote memory.
137145
pub async fn get(&self, buf: &mut [u8], remote_addr: u64, rkey: &RKey) -> Result<(), Error> {
138146
trace!("get: endpoint={:?} len={}", self.handle, buf.len());
139147
unsafe extern "C" fn callback(request: *mut c_void, status: ucs_status_t) {

src/ucp/endpoint/stream.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use super::*;
22

33
impl Endpoint {
4+
/// Sends data through stream.
45
pub async fn stream_send(&self, buf: &[u8]) -> Result<usize, Error> {
56
trace!("stream_send: endpoint={:?} len={}", self.handle, buf.len());
67
unsafe extern "C" fn callback(request: *mut c_void, status: ucs_status_t) {
@@ -36,6 +37,7 @@ impl Endpoint {
3637
Ok(buf.len())
3738
}
3839

40+
/// Receives data from stream.
3941
pub async fn stream_recv(&self, buf: &mut [MaybeUninit<u8>]) -> Result<usize, Error> {
4042
trace!("stream_recv: endpoint={:?} len={}", self.handle, buf.len());
4143
unsafe extern "C" fn callback(request: *mut c_void, status: ucs_status_t, length: u64) {

src/ucp/endpoint/tag.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@ use super::*;
22
use std::io::{IoSlice, IoSliceMut};
33

44
impl Worker {
5+
/// Receives a message with `tag`.
56
pub async fn tag_recv(&self, tag: u64, buf: &mut [MaybeUninit<u8>]) -> Result<usize, Error> {
67
self.tag_recv_mask(tag, u64::max_value(), buf)
78
.await
89
.map(|info| info.1)
910
}
1011

12+
/// Receives a message with `tag` and `tag_mask`.
1113
pub async fn tag_recv_mask(
1214
&self,
1315
tag: u64,
@@ -56,6 +58,7 @@ impl Worker {
5658
.await
5759
}
5860

61+
/// Like `tag_recv`, except that it reads into a slice of buffers.
5962
pub async fn tag_recv_vectored(
6063
&self,
6164
tag: u64,
@@ -103,6 +106,7 @@ impl Worker {
103106
}
104107

105108
impl Endpoint {
109+
/// Sends a messages with `tag`.
106110
pub async fn tag_send(&self, tag: u64, buf: &[u8]) -> Result<usize, Error> {
107111
trace!("tag_send: endpoint={:?} len={}", self.handle, buf.len());
108112
unsafe extern "C" fn callback(request: *mut c_void, status: ucs_status_t) {
@@ -134,6 +138,7 @@ impl Endpoint {
134138
Ok(buf.len())
135139
}
136140

141+
/// Like `tag_send`, except that it reads into a slice of buffers.
137142
pub async fn tag_send_vectored(&self, tag: u64, iov: &[IoSlice<'_>]) -> Result<usize, Error> {
138143
trace!(
139144
"tag_send_vectored: endpoint={:?} iov.len={}",

src/ucp/listener.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use futures::stream::StreamExt;
66
use std::mem::MaybeUninit;
77
use std::net::SocketAddr;
88

9+
/// Listening on a specific address and accepting connections from clients.
910
#[derive(Debug)]
1011
pub struct Listener {
1112
handle: ucp_listener_h,
@@ -14,6 +15,9 @@ pub struct Listener {
1415
recver: mpsc::UnboundedReceiver<ConnectionRequest>,
1516
}
1617

18+
/// An incoming connection request.
19+
///
20+
/// The request must be explicitly accepted by [Worker::accept] or rejected by [Listener::reject].
1721
#[derive(Debug)]
1822
#[must_use = "connection must be accepted or rejected"]
1923
pub struct ConnectionRequest {
@@ -83,6 +87,7 @@ impl Listener {
8387
})
8488
}
8589

90+
/// Returns the local socket address of this listener.
8691
pub fn socket_addr(&self) -> Result<SocketAddr, Error> {
8792
#[allow(clippy::uninit_assumed_init)]
8893
let mut attr = ucp_listener_attr_t {
@@ -98,6 +103,7 @@ impl Listener {
98103
Ok(sockaddr.into_addr().unwrap())
99104
}
100105

106+
/// Waiting for the next connection request.
101107
pub async fn next(&mut self) -> ConnectionRequest {
102108
self.recver.next().await.unwrap()
103109
}

src/ucp/worker.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ impl Worker {
8282
unsafe { ucp_worker_print_info(self.handle, stderr) };
8383
}
8484

85+
/// Thread safe level of the context.
8586
pub fn thread_mode(&self) -> ucs_thread_mode_t {
8687
let mut attr = MaybeUninit::<ucp_worker_attr>::uninit();
8788
unsafe { &mut *attr.as_mut_ptr() }.field_mask =
@@ -111,18 +112,22 @@ impl Worker {
111112
})
112113
}
113114

115+
/// Create a new [`Listener`].
114116
pub fn create_listener(self: &Rc<Self>, addr: SocketAddr) -> Result<Listener, Error> {
115117
Listener::new(self, addr)
116118
}
117119

120+
/// Connect to a remote worker by address.
118121
pub fn connect_addr(self: &Rc<Self>, addr: &WorkerAddress) -> Result<Endpoint, Error> {
119122
Endpoint::connect_addr(self, addr.handle)
120123
}
121124

125+
/// Connect to a remote listener.
122126
pub async fn connect_socket(self: &Rc<Self>, addr: SocketAddr) -> Result<Endpoint, Error> {
123127
Endpoint::connect_socket(self, addr).await
124128
}
125129

130+
/// Accept a connection request.
126131
pub async fn accept(self: &Rc<Self>, connection: ConnectionRequest) -> Result<Endpoint, Error> {
127132
Endpoint::accept(self, connection).await
128133
}

0 commit comments

Comments
 (0)