I am trying to make a CUDA tool and I have to make it scalable. I need to give number of GPU a system have as an argument to my tool. Please tell me if there is any command for getting number of GPUs directly??
Asked
Active
Viewed 1.4k times
9
-
`lshw` is good when it comes to determining hardware. If I'm not forgetting the syntax, `lshw -c graphics` should give you the desired result – Sergiy Kolodyazhnyy Jul 11 '17 at 04:47
4 Answers
11
This command gets the number of GPUs directly, assuming you have nvidia-smi.
nvidia-smi --query-gpu=name --format=csv,noheader | wc -l
It prints the names of the GPUs, one per line, and then counts the number of lines.
tuzhucheng
- 111
- 1
- 3
3
You can use sudo lshw -C display to list your video card(s), then google each one to see how many cores it has.
treelzebub
- 31
- 1
-
Since I want to make a tool, I don't think using sudo command will be safe. Is there is any other way which do not require any permission since my tool will be using the common server here. – agangwal Jul 11 '17 at 07:00
-
And I don't want to see cores. I only want to get number of GPU cards – agangwal Jul 11 '17 at 07:02
0
If you want to use it in a script, I'd suggest to using it like this:
nvidia-smi --query-gpu=name --format=csv,noheader | head -1
And also validate the number:
GPU_num="$(nvidia-smi --query-gpu=name --format=csv,noheader | head -1)"
! [[ "$GPU_num" =~ ^[0-9]+$ ]] && echo "Not a number)"
It's better to count the number of lines, because the line can also be an error.
Feriman
- 198
- 4