【解决问题】【Tensorflow】failed to create cublas handle: CUBLAS_STATUS_ALLOC_FAILED

【解决问题】【Tensorflow】failed to create cublas handle: CUBLAS_STATUS_ALLOC_FAILED

  • 前言
  • 问题描述
  • 解决问题
  • 参考链接

前言

学了好多天的深度学习,终于学到使用gpu了,本来很开心,但是和同学聊天得知我的1660Ti跑深度学习,啥也不是,顿是不抱什么希望了,笔记本用来学习就好了,真跑深度学习还得用实验室电脑,哎,还是没钱的原因

问题描述

使用gpu时出现了报错

2021-11-09 20:43:26.114720: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cublas64_100.dll
2021-11-09 20:43:26.386261: E tensorflow/stream_executor/cuda/cuda_blas.cc:238] failed to create cublas handle: CUBLAS_STATUS_ALLOC_FAILED
2021-11-09 20:43:26.386617: E tensorflow/stream_executor/cuda/cuda_blas.cc:238] failed to create cublas handle: CUBLAS_STATUS_ALLOC_FAILED
2021-11-09 20:43:26.386735: W tensorflow/stream_executor/stream.cc:1919] attempting to perform BLAS operation using StreamExecutor without BLAS support
Traceback (most recent call last):
  File "first.py", line 30, in <module>
    gpu_time = timeit.timeit(gpu_run,number=10)
  File "D:\Anaconda\Anaconda3\envs\tensorflow2_0_0_gpu\lib\timeit.py", line 233, in timeit
    return Timer(stmt, setup, timer, globals).timeit(number)
  File "D:\Anaconda\Anaconda3\envs\tensorflow2_0_0_gpu\lib\timeit.py", line 177, in timeit
    timing = self.inner(it, self.timer)
  File "", line 6, in inner
  File "first.py", line 21, in gpu_run
    c = tf.matmul(gpu_a,gpu_b)
  File "D:\Anaconda\Anaconda3\envs\tensorflow2_0_0_gpu\lib\site-packages\tensorflow_core\python\util\dispatch.py", line 180, in wrapper
    return target(*args, **kwargs)
  File "D:\Anaconda\Anaconda3\envs\tensorflow2_0_0_gpu\lib\site-packages\tensorflow_core\python\ops\math_ops.py", line 2765, in matmul
    a, b, transpose_a=transpose_a, transpose_b=transpose_b, name=name)
  File "D:\Anaconda\Anaconda3\envs\tensorflow2_0_0_gpu\lib\site-packages\tensorflow_core\python\ops\gen_math_ops.py", line 6126, in mat_mul
    _six.raise_from(_core._status_to_exception(e.code, message), None)
  File "", line 3, in raise_from
tensorflow.python.framework.errors_impl.InternalError: Blas GEMM launch failed : a.shape=(10000, 1000), b.shape=(1000, 2000), m=10000, n=2000, k=1000 [Op:MatMul] name: MatMul/

顿时给我急得,一顿查找原因,我咋显存不足了,程序运行gpu都没跑满

解决问题

有两个主要原因
1、cudnn、cuda的版本与tensorflow不适用,但是我的是按照教程来的,确认好几遍,保证是可以的,这个排除
2、gpu的显存不足,可以通过官网上的方法解决:T因为ensorFlow2.0支持两种GPU运算的方式:
(1)动态分配显存
(2)设置硬性显存(比如限制只能用1g显存,其他的去玩游戏
把模式调成(1)动态分配即可,代码为;

import tensorflow as tf

gpus = tf.config.experimental.list_physical_devices(device_type='GPU')
tf.config.experimental.set_memory_growth(gpus[0], True)

参考链接

TensorFlow2.0!!!!Could not create cudnn handle: CUDNN_STATUS_ALLOC_FAILED错误解决方法

你可能感兴趣的:(深度学习,深度学习,tensorflow,python)