0

I'm a newbie using cuda. My version cuda is 10.02. I have a problem when I call hello world program. This is the file hello.cu:

#include <cstdlib>
#include <cstdio>
#include <cuda.h>

using namespace std;

__global__ void mykernel(void) {
printf("GPU Hello World!\n");
}

int main(void) {
printf("CPU Hello World! \n");
mykernel<<<1,1>>>();
return 0;
}

But only receive the output:

CPU Hello World! 

I am quite rookie on this, so, what can be happening? should I do something to call the kernel function?

talonmies
  • 70,661
  • 34
  • 192
  • 269
nghia le
  • 1
  • 1
  • 2
    Add `cudaDeviceSyncronize()` and you will get the second print too. Btw it would be a better hello world program if you would do proper [error checking](https://stackoverflow.com/q/14038589/7968757). And the title is misleading. You don't have compilation but runtime issues and also no error but an unexpected result. – BlameTheBits Jul 13 '20 at 06:36
  • Thanks for your support. But when I add cudaDeviceSyncronize() I receive an error:error: identifier "cudaDeviceSyncronize" is undefined 1 error detected in the compilation of "/tmp/tmpxft_00003051_00000000-8_hello.cpp1.ii". – nghia le Jul 13 '20 at 06:45
  • Ohhh!!! I understand the problem. this is cudaDeviceSynchronize(); but you write: cudaDeviceSyncronize(). Thank you for your support!!! many thanks! – nghia le Jul 13 '20 at 06:55
  • Yeah, just was about to write that. Sorry for the misspelling. – BlameTheBits Jul 13 '20 at 06:57
  • Question to the community: Does [this answer](https://stackoverflow.com/a/12591765/7968757) answer the question here and should this be flagged as a duplicate? I think the real answer is only in the comment below the linked answer. I generally think that this is a somewhat common problem which may needs its own answer. – BlameTheBits Jul 13 '20 at 07:08
  • Yes I think the same thing. – nghia le Jul 13 '20 at 07:26

0 Answers0