How can I see GPU memory used?

I would like to monitor GPU memory used in NX. I tried the code attached below given in the previous form for this tittle. However when I used it, it said that 6.8G GPU memory is used but using htop I saw that only 3.28G of the memory is used. Assuming that this shows that the given code does not function accurately, I would like to request a new method in this regard.
“”"
#include
#include <unistd.h>
#include “cuda.h”

int main()
{
// show memory usage of GPU
size_t free_byte ;
size_t total_byte ;

while (true )
{
    cudaError_t cuda_status = cudaMemGetInfo( &free_byte, &total_byte ) ;

    if ( cudaSuccess != cuda_status ){
        std::cout << "Error: cudaMemGetInfo fails, " << cudaGetErrorString(cuda_status) << std::endl;
        exit(1);
    }

    double free_db = (double)free_byte ;
    double total_db = (double)total_byte ;
    double used_db = total_db - free_db ;

    std::cout << "GPU memory usage: used = " << used_db/1024.0/1024.0 << ", free = "
              << free_db/1024.0/1024.0 << " MB, total = " << total_db/1024.0/1024.0 << " MB" << std::endl;
    sleep(1);
}

“”"
Thx

Hi,

You can also refer to Tegrastats utility That can show GPU utilization directly.
For example:

GR3D_FREQ 40%@1377

$ sudo tegrastats
RAM 3215/31921MB (lfb 6739x4MB) SWAP 0/15960MB (cached 0MB) CPU [1%@2265,0%@2265,0%@2265,0%@2265,0%@2265,71%@2265,0%@2265,3%@2265] EMC_FREQ 1%@2133 GR3D_FREQ 40%@1377 VIC_FREQ 0%@115 APE 150 MTS fg 0% bg 8% AO@38.5C GPU@39.5C Tdiode@44.5C PMIC@100C AUX@38C CPU@40.5C thermal@39.05C Tboard@40C GPU 3654/1760 CPU 1979/1387 SOC 2283/2301 CV 0/0 VDDRQ 457/457 SYS5V 2224/2224


You will find more information on it here :
https://docs.nvidia.com/drive/drive_os_5.1.6.1L/nvvib_docs/index.html#page/DRIVE_OS_Linux_SDK_Development_Guide/Utilities/util_tegrastats.html

Further than GPU usage, be aware that Jetsons have iGPU, so the same physical memory is shared by CPUs and GPU.
I’m unable to say how to see what is allocated by GPU only (though, it should be contiguous NVMM memory). Someone better skilled may better answer.

1 Like

Thanks for your answers with the suggested solution I can only see the percentage of GPU usage. I still want to know reach vram allocation. Any help would be appreciated.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.