[英]tensorflow can not find GPU
我安裝了 TensorFlow-GPU 2.1.0,但當被問及版本時,答案是 1.13.1
import tensorflow as tf
print(tf.__version__)
最大的問題是當我運行 GPU 測試時,答案是 False
tf.test.is_gpu_available()
我試過這個
print("Num GPUs Available:",len(tf.config.experimental.list_physical_devices('GPU')))
答案是 AttributeError: module 'tensorflow' has no attribute 'config' 但是我運行這個腳本
from numba import vectorize, jit, cuda
# to measure exec time
from timeit import default_timer as timer
# normal function to run on cpu
def func(a):
for i in range(10000000):
a[i]+= 1
# function optimized to run on gpu
@vectorize(['float64(float64)'], target ="cuda")
def func2(x):
return x+1
# kernel to run on gpu
@cuda.jit
def func3(a, N):
tid = cuda.grid(1)
if tid < N:
a[tid] += 1
if __name__=="__main__":
n = 10000000
a = np.ones(n, dtype = np.float64)
for i in range(0,5):
start = timer()
func(a)
print(i, " without GPU:", timer()-start)
for i in range(0,5):
start = timer()
func2(a)
print(i, " with GPU ufunc:", timer()-start)
threadsperblock = 1024
blockspergrid = (a.size + (threadsperblock - 1)) // threadsperblock
for i in range(0,5):
start = timer()
func3[blockspergrid, threadsperblock](a, n)
print(i, " with GPU kernel:", timer()-start)
the answers are 0 without GPU: 5.481482100000051 1 without GPU: 5.6241342000000145 2 without GPU: 5.62558580000001 3 without GPU: 5.299320899999998 4 without GPU: 5.424306600000023 0 with GPU ufunc: 0.4764495000000011 1 with GPU ufunc: 0.118225099999961 2 with GPU ufunc: 0.12550920000001042 3 with GPU ufunc : 0.11633530000000292 4 with GPU ufunc: 0.11252430000001823 0 with GPU kernel: 0.20753619999999273 1 with GPU kernel: 0.08865670000000136 2 with GPU kernel: 0.08246159999998781 3 with Z52F9EC21735243AD9917 CDA3CA077D32Z kernel: 0.08481519999998 4 with GPU kernel: 0.08220890000001191 How can I make the GPU visible for TensorFlow?
問題是由於我的設備上存在兩個 Cuda 版本(10 和 11)。 我卸載了 Cuda 10 然后問題就解決了
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.