Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/cli-design.md
Original file line number Diff line number Diff line change
Expand Up @@ -1693,7 +1693,7 @@ on these hosts and are unverified when no GPU is selected or detected.
- PCI identifies the ConnectX-7 physical function (`15b3:1021`) even if its
RDMA driver has not bound. The fabric check is not applicable when the
adapter is absent.
- The report uses serving's RoCEv2 GID index and lists the selected
- The report uses serving's per-device RoCEv2 GID indices and lists the selected
ConnectX-7 devices, interface names, IPv4 prefixes, and observed MTUs.
One active device with an assigned IPv4 address and RoCEv2 GID is
sufficient. The report identifies active devices skipped by discovery.
Expand Down
106 changes: 99 additions & 7 deletions flare-cli/src/doctor/spark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,12 +144,12 @@ fn inspect(
));
}

// Use the same GID index and assigned-address verification as serving.
// Use the same per-device GID indices and assigned-address verification as serving.
let fabric = discover();
let mut ready = Vec::new();
if let Ok(fabric) = &fabric {
let mut unresolved = Vec::new();
for endpoint in &fabric.endpoints {
for (idx, endpoint) in fabric.endpoints.iter().enumerate() {
// Serving discovers every RDMA adapter. This check covers ConnectX-7 devices.
if !active.contains(&endpoint.name) {
continue;
Expand All @@ -158,9 +158,13 @@ fn inspect(
unresolved.push(endpoint.name.as_str());
continue;
};
let Some(gid_index) = fabric.gid_index_for(idx) else {
unresolved.push(endpoint.name.as_str());
continue;
};
let netdev = root
.join(&endpoint.name)
.join(format!("ports/1/gid_attrs/ndevs/{}", fabric.gid_index));
.join(format!("ports/1/gid_attrs/ndevs/{gid_index}"));
let Some(interface) = read(&netdev) else {
unresolved.push(endpoint.name.as_str());
continue;
Expand All @@ -170,6 +174,7 @@ fn inspect(
ready.push(Interface {
device: &endpoint.name,
interface,
gid_index,
address,
prefix,
mtu,
Expand All @@ -181,11 +186,12 @@ fn inspect(
.map(Interface::describe)
.collect::<Vec<_>>()
.join(", ");
let ready_gids: Vec<u32> = ready.iter().map(|port| port.gid_index).collect();
let gid_label = format_gid_indices(&ready_gids);
let mut detail = format!(
"{} of {} active CX7 devices supply IPv4 endpoints for serving at RoCEv2 GID index {}: {listed}.",
"{} of {} active CX7 devices supply IPv4 endpoints for serving at RoCEv2 GID {gid_label}: {listed}.",
ready.len(),
active.len(),
fabric.gid_index
);
let mut warnings = configuration_warnings(&ready);
if ready.iter().any(Interface::is_link_local) {
Expand Down Expand Up @@ -236,8 +242,8 @@ fn inspect(
let reason = match fabric {
Err(error) => error.to_string(),
Ok(fabric) => format!(
"discovery could not verify a local IPv4 address and prefix on a ConnectX-7 device at RoCEv2 GID index {}",
fabric.gid_index
"discovery could not verify a local IPv4 address and prefix on a ConnectX-7 device at RoCEv2 GID {}",
format_gid_indices(&fabric.gid_indices)
),
};
Ok(result(
Expand All @@ -250,9 +256,25 @@ fn inspect(
))
}

fn format_gid_indices(indices: &[u32]) -> String {
match indices {
[] => "index (none)".into(),
[first, rest @ ..] if rest.iter().all(|&g| g == *first) => format!("index {first}"),
_ => format!(
"indices [{}]",
indices
.iter()
.map(u32::to_string)
.collect::<Vec<_>>()
.join(", ")
),
}
}

struct Interface<'a> {
device: &'a str,
interface: String,
gid_index: u32,
address: Ipv4Addr,
prefix: u8,
mtu: Option<u32>,
Expand Down Expand Up @@ -491,13 +513,15 @@ mod tests {
Interface {
device: "roce0",
interface: "enp1s0f0np0".into(),
gid_index: 3,
address: Ipv4Addr::new(192, 168, 0, 0),
prefix: 31,
mtu: Some(9000),
},
Interface {
device: "roce1",
interface: "enp1s0f1np1".into(),
gid_index: 3,
address: Ipv4Addr::new(192, 168, 1, 15),
prefix: 24,
mtu: Some(9000),
Expand All @@ -521,4 +545,72 @@ mod tests {
interfaces.iter_mut().for_each(|port| port.prefix = 16);
assert!(configuration_warnings(&interfaces).is_empty());
}

#[test]
fn cx7_readiness_handles_distinct_per_hca_gid_indices() {
let dir = tempfile::tempdir().unwrap();
let sysfs = dir.path();
add_spark(sysfs);
let root = sysfs.join("class/infiniband");
for (dev, net, gid_idx, gid_hex) in [
("roce0", "enP2p1s0f0np0", 3, "c0a8:650a"),
("roce1", "enp1s0f0np0", 5, "c0a8:640a"),
] {
write(&root, &format!("{dev}/device/vendor"), "0x15b3\n");
write(&root, &format!("{dev}/device/device"), "0x1021\n");
let port = root.join(dev).join("ports/1");
write(&port, "state", "4: ACTIVE\n");
write(
&port,
&format!("gid_attrs/ndevs/{gid_idx}"),
&format!("{net}\n"),
);
write(&port, &format!("gid_attrs/types/{gid_idx}"), "RoCE v2\n");
write(
&port,
&format!("gids/{gid_idx}"),
&format!("0000:0000:0000:0000:0000:ffff:{gid_hex}\n"),
);
write(sysfs, &format!("class/net/{net}/mtu"), "9000\n");
}
// Decoy IPv6 RoCEv2 entry at index 3 on roce1 so reading a uniform ndevs/3 would fail.
let roce1_port = root.join("roce1/ports/1");
write(&roce1_port, "gid_attrs/ndevs/3", "decoy0\n");
write(&roce1_port, "gid_attrs/types/3", "RoCE v2\n");
write(
&roce1_port,
"gids/3",
"fe80:0000:0000:0000:0200:00ff:fe00:0001\n",
);

let rep = report(sysfs, |netdev, _| {
matches!(netdev, "enP2p1s0f0np0" | "enp1s0f0np0").then_some(24)
});
let check = cx7(&rep);
assert!(rep.ok);
assert_eq!(check.status, CheckStatus::Pass, "{}", check.detail);
assert!(
check.detail.contains("2 of 2 active CX7 devices"),
"{}",
check.detail
);
assert!(check.detail.contains("indices [3, 5]"), "{}", check.detail);
assert!(check.detail.contains("enp1s0f0np0"), "{}", check.detail);
assert!(!check.detail.contains("decoy0"), "{}", check.detail);

// When no local IPv4 prefix resolves, the Warn fallback also reports all selected indices.
let warn_rep = report(sysfs, |_, _| None);
let warn_check = cx7(&warn_rep);
assert_eq!(
warn_check.status,
CheckStatus::Warn,
"{}",
warn_check.detail
);
assert!(
warn_check.detail.contains("indices [3, 5]"),
"{}",
warn_check.detail
);
}
}
30 changes: 27 additions & 3 deletions heliopause/src/python.rs
Original file line number Diff line number Diff line change
Expand Up @@ -665,6 +665,7 @@ fn flare_heliopause(module: &Bound<'_, PyModule>) -> PyResult<()> {
module.add_class::<NativeServer>()?;
module.add_function(wrap_pyfunction!(current_context, module)?)?;
module.add_function(wrap_pyfunction!(memory_inventory, module)?)?;
module.add_function(wrap_pyfunction!(roce_devices, module)?)?;
module.add_function(wrap_pyfunction!(roce_gid_index, module)?)?;
module.add_function(wrap_pyfunction!(serve_tensor_parallel_rank, module)?)?;
#[cfg(target_os = "linux")]
Expand All @@ -689,14 +690,36 @@ fn memory_inventory(py: Python<'_>) -> PyResult<Bound<'_, pyo3::types::PyDict>>
Ok(result)
}

/// This host's RoCE GID index by the rule native serving uses: 3 when every active device has a
/// RoCEv2 IPv4 GID there, otherwise the lowest index at which one does.
/// The first selected RoCE device's GID index by the rule native serving uses: each active device
/// prefers index 3 when it has a RoCEv2 IPv4 GID there, otherwise its own lowest RoCEv2 IPv4 GID
/// index. Prefer `roce_devices` when HCAs on the host may have distinct GID indices.
#[pyfunction]
fn roce_gid_index() -> PyResult<u32> {
#[cfg(target_os = "linux")]
{
crate::execution::roce_fabric::discover()
.map(|fabric| fabric.gid_index)
.map(|fabric| fabric.gid_index())
.map_err(|error| PyRuntimeError::new_err(error.to_string()))
}
#[cfg(not(target_os = "linux"))]
Err(PyRuntimeError::new_err("RoCE preparation requires Linux"))
}

/// This host's discovered RoCE devices and their per-device RoCEv2 IPv4 GID indices, in the same
/// name-sorted order as native serving discovery.
#[pyfunction]
fn roce_devices() -> PyResult<Vec<(String, u32)>> {
#[cfg(target_os = "linux")]
{
crate::execution::roce_fabric::discover()
.map(|fabric| {
fabric
.endpoints
.into_iter()
.zip(fabric.gid_indices)
.map(|(endpoint, gid_index)| (endpoint.name, gid_index))
.collect()
})
.map_err(|error| PyRuntimeError::new_err(error.to_string()))
}
#[cfg(not(target_os = "linux"))]
Expand All @@ -721,6 +744,7 @@ mod binding_tests {
}
assert!(module.hasattr("GraphExecutor").unwrap());
assert!(module.hasattr("current_context").unwrap());
assert!(module.hasattr("roce_devices").unwrap());
assert_eq!(
module.hasattr("Server").unwrap(),
cfg!(all(feature = "server", feature = "qualification"))
Expand Down
42 changes: 31 additions & 11 deletions helios/native/roce_proxy.c
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ typedef struct {
uint16_t lid;
enum ibv_mtu mtu;
uint32_t max_inline;
int gid_index;
} roce_hca_t;

typedef struct {
Expand All @@ -264,7 +265,6 @@ typedef struct {
int n_hca;
int n_rail;
int n_lane;
int gid_index;
int traffic_class;
roce_hca_t hca[ROCE_MAX_HCAS];
uint8_t* region;
Expand Down Expand Up @@ -420,7 +420,7 @@ int roce_layout(int world, uint64_t slot_bytes, uint64_t pipe_bytes, uint64_t va

uint64_t roce_blob_bytes(void) { return sizeof(roce_blob_t); }

static int open_hca(roce_ctx_t* c, int h, const char* name) {
static int open_hca(roce_ctx_t* c, int h, const char* name, int gid_index) {
int num = 0;
struct ibv_device** list = ibv_get_device_list(&num);
if (list == NULL) {
Expand Down Expand Up @@ -457,7 +457,8 @@ static int open_hca(roce_ctx_t* c, int h, const char* name) {
}
hca->lid = port.lid;
hca->mtu = port.active_mtu;
if (ibv_query_gid(hca->ctx, ROCE_PORT, c->gid_index, &hca->gid) != 0) {
hca->gid_index = gid_index;
if (ibv_query_gid(hca->ctx, ROCE_PORT, hca->gid_index, &hca->gid) != 0) {
set_err(c, "ibv_query_gid", errno);
return -1;
}
Expand Down Expand Up @@ -527,17 +528,25 @@ static int open_hca(roce_ctx_t* c, int h, const char* name) {
return 0;
}

roce_ctx_t* roce_create(int world, int rank, const char* const* hca_names, int n_hca, int gid_index,
int traffic_class, int n_lane, void* region, uint64_t region_bytes,
uint64_t slot_bytes, uint64_t pipe_bytes, uint64_t varlen_bytes, char* err,
uint64_t err_len) {
roce_ctx_t* roce_create_with_gids(int world, int rank, const char* const* hca_names, int n_hca,
const int* gid_indices, int traffic_class, int n_lane,
void* region, uint64_t region_bytes, uint64_t slot_bytes,
uint64_t pipe_bytes, uint64_t varlen_bytes, char* err,
uint64_t err_len) {
uint64_t layout[17];
if (roce_layout(world, slot_bytes, pipe_bytes, varlen_bytes, layout) != 0 ||
layout[4] > region_bytes || rank < 0 || rank >= world || n_hca < 1 || n_hca > ROCE_MAX_HCAS ||
traffic_class < 0 || traffic_class > 255 || n_lane < 1 || n_lane > ROCE_MAX_LANES) {
gid_indices == NULL || traffic_class < 0 || traffic_class > 255 || n_lane < 1 ||
n_lane > ROCE_MAX_LANES) {
snprintf(err, err_len, "invalid roce runtime geometry");
return NULL;
}
for (int h = 0; h < n_hca; h++) {
if (gid_indices[h] < 0 || gid_indices[h] > 255) {
snprintf(err, err_len, "invalid roce gid index %d for HCA %d", gid_indices[h], h);
return NULL;
}
}
roce_ctx_t* c = calloc(1, sizeof(*c));
if (c == NULL) {
snprintf(err, err_len, "out of memory");
Expand All @@ -546,7 +555,6 @@ roce_ctx_t* roce_create(int world, int rank, const char* const* hca_names, int n
c->world = world;
c->rank = rank;
c->n_hca = n_hca;
c->gid_index = gid_index;
c->traffic_class = traffic_class;
c->n_lane = n_lane;
c->region = region;
Expand All @@ -565,7 +573,7 @@ roce_ctx_t* roce_create(int world, int rank, const char* const* hca_names, int n
c->varlen_flag_off = layout[14];
c->varlen_bytes = layout[15];
for (int h = 0; h < n_hca; h++) {
if (open_hca(c, h, hca_names[h]) != 0) {
if (open_hca(c, h, hca_names[h], gid_indices[h]) != 0) {
snprintf(err, err_len, "%s", c->err);
roce_destroy(c);
return NULL;
Expand All @@ -574,6 +582,18 @@ roce_ctx_t* roce_create(int world, int rank, const char* const* hca_names, int n
return c;
}

roce_ctx_t* roce_create(int world, int rank, const char* const* hca_names, int n_hca, int gid_index,
int traffic_class, int n_lane, void* region, uint64_t region_bytes,
uint64_t slot_bytes, uint64_t pipe_bytes, uint64_t varlen_bytes, char* err,
uint64_t err_len) {
int gids[ROCE_MAX_HCAS];
for (int h = 0; h < ROCE_MAX_HCAS; h++) {
gids[h] = gid_index;
}
return roce_create_with_gids(world, rank, hca_names, n_hca, gids, traffic_class, n_lane, region,
region_bytes, slot_bytes, pipe_bytes, varlen_bytes, err, err_len);
}

// Enable before exchanging blobs; startup allocation, never during replay.
int roce_enable_ring_open(roce_ctx_t* c);
int roce_enable_ring(roce_ctx_t* c) {
Expand Down Expand Up @@ -651,7 +671,7 @@ static int connect_qp(roce_ctx_t* c, int h, int r, int p, int lane, const roce_b
rtr.ah_attr.src_path_bits = 0;
rtr.ah_attr.port_num = ROCE_PORT;
memcpy(rtr.ah_attr.grh.dgid.raw, peer->gid[r], 16);
rtr.ah_attr.grh.sgid_index = (uint8_t)c->gid_index;
rtr.ah_attr.grh.sgid_index = (uint8_t)hca->gid_index;
rtr.ah_attr.grh.hop_limit = 64;
rtr.ah_attr.grh.traffic_class = (uint8_t)c->traffic_class;
rtr.ah_attr.grh.flow_label = 0;
Expand Down
Loading