我正在尝试按照installation instructions在运行OS X 10.12的NVIDIA GeForce显卡的MacBook Pro上安装Torch(带有CUDA支持)。
我正在使用CUDA 8.0。虽然CUDA system requirements不支持OS X 10.12和Apple LLVM 8,但CUDA download page有一个用于下载OS X 10.12和Apple LLVM 8兼容CUDA的链接。
torch安装脚本的默认设置指定了clang编译器,并找到
-- The C compiler identification is AppleClang 8.0.0.8000042
-- The CXX compiler identification is AppleClang 8.0.0.8000042
它会毫无问题地运行多个安装任务,但会反复尝试并无法找到OpenMP
-- Try OpenMP C flag = [-fopenmp=libomp]
-- Performing Test OpenMP_FLAG_DETECTED
-- Performing Test OpenMP_FLAG_DETECTED - Failed
-- Try OpenMP C flag = [ ]
-- Performing Test OpenMP_FLAG_DETECTED
-- Performing Test OpenMP_FLAG_DETECTED - Failed
-- Try OpenMP C flag = [-fopenmp]
... (attempt with many other flags) ...
-- Could NOT find OpenMP (missing: OpenMP_C_FLAGS OpenMP_CXX_FLAGS)
来自OpenMP网站的引言表明OpenMP与clang一起发布(更多内容见下文)。我找不到任何关于OpenMP是否也包含在Apple LLVM中的权威来源。 Several answers表明它不是,而且这两者是不相容的。所以我决定安全地玩,并尝试用llvm-clang编译。
随着Clang 3.8.0的发布,启用了OpenMP 3.1支持 默认情况下为Clang,因此OpenMP运行时构建为 Clang构建的正常部分,并与二进制一起分发 分布。
我使用自制软件安装llvm并更改了火炬安装脚本中的以下行
# If we're on OS X, use clang
if [[ `uname` == "Darwin" ]]; then
# make sure that we build with Clang. CUDA's compiler nvcc
# does not play nice with any recent GCC version.
export CC=/usr/local/opt/llvm/bin/clang
export CXX=/usr/local/opt/llvm/bin/clang++
fi
找到了正确的编译器
-- The C compiler identification is Clang 3.9.1
-- The CXX compiler identification is Clang 3.9.1
但我仍然收到错误
-- Could NOT find OpenMP (missing: OpenMP_C_FLAGS OpenMP_CXX_FLAGS)
建议我没有正确配置编译器,或者我对OpenMP网站的读取不正确。
此外,我认为由于支持Apple LLVM,因此也支持其他LLVM发行版。但是,脚本会抛出另一个错误
nvcc fatal : The version ('30901') of the host compiler ('clang') is not supported
这表明无论OpenMP支持如何,我都无法使用此编译器。
最后,我尝试使用gcc编译器,尽管火炬安装脚本中有警告,但它不在CUDA支持的编译器列表中。
# If we're on OS X, use clang
if [[ `uname` == "Darwin" ]]; then
# make sure that we build with Clang. CUDA's compiler nvcc
# does not play nice with any recent GCC version.
export CC=/usr/local/opt/gcc/bin/gcc-6
export CXX=/usr/local/opt/gcc/bin/g++-6
fi
正确发现了编译器
-- The C compiler identification is GNU 6.2.0
-- The CXX compiler identification is GNU 6.2.0
还正确找到了OpenMP库
-- Try OpenMP C flag = [-fopenmp]
-- Performing Test OpenMP_FLAG_DETECTED
-- Performing Test OpenMP_FLAG_DETECTED - Success
-- Try OpenMP CXX flag = [-fopenmp]
-- Performing Test OpenMP_FLAG_DETECTED
-- Performing Test OpenMP_FLAG_DETECTED - Success
-- Found OpenMP: -fopenmp
-- Compiling with OpenMP support
这表明如果使用编译器正确配置了torch安装脚本,它就能够检测到OpenMP。
但正如评论所暗示的那样,CUDA会抛出错误
nvcc fatal : GNU C/C++ compiler is no longer supported as a host compiler on Mac OS X.
所以我不能简单地通过使用gcc编译器来解决我的问题。
我可以用什么编译器来安装支持OpenMP和nvcc的Torch?
如果答案是我已经尝试过的编译器之一,我该如何修改安装脚本或编译器配置才能使其正常工作?