How to separate CUDA code into multiple files

后端 未结 4 971
南笙
南笙 2020-12-13 07:25

I am trying separate a CUDA program into two separate .cu files in effort to edge closer to writing a real app in C++. I have a simple little program that:

Allocate

4条回答
  •  难免孤独
    2020-12-13 08:14

    You are including mykernel.cu in kernelsupport.cu, when you try to link the compiler sees mykernel.cu twice. You'll have to create a header defining TestDevice and include that instead.

    re comment:

    Something like this should work

    // MyKernel.h
    #ifndef mykernel_h
    #define mykernel_h
    __global__ void TestDevice(int* devicearray);
    #endif
    

    and then change the including file to

    //KernelSupport.cu
    #ifndef _KERNEL_SUPPORT_
    #define _KERNEL_SUPPORT_
    
    #include 
    #include 
    // ...
    

    re your edit

    As long as the header you use in c++ code doesn't have any cuda specific stuff (__kernel__,__global__, etc) you should be fine linking c++ and cuda code.

提交回复
热议问题