开发者

cuda header files

开发者 https://www.devze.com 2023-04-01 15:46 出处:网络
I have a file named \"KernelUtil.cu\" as follo开发者_Go百科ws __device__ int add(int a, int b) { return a+b;

I have a file named "KernelUtil.cu" as follo开发者_Go百科ws

     __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


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).

0

精彩评论

暂无评论...
验证码 换一张
取 消