1

I have compiled my cuda script via the following command into a shared library :

nvcc --ptxas-options=-v --compiler-options '-fPIC' -o test_function.so mologram.cu 

Then, in Python:

import ctypes
from numpy.ctypeslib import ndpointer

lib = ctypes.cdll.LoadLibrary('./test_function.so')

Throws the following error message:

OSError                                   Traceback (most recent call last)
<ipython-input-12-02ce09d7f391> in <module>()
      2 from numpy.ctypeslib import ndpointer
      3 
----> 4 lib = ctypes.cdll.LoadLibrary('./test_function.so')


/usr/lib/python2.7/ctypes/__init__.pyc in LoadLibrary(self, name)
    438 
    439     def LoadLibrary(self, name):
--> 440         return self._dlltype(name)
    441 
    442 cdll = LibraryLoader(CDLL)

/usr/lib/python2.7/ctypes/__init__.pyc in __init__(self, name, mode, handle, use_errno, use_last_error)
    360 
    361         if handle is None:
--> 362             self._handle = _dlopen(self._name, mode)
    363         else:
    364             self._handle = handle

OSError: ./test_function.so: cannot dynamically load executable

I have done similar scripts in the past and never encounter this error. I am baffled as to why this error message appears.

Any input appreciated

1
  • You can't load the shared library because it isn't a shared library... Commented Mar 24, 2017 at 15:06

1 Answer 1

2

I have compiled my cuda script via the following command into a shared library

nvcc --ptxas-options=-v --compiler-options '-fPIC' -o test_function.so mologram.cu

But you haven't. That only compiles mologram.cu to an object file. If you consult the documentation, you will see that shared library compilation and linkage requires the --shared option. So

nvcc --ptxas-options=-v --compiler-options '-fPIC' --shared -o test_function.so mologram.cu

is probably what you want to do.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.