Skip to content
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

[Idea] Get GPU info #107

Closed
PandaFoss opened this issue May 4, 2021 · 36 comments
Closed

[Idea] Get GPU info #107

PandaFoss opened this issue May 4, 2021 · 36 comments
Assignees
Labels
area/fetching Has something to do with the fetched information. other/help-wanted Your help is needed. type/feature Request a new feature.

Comments

@PandaFoss
Copy link

First question, where to get the information from?

I found in the pciutils repository the following:

In runs on the following systems:

Linux (via /sys/bus/pci, /proc/bus/pci or i386 ports)
FreeBSD (via /dev/pci)
NetBSD (via libpci)
OpenBSD (via /dev/pci)
GNU/kFreeBSD (via /dev/pci)
Solaris/i386 (direct port access)
Aix (via /dev/pci and odmget)
GNU Hurd (direct port access)
Windows (direct port access, see README.Windows for caveats)
CYGWIN (direct port access)
BeOS (via syscalls)
Haiku (via /dev/misc/poke)
Darwin (via IOKit)
DOS/DJGPP (via i386 ports)
SylixOS (via /proc/pci)

There are many possible places to search, depending on the kernel (or operating system). But in some cases it's a matter of reading a plain text file. In order not to make the issue too long, I recommend the first part of this article. As you can see in the article, it is possible to read the vendor identifier, device identifier and class identifier.

Step two: mapping identifiers to GPUs

I quote again the previous repository, the following:

The database of PCI IDs (the pci.ids file) gets out of date much faster
than I release new versions of this package, so it is maintained separately.

It lives at https://pci-ids.ucw.cz/, where you can browse the database,
download the most recent pci.ids file (e.g., by running the update-ids utility)
and also submit new entries.

If we go through that website, we can corroborate that the GPU information (in addition to other devices that are not relevant) can be obtained from these ID's.

At first I thought that the pci.ids file should be downloaded regularly to keep it updated but, at least in Arch Linux, I found it in /usr/share/hwdata/pci.ids.

I'm not sure this is the best way to solve it, but I think it can work, without relying on system commands or external crates.

@grtcdr
Copy link
Member

grtcdr commented May 4, 2021

Hey @PandaFoss!

Thank you for the detailed information you've provided and the great article too 😄

If implemented correctly, I believe this is the best shot we have at correctly identifying GPU information no matter the system. If it turns out to be a lengthy implementation, then we might consider turning this into a separate crate.

My suggestion is we start with Linux, it's the first one to get new features and it's where I do all my work.

@PandaFoss
Copy link
Author

I'm a Linux user myself, so I think it's best to start there. I'm not an experienced Rust user but I'd love to contribute as much as I can.

@grtcdr
Copy link
Member

grtcdr commented May 4, 2021

I'm going to start working on this, most likely in a different repository, once I have a good bit of code setup, I'll share it with you and we can commence the real work.

@grtcdr grtcdr self-assigned this May 7, 2021
@grtcdr
Copy link
Member

grtcdr commented Jun 23, 2021

Hey! It's been a while, but I've resumed my work on this feature :)

pci_fetch is the library that handles fetching PCI devices and soon enough it'll also integrate with pci.ids to get the strings associated with the connected PCI devices. So as you can already tell, the library is still a work in progress.

My apologies for the month long delay it took, uni's been hectic :/

@grtcdr
Copy link
Member

grtcdr commented Jun 23, 2021

Slowly but surely imitating lspci.

image

@grtcdr
Copy link
Member

grtcdr commented Jun 24, 2021

@PandaFoss Feel free to take a look around the code if you'd like to contribute, I cleaned it up and made it a lot more library-use friendly.

And here's a nice little demo 😃

output.mp4

What do you think @uttarayan21?

@PandaFoss
Copy link
Author

@PandaFoss Feel free to take a look around the code if you'd like to contribute, I cleaned it up and made it a lot more library-use friendly.

And here's a nice little demo smiley
output.mp4

What do you think @uttarayan21?

Incredible work. I've been pretty busy lately but as soon as I can I'll take a closer look at the code (which from what I can see is great). Thank you!

@grtcdr
Copy link
Member

grtcdr commented Jun 24, 2021

Incredible work.

Thanks! I wish I had the time to do it sooner, this was a great experience 😄

I've been pretty busy lately but as soon as I can I'll take a closer look at the code

Great, I'd love to hear your feedback when you're free.

@uttarayan21
Copy link
Member

@PandaFoss Feel free to take a look around the code if you'd like to contribute, I cleaned it up and made it a lot more library-use friendly.

And here's a nice little demo smiley
output.mp4

What do you think @uttarayan21?

Looks really cool 👍

But since you are using GPL-2.0 for pci_fetch, you might want to change that to MIT or Apache or any permissive license since GPL-2.0 requires you to license macchina under GPL-2.0 as well.
see here

@grtcdr
Copy link
Member

grtcdr commented Jun 24, 2021

But since you are using GPL-2.0 for pci_fetch, you might want to change that to MIT or Apache or any permissive license since GPL-2.0 requires you to license macchina under GPL-2.0 as well.
see here

Oh, good catch, will do!

@grtcdr
Copy link
Member

grtcdr commented Jun 25, 2021

libmacchina v0.5.0 now integrates with aparato (previously named pci_fetch), so I'll move this issue back over to macchina so we can print the new readouts.

@grtcdr grtcdr transferred this issue from Macchina-CLI/libmacchina Jun 25, 2021
@grtcdr
Copy link
Member

grtcdr commented Jun 30, 2021

I'm afraid the future won't be shipped until I can sort out the performance issues within aparato.

@grtcdr grtcdr linked a pull request Aug 10, 2021 that will close this issue
5 tasks
@grtcdr
Copy link
Member

