Skip to content

Commit 0a5e8b1

Browse files
: actor_mesh: remove redundant params (#481)
Summary: - remove the `DestinationPort` arg from `CastMessageEnvelope::new` since it can be calculated from the other arguments - remove now unnecessary arguments from the utility `actor_mesh::actor_mesh_cast` (proc mesh shape and actor name) - generally make the handling of generics consistent in these interfaces Differential Revision: D78030552
1 parent 1532c7f commit 0a5e8b1

File tree

3 files changed

+34
-33
lines changed

3 files changed

+34
-33
lines changed

hyperactor_mesh/src/actor_mesh.rs

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ use crate::CommActor;
4545
use crate::Mesh;
4646
use crate::comm::multicast::CastMessage;
4747
use crate::comm::multicast::CastMessageEnvelope;
48-
use crate::comm::multicast::DestinationPort;
4948
use crate::comm::multicast::Uslice;
5049
use crate::comm::multicast::set_cast_info_on_headers;
5150
use crate::metrics;
@@ -54,32 +53,31 @@ use crate::reference::ActorMeshId;
5453
use crate::reference::ActorMeshRef;
5554
use crate::reference::ProcMeshId;
5655

57-
/// Common implementation for ActorMeshes and ActorMeshRefs to cast an [`M`]-typed message
56+
/// Common implementation for `ActorMesh`s and `ActorMeshRef`s to cast
57+
/// an `M`-typed message
5858
#[allow(clippy::result_large_err)] // TODO: Consider reducing the size of `CastError`.
59-
pub(crate) fn actor_mesh_cast<M: Castable + Clone, A>(
59+
pub(crate) fn actor_mesh_cast<A, M>(
6060
caps: &impl cap::CanSend,
6161
actor_mesh_id: ActorMeshId,
6262
actor_mesh_shape: &Shape,
63-
_proc_mesh_shape: &Shape,
64-
actor_name: &str,
6563
sender: &ActorId,
6664
comm_actor_ref: &ActorRef<CommActor>,
6765
selection: Selection,
6866
message: M,
6967
) -> Result<(), CastError>
7068
where
71-
A: RemoteHandles<M> + RemoteHandles<IndexedErasedUnbound<M>>,
69+
A: RemoteActor + RemoteHandles<IndexedErasedUnbound<M>>,
70+
M: Castable + RemoteMessage,
7271
{
7372
let _ = metrics::ACTOR_MESH_CAST_DURATION.start(hyperactor::kv_pairs!(
7473
"message_type" => M::typename(),
7574
"message_variant" => message.arm().unwrap_or_default(),
7675
));
7776

7877
let slice = actor_mesh_shape.slice().clone();
79-
let message = CastMessageEnvelope::new(
78+
let message = CastMessageEnvelope::new::<A, M>(
8079
actor_mesh_id,
8180
sender.clone(),
82-
DestinationPort::new::<A, M>(actor_name.to_string()),
8381
actor_mesh_shape.clone(),
8482
message,
8583
None, // TODO: reducer typehash
@@ -101,30 +99,29 @@ pub trait ActorMesh: Mesh<Id = ActorMeshId> {
10199
/// The type of actor in the mesh.
102100
type Actor: RemoteActor;
103101

104-
/// Cast an [`M`]-typed message to the ranks selected by `sel`
105-
/// in this ActorMesh.
102+
/// Cast an `M`-typed message to the ranks selected by `sel` in
103+
/// this ActorMesh.
106104
#[allow(clippy::result_large_err)] // TODO: Consider reducing the size of `CastError`.
107-
fn cast<M: Castable + Clone>(&self, selection: Selection, message: M) -> Result<(), CastError>
105+
fn cast<M>(&self, selection: Selection, message: M) -> Result<(), CastError>
108106
where
109-
Self::Actor: RemoteHandles<M> + RemoteHandles<IndexedErasedUnbound<M>>,
107+
Self::Actor: RemoteHandles<IndexedErasedUnbound<M>>,
108+
M: Castable + RemoteMessage,
110109
{
111-
actor_mesh_cast::<M, Self::Actor>(
112-
self.proc_mesh().client(),
113-
self.id(),
114-
self.shape(),
115-
self.proc_mesh().shape(),
116-
self.name(),
117-
self.proc_mesh().client().actor_id(),
118-
self.proc_mesh().comm_actor(),
119-
selection,
120-
message,
110+
actor_mesh_cast::<Self::Actor, M>(
111+
self.proc_mesh().client(), // send capability
112+
self.id(), // actor mesh id (destination mesh)
113+
self.shape(), // actor mesh shape
114+
self.proc_mesh().client().actor_id(), // sender
115+
self.proc_mesh().comm_actor(), // comm actor
116+
selection, // the selected actors
117+
message, // the message
121118
)
122119
}
123120

124121
/// The ProcMesh on top of which this actor mesh is spawned.
125122
fn proc_mesh(&self) -> &ProcMesh;
126123

127-
/// The name global name of actors in this mesh.
124+
/// The name given to the actors in this mesh.
128125
fn name(&self) -> &str;
129126

130127
fn world_id(&self) -> &WorldId {

hyperactor_mesh/src/comm/multicast.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,19 +62,23 @@ pub struct CastMessageEnvelope {
6262

6363
impl CastMessageEnvelope {
6464
/// Create a new CastMessageEnvelope.
65-
pub fn new<T: Castable + Serialize + Named>(
65+
pub fn new<A, M>(
6666
actor_mesh_id: ActorMeshId,
6767
sender: ActorId,
68-
dest_port: DestinationPort,
6968
shape: Shape,
70-
message: T,
69+
message: M,
7170
reducer_typehash: Option<u64>,
72-
) -> Result<Self, anyhow::Error> {
71+
) -> Result<Self, anyhow::Error>
72+
where
73+
A: RemoteActor + RemoteHandles<IndexedErasedUnbound<M>>,
74+
M: Castable + RemoteMessage,
75+
{
7376
let data = ErasedUnbound::try_from_message(message)?;
77+
let actor_name = actor_mesh_id.1.to_string();
7478
Ok(Self {
7579
actor_mesh_id,
7680
sender,
77-
dest_port,
81+
dest_port: DestinationPort::new::<A, M>(actor_name),
7882
data,
7983
reducer_typehash,
8084
shape,

hyperactor_mesh/src/reference.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use std::marker::PhantomData;
1414
use hyperactor::ActorRef;
1515
use hyperactor::Named;
1616
use hyperactor::RemoteHandles;
17+
use hyperactor::RemoteMessage;
1718
use hyperactor::actor::RemoteActor;
1819
use hyperactor::cap;
1920
use hyperactor::message::Castable;
@@ -54,7 +55,7 @@ macro_rules! mesh_id {
5455
)]
5556
pub struct ProcMeshId(pub String);
5657

57-
/// Actor Mesh ID. Tuple of the ProcMesh ID and Actor Mesh ID.
58+
/// Actor Mesh ID. Tuple of the ProcMesh ID and actor name.
5859
#[derive(
5960
Debug,
6061
Serialize,
@@ -123,21 +124,20 @@ impl<A: RemoteActor> ActorMeshRef<A> {
123124
/// Cast an [`M`]-typed message to the ranks selected by `sel`
124125
/// in this ActorMesh.
125126
#[allow(clippy::result_large_err)] // TODO: Consider reducing the size of `CastError`.
126-
pub fn cast<M: Castable + Clone>(
127+
pub fn cast<M>(
127128
&self,
128129
caps: &(impl cap::CanSend + cap::CanOpenPort),
129130
selection: Selection,
130131
message: M,
131132
) -> Result<(), CastError>
132133
where
133134
A: RemoteHandles<M> + RemoteHandles<IndexedErasedUnbound<M>>,
135+
M: Castable + RemoteMessage,
134136
{
135-
actor_mesh_cast::<M, A>(
137+
actor_mesh_cast::<A, M>(
136138
caps,
137139
self.mesh_id.clone(),
138140
self.shape(),
139-
self.proc_mesh_shape(),
140-
self.name(),
141141
caps.mailbox().actor_id(),
142142
&self.comm_actor_ref,
143143
selection,

0 commit comments

Comments
 (0)