Multiple definitions of kernel issue Using separate files for kernel and host code, having issue hav

Hello,

I am trying to create separate files for my kernel code and host code for the first time, and I am encountering some issues getting the files to “recognize” each other. I’ve looked at the Programming Guide, as well as the examples that ship with the SDK, and they all seem to use the same style I am using (except their work, of course!). Additionally, I didn’t find any other topics on the Forum about this, so I decided to post this.

The error message I am getting is:

nvcc -arch sm_11 myCode.cu myCode_kernel.cu -o myCode

/tmp/tmpxft_00006038_00000000-24_myCode_kernel.o: In function `temp__entry(float, float)':

tmpxft_00006038_00000000-23_myCode_kernel.ii:(.text+0x21a): multiple definition of `temp__entry(float, float)’

/tmp/tmpxft_00006038_00000000-15_myCode.o:tmpxft_00006038_00000000-14_myCode.ii:(.text+0x470): first defined here

/tmp/tmpxft_00006038_00000000-24_myCode_kernel.o: In function `__device_stub__Z4tempff’:

tmpxft_00006038_00000000-23_myCode_kernel.ii:(.text+0x19a): multiple definition of `__device_stub__Z4tempff’

/tmp/tmpxft_00006038_00000000-15_myCode.o:tmpxft_00006038_00000000-14_myCode.ii:(.text+0x3f0): first defined here

collect2: ld returned 1 exit status

make: *** [myCode] Error 255

Here’s how I’m including my kernel code:

[codebox]#include <myCode_kernel.cu>[/codebox]

All that I have in that file is:

[codebox]#ifndef MYCODE_KERNEL_H

#define MYCODE_KERNEL_H

global void temp(float x, float y)

{

// purposely blank, I’ve had some simple things in here as well like int i = 0; ++i; (and the same thing happened)

}

#endif // #ifndef MYCODE_KERNEL_H[/codebox]

Here’s how I call the kernel:

[codebox]temp<<<1, 1>>>(1, 2);[/codebox]

My guess is that I’m somehow including the files incorrectly (or something like that), but I’ve tried both "#include <myCode_kernel.cu> and "#include “myCode_kernel.cu>” " and neither seems to resolve this issue.

Additional Information:

  • Even if I don’t call the kernel in my host code (or reference it at all), this same issue occurs.

  • I tried looking for the temp files in the error message, but they don’t seem to be in the tmp folder…

  • I am using CUDA 2.2.

  • I am compiling with sm_11 (if you didn’t see that above).

Any help would be greatly appreciated!

Thanks,

Matt

Sorry for the non-grammatically correct info sentence in the topic header, I must have mistakenly typed it twice!

Matt

Hi everyone,

Apparently I was wrong, people have encountered this problem before :)

There are 2 other forum posts that deal with this issue:

The issues appears to be in the fact that people (including me) follow the template provided in the SDK examples, but this template doesn’t work for our code (since we’re not located in the same directories? Not exactly sure why.)

The solution is to create a (separate) header file for the kernel (say myCode_kernel.h), then predeclare your functions in that header file, then import that header file into your CPU code file (myCode.c in this example).

By the way, this is a linking issue, not a compiling issue as I stated before.

,
Matt