tensorflow找不到GPU

时间:2020-07-14 13:59:59

标签: python tensorflow 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:模块'tensorflow'没有属性'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) 

答案是 0不带GPU:5.481482100000051 1个不带GPU的:5.6241342000000145 2个不带GPU的:5.62558580000001 3不带GPU:5.299320899999998 4个没有GPU:5.424306600000023 使用GPU ufunc的0:0.4764495000000011 1个,带有GPU ufunc:0.118225099999961 2个,带有GPU ufunc:0.12550920000001042 3与GPU ufunc:0.11633530000000292 4使用GPU ufunc:0.11252430000001823 使用GPU内核的0:0.20753619999999273 1个具有GPU内核的:0.08865670000000136 2个具有GPU内核的:0.08246159999998781 3使用GPU内核:0.08481519999998 4使用GPU内核:0.08220890000001191 如何使TensorFlow可见GPU?

1 个答案:

答案 0 :(得分:0)

问题是由于我的设备上存在两个Cuda版本(10和11)。我卸载了Cuda 10,然后问题解决了