grtcdr commented Aug 10, 2021

sneak peek

image

@grtcdr grtcdr added area/fetching Has something to do with the fetched information. type/feature Request a new feature. and removed libmacchina labels Nov 16, 2021
@grtcdr grtcdr added the other/help-wanted Your help is needed. label Apr 2, 2022
@brunoanc
Copy link

brunoanc commented Jun 5, 2022

What's the current status on this? I'd love to help, as I have some Rust experience.

@grtcdr
Copy link
Member

grtcdr commented Jun 6, 2022

Hi @PowerBall253,

Thanks for taking interest!

aparato was originally supposed to help us determine this information, but it's been unmaintained for very long now. If you'd like to contribute, I suggest looking at other pci.ids parsers and hooking them with libmacchina, then we can add support for that readout in macchina.

@Rolv-Apneseth
Copy link
Contributor

Rolv-Apneseth commented Mar 7, 2023

Hi, I have no experience with this but I would like to work on as I would like to have that output. I would appreciate some guidance if you can point me in the right direction.

So, first I find a library which can parse pci.ids, maybe like this one? Do I then use some other method to get the currently connected pci vga device or how do I go about this?

@grtcdr
Copy link
Member

grtcdr commented Mar 8, 2023

Hey there, nice to see you again!

Thanks for taking interest in this :)

You could iterate over the entries in /sys/bus/pci/devices/, map those to their real name using the pci-ids parser and filter out the graphics cards.

For example, /sys/bus/pci/devices/0000:00:14.0/class has a value of 0x0c0330 on my machine, which the pci.ids database maps to:

C 0c  Serial bus controller            <----------------- Here
        00  FireWire (IEEE 1394)
                00  Generic
                10  OHCI
        01  ACCESS Bus
        02  SSA
        03  USB controller             <----------------- Then here
                00  UHCI
                10  OHCI
                20  EHCI
                30  XHCI               <----------------- And finally, over here.

That's not a GPU, we should move on to the next PCI device (and so on and so forth).

@Rolv-Apneseth
Copy link
Contributor

Ok thanks for the guidance, I'll have a look at it when I have some free time for sure and come back here if I get stuck

@grtcdr
Copy link
Member

grtcdr commented Mar 11, 2023

You're welcome, thanks for stepping up to work on this feature. (no pressure, though)

@Rolv-Apneseth
Copy link
Contributor

I have something working. Does this issue need to be moved to libmacchina first or shall I just open a PR over there? I also have some code ready for macchina to actually display the GPU.

@grtcdr
Copy link
Member

grtcdr commented Mar 15, 2023

You can create a PR directly :)

@Rolv-Apneseth
Copy link
Contributor

Since that pr has been merged to libmacchina, is there a version update that needs to happen before I can make a pr here to utilise the new functionality? I have code ready just not sure if the crate needs an update first.

@grtcdr
Copy link
Member

grtcdr commented Mar 23, 2023

I'll get to that tomorrow.

is there a version update that needs to happen before I can make a pr here to utilise the new functionality?

Yes, the only other alternative is to point libmacchina to the git branch temporarily which you won't need to do.

@Rolv-Apneseth
Copy link
Contributor

Ok cool, thank you

@luccahuguet
Copy link

this issue was created in may 2021, and I just needed this today, exactly when it is very close to being merged... feeling lucky!

thank you very much for the project Macchina team, and the gpu part too @Rolv-Apneseth

@jtrv
Copy link

jtrv commented Mar 27, 2023

The newest commit related to this issue seems to be broken for me

thread 'main' panicked at 'Could not find opening square bracket for sub device: Reference RX 5700 XT', /home/user/.local/share/cargo/registry/src/index.crates.io-6f17d22bba15001f/libmacchina-6.4.0/src/linux/pci_devices.rs:86:22

@Rolv-Apneseth
Copy link
Contributor

Rolv-Apneseth commented Mar 27, 2023

It was working before and only the latest commit broke it? That's weird, but I'll have a look as it's just a matter of how the strings are being processed I think

edit: sorry misread the first time, assuming you didn't try it before then, but yes I'll have a look

@grtcdr
Copy link
Member

grtcdr commented Mar 27, 2023

He's using device 731f 1002 0b36 which doesn't have a subdevice name. We should return the device string when an opening brace can't be located.

@Rolv-Apneseth
Copy link
Contributor

He's using device 731f 1002 0b36 which doesn't have a subdevice name. We should return the device string when an opening brace can't be located.

Alright will do

@grtcdr
Copy link
Member

grtcdr commented Mar 27, 2023

In that case we should rename the get_sub_device_name function to something more generic, e.g. get_device_name.

@grtcdr
Copy link
Member

grtcdr commented Mar 28, 2023

@JacobTravers Can you git pull and try again?

@uttarayan21
Copy link
Member

Is it not implemented for windows ?
image

@Rolv-Apneseth
Copy link
Contributor

No sorry not yet, I only implemented it for Linux. I believe it would also require internet access to get pci.ids.

@grtcdr
Copy link
Member

grtcdr commented Mar 28, 2023

@uttarayan21 I would really appreciate it if you reviewed PR Macchina-CLI/libmacchina#149 which adds GPU support to libmacchina for Windows.

@jtrv
Copy link

jtrv commented Mar 28, 2023

@JacobTravers Can you git pull and try again?

Works fine now 👍🏽

@Rolv-Apneseth
Copy link
Contributor

Thanks for reporting that issue @JacobTravers

@grtcdr grtcdr closed this as completed May 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/fetching Has something to do with the fetched information. other/help-wanted Your help is needed. type/feature Request a new feature.
Development

Successfully merging a pull request may close this issue.

7 participants