NVML GPU Memory Usage C example


I have a C/C++ application for which I want to mimic the per-process “GPU Memory Usage” parameter the nvidia-smi application provides. Is there an example for a C/C++ application using NVML or comparible on how to achieve this?


PS: If there is a way to get the information for a process using a bash or python script that would be nice too.