Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cuda header files

Tags:

cuda

I have a file named "KernelUtil.cu" as follows

     __device__ int add(int a, int b)
      {
         return a+b;
      }

I have my main program which is "main.cu". I need to call the "add" function from here. How can I do it?? The following doesnt work.

    #include "KernelUtil.cu"
     __global__ void test()
   {
      int c = add(10,10);
   } 
   int main()
      {
           test<<<1,1>>>();
      }

giving an error add is already defined in main.cu

like image 287
user570593 Avatar asked Mar 10 '26 01:03

user570593


1 Answers

I expect that you have a rule that automatically compiles all .cu files, meaning KernelUtil.cu is effectively compiled twice, once on its own and once when included in main.cu, and therefore add is duplicated.

Try renaming KernelUtil.cu to KernelUtil.h (or .cuh).

like image 183
Tom Avatar answered Mar 12 '26 00:03

Tom



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!