-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add hardware topology module #105
Conversation
Signed-off-by: bg-furiosa <[email protected]>
Signed-off-by: bg-furiosa <[email protected]>
Signed-off-by: bg-furiosa <[email protected]>
Signed-off-by: bg-furiosa <[email protected]>
Signed-off-by: bg-furiosa <[email protected]>
Signed-off-by: bg-furiosa <[email protected]>
Signed-off-by: bg-furiosa <[email protected]>
Signed-off-by: bg-furiosa <[email protected]>
Signed-off-by: bg-furiosa <[email protected]>
Signed-off-by: bg-furiosa <[email protected]>
Signed-off-by: bg-furiosa <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Before reviewing at the code level, I want to comment on the design.
First, we need to simplify the implementation of Topology
.
Right now, the struct is behaving mutable with state, but it can actually have deterministic values at initialization time.
This makes the interface more compact and clear.
Second, if you need to add a dependency on hwloc, it would be better to build it from source code and include it in the build output via a static link rather than relying on some arbitrary OS package manager.
Meanwhile, there are hwloc implementations on crates.io. Please comment if you think we should use them.
(e.g., https://github.com/HadrienG2/hwlocality)
Signed-off-by: bg-furiosa <[email protected]>
Signed-off-by: bg-furiosa <[email protected]>
Signed-off-by: bg-furiosa <[email protected]>
Signed-off-by: bg-furiosa <[email protected]>
Signed-off-by: bg-furiosa <[email protected]>
Signed-off-by: bg-furiosa <[email protected]>
Signed-off-by: bg-furiosa <[email protected]>
Signed-off-by: bg-furiosa <[email protected]>
Signed-off-by: bg-furiosa <[email protected]>
Signed-off-by: bg-furiosa <[email protected]>
Signed-off-by: bg-furiosa <[email protected]>
Signed-off-by: bg-furiosa <[email protected]>
Signed-off-by: bg-furiosa <[email protected]>
Signed-off-by: bg-furiosa <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I started by looking at the big flows. I'm not completely done with the review, but I'll continue with the review after seeing the changes for comments.
Signed-off-by: bg-furiosa <[email protected]>
Signed-off-by: bg-furiosa <[email protected]>
Signed-off-by: bg-furiosa <[email protected]>
Signed-off-by: bg-furiosa <[email protected]>
Signed-off-by: bg-furiosa <[email protected]>
Signed-off-by: bg-furiosa <[email protected]>
Signed-off-by: bg-furiosa <[email protected]>
Signed-off-by: bg-furiosa <[email protected]>
Signed-off-by: bg-furiosa <[email protected]>
Signed-off-by: bg-furiosa <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I left some comments. Let's just resolve those and be done with it.
device-api/Cargo.toml
Outdated
@@ -8,6 +8,8 @@ license = { workspace = true } | |||
homepage = { workspace = true } | |||
repository = { workspace = true } | |||
readme = { workspace = true } | |||
build = "build.rs" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be omitted.
device-api/src/topology/mod.rs
Outdated
use std::collections::BTreeMap; | ||
|
||
use itertools::iproduct; | ||
use libc::link; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is this dependency? If it is not used, you can remove this line and remove the libc dependency as well.
device-api/bin/show_topology.rs
Outdated
@@ -0,0 +1,36 @@ | |||
use cli_table::{print_stdout, Cell, Style, Table}; | |||
use furiosa_device::{list_devices, topology, DeviceError}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use furiosa_device::{list_devices, topology, DeviceError}; | |
use furiosa_device::{list_devices, topology::Topology, DeviceError}; |
device-api/bin/show_topology.rs
Outdated
return Ok(()); | ||
} | ||
|
||
let topology = topology::Topology::new(devices.clone())?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let topology = topology::Topology::new(devices.clone())?; | |
let topology = Topology::new(devices.clone())?; |
device-api/bin/show_topology.rs
Outdated
let mut rows = vec![]; | ||
let mut header = vec!["Device".cell().bold(true)]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let mut rows = vec![]; | |
let mut header = vec!["Device".cell().bold(true)]; | |
let mut rows = Vec::with_capacity(devices.len() + 1); | |
let mut header = Vec::with_capacity(devices.len() + 1); | |
header.push("Device".cell().bold(true)); |
device-api/src/topology/mod.rs
Outdated
let mut link_type: LinkType = LinkTypeUnknown; | ||
|
||
if dev1_bdf == dev2_bdf { | ||
link_type = LinkTypeSoc | ||
} else { | ||
link_type = topology_provider.get_common_ancestor_obj(&dev1_bdf, &dev2_bdf)?; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let mut link_type: LinkType = LinkTypeUnknown; | |
if dev1_bdf == dev2_bdf { | |
link_type = LinkTypeSoc | |
} else { | |
link_type = topology_provider.get_common_ancestor_obj(&dev1_bdf, &dev2_bdf)?; | |
} | |
let link_type = if dev1_bdf == dev2_bdf { | |
LinkTypeSoc | |
} else { | |
topology_provider.get_common_ancestor_obj(&dev1_bdf, &dev2_bdf)? | |
} |
device-api/src/topology/mod.rs
Outdated
(dev1_bdf, dev2_bdf) | ||
}; | ||
|
||
topology_matrix.insert(key, link_type); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
topology_matrix.insert(key, link_type); | |
topology_matrix.entry(key).or_insert(link_type); |
device-api/src/topology/hwloc.rs
Outdated
} | ||
} | ||
|
||
pub unsafe fn hwloc_get_common_ancestor_obj( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason why the access specifier for this function is pub
? Are there other places it's used?
device-api/src/topology/hwloc.rs
Outdated
static ref BDF_NOTATION_PATTERN: Regex = Regex::new(r"^(?:(?P<domain>[0-9a-fA-F]+):)?(?P<bus>[0-9a-fA-F]+):(?P<dev>[0-9a-fA-F]+)\.(?P<func>[0-9a-fA-F]+)").unwrap(); | ||
} | ||
|
||
pub unsafe fn hwloc_get_pcidev_by_busidstring( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason why the access specifier for this function is pub
? (2)
device-api/Cargo.toml
Outdated
thiserror = "1" | ||
tokio = { workspace = true } | ||
tracing = "0.1" | ||
tracing-subscriber = { version = "0.3.1", features = ["env-filter", "json"] } | ||
libc = "0.2.153" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's make sure this is the dependency we actually need.
Signed-off-by: bg-furiosa <[email protected]>
Signed-off-by: bg-furiosa <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍
PR Description
What type of PR is this?
Special notes for reviewer