我的笔记本采用大黄蜂显卡模式, 只有当optirun执行的时候显卡才可见(否则为inter核显)
写一个死循环的cpp程序
#include<stdio.h>
#include<unistd.h>
int main()
{
while(1)
{
sleep(60);
}
return 0;
}
编译好为mysleep
复制到/usr/bin
执行optirun mysleep
这时NVIDIA显卡就持续启动了
(base) tqc@tqc-PC:~/Desktop$ nvidia-smi
Mon Aug 12 11:26:10 2019
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 390.87 Driver Version: 390.87 |
|-------------------------------+----------------------+----------------------+
| GPU Name Persistence-M| Bus-Id Disp.A | Volatile Uncorr. ECC |
| Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. |
|===============================+======================+======================|
| 0 GeForce GTX 1060 Off | 00000000:01:00.0 Off | N/A |
| N/A 41C P8 3W / N/A | 7MiB / 6078MiB | 0% Default |
+-------------------------------+----------------------+----------------------+
+-----------------------------------------------------------------------------+
| Processes: GPU Memory |
| GPU PID Type Process name Usage |
|=============================================================================|
| 0 19767 G /usr/lib/xorg/Xorg 5MiB |
+-----------------------------------------------------------------------------+
这时运行一个tensorflow-gpu的demo程序
import tensorflow as tf
with tf.Session(config=tf.ConfigProto(allow_soft_placement=True, log_device_placement=False)) as sess:
a = tf.constant(1)
b = tf.constant(3)
c = a + b
print('结果是:%d\n 值为:%d' % (sess.run(c), sess.run(c)))
可能还会报错.
在终端执行以下代码
sudo ldconfig /usr/local/cuda-9.0/lib64
好了
不知道以后还会有什么问题, 瑟瑟发抖