$ sudo rm -rf /usr/local/cuda
$ sudo ln -s /usr/local/cuda-9.0 /usr/local/cuda
$ vim ~/.bashrc
#在文件结尾处添加
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda/lib64
export PATH=$PATH:/usr/local/cuda/bin
export CUDA_HOME=$CUDA_HOME:/usr/local/cuda
$ source ~/.bashrc
$ nvcc -V
修改 /etc/profile 文件
sudo vim /etc/profile
在末尾加上
export PATH=/usr/local/cuda/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/cuda/lib64$LD_LIBRARY_PATH
export CUDA_HOME=/usr/local/cuda
再source一下就可以了
source /etc/profile
虚拟环境配置
新建
$ virtualenv --system-site-packages voca --python=python2.7
退出
$ deactivate
删除
$ rm -r venv
$ tar -xzvf cudnn-9.0-linux-x64-v7.tgz
$ sudo cp cuda/include/cudnn.h /usr/local/cuda/include
$ sudo cp cuda/lib64/libcudnn* /usr/local/cuda/lib64
TensorFlow
安装
$ pip install tensorflow-gpu==1.12.1
$ python
import tensorflow as tf
hello=tf.constant('hello, tensorworld')
sess=tf.Session()
print(sess.run(hello))
代码中屏蔽其他gpu:
import os
os.environ['CUDA_VISIBLE_DEVICES']='2'
代码中指定gpu:
tf.device('/gpu:2')
命令行中屏蔽其他gpu:
$ CUDA_VISIBLE_DEVICES=2 python train.py
Failed to get convolution algorithm. This is probably because cuDNN failed to initialize
tensorflow版本过高
$ pip install --upgrade tensorflow-gpu==1.8.0
could not create cudnn handle: CUDNN_STATUS_INTERNAL_ERROR
The problem occurs due to memory segmentation issue in GPU. We can solve this issue by Allowing GPU memory growth in Tensorflow session or fixed memory allocation.
config = tf.ConfigProto()
config.gpu_options.allow_growth=True
sess = tf.Session(config=config)
OR,
To only allocate 70% of the total memory of each GPU by:
config.gpu_options.per_process_gpu_memory_fraction = 0.7
- 取消自动缩进
在命令模式下,使用“:set nosmartindent”和“:set noautoindent”取消自动缩进,然后再粘贴即可。完成后再开启自动缩进“:set smartindent”和“:set autoindent”,以上命令都可使用简写,比如“:set si”,可通过Vim的帮助“:help smartindent”查看相应说明。 - Paste模式
Vim的编辑模式中,还有一个Paste模式,在该模式下,可将文本原本的粘贴到Vim中,以避免一些格式错误。通过“:set paste”和“:set nopaste”进入和退出该模式。更简便的方式是,在Vim中设置一个进入和退出Paste模式的快捷键,往“~/.vimrc”中添加一行配置“set pastetoggle=<F12>”,这样即可通过F12快速的在Paste模式中切换,当然快捷键在不冲突的前提下可以任意指定,具体如何指定,参考附带的教程链接。