Search code examples
pythoncudapycuda

how to create a cuda shared library used in python


I have created a C shared library which is used in python it works perfectly when i test it. I compile like this:

 gcc -shared -std=c99 -I/usr/include/python2.6 -fPIC -lpython2.6 -opymod.so pymod.c

I have a cuda source code "pymod.cu" which is the same as "pymod.c" and i really don't know how to compile it with nvcc.

Thank you in advance.


Solution

  • You need to first compile using nvcc, then build the shared library using gcc:

    nvcc -c test.cu -o test.o -Xcompiler -fPIC 
    gcc -shared -fPIC -o libtest.so test.o