Celeb Glow
news | March 27, 2026

How to get number of gpu cards I have from a command line?

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??

1

3 Answers

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.

1
nvidia-smi --list-gpus | wc -l

This will first list the GPUS one per line and then counts the lines of output which is the number of GPUS

You can use sudo lshw -C display to list your video card(s), then google each one to see how many cores it has.

2

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy