我用window10+AMD 4800U(核显)+pytorch_directml做了测试,GPU加速比CPU快2倍以上。
但要注意,如果显存不够(不包括共享显存),则GPU不会工作,测试代码如下:
import torch as t
import torch_directml as dml
import numpy as np
import time
device = dml.device()
x = np.random.random((100,100))
x = t.from_numpy(x)
print(x.device)
t0=time.time()
for i in range(100000):
t.matmul(x,t.matmul(x,x))
print(time.time()-t0)
x = x.to(device)
print(x.device)
t0=time.time()
for i in range(100000):
t.matmul(x,t.matmul(x,x))
print(time.time()-t0)
但要注意,如果显存不够(不包括共享显存),则GPU不会工作,测试代码如下:
import torch as t
import torch_directml as dml
import numpy as np
import time
device = dml.device()
x = np.random.random((100,100))
x = t.from_numpy(x)
print(x.device)
t0=time.time()
for i in range(100000):
t.matmul(x,t.matmul(x,x))
print(time.time()-t0)
x = x.to(device)
print(x.device)
t0=time.time()
for i in range(100000):
t.matmul(x,t.matmul(x,x))
print(time.time()-t0)