Hello Experts!
I am a newbie. Just installed pytorch with cudatoolkit on Ubuntu 22.04 on Lenovo IdeaPad-Gaming-3
It has two video cards
0000:00:02.0 VGA compatible controller [0300]: Intel Corporation Alder Lake-P GT1 [UHD Graphics] [8086:46a3] (rev 0c)
Subsystem: Lenovo Device [17aa:3af6]
Kernel driver in use: i915
Kernel modules: i915
0000:01:00.0 VGA compatible controller [0300]: NVIDIA Corporation GA107M [GeForce RTX 3050 Mobile] [10de:25a2] (rev a1)
Subsystem: Lenovo GA107M [GeForce RTX 3050 Mobile] [17aa:3af6]
Kernel driver in use: nvidia
Kernel modules: nvidiafb, nouveau, nvidia_drm, nvidia
As a first step I am trying to explore cuda using below test:
import time
import torchtorch.cuda.is_available()
#matrix_size=32 * 512
matrix_size=32 * 256
#matrix_size=32 * 128x=torch.randn(matrix_size,matrix_size)
y=torch.randn(matrix_size,matrix_size)print(“******************* CPU SPEED *****************”)
start=time.time()
result=torch.matmul(x,y)
print(time.time()-start)
print(“verify device:”,result.device)x_gpu=x.to(device)
y_gpu=y.to(device)
torch.cuda.synchronize()for i in range(3):
print(“******************* GPU SPEED *****************”)
start=time.time()
result_gpu=torch.matmul(x_gpu,y_gpu)
torch.cuda.synchronize()
print(time.time()-start)
print(“verify device:”,result_gpu.device)
It works fine up to matrix size 32*256 giving 10 times performance gain on GPU:
******************* CPU SPEED *****************
2.9146814346313477
verify device: cpu
******************* GPU SPEED *****************
0.654292106628418
verify device: cuda:0
******************* GPU SPEED *****************
0.23547625541687012
verify device: cuda:0
******************* GPU SPEED *****************
0.23913264274597168
verify device: cuda:0
But with matrix size 32*512 I am getting out of memory problem:
RuntimeError: CUDA out of memory. Tried to allocate 1024.00 MiB (GPU 0; 3.81 GiB total capacity; 768.00 MiB already allocated; 1.03 GiB free; 768.00 MiB reserved in total by PyTorch)
That’s natural I reached the limit.
Thinking about how can I use whole NVIDIA card memory for calculations?
Currently I am using NVIDIA as prime, the first thing that comes to my mind is to use another card (intel) for video to serve my monitor and use whole NVIDIA for calculations.
I tried to
sudo prime-select intel
reboot and the try to run above code, but no success.
torch.cuda.is_available()
returns False.
Does it makes any sense what I am trying to do?
Is it possible to use Intel card for video, and NVIDIA for calculations?
Appreciate any comment/advice.