Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I determine the number of CUDA devices on my system (without compiling anything)?

I want to determine the number of CUDA devices on my system. Of course I can do this using the CUDA runtime API in a C program I compile, but - what's the simplest/most straightforward way to do this without compiling any code?

Assumptions:

  • CUDA >= 7.0 is installed
  • up-to-date nVIDIA drivers are installed
  • You may provide different solutions for UNIX-like and non-UNIX-like OSes.
like image 888
einpoklum Avatar asked Oct 28 '25 11:10

einpoklum


1 Answers

If you're on Linux or a UNIX-like system, this works:

nvidia-smi  -L | wc -l

Explanation:

  • nvidia-smi is nVIDIA's "system management interface" utility. You can use it to determine all sorts of information about your GPUs and also to carry out some maintenance actions.
  • nvidia-smi -L lists the GPUs available on the system.
  • wc is the UNIX word/line/character counting utility
  • wc -l counts the number of lines on the standard input

... but is kind of brittle. I wish I had something a bit more robust.

like image 54
einpoklum Avatar answered Oct 31 '25 10:10

einpoklum



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!