您的足迹: 操作gpu显存

强行占用20G的显存

这是本文档旧的修订版!


强行占用20G的显存

因为某些特定的原因,我们必须占用20G的显存

use_gpu.py
import torch
import time
device = torch.device("cuda")
total_memory = torch.cuda.get_device_properties(0).total_memory
target_memory = total_memory * 0.3
num_elements = int(target_memory / 4)
tensor = torch.randn(num_elements, dtype=torch.float32, device=device)
time.sleep(3600000000)
del tensor
torch.cuda.empty_cache()
linux/gpu/nvidia显卡/常用脚本/操作gpu显存.1761217812.txt.gz · 最后更改: 2025/10/23 11:10
CC Attribution 4.0 International 除额外注明的地方外,本维基上的内容按下列许可协议发布: CC Attribution 4.0 International