The different answers explain what the use case of the code snippet is, e.g. printing the information of nvidia-smi inside the script, checking the current and max. allocated memory, and printing the total memory of a specific device, so you can chose whatever fits your use case of “memory usage”.