简体   繁体   English

用cython包装c ++和CUDA代码

[英]Wrapping c++ and CUDA code with cython

I want to wrap c++ and CUDA code with cython. 我想用cython包装c ++和CUDA代码。 I looked npcuda-example ( https://github.com/rmcgibbo/npcuda-example ) and I change setup.py as follows. 我看了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"])

And, I run setup.py for my code, but, I have a nvcc error "fatal error: 'mutex' file not found" I guess "-std=c++11" option can not pass nvcc compiler. 并且,我为我的代码运行setup.py,但是,我有一个nvcc错误"fatal error: 'mutex' file not found"我猜“-std = c ++ 11”选项无法通过nvcc编译器。 How can I wrap c++ and CUDA code include c++11 code? 如何包装c ++和CUDA代码包含c ++ 11代码?

Thank you for answering. 谢谢你的回答。 I solved this problem. 我解决了这个问题。 Command "distutils.util.get_platform()" return mac os x 10.5 on my Mac. 命令“distutils.util.get_platform()”在我的Mac上返回mac os x 10.5。 So I change python anaconda to system default python, I can compile c++11 code. 所以我将python anaconda更改为系统默认python,我可以编译c ++ 11代码。 But I can not compile my all code. 但我无法编译我的所有代码。
In accordance with Saullo Castro's answer, first I build my code to library using CUDA_ADD_LIBRARY of CMake CUDA Package. 根据Saullo Castro的回答,首先我使用CMake CUDA Package的CUDA_ADD_LIBRARY将我的代码构建到库中。 And I compile only wrapper.pyx with this library. 我只使用这个库编译wrapper.pyx。 Then I can wrap my c++ code with cython. 然后我可以用cython包装我的c ++代码。
Thank you!! 谢谢!!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM