AI: Desempeño de GPU vs CPU en multiplicación de matrices
import torch
import numpy as np
import time
device = 'cuda' if torch.cuda.is_available else 'cpu'
print(device)
torch_rand1 = torch.rand(100,100,100,100).to(device)
torch_rand2 = torch.rand(100,100,100,100).to(device)
np_rand1 = torch.rand(100,100,100,100)
np_rand2 = torch.rand(100,100,100,100)
start_time = time.time()
rand = (torch_rand1 @ torch_rand2)
end_time = time.time()
elapsed_time = end_time - start_time
print(f"{elapsed_time:.8f}")
start_time = time.time()
rand = np.multiply(np_rand1,np_rand2)
end_time = time.time()
elapsed_time = end_time - start_time
print(f"{elapsed_time:8f}")
Comentarios
Publicar un comentario