Skip to content

Instantly share code, notes, and snippets.

@donglixp
Created December 6, 2023 11:22
Show Gist options
  • Save donglixp/d8f799fad4e5301ee697aecbde70b2c6 to your computer and use it in GitHub Desktop.
Save donglixp/d8f799fad4e5301ee697aecbde70b2c6 to your computer and use it in GitHub Desktop.
gpu_zombie.py
import torch
ngpus = torch.cuda.device_count()
N, M, K = 1280, 2560, 5120
def matmul():
A = []
B = torch.randn(M, K, device='cuda:0')
for i in range(ngpus):
A.append(torch.randn(N // ngpus, M, device='cuda:'+str(i)))
B_ = [B]
for i in range(ngpus):
if i != 0:
B_.append(B.to('cuda:'+str(i)))
C_ = []
for i in range(ngpus):
C_.append(torch.matmul(A[i], B_[i]))
C = torch.empty(N, K)
for i in range(ngpus):
start_index = i * (N//ngpus)
C[start_index:start_index + N//ngpus, :].copy_(C_[i])
while True:
matmul()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment