Skip to main content

hyperactor/
lib.rs

1/*
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 * All rights reserved.
4 *
5 * This source code is licensed under the BSD-style license found in the
6 * LICENSE file in the root directory of this source tree.
7 */
8
9//! Hyperactor is an actor system intended for managing large scale compute.
10//!
11//! # Actor data model
12//!
13//! Hyperactor is designed to support large scale (millions of nodes)
14//! machine learning workloads where actor topologies communicate through
15//! high fanout multicast messaging.
16//!
17//! Supporting this scale requires us to impose additional structure
18//! at the level of the framework, so that we can efficiently refer to
19//! _meshes_ of actors that implement the same worker runtimes.
20//!
21//! Similarly, Hyperactor must co-schedule actors in order to support
22//! collective communicaton between actors.
23//!
24//! Hyperactor is organized into a hierarchy:
25//!
26//! * Each _proc_ represents a single actor runtime instance, and hosts
27//!   zero or more actors.
28//! * Actors are _spawned_ into procs, and assigned a global name.
29//!   Actors spawned in this way are assigned a local PID (pid) of 0.
30//!   Actors in turn can spawn local actors. These inherit the global pid
31//!   of their parent, but receive a unique pid.
32//!
33//! This scheme confers several benefits:
34//!
35//! * Routing of messages can be performed by prefix. For example, we
36//!   can identify the _proc_ of the actor and send the message to it,
37//!   which can then in turn be routed locally.
38//!
39//! * We can represent meshes of actors in a uniform and compact way.
40//!   This is the basis on which we implement efficient multicasting
41//!   within the system.
42//!
43//!
44//! | Entity    | Identifier                    |
45//! |-----------|-------------------------------|
46//! | Proc      | `addr,proc_name`              |
47//! | Actor     | `addr,proc_name,name[pid]`    |
48
49#![feature(anonymous_lifetime_in_impl_trait)]
50#![feature(assert_matches)]
51#![feature(associated_type_defaults)]
52#![feature(box_patterns)]
53#![feature(btree_cursors)]
54#![feature(error_reporter)]
55#![feature(impl_trait_in_assoc_type)]
56#![feature(never_type)]
57#![feature(panic_update_hook)]
58#![feature(type_alias_impl_trait)]
59#![feature(trait_alias)]
60#![deny(missing_docs)]
61
62pub mod accum;
63pub mod actor;
64pub mod actor_local;
65pub mod addr;
66pub mod channel;
67pub mod config;
68pub mod context;
69pub mod endpoint;
70/// Gateway management for proc connectivity.
71pub mod gateway;
72pub mod id;
73mod init;
74pub mod introspect;
75pub mod mailbox;
76pub mod message;
77pub mod metrics;
78pub mod ordering;
79pub mod panic_handler;
80mod parse;
81pub mod port;
82pub mod proc;
83pub mod ref_;
84pub mod remote;
85mod signal_handler;
86mod stdio_redirect;
87pub mod subject;
88pub mod supervision;
89pub mod sync;
90/// Test utilities.
91pub mod testing;
92pub mod time;
93
94#[cfg(fbcode_build)]
95pub mod meta;
96
97/// Re-exports of external crates used by hyperactor_macros codegen.
98/// This module is not part of the public API and should not be used directly.
99#[doc(hidden)]
100pub mod internal_macro_support {
101    pub use anyhow;
102    pub use async_trait;
103    pub use inventory;
104    pub use opentelemetry;
105    pub use paste::paste;
106    pub use serde_json;
107    pub use tracing;
108    pub use typeuri;
109}
110
111pub use actor::Actor;
112pub use actor::ActorHandle;
113pub use actor::AnyActorHandle;
114pub use actor::Handler;
115pub use actor::HandlerInfo;
116pub use actor::RemoteHandles;
117pub use actor::RemoteSpawn;
118pub use actor_local::ActorLocal;
119pub use addr::ActorAddr;
120pub use addr::Addr;
121pub use addr::AddrParseError;
122pub use addr::Location;
123pub use addr::PortAddr;
124pub use addr::ProcAddr;
125pub use endpoint::Endpoint;
126pub use endpoint::EndpointLocation;
127pub use endpoint::RemoteEndpoint;
128pub use gateway::Gateway;
129#[doc(inline)]
130pub use hyperactor_macros::Bind;
131#[doc(inline)]
132pub use hyperactor_macros::HandleClient;
133#[doc(inline)]
134pub use hyperactor_macros::Handler;
135#[doc(inline)]
136pub use hyperactor_macros::RefClient;
137#[doc(inline)]
138pub use hyperactor_macros::Unbind;
139#[doc(inline)]
140pub use hyperactor_macros::behavior;
141#[doc(inline)]
142pub use hyperactor_macros::export;
143#[doc(inline)]
144pub use hyperactor_macros::handle;
145#[doc(inline)]
146pub use hyperactor_macros::instrument;
147#[doc(inline)]
148pub use hyperactor_macros::instrument_infallible;
149pub use hyperactor_macros::observe_async;
150pub use hyperactor_macros::observe_result;
151#[doc(inline)]
152pub use hyperactor_macros::spawnable;
153#[doc(inline)]
154pub use hyperactor_macros::uid;
155pub use hyperactor_telemetry::declare_static_counter;
156pub use hyperactor_telemetry::declare_static_gauge;
157pub use hyperactor_telemetry::declare_static_histogram;
158pub use hyperactor_telemetry::declare_static_timer;
159pub use hyperactor_telemetry::key_value;
160pub use hyperactor_telemetry::kv_pairs;
161pub use id::ActorId;
162pub use id::Id;
163pub use id::Label;
164pub use id::PortId;
165pub use id::ProcId;
166pub use id::Uid;
167#[doc(inline)]
168pub use init::initialize;
169#[doc(inline)]
170pub use init::initialize_with_current_runtime;
171#[doc(inline)]
172pub use init::initialize_with_log_prefix;
173pub use mailbox::Data;
174pub use mailbox::Mailbox;
175pub use mailbox::Message;
176pub use mailbox::OncePortHandle;
177pub use mailbox::PortHandle;
178pub use mailbox::RemoteMessage;
179pub use proc::AttachRequest;
180pub use proc::AttachRx;
181pub use proc::BootstrapAssignment;
182pub use proc::Context;
183pub use proc::Host2Client;
184pub use proc::Instance;
185pub use proc::InstanceCell;
186pub use proc::Proc;
187pub use proc::WeakProc;
188pub use ref_::ActorRef;
189pub use ref_::OncePortRef;
190pub use ref_::PortRef;
191pub use ref_::UnboundPort;
192pub use ref_::UnboundPortKind;
193pub use remote::Accepts;
194/// Rank or position index used by distributed mesh helpers.
195pub type Index = usize;
196#[doc(inline)]
197pub use signal_handler::SignalCleanupGuard;
198#[doc(inline)]
199pub use signal_handler::SignalDisposition;
200#[doc(inline)]
201pub use signal_handler::query_signal_disposition;
202#[doc(inline)]
203pub use signal_handler::register_signal_cleanup;
204#[doc(inline)]
205pub use signal_handler::register_signal_cleanup_scoped;
206#[doc(inline)]
207pub use signal_handler::sigpipe_disposition;
208#[doc(inline)]
209pub use signal_handler::unregister_signal_cleanup;
210
211mod private {
212    /// Public trait in a private module for sealing traits within this crate:
213    /// [Sealed trait pattern](https://rust-lang.github.io/api-guidelines/future-proofing.html#sealed-traits-protect-against-downstream-implementations-c-sealed).
214    pub trait Sealed {}
215
216    // These two implement context capabilities:
217    impl<A: crate::Actor> Sealed for crate::proc::Instance<A> {}
218    impl<A: crate::Actor> Sealed for &crate::proc::Instance<A> {}
219    impl<A: crate::Actor> Sealed for crate::proc::Context<'_, A> {}
220    impl<A: crate::Actor> Sealed for &crate::proc::Context<'_, A> {}
221    impl Sealed for crate::mailbox::Mailbox {}
222    impl Sealed for &crate::mailbox::Mailbox {}
223    impl<A: crate::Actor> Sealed for &crate::actor::ActorHandle<A> {}
224    impl<M: crate::Message> Sealed for &crate::mailbox::PortHandle<M> {}
225    impl<M: crate::Message> Sealed for crate::mailbox::OncePortHandle<M> {}
226    impl<A: crate::actor::Referable> Sealed for &crate::ref_::ActorRef<A> {}
227    impl<M: crate::RemoteMessage> Sealed for &crate::ref_::PortRef<M> {}
228    impl<M: crate::RemoteMessage> Sealed for crate::ref_::OncePortRef<M> {}
229}