I installed TensorFlow-GPU 2.1.0 but when asked the version the answer is 1.13.1
import tensorflow as tf
print(tf.__version__)
the big problem is when I run the GPU test the answer is False
tf.test.is_gpu_available()
I tried this
print("Num GPUs Available:",len(tf.config.experimental.list_physical_devices('GPU')))
the answer is AttributeError: module 'tensorflow' has no attribute 'config' but he I run this script
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?
The problem was due to the presence of two Cuda versions (10 and 11) on my device. I uninstalling the Cuda 10 and then the problem was solved
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.