I am trying the following simple CUDA C code but getting garbage value printed:
#include <stdio.h>
__global__ void hellocuda(int* tidx){
*tidx = 100;
}
int main(){
int* d_tidx;
int* c;
cudaMalloc((void**) &d_tidx, 1);
c = (int*)malloc(sizeof(int));
hellocuda<<<1,1>>>(d_tidx);
cudaMemcpy(c, d_tidx, sizeof(int), cudaMemcpyDeviceToHost);
printf("%d\n", *c);
return EXIT_SUCCESS;
}
The output I am getting on this is: -273093020
Could someone help debugging this code. Thanks.