GPU usage info (nvidia-smi is not there)

Dear All!

How to get GPU usage through C++ interface?

The “nvidia-smi” app requires a GPU which is using the PCI bus. On a Jetson the GPU is instead directly wired to the memory controller, so anything requiring a PCI query cannot work. Normally one would use “tegrastats” to see such information.

I know this, but “tegrastats” is just an executable program. I want to get some GPU information in my program in real time. I don’t know how to get GPU information through the C++ interface.

The interesting thing about tegrastats is that it simply reads files in “/sys” or “proc”. As an interesting experiment, if you don’t already have “strace” installed, do so with “sudo apt-get install strace”. Then run tegrastats via strace, but redirect the “standard output” to “/dev/null”:
sudo strace tegrastats 1>/dev/null

You’ll see just the strace output, including the calls to files in “/proc” and “/sys”. This repeats, so just hit CTRL-c to stop after one reading. You can easily read those files from C++ instead of tegrastats, but it won’t be as convenient as using C++ to open tegrastats for one reading, and then closing.

You may try:

sudo cat /sys/devices/gpu.0/load
sudo cat /sys/kernel/debug/clk/gpcclk/clk_rate

You may read these nodes from C++ code.

2 Likes