您的位置:首页 > 大数据 > 人工智能

TensorFlow 报错 failed call to cuDevicePrimaryCtxRetain: CUDA_ERROR_INVALID_DEVICE

2017-06-16 14:39 2046 查看
今天使用python virtualenv安装TensorFlow gpu版,一直报错各种配置版本按官网来的https://www.tensorflow.org/cuda8.0 cudnn5.1错误如下2017-06-16 13:53:53.632070: W tensorflow/stream_executor/cuda/cuda_driver.cc:523] A non-primary context 0x3f287f0 exists before initializing the StreamExecutor. We haven't verified StreamExecutor works with that.2017-06-16 13:53:53.632367: E tensorflow/core/common_runtime/direct_session.cc:138] Internal: failed initializing StreamExecutor for CUDA device ordinal 1: Internal: failed call to cuDevicePrimaryCtxRetain: CUDA_ERROR_INVALID_DEVICETraceback (most recent call last):  File "<stdin>", line 1, in <module>  File "/home/zw/jy/lib/python3.5/site-packages/tensorflow/python/client/session.py", line 1292, in __init__    super(Session, self).__init__(target, graph, config=config)  File "/home/zw/jy/lib/python3.5/site-packages/tensorflow/python/client/session.py", line 562, in __init__    self._session = tf_session.TF_NewDeprecatedSession(opts, status)  File "/usr/lib/python3.5/contextlib.py", line 66, in __exit__    next(self.gen)  File "/home/zw/jy/lib/python3.5/site-packages/tensorflow/python/framework/errors_impl.py", line 466, in raise_exception_on_not_ok_status    pywrap_tensorflow.TF_GetCode(status))tensorflow.python.framework.errors_impl.InternalError: Failed to create session.后来参考一下连接解决错误 https://stackoverflow.com/questions/37893755/tensorflow-set-cuda-visible-devices-within-jupyter https://stackoverflow.com/questions/44375177/tensorflow-unusual-cuda-related-error http://www.cnblogs.com/darkknightzh/p/6591923.html 原因是在创建session时没有使用我想让它用的gpu所以需要设置
CUDA_VISIBLE_DEVICES
方法1 在python程序中
import os
os.environ["CUDA_VISIBLE_DEVICES"] = "1"
方法2
运行时 
CUDA_VISIBLE_DEVICES=1 python **.py
方法3
直接在环境变量中 export 

                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