@
一、检查GPU是否可用
lspci | grep -i nvidia
出现如下内容则说明有GPU
二、安装nvidia-docker
sudo apt-get install -y nvidia-docker2
sudo systemctl daemon-reload
sudo systemctl restart docker
三、验证 nvidia-docker 安装
sudo docker run --runtime=nvidia --rm nvidia/cuda nvidia-smi
有时候会报如下错误
需要改写/etc/docker/daemon.json文件,改成如下形式即可
{
"registry-mirrors": ["https://registry.docker-cn.com"],
"runtimes": {
"nvidia": {
"path": "/usr/bin/nvidia-container-runtime",
"runtimeArgs": []
}
}
}
四、安装Tensorflow-GPU
docker run --gpus all -it --rm tensorflow/tensorflow:latest-gpu
python -c "import tensorflow as tf; print(tf.reduce_sum(tf.random.normal([1000, 1000])))"