这两行取自PyCuda/Examples
中的ThrustInterop.py
import codepy.toolchain
codepy.toolchain.guess_toolchain()
我知道这应该返回$HOME/.aksetup-defaults.py
中找到的C ++编译器的Toolchain实例。
BOOST_COMPILER = 'gcc'
BOOST_INC_DIR = ['/usr/local/Cellar/boost/1.57.0/include/']
BOOST_LIB_DIR = ['/usr/local/Cellar/boost/1.57.0/lib/']
BOOST_PYTHON_LIBNAME = ['boost_python']
BOOST_THREAD_LIBNAME = ['boost_thread']
CUDADRV_LIBNAME = ['cuda']
CUDADRV_LIB_DIR = ['${CUDA_ROOT}/lib']
CUDART_LIBNAME = ['cudart']
CUDART_LIB_DIR = ['${CUDA_ROOT}/lib']
CUDA_ENABLE_CURAND = True
CUDA_ENABLE_GL = True
CUDA_INC_DIR = ['${CUDA_ROOT}/include']
CUDA_TRACE = False
CURAND_LIBNAME = ['curand']
CURAND_LIB_DIR = ['${CUDA_ROOT}/lib']
USE_SHIPPED_BOOST = False
在Python 2.7.6下,我得到以下异常
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Library/Python/2.7/site-packages/codepy/toolchain.py", line 433, in guess_toolchain
raise ToolchainGuessError("unknown compiler")
codepy.toolchain.ToolchainGuessError: unknown compiler
在使用Python 3.4.1的集群上:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/cluster/home03/math/echeverl/local2/lib/python3.4/site-packages/codepy/toolchain.py", line 439, in guess_nvcc_toolchain
gcc_kwargs = _guess_toolchain_kwargs_from_python_config()
File "/cluster/home03/math/echeverl/local2/lib/python3.4/site-packages/codepy/toolchain.py", line 398, in _guess_toolchain_kwargs_from_python_config
so_ext=make_vars["SO"],
KeyError: 'SO'
查看图书馆后,发现它无法识别clang
,因此我修改了toolchain.py
中的'guess_toolchain'
def guess_toolchain():
"""Guess and return a :class:`Toolchain` instance.
Raise :exc:`ToolchainGuessError` if no toolchain could be found.
"""
kwargs = _guess_toolchain_kwargs_from_python_config()
from pytools.prefork import call_capture_output
result, version, stderr = call_capture_output([kwargs["cc"], "--version"])
if result != 0:
raise ToolchainGuessError("compiler version query failed: "+stderr)
#Original Code
# if "Free Sofware Foundation" in version:
#Modified line to recognize clang
if ("Free Software Foundation" in version) or ("clang" in version):
if "-Wstrict-prototypes" in kwargs["cflags"]:
kwargs["cflags"].remove("-Wstrict-prototypes")
if "darwin" in version:
# Are we running in 32-bit mode?
# The python interpreter may have been compiled as a Fat binary
# So we need to check explicitly how we're running
# And update the cflags accordingly
import sys
if sys.maxint == 0x7fffffff:
kwargs["cflags"].extend(['-arch', 'i386'])
return GCCToolchain(**kwargs)
else:
raise ToolchainGuessError("unknown compiler")
如何告诉codepy.toolchain
使用哪个编译器?
答案 0 :(得分:2)
将CC
环境变量设置为适当的值可能会有所帮助。还要检查存储在Python Makefile
目录中config
下的Python lib
。这就是配置信息首先来自的地方。
答案 1 :(得分:0)
我将文件~/.aksetup-defaults.py
修改为:
#For CUDA
CUDA_ROOT=['/Developer/NVIDIA/CUDA-5.0/']
CUDADRV_LIB_DIR=['/Developer/NVIDIA/CUDA-5.0/lib']
CUDA_INC_DIR=['/Developer/NVIDIA/CUDA-5.0/include']
#For Boost
BOOST_INC_DIR=['${HOME}/pool/include/']
BOOST_LIB_DIR=['${HOME}/pool/lib']
USE_SHIPPED_BOOST=False
这解决了toolchain
的问题,但我仍在试图弄清楚如何编译。