How to create cuda libxxx.so library?

Hi,I hava three file:sum.h sum.cu main.cu
I want to complile sum.cu into libsum.so library,call it in main function
//
/sum.cu/
/
/
device int sum(int a,int b)
{
return a + b;
}

//
/sum.h/
/
/
extern “C”{
extern device int sum(int,int);
}
//
/main.cu/
/
/
#include <stdio.h>
#include “sum.h”
global void kernel(int a,int b,int *result)
{
*result = sum(a,b);
}
int main()
{
int *d_result,h_result;

    cudaMalloc((void **)&d_result,sizeof(int));

    kernel<<<1,1>>>(3,4,d_result);

    cudaMemcpy(&h_result,d_result,sizeof(int),cudaMemcpyDeviceToHost);

    printf("h_result = %d\n",h_result);

}

1、nvcc -compile sum.cu(generate sum.o)
2、nvcc -shared -o libmysum.so sum.o (genertate libmysum.so)
3、when I do This :nvcc -o main main.cu
the error is:./main.cu(6): Error: External calls are not supported (found non-inlined call to sum)

Can anybody help me ?does anyone known how to create .SO dynamically link file?

Since there is currently no linker support for device functions, it is not possible to create a library of device functions. A workaround is to place the device functions in header files, which is how the CUDA math “library” is set up. Libraries of host functions that call kernels on the device are possible however, as demonstrated by CUBLAS and CUFFT.

Hi,

I created a library for my project but in addition to the functions device it calls the kernels and hosts functions but I think it’s a trace.

nvcc --use_fast_math -shared -Xlinker '-rpath /usr/local/cuda/lib64/' -L/usr/local/cuda/lib64/ -lcuda -o libXXX.so XXX.cu -Xcompiler '-fPIC' -arch sm_23

And linked library width other C++ library :

g++ -L/CUDA_LIBRARY_PATH/ -lXXX -Wl,-rpath,/CUDA_LIBRARY_PATH -shared -o libYYY.so -fPIC -I/CUDA_LIBRARY_PATH/ YYY.cpp

(Sorry for english I’m french …)

Thanks,It’s helpful for me!