Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wrapping c++ and CUDA code with cython

I want to wrap c++ and CUDA code with cython. I looked npcuda-example (https://github.com/rmcgibbo/npcuda-example) and I change setup.py as follows.

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. How can I wrap c++ and CUDA code include c++11 code?

like image 213
nyatsui Avatar asked Oct 30 '22 06:10

nyatsui


1 Answers

Thank you for answering. I solved this problem. Command "distutils.util.get_platform()" return mac os x 10.5 on my Mac. So I change python anaconda to system default python, I can compile c++11 code. 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. And I compile only wrapper.pyx with this library. Then I can wrap my c++ code with cython.
Thank you!!

like image 63
nyatsui Avatar answered Nov 08 '22 15:11

nyatsui