But what I need is to isolate it down to just this part: [Radeon 680M] at best or this part Advanced Micro Devices, Inc. [AMD/ATI] Rembrandt [Radeon 680M] at worst.
I preferably want to do this without lspci, and I need a generic way of doing it (e.g. a way to do it for any device, not just this specific device, which means using cut and sed or awk to isolate only the part I need from lspci is not a satisfying option)
Where does lspci find the name and can I use the same method somehow?
So that’s the question, how do I identify a device’s name, and only the name from the PCI ID?
Program sed is capable of finding various strings inside a string (and much more). It uses regular expressions. You can find many parts of a string this way too.
Thanks; using the -m option I can reliably isolate the name portion in lspci like this
lspci -md 1002:1681 | cut -d '"' -f6
it’ll give me
Rembrandt [Radeon 680M]
or with the nvidia option GA104 [Geforce RTX 3070 Ti Laptop GPU]
I would prefer the output of the sed approach you provided me with, but it’s not reliable across different hardware.
However reading the man page for the -i option told me that fstab reads the names from /usr/share/hwdata/pci.ids but it’s not a text file, is there any way I can access the data in it without lspci?
OHHH, it is, I used cat on the file and i got a jarbled output but i guess it was just cuz it was too long for cat, and not cuz it was in some weird binary format like is usually the case when that happens.
Yeah now we’re in business, just need to figure out how to parse the file so i can get the correct device name.
After a lot of pain (awk kills me, and so does any sed more complicated than the basic substitiotn command) I have figured it out.
$ awk "/^1002/{a=1;next}/^.... /{a=0}a" /usr/share/hwdata/pci.ids | sed -n "0,/\s*1681 /s///p"
Rembrandt [Radeon 680M]
I’ve made it go through all my gpus and print their names one by one in the below code sample:
#!/bin/bash
PCI_IDS=$(find /usr/share -maxdepth 2 -name "pci.ids" -print -quit) #Some distros don't store it in the same place.
for CARD in /sys/class/drm/card[0-99]/device;
do
VENDOR=$(cut -b 3-6 $CARD/vendor)
ID=$(cut -b 3-6 $CARD/device)
# First we get all lines between the VENDOR and the next vendor;
# then we find an exact match to our ID and print only the name;
# Then we look for values inside [brackets] and print only those if there are any.
NAME=$(awk "/^$VENDOR/{a=1;next}/^.... /{a=0}a" $PCI_IDS | sed -n "0,/\s*$ID /s///p" | awk -F'[][]' '{if ($2) {print $2} else {print $0}}')
echo $NAME
done
It also has a bunch of safety checks like the sed command will never print more than 1 line, and it uses symbols to represent leading whitespace so all unwanted whitespace will 100% be removed. And the awk at the end that gets the values between brackets will print the full name if it doesn’t find brackets.
For me it outputs:
Geforce RTX 3070 Ti Laptop GPU
Radeon 680M
So there it is, a reliable way that doesn’t rely on lspci to get the names.
Maybe someone better with awk could make this just be the one awk command but awk is extremely confusing to me. I’ve gone online, copied awk commands, pasted them and modified them like a 100 times now and I still cannot make headas or tails of the syntax, damn thing is like an alien language!
Well, yeah, exactly.
There is 1 card, it starts at -1, so with +1 from that single card the numeral becomes 0, card0 does not exist, and no more addition occurs.
I see, a technically correct answer but not specific enough.
To get Radeon RX 570 Pulse 4GB we’d need to find these numbers 1da2 e353 but i don’t know where to find them, the 1da2 seems to refer to sapphire, and e353 refers to the specific device, but it seems even with that you’re not guaranteed to get an accurate name.
As you said it says your card is 4GB but it’s 8GB, and many of the options would output results like Nitro+ Radeon RX 570/580/590 or in the worst case Navi 10 [Radeon RX 5600 OEM/5600 XT / 5700/5700 XT]Navi 10 [Radeon RX 5600 OEM/5600 XT / 5700/5700 XT]
It seems liek sapphire reuses their device identifiers a lot.
Radeon RX 470/480/570/570X/580/580X/590 is the AMD identifier for your card. It’s strange that AMD is using one identifier for 2 whole generations of cards (every ellesmere based card)
No I knew about those, that’s exactly how i found out the exact numbers for your card, the problem is finiding them somewhere in /sys/class/drm/card*/device/ ideally; because the script isn’t meant to know beforehand what card you’ve got, it’s supposed to find out through gathering the vendor and device ids.