Giter VIP home page Giter VIP logo

hwloc2-rs's Introduction

hwloc2-rs

MIT licensed crates.io

This project is a successor to daschl/hwloc-rs, except that this library supports 2.x.x versions of hwloc. This library tries to maintain most of the API layer that daschl/hwloc-rs set forth.

Hwloc is a C library from Open MPI for detecting the hierarchical topology of modern architectures. This includes objects such as NUMA memory nodes, sockets, shared data & instruction caches, cores, and simultaneous multi threading.

Prerequisites

A system installed with hwloc 2.2.0.

Please note, this is not the default version installed by package managers of many mainstream distributions right now. You will probably have to install it from source:

You can download the source from https://www.open-mpi.org/projects/hwloc/

Usage

First, add the following to your Cargo.toml:

[dependencies]
hwloc2 = "2.2.0"

Next, add this to your crate root:

extern crate hwloc2;

Here is a quick example which walks the Topology and prints it out:

extern crate hwloc2;

use hwloc2::Topology;

fn main() {
	let topo = Topology::new().unwrap();

	for i in 0..topo.depth() {
		println!("*** Objects at level {}", i);

		for (idx, object) in topo.objects_at_depth(i).iter().enumerate() {
			println!("{}: {}", idx, object);
		}
	}
}

You can also look at more examples, if you want to run them check out the next section below.

Running Examples

The library ships with examples, and to run them you need to clone the repository and then run them through cargo run --example=.

$ git clone https://github.com/ichbinjoe/hwloc2-rs.git
$ cd hwloc-rs

To run an example (which will download the dependencies and build it) you can use cargo run -example=:

$ cargo run --example=walk_tree
   Compiling hwloc v2.2.0 (/directory/hwloc2-rs)
    Finished dev [unoptimized + debuginfo] target(s) in 0.54s
     Running `target/debug/examples/walk_tree`
*** Printing overall tree
Machine (): #0
 Package (): #0
  L3 (8192KB): #4294967295
   L2 (512KB): #4294967295
    L1d (32KB): #4294967295
     Core (): #0
      PU (): #0
      PU (): #8
   L2 (512KB): #4294967295
    L1d (32KB): #4294967295
     Core (): #1
      PU (): #1
      PU (): #9
   L2 (512KB): #4294967295
    L1d (32KB): #4294967295
     Core (): #2
      PU (): #2
      PU (): #10
   L2 (512KB): #4294967295
    L1d (32KB): #4294967295
     Core (): #3
      PU (): #3
      PU (): #11
  L3 (8192KB): #4294967295
   L2 (512KB): #4294967295
    L1d (32KB): #4294967295
     Core (): #4
      PU (): #4
      PU (): #12
   L2 (512KB): #4294967295
    L1d (32KB): #4294967295
     Core (): #5
      PU (): #5
      PU (): #13
   L2 (512KB): #4294967295
    L1d (32KB): #4294967295
     Core (): #6
      PU (): #6
      PU (): #14
   L2 (512KB): #4294967295
    L1d (32KB): #4294967295
     Core (): #7
      PU (): #7
      PU (): #15

License

This project uses the MIT license, please see the LICENSE file for more information.

hwloc2-rs's People

Contributors

daschl avatar fsck avatar ichbinjoe avatar johalun avatar trolldemorted avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

hwloc2-rs's Issues

Panicked when running example=bind_thread

Aborts on Centos with:
thread 'main' panicked at 'called Result::unwrap()on anErr value: TypeDepthUnknown', examples/bind_threads.rs:29:9

Btw, using 'hwloc2' instead of 'hwloc'.

lstopo version is:
lstopo 2.2.0

Support for aarch64?

I'm using Macbook Air M1 and AWS linux arm server. Is there support for aarch64 architecutre?

Thoughts on supporting PCI devices on the socket/NUMA they are attached to?

I hacked this together myself this afternoon just to reassure myself the data was there, but I wonder if there's a plan for how to support it properly?

For the record, this involved:

  1. changing some u32 to i32 to support referencing the special PCI depths (in Topology, and in the FFI bindings)
  2. fixing the mapping in depth_for_type (bug,it skipped over TypeDepthNumaNode and so the index mappings were all off)
  3. fixing the ffi for hwloc_topology_set_io_types_filter (bug, it doesn't take an ObjectType)

A bunch of those FFI which take c_uchar probably ought to take i32 to support passing the TypeFilter into them.

In any case, this doesn't really feel like the best way to support PCI devices -- it seems like perhaps rather than threading through positive depths as the existing positive integers in an Ok, and the negative depths as enums in an Err, we ought to support them all in a separate proper enum or something ?

I'm pretty new at Rust, so please bear that in mind. My goal is to see this library to the point where one can pull out the distances between cores on different (possibly sub-)NUMA nodes, as well as to various PCI devices attached to the sockets.

Is this still maintained ? -> Seems not, so I forked

As this repo has not received updates for several years and the author has no recorded public activity on github for the past year, I suspect it is not maintained anymore.

So I've set up a personal fork at https://github.com/HadrienG2/hwloc2-rs (see below) on which I'm applying every non-risky patch from the public forks listed in the network graph, as well as a few fixes/improvements on my own.

@Ichbinjoe if you are still around, please tell me if you would be interested in resuming maintenance of this repo or letting me join you as a maintainer. If I get no reply from your side, I will eventually re-upload my fork as yet another similarly named crate on crates.io...

Panic with "The provided depth 4294967292 is out of bounds." when trying to list NUMA nodes

Trying to run this:

use hwloc2::{Topology, ObjectType};

fn main() {
    let topo = Topology::new().expect("Failed to get topology");
    for parent in topo.objects_with_type(&ObjectType::NUMANode).expect("Failed to get objects") {
    }
}

leads to this crash:

thread 'main' panicked at 'The provided depth 4294967292 is out of bounds.', /home/fpr/local/cargo/registry/src/github.com-1ecc6299db9ec823/hwloc2-2.2.0/src/lib.rs:373:13

Running on: Dell XPS 15 9750 laptop
OS: Debian testing 64-bit
hwloc2 version: 2.2.0
hwloc native version: Tried in Debian with 2.4.0 and in a Nix 20.09 environment with 2.2.0.

Compiling and running the example in the documentation completes successfully with the following output:

*** Objects at level 0
0: Machine ()
*** Objects at level 1
0: Package ()
*** Objects at level 2
0: L3 (9216KB)
*** Objects at level 3
0: L2 (256KB)
1: L2 (256KB)
2: L2 (256KB)
3: L2 (256KB)
4: L2 (256KB)
5: L2 (256KB)
*** Objects at level 4
0: L1d (32KB)
1: L1d (32KB)
2: L1d (32KB)
3: L1d (32KB)
4: L1d (32KB)
5: L1d (32KB)
*** Objects at level 5
0: Core ()
1: Core ()
2: Core ()
3: Core ()
4: Core ()
5: Core ()
*** Objects at level 6
0: PU ()
1: PU ()
2: PU ()
3: PU ()
4: PU ()
5: PU ()
6: PU ()
7: PU ()
8: PU ()
9: PU ()
10: PU ()
11: PU ()

I note that this listing contains no reference to a NUMA node whereas lstopo on my system does. However, it seems that a panic of this form is surely not the correct behaviour in this case.

Reading the hwloc2 documentation, I note that HWLOC_TYPE_DEPTH_NUMANODE along with a number of other virtual depths are represened as negative values. I wonder if there is code attempting to treat them as actual depths. My attempt to work around this issue by using the depth_for_type and related functions for locating a depth value to iterate at also returned strange errors for me.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.