用cython包装c ++和CUDA代码

nya*_*sui 5 python cuda cython c++11

我想用cython包装c ++和CUDA代码.我看了npcuda-example(https://github.com/rmcgibbo/npcuda-example),我按如下方式更改setup.py.

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"])
Run Code Online (Sandbox Code Playgroud)

而且,我为我的代码运行setup.py,但是,我有一个nvcc错误,"fatal error: 'mutex' file not found" 我猜"-std = c ++ 11"选项无法通过nvcc编译器.如何包装c ++和CUDA代码包含c ++ 11代码?

nya*_*sui 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++ 代码。
谢谢你!!