Skip to main content

dynamo_runtime/routing_policy/
types.rs

1// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2// SPDX-License-Identifier: Apache-2.0
3
4#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
5pub struct RouteTarget {
6    pub worker_id: u64,
7    pub dp_rank: Option<u32>,
8}
9
10impl RouteTarget {
11    pub const fn worker(worker_id: u64) -> Self {
12        Self {
13            worker_id,
14            dp_rank: None,
15        }
16    }
17
18    pub const fn new(worker_id: u64, dp_rank: Option<u32>) -> Self {
19        Self { worker_id, dp_rank }
20    }
21}
22
23#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
24pub(crate) enum RouteDevice {
25    Cpu,
26    #[default]
27    Accelerator,
28}
29
30#[derive(Clone, Copy, Debug, PartialEq, Eq)]
31pub(crate) struct RouteCandidate {
32    pub(crate) target: RouteTarget,
33    pub(crate) device: RouteDevice,
34    pub(crate) cache_hits: usize,
35}
36
37impl RouteCandidate {
38    pub(crate) const fn worker(worker_id: u64) -> Self {
39        Self {
40            target: RouteTarget::worker(worker_id),
41            device: RouteDevice::Accelerator,
42            cache_hits: 0,
43        }
44    }
45}
46
47#[derive(Clone, Copy, Debug)]
48pub(crate) struct RouteContext {
49    pub(crate) required_cache_hits: usize,
50    pub(crate) non_cpu_to_cpu_ratio: usize,
51}
52
53impl Default for RouteContext {
54    fn default() -> Self {
55        Self {
56            required_cache_hits: 0,
57            non_cpu_to_cpu_ratio: 8,
58        }
59    }
60}
61
62#[derive(Clone, Copy, Debug, PartialEq, Eq)]
63pub(crate) enum AdmissionKind {
64    None,
65    Occupancy,
66}
67
68#[derive(Clone, Copy, Debug, PartialEq, Eq)]
69pub(crate) struct RouteDecision {
70    pub(crate) target: RouteTarget,
71    pub(crate) admission: AdmissionKind,
72}