Can python distutils compile CUDA code?

前端 未结 2 1973
梦如初夏
梦如初夏 2021-02-06 00:36

I have CUDA code which I want to build a dynamic library to Python using distutils. But it seems distutils doesn\'t recognize \".cu\" file even if the \"nvcc\" compiler is insta

2条回答
  •  北恋
    北恋 (楼主)
    2021-02-06 01:18

    As an alternative to distutils/setuptools, you could use scikit-build (along with CMakeLists.txt, pyproject.toml, and setup.cfg/setup.py):

    from pathlib import Path
    from skbuild import setup
    from setuptools import find_packages
    
    # https://github.com/scikit-build/scikit-build/issues/521#issuecomment-753035688
    for i in (Path(__file__).resolve().parent / "_skbuild").rglob("CMakeCache.txt"):
        i.write_text(re.sub("^//.*$\n^[^#].*pip-build-env.*$", "", i.read_text(), flags=re.M))
    
    setup(cmake_args=[f"-DPython3_ROOT_DIR={sys.prefix}"],
          packages=find_packages(exclude=["tests"]))
    

提交回复
热议问题