Created
December 6, 2023 11:22
-
-
Save donglixp/d8f799fad4e5301ee697aecbde70b2c6 to your computer and use it in GitHub Desktop.
gpu_zombie.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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