## Get Id of default devicetorch.cuda.current_device# 0
cuda.Device(0).name # '0' is the id of your GPU# Tesla K80
或者
torch.cuda.get_device_name(0) # Get name device with ID '0'# 'Tesla K80'
我编写了一个简单的类来获取有关您的cuda兼容GPU的信息:
要获取当前的内存使用情况,可以使用pyTorch的函数,例如:
mport torch# Returns the current GPU memory usage by# tensors in bytes for a given devicetorch.cuda.memory_allocated# Returns the current GPU memory managed by the# caching allocator in bytes for a given devicetorch.cuda.memory_cached
运行应用程序后,可以使用简单的命令清除缓存:
# Releases all unoccupied cached memory currently held by# the caching allocator so that those can be used in other# GPU application and visible in nvidia-smitorch.cuda.empty_cache
但是,使用此命令不会通过张量释放占用的GPU内存&#

本文介绍了如何在PyTorch中利用CUDA加速算法,包括获取GPU信息、监控内存使用、在GPU上存储张量及运行模型、选择GPU运算、数据并行处理以及使用torch.multiprocessing。通过实例展示了在多GPU环境中进行有效计算的方法。
最低0.47元/天 解锁文章
1115

被折叠的 条评论
为什么被折叠?



