两次调用tf.Session()会导致致命错误:无法获取设备0的设备属性13

时间:2019-07-20 02:19:40

标签: python tensorflow

我刚刚使用CUDA 10.0.130和cudnn v7.6.1.34安装了Tensor Flow 1.14.0。 当我在一个python会话中第一次调用tf.Session()时,它工作良好,但是当我尝试再次调用它时,即使我关闭了第一个会话,它也会崩溃。

再现此故障的最小示例如下

(tensorflow-gpu) C:\Users\Argen>python
Python 3.7.3 (default, Apr 24 2019, 15:29:51) [MSC v.1915 64 bit (AMD64)] :: Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
>>> a = tf.Session()
2019-07-20 12:04:23.279225: I tensorflow/stream_executor/platform/default/dso_loader.cc:42] Successfully opened dynamic library nvcuda.dll
2019-07-20 12:04:23.912859: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1640] Found device 0 with properties:
name: GeForce 940M major: 5 minor: 0 memoryClockRate(GHz): 1.176
pciBusID: 0000:01:00.0
2019-07-20 12:04:23.921996: I tensorflow/stream_executor/platform/default/dlopen_checker_stub.cc:25] GPU libraries are statically linked, skip dlopen check.
2019-07-20 12:04:23.927364: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1763] Adding visible gpu devices: 0
2019-07-20 12:04:23.931103: I tensorflow/core/platform/cpu_feature_guard.cc:142] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2
2019-07-20 12:04:23.938320: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1640] Found device 0 with properties:
name: GeForce 940M major: 5 minor: 0 memoryClockRate(GHz): 1.176
pciBusID: 0000:01:00.0
2019-07-20 12:04:23.944323: I tensorflow/stream_executor/platform/default/dlopen_checker_stub.cc:25] GPU libraries are statically linked, skip dlopen check.
2019-07-20 12:04:23.950175: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1763] Adding visible gpu devices: 0
2019-07-20 12:04:26.671775: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1181] Device interconnect StreamExecutor with strength 1 edge matrix:
2019-07-20 12:04:26.678254: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1187]      0
2019-07-20 12:04:26.681610: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1200] 0:   N
2019-07-20 12:04:26.686087: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1326] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 1391 MB memory) -> physical GPU (device: 0, name: GeForce 940M, pci bus id: 0000:01:00.0, compute capability: 5.0)
>>> a.close()
>>> a = tf.Session()
2019-07-20 12:06:57.801849: F tensorflow/stream_executor/lib/statusor.cc:34] Attempting to fetch value instead of handling error Internal: failed to get device attribute 13 for device 0: CUDA_ERROR_UNKNOWN: unknown error

我的环境是: 赢10专业 英特尔(R)高清显卡520和NVIDIA GeForce 940M Python 3.7.3

1 个答案:

答案 0 :(得分:1)

默认情况下,TensorFlow在进程的生存期而不是会话对象的生存期中分配GPU内存。有关更多详细信息,请访问:https://www.tensorflow.org/programmers_guide/using_gpu#allowing_gpu_memory_growth

因此,如果要释放内存,则必须退出Python解释器,而不仅仅是关闭会话。

希望有帮助。