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//! _gangs_ of actors that implement the same worker runtimes.
20//!
21//! Similarly, Hyperactor must gang-schedule actors in order to support
22//! collective communicaton between actors.
23//!
24//! Hyperactor is organized into a hierarchy, wherein parents manage
25//! the lifecycle of their children:
26//!
27//! * Each _world_ represents a fixed number of _procs_, scheduled as
28//!   a gang.
29//! * Each _proc_ represents a single actor runtime instance, and hosts
30//!   zero or more actors.
31//! * Actors are _spawned_ into worlds, and assigned a global name.
32//!   Actors spawned in this way are assigned a local PID (pid) of 0.
33//!   Actors in turn can spawn local actors. These inherit the global pid
34//!   of their parent, but receive a unique pid.
35//!
36//! Actors that share a name within a world are called a _gang_.
37//!
38//! This scheme confers several benefits:
39//!
40//! * Routing of messages can be performed by prefix. For example, we
41//!   can route a message to an actor based on the world the actor belongs
42//!   to; from there, we can identify the _proc_ of the actor and send
43//!   the message to it, which can then in turn be routed locally.
44//!
45//! * We can represent gangs of actors in a uniform and compact way.
46//!   This is the basis on which we implement efficient multicasting
47//!   within the system.
48//!
49//!
50//! | Entity    | Identifier                |
51//! |-----------|---------------------------|
52//! | World     | `worldid`                 |
53//! | Proc      | `worldid[rank]`           |
54//! | Actor     | `worldid[rank].name[pid]` |
55//! | Gang      | `worldid.name`            |
56
57#![feature(anonymous_lifetime_in_impl_trait)]
58#![feature(assert_matches)]
59#![feature(associated_type_defaults)]
60#![feature(btree_cursors)]
61#![feature(const_type_id)]
62#![feature(error_reporter)]
63#![feature(impl_trait_in_assoc_type)]
64#![feature(never_type)]
65#![feature(panic_update_hook)]
66#![feature(type_alias_impl_trait)]
67#![feature(trait_alias)]
68#![deny(missing_docs)]
69
70pub mod accum;
71pub mod actor;
72pub mod attrs;
73pub mod cap;
74pub mod channel;
75pub mod checkpoint;
76pub mod clock;
77pub mod config;
78pub mod data;
79mod init;
80pub mod mailbox;
81pub mod message;
82pub mod metrics;
83pub mod panic_handler;
84mod parse;
85pub mod proc;
86pub mod reference;
87mod signal_handler;
88pub mod simnet;
89pub mod supervision;
90pub mod sync;
91/// Test utilities
92pub mod test_utils;
93
94pub use actor::Actor;
95pub use actor::ActorHandle;
96pub use actor::Handler;
97pub use actor::RemoteHandles;
98// Re-export public dependencies of hyperactor_macros codegen.
99#[doc(hidden)]
100pub use anyhow;
101#[doc(hidden)]
102pub use async_trait;
103// Re-exported to use in Named derive macro.
104#[doc(hidden)]
105pub use cityhasher;
106#[doc(hidden)]
107pub use dashmap; // For intern_typename!
108pub use data::Named;
109#[doc(hidden)]
110pub use hyperactor_macros::Actor;
111#[doc(inline)]
112pub use hyperactor_macros::Bind;
113#[doc(inline)]
114pub use hyperactor_macros::HandleClient;
115#[doc(inline)]
116pub use hyperactor_macros::Handler;
117#[doc(inline)]
118pub use hyperactor_macros::Named;
119#[doc(inline)]
120pub use hyperactor_macros::RefClient;
121#[doc(inline)]
122pub use hyperactor_macros::Unbind;
123#[doc(inline)]
124pub use hyperactor_macros::alias;
125#[doc(inline)]
126pub use hyperactor_macros::export;
127#[doc(inline)]
128pub use hyperactor_macros::forward;
129#[doc(inline)]
130pub use hyperactor_macros::instrument;
131#[doc(inline)]
132pub use hyperactor_macros::instrument_infallible;
133pub use hyperactor_telemetry::declare_static_counter;
134pub use hyperactor_telemetry::declare_static_gauge;
135pub use hyperactor_telemetry::declare_static_histogram;
136pub use hyperactor_telemetry::declare_static_timer;
137pub use hyperactor_telemetry::key_value;
138pub use hyperactor_telemetry::kv_pairs;
139#[doc(inline)]
140pub use init::initialize;
141#[doc(inline)]
142pub use init::initialize_with_current_runtime;
143#[doc(inline)]
144pub use init::initialize_with_log_prefix;
145// Re-exported to make this available to callers of the `register!` macro.
146#[doc(hidden)]
147pub use inventory::submit;
148pub use mailbox::Data;
149pub use mailbox::Mailbox;
150pub use mailbox::Message;
151pub use mailbox::OncePortHandle;
152pub use mailbox::PortHandle;
153pub use mailbox::RemoteMessage;
154// Re-exported to support opentelemetry in hyperactor_macros codegen.
155#[doc(hidden)]
156pub use opentelemetry;
157#[doc(hidden)]
158pub use paste::paste;
159pub use proc::Context;
160pub use proc::Instance;
161pub use reference::ActorId;
162pub use reference::ActorRef;
163pub use reference::GangId;
164pub use reference::GangRef;
165pub use reference::OncePortRef;
166pub use reference::PortId;
167pub use reference::PortRef;
168pub use reference::ProcId;
169pub use reference::WorldId;
170// Re-exported to support tracing in hyperactor_macros codegen.
171#[doc(hidden)]
172pub use serde_json;
173#[doc(inline)]
174pub use signal_handler::SignalCleanupGuard;
175#[doc(inline)]
176pub use signal_handler::SignalDisposition;
177#[doc(inline)]
178pub use signal_handler::query_signal_disposition;
179#[doc(inline)]
180pub use signal_handler::register_signal_cleanup;
181#[doc(inline)]
182pub use signal_handler::register_signal_cleanup_scoped;
183#[doc(inline)]
184pub use signal_handler::sigpipe_disposition;
185#[doc(inline)]
186pub use signal_handler::unregister_signal_cleanup;
187// Re-exported to support tracing in hyperactor_macros codegen.
188#[doc(hidden)]
189pub use tracing;