[英]tensorflow Mac OS gpu support
According to 根据
https://www.tensorflow.org/install/install_mac Note: As of version 1.2, TensorFlow no longer provides GPU support on Mac OS X. GPU support for OS X is no longer provided.
https://www.tensorflow.org/install/install_mac注意:从版本1.2开始,TensorFlow不再在Mac OS X上提供GPU支持。不再提供对OS X的GPU支持。
However, I would want to run an e-gpu setup like akitio node with a 1080 ti via thunderbolt 3. 但是,我想通过thunderbolt 3来运行像akitio节点这样的e-gpu设置。
What steps are required to get this setup to work? 要使此设置生效,需要执行哪些步骤? So far I know that
到目前为止,我知道
are required. 是必要的。 What else is needed to get CUDA / tensorflow to work?
还有什么需要让CUDA / tensorflow工作?
I wrote a little tutorial on compiling TensorFlow 1.2 with GPU support on macOS . 我在macOS上编写了一个关于编译TensorFlow 1.2和GPU支持的小教程。 I think it's customary to copy relevant parts to SO, so here it goes:
我认为将相关部分复制到SO是习惯做法,所以在这里:
pip install tensorflow-gpu
. pip install tensorflow-gpu
。 Once you get that working, the CUDA set-up would also work if you're compiling TensorFlow. git checkout r1.0
with git checkout r1.2
. git checkout r1.0
替换git checkout r1.2
。 When doing ./configure
, pay attention to the Python library path: it sometimes suggests an incorrect one. ./configure
,请注意Python库路径:它有时会提示不正确的路径。 I chose the default options in most cases, except for: Python library path, CUDA support and compute capacity. /usr/bin/gcc
as your compiler will actually use Clang that comes with macOS / XCode. /usr/bin/gcc
作为编译器实际上将使用macOS / XCode附带的Clang。 Below is my full configuration. tensorflow/third_party/gpus/cuda/BUILD.tpl
, which contained linkopts = [“-lgomp”]
(but the location of the line might obviously change). tensorflow/third_party/gpus/cuda/BUILD.tpl
第98行,其中contained linkopts = [“-lgomp”]
(但该行的位置可能会明显改变)。 Some people had issues with zmuldefs , but I assume that was with earlier versions; Using python library path: /Users/m/code/3rd/conda/envs/p3gpu/lib/python3.6/site-packages
使用python库路径:/Users/m/code/3rd/conda/envs/p3gpu/lib/python3.6/site-packages
Do you wish to build TensorFlow with MKL support?
您是否希望使用MKL支持构建TensorFlow? [y/N] N
[y / N] N.
No MKL support will be enabled for TensorFlow
不会为TensorFlow启用MKL支持
Please specify optimization flags to use during compilation when bazel option "--config=opt" is specified [Default is -march=native]:
当指定bazel选项“--config = opt”时,请指定在编译期间使用的优化标志[Default is -march = native]:
Do you wish to build TensorFlow with Google Cloud Platform support?
您是否希望通过Google Cloud Platform支持构建TensorFlow? [y/N]
[Y / N]
No Google Cloud Platform support will be enabled for TensorFlow
不会为TensorFlow启用Google Cloud Platform支持
Do you wish to build TensorFlow with Hadoop File System support?
您是否希望使用Hadoop文件系统支持构建TensorFlow? [y/N]
[Y / N]
No Hadoop File System support will be enabled for TensorFlow
不会为TensorFlow启用Hadoop文件系统支持
Do you wish to build TensorFlow with the XLA just-in-time compiler (experimental)?
您是否希望使用XLA即时编译器(实验性)构建TensorFlow? [y/N]
[Y / N]
No XLA support will be enabled for TensorFlow
TensorFlow不会启用XLA支持
Do you wish to build TensorFlow with VERBS support?
您是否希望使用VERBS支持构建TensorFlow? [y/N]
[Y / N]
No VERBS support will be enabled for TensorFlow
不会为TensorFlow启用VERBS支持
Do you wish to build TensorFlow with OpenCL support?
您是否希望在OpenCL支持下构建TensorFlow? [y/N]
[Y / N]
No OpenCL support will be enabled for TensorFlow
不会为TensorFlow启用OpenCL支持
Do you wish to build TensorFlow with CUDA support?
您是否希望通过CUDA支持构建TensorFlow? [y/N] y
[y / N] y
CUDA support will be enabled for TensorFlow
将为TensorFlow启用CUDA支持
Do you want to use clang as CUDA compiler?
你想使用clang作为CUDA编译器吗? [y/N]
[Y / N]
nvcc will be used as CUDA compiler
nvcc将用作CUDA编译器
Please specify the CUDA SDK version you want to use, eg 7.0.
请指定您要使用的CUDA SDK版本,例如7.0。 [Leave empty to use system default]:
[留空以使用系统默认值]:
Please specify the location where CUDA toolkit is installed.
请指定安装CUDA工具包的位置。 Refer to README.md for more details.
有关更多详细信息,请参阅README.md。 [Default is /usr/local/cuda]:
[默认为/ usr / local / cuda]:
Please specify which gcc should be used by nvcc as the host compiler.
请指定nvcc应使用哪个gcc作为主机编译器。 [Default is /usr/bin/gcc]:
[默认为/ usr / bin / gcc]:
Please specify the cuDNN version you want to use.
请指定您要使用的cuDNN版本。 [Leave empty to use system default]:
[留空以使用系统默认值]:
Please specify the location where cuDNN library is installed.
请指定cuDNN库的安装位置。 Refer to README.md for more details.
有关更多详细信息,请参阅README.md。 [Default is /usr/local/cuda]:
[默认为/ usr / local / cuda]:
Please specify a list of comma-separated Cuda compute capabilities you want to build with.
请指定要使用的逗号分隔Cuda计算功能列表。
You can find the compute capability of your device at: https://developer.nvidia.com/cuda-gpus .
您可以在以下网址找到设备的计算能力: https : //developer.nvidia.com/cuda-gpus 。
Please note that each additional compute capability significantly increases your build time and binary size.
请注意,每个额外的计算能力都会显着增加构建时间和二进制文件大小。
[Default is: "3.5,5.2"]: 6.1
[默认为:“3.5,5.2”]:6.1
INFO: Starting clean (this may take a while).
信息:开始清洁(这可能需要一段时间)。 Consider using --async if the clean takes more than several minutes.
如果清理时间超过几分钟,请考虑使用--async。
Configuration finished
配置完成
Assuming that you have already setup your eGPU box and attached the TB3 cable from the eGPU to your TB3 port: 假设您已经设置了eGPU盒并将TB3电缆从eGPU连接到TB3端口:
1. Download the automate-eGPU script and run it 1.下载automate-eGPU脚本并运行它
curl -o ~/Desktop/automate-eGPU.sh
https://raw.githubusercontent.com/goalque/automate-eGPU/master/automate-eGPU.sh
&& chmod +x ~/Desktop/automate-eGPU.sh && cd ~/Desktop && sudo
./automate-eGPU.sh
You might get an error saying: 您可能会收到错误消息:
"Boot into recovery partition and type: csrutil disable"
“启动到恢复分区并键入:csrutil disable”
All you need to do now is to restart your computer and when it's restarting hold down cmd + R
to enable the recovery mode. 您现在需要做的就是重新启动计算机,当它重新启动时按住
cmd + R
以启用恢复模式。 Then locate the Terminal while in recovery mode and type in: 然后在恢复模式下找到终端并输入:
csrutil disable
Then restart your computer and re-run the automate-eGPU.sh
script 然后重新启动计算机并重新运行
automate-eGPU.sh
脚本
2: Download and installing CUDA 2:下载并安装CUDA
Run the cuda_8.0.61_mac.dmg
file and follow through the installation phase. 运行
cuda_8.0.61_mac.dmg
文件并按照安装阶段进行操作。 Then afterwards you will need to set the paths. 然后你需要设置路径。
Go to your Terminal and type: 转到您的终端并输入:
vim ~/.bash_profile
Or whether you have stored your environmental variables and then add these three lines: 或者您是否已存储环境变量,然后添加以下三行:
export CUDA_HOME=/usr/local/cuda
export DYLD_LIBRARY_PATH="$CUDA_HOME/lib:$CUDA_HOME:$CUDA_HOME/extras/CUPTI/lib"
export LD_LIBRARY_PATH=$DYLD_LIBRARY_PATH
3. Downloading and installing cuDNN 3.下载并安装cuDNN
To download cuDNN is a bit more troublesome you have to sign up to be a developer for Nvidia and then afterwards you can download it. 要下载cuDNN有点麻烦,你必须注册成为Nvidia的开发人员,然后你可以下载它。 Make sure to download
cuDNN v5.1 Library for OSX
as it's the one that Tensorflow v1.1 expects Note that we can't use Tensorflow v1.2 as there is no GPU support for Macs :(( 确保下载
cuDNN v5.1 Library for OSX
因为它是Tensorflow v1.1所期望的注意我们不能使用Tensorflow v1.2,因为没有GPU支持Mac:((
[![enter image description here][1]][1] [![在此输入图片说明] [1]] [1]
Now you will download a zip file called cudnn-8.0-osx-x64-v5.1.tgz
, unzip and, which will create a file called cuda
and cd to it using terminal. 现在你将下载一个名为
cudnn-8.0-osx-x64-v5.1.tgz
的zip文件,解压缩,它将使用终端创建一个名为cuda
和cd的文件。 Assuming that the folder is in Downloads 假设该文件夹位于下载中
Open terminal and type: 打开终端并输入:
cd ~/Downloads/cuda
Now we need to copy cuDNN
files to where CUDA
is stored so: 现在我们需要将
cuDNN
文件复制到存储CUDA
位置,这样:
sudo cp include/* /usr/local/cuda/include/
sudo cp lib/* /usr/local/cuda/lib/
4. Now install Tensorflow-GPU v1.1 in your conda/virtualenv 4.现在在conda / virtualenv中安装Tensorflow-GPU v1.1
For me since I use conda
I created a new environment using Terminal: 对我来说,因为我使用
conda
我使用Terminal创建了一个新环境:
conda create -n egpu python=3
source activate egpu
pip install tensorflow-gpu # should install version 1.1
5. Verify that it works 5.验证它是否有效
First you have to restart your computer then: 首先,您必须重新启动计算机:
In terminal type python
and enter: 在终端类型
python
输入:
import tensorflow as tf
with tf.device('/gpu:0'):
a = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[2, 3], name='a')
b = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[3, 2], name='b')
c = tf.matmul(a, b)
with tf.Session() as sess:
print (sess.run(c))
If you have a GPU this should run with no problem, if it does then you should get a stack trace (just a bunch of error messages) and it should include 如果你有一个GPU应该运行没有问题,如果它,那么你应该得到一个堆栈跟踪(只是一堆错误消息),它应该包括
Cannot assign a device to node 'MatMul': Could not satisfy explicit device specification '/device:GPU:0' because no devices matching that specification are registered in this process
无法将设备分配给节点'MatMul':无法满足显式设备规范'/ device:GPU:0',因为在此过程中没有注册与该规范匹配的设备
If not then you're done congratz! 如果没有那么你就完成了祝贺! I just got mine set up today and it's working perfectly :)
我刚刚安装了我的设备并且工作正常:)
I could finally make it work with the following setup 我终于可以使用以下设置了
I wrote a gist with the procedure: 我写了一个关于程序的要点:
https://gist.github.com/jganzabal/8e59e3b0f59642dd0b5f2e4de03c7687 https://gist.github.com/jganzabal/8e59e3b0f59642dd0b5f2e4de03c7687
Here is my solution to install an e-gpu on a mac. 这是我在mac上安装e-gpu的解决方案。 Tensorflow doesn't support tensorflow-gpu anymore, so there are definitely better approaches to get it working:
Tensorflow不再支持tensorflow-gpu,所以肯定有更好的方法让它工作:
My configuration: 我的配置:
Advantages of windows bootcamp installation: windows bootcamp安装的优点:
Howto: 如何:
Command: 命令:
pip install tensorflow-gpu==1.5.0rc0
Check your installation 检查您的安装
The display driver has been installed correctly when you can plug a screen to the GTX 1080 ti card. 当您可以将屏幕插入GTX 1080 ti卡时,显示驱动程序已正确安装。
Call C:\\Program Files\\NVIDIA Corporation\\NVSMI\\nvidia-smi.exe to check if your video card is available for CUDA. 调用C:\\ Program Files \\ NVIDIA Corporation \\ NVSMI \\ nvidia-smi.exe检查您的视频卡是否可用于CUDA。
Execute the following tensorflow command to see available devices: 执行以下tensorflow命令以查看可用设备:
from tensorflow.python.client import device_lib
device_lib.list_local_devices()
Troubleshooting and hints: 故障排除和提示:
Ubuntu solution: Ubuntu解决方案:
I couldn't find a working solution but here are some approaches: 我找不到一个有效的解决方案,但这里有一些方法:
It seems that my GTX 680 (iMac) and my GTX 1080 ti won't work together. 我的GTX 680(iMac)和我的GTX 1080 ti似乎无法协同工作。 Ubuntu could not be started anymore after installing the display driver via apt-get: Ubuntu not starting anmore .
通过apt-get安装显示驱动程序后, Ubuntu无法再启动 : Ubuntu无法启动 。 Try to download the official display driver from NVIDIA download page .
尝试从NVIDIA下载页面下载官方显示驱动程序。
OSX Solution: Tensorflow GPU is only supported up to tensorflow 1.1. OSX解决方案: Tensorflow GPU仅支持tensorflow 1.1。 I tried to install a newer version but couldn't build tensorflow-gpu with cuda support.
我试图安装更新版本,但无法使用cuda支持构建tensorflow-gpu。 Here are some approaches:
以下是一些方法:
Conclusion: The windows installation is easier than OSX or Ubuntu installation because display drivers work properly and tensorflow and must not be build on your own. 结论: Windows安装比OSX或Ubuntu安装更容易,因为显示驱动程序正常工作和张量流,不能自行构建。 Always check the software version you use.
始终检查您使用的软件版本。 The must match exactly.
必须完全匹配。
I hope this will help you! 我希望这能帮到您!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.