2016-03-27 64 views
3

我想用cython包装C++和CUDA代码。 我看了npcuda-example(https://github.com/rmcgibbo/npcuda-example),我改变了setup.py,如下所示。用cython包装C++和CUDA代码

ext = Extension('MyWrap', 
      sources=['src/my_code.cu', 'python/my_wrap.pyx'], 
      library_dirs=[CUDA['lib']], 
      libraries=['cudart'], 
      language='c++', 
      runtime_library_dirs=[CUDA['lib']], 
      # this syntax is specific to this build system 
      # we're only going to use certain compiler args with nvcc and not with gcc 
      # the implementation of this trick is in customize_compiler() below 
      extra_compile_args={'clang++': ['-std=c++11','-O3'], 
           'nvcc': ['-std=c++11','-gencode','arch=compute_30,code=sm_30']}, 
      include_dirs = [numpy_include, CUDA['include'], 'src'], 
      extra_link_args=["-std=c++11"]) 

而且,我跑setup.py我的代码, 但是,我有一个NVCC错误"fatal error: 'mutex' file not found" 我猜 “-std = C++ 11” 选项不能通过编译器NVCC。 如何包装C++和CUDA代码包含C++ 11代码?

+0

出于好奇:你为什么要这么做?如果您已经在C++和CUDA中使用了高性能代码,那么您需要什么样的Cython? – Chiel

+0

是的,我有C++和CUDA代码。 我想让我的代码的python界面。 – nyatsui

+0

我解决了这个问题。我用pyenv使用mac os x和anaconda。 distutils.util.get_platform()返回mac os x 10.5。然后我将python anaconda更改为系统默认的python,我可以编译我的代码。 – nyatsui

回答

2

谢谢你的回答。 我解决了这个问题。命令“distutils.util.get_platform()”在我的Mac上返回mac os x 10.5。所以我将python anaconda更改为系统默认的python,我可以编译C++ 11代码。但我无法编译我的所有代码。
根据Saullo Castro的回答,首先我使用CMake CUDA包的CUDA_ADD_LIBRARY构建我的代码库。我只用这个库编译wrapper.pyx。然后我可以用cython包装我的C++代码。
谢谢!