TensorFlow学习笔记 速记2 报错:failed call to cuDevicePrimaryCtxRetain: CUDA_ERROR_INVALID_DEVICE

版本:

tensorflow-gpu

原因:

在创建session时没有使用我想让它用的gpu

解决方案:

1. 在python程序中:

import os
os.environ["CUDA_VISIBLE_DEVICES"] = "0"

2. 运行时:

CUDA_VISIBLE_DEVICES=0 python **.py

3. 直接在环境变量中 export

export CUDA_VISIBLE_DEVICES='0'
python **.py