2016-03-27 4 views
3

Ich möchte C++ und CUDA-Code mit Cython umhüllen. Ich schaute npcuda-Beispiel (https://github.com/rmcgibbo/npcuda-example) und ich ändere setup.py wie folgt.Wrapping C++ und CUDA-Code mit Cython

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"]) 

Und ich setup.py für meinen Code ausführen, aber, ich habe einen Fehler nvcc "fatal error: 'mutex' file not found" I "-std = C++ 11" Option erraten kann nicht nvcc Compiler übergeben. Wie kann ich C++ - und CUDA-Code einbinden include C++ 11-Code?

+0

Nur aus Neugier: Warum willst du das? Wofür benötigen Sie Cython, wenn Sie Ihren leistungsfähigen Code bereits in C++ und CUDA haben? – Chiel

+0

Ja, ich habe C++ und CUDA-Code. Ich möchte Python-Schnittstelle meines Codes machen. – nyatsui

+0

Ich löse dieses Problem. Ich benutze Mac OS X und Anaconda mit Pyenv. distutils.util.get_platform() return mac os x 10.5. Dann ändere ich Python Anakonda zum Systemstandard Python, ich kann meinen Code kompilieren. – nyatsui

Antwort

2

Vielen Dank für Ihre Antwort. Ich löste dieses Problem. Befehl "distutils.util.get_platform()" gibt Mac OS X 10.5 auf meinem Mac zurück. Also ändere ich Python Anaconda zu Systemstandard Python, ich kann C++ 11 Code kompilieren. Aber ich kann meinen gesamten Code nicht kompilieren.
Gemäß der Antwort von Saúllo Castro baue ich zuerst meinen Code in die Bibliothek mit CUDA_ADD_LIBRARY des CMake CUDA Pakets. Und ich kompiliere nur wrapper.pyx mit dieser Bibliothek. Dann kann ich meinen C++ Code mit Cython umhüllen.
Danke !!