目录
pull
docker pull nvidia/cuda:11.2.0-cudnn8-devel-ubi7
docker tag nvidia/cuda:11.2.0-cudnn8-devel-ubi7 registry.cn-hangzhou.aliyuncs.com/mkmk/all:nvidia-cuda-11.2.0-cudnn8-devel-ubi7
docker push registry.cn-hangzhou.aliyuncs.com/mkmk/all:nvidia-cuda-11.2.0-cudnn8-devel-ubi7
gpu tf
docker run --gpus all -it tensorflow/tensorflow:latest-gpu bash
docker pull tensorflow/tensorflow:2.4.1-gpu
docker pull tensorflow/tensorflow:2.4.1-gpu-jupyter
docker tag tensorflow/tensorflow:2.4.1-gpu registry.cn-hangzhou.aliyuncs.com/mkmk/all:tf-2.4.1-gpu
docker tag tensorflow/tensorflow:2.4.1-gpu-jupyter registry.cn-hangzhou.aliyuncs.com/mkmk/all:tf-2.4.1-gpu-jupyter
docker push registry.cn-hangzhou.aliyuncs.com/mkmk/all:tf-2.4.1-gpu
docker push registry.cn-hangzhou.aliyuncs.com/mkmk/all:tf-2.4.1-gpu-jupyter
使用镜像
register_url='192.168.170.100:5000'
docker stop gpu-jupyter1 && docker rm gpu-jupyter1
docker run -it --gpus=all --name gpu-jupyter1 -p 8888:8888 ${register_url}/tensorflow/tensorflow:2.4.1-gpu-jupyter
# 将输出的 ip 修改为 真实 ip
# 完整 命令 调试 使用
docker run -d --gpus=all --name gpu-jupyter1 -p 8888:8888 ${register_url}/tensorflow/tensorflow:2.4.1-gpu-jupyter bash -c "source /etc/bash.bashrc && jupyter notebook --notebook-dir=/tf --ip 0.0.0.0 --no-browser --allow-root"
测试 是否 使用的 gpu
import tensorflow as tf
tf.test.is_gpu_available(
cuda_only=False,
min_cuda_compute_capability=None
)
# 简化一点
print("is_gpu: ", tf.test.is_gpu_available())
# 查看 所有的 可用设备
from tensorflow.python.client import device_lib
print(device_lib.list_local_devices())
# 加法
# cpu
%%time
with tf.device("/device:CPU:0"):
a=tf.zeros([1000,1000])
print("a on gpu:",a.device.endswith('GPU:0'))
for i in range(10000):
b=tf.add(a,a)
a on gpu: False
CPU times: user 7.74 s, sys: 1.2 s, total: 8.94 s
Wall time: 3.39 s
# gpu
%%time
with tf.device("/device:GPU:0"):
a=tf.zeros([1000,1000])
print("a on gpu:",a.device.endswith('GPU:0'))
for i in range(10000):
b=tf.add(a,a)
a on gpu: True
CPU times: user 900 ms, sys: 1.22 s, total: 2.12 s
Wall time: 2.12 s
来来来聊一晚
标签:镜像,--,cuda11,gpu,tf,tensorflow,docker,2.4 From: https://www.cnblogs.com/ltgybyb/p/16907450.html