How do know if the GPU memory size applied for exceeds the total GPU memory?

using libtorch. When exceeded total gpu memory, the program does not crash, the reason is that the CPU memory is used as gpu memory, which causes the program to be slow, how to solve it?


nvmlMemory_t memoryInfo;
result = nvmlDeviceGetMemoryInfo(device, &memoryInfo);

When exceeded total gpu memory. The value of memoryInfo looks like everything is fine…