RafaelJVicente / setuptools-cuda-cpp

MIT License
3 stars 1 forks source link

ImportError: [libraryname].so: undefined symbol: [function name] #1

Open szuboy opened 1 year ago

szuboy commented 1 year ago

I'm extending my Python program with a Cuda module that uses the setuptools-cuda-cpp.

The setup.py file compiles fine, but when I try running it from Python, I get this error:

ImportError: /home/medai02/anaconda3/lib/python3.6/site-packages/my_cuda_package-0.0.1-py3.6-linux-x86_64.egg/my_cuda_package/cuda_ext.cpython-36m-x86_64-linux-gnu.so: undefined symbol: calculate_launcher

The etup.py is modified based on the given example:

import numpy
from distutils import sysconfig
from setuptools import setup
from setuptools_cpp_cuda import CUDAExtension, BuildExtension, fix_dll

cuda_ext_path = Path('src/my_cuda_package/cuda_ext')
cuda_ext = CUDAExtension(
    name='my_cuda_package.cuda_ext',
    include_dirs=[cuda_ext_path, sysconfig.get_python_inc(), numpy.get_include()],
    sources=[
        cuda_ext_path / 'cmatrices_wrapper.c',
        cuda_ext_path / 'cmatrices_kernel.cu'
    ],
    libraries=fix_dll(['cudart']),
    extra_compile_args={'cxx': ['-g'],
                        'nvcc': ['-O2', '-arch=sm_60']},
)

setup(
    name='my-cuda-package',
    version='0.0.1',
    install_requires=['numpy', ],
    extras_require={'cython': ['cython'], },
    ext_modules=[cuda_ext],
    cmdclass={'build_ext': BuildExtension},
)

This is the tree of my project:

│  setup.py
│
└─src
    └─my_cuda_package
        │  __init__.py
        │
        └─cuda_ext
            │  cmatrices_kernel.cu
            │  cmatrices_wrapper.c
            │  cmatrices_kernel.h
RafaelJVicente commented 1 year ago

Seems like you are importing something from the cmatrices_kernel.h in the cmatrices_wrapper.c called "calculate_launcher " that hasn't been linked properly. I haven't test it with .c files, but it should work. Can you also share me the wrapper and the .h?