![](/img/trans.png)
[英]Wrapping C++ code with function pointer as template parameter in cython
[英]Wrapping c++ and CUDA code with cython
我想用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"])
並且,我為我的代碼運行setup.py,但是,我有一個nvcc錯誤"fatal error: 'mutex' file not found"
我猜“-std = c ++ 11”選項無法通過nvcc編譯器。 如何包裝c ++和CUDA代碼包含c ++ 11代碼?
謝謝你的回答。 我解決了這個問題。 命令“distutils.util.get_platform()”在我的Mac上返回mac os x 10.5。 所以我將python anaconda更改為系統默認python,我可以編譯c ++ 11代碼。 但我無法編譯我的所有代碼。
根據Saullo Castro的回答,首先我使用CMake CUDA Package的CUDA_ADD_LIBRARY將我的代碼構建到庫中。 我只使用這個庫編譯wrapper.pyx。 然后我可以用cython包裝我的c ++代碼。
謝謝!!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.