char *** symbol;
int *** tree;
// Allocate memory to tree and symbol;
dp<<<1,3>>>(tree,symbol,threshold);
GPU CODE
global void dp(int ***tree, char **symbol1,int threshold)
{
int ind_tree=blockDim.xblockIdx.x+threadIdx.x;
for(int i=0;i<3;i++)
{
for(int j=0;j<pow(4.0,i);j++)
…
…
// value of symbol1 updated in order to update symbol on CPU
…
…
}
The code works fine when I run in EmuDebug mode however when ran otherwise the code messes up somewhere in the kernel.
The values that I get back in ***symbol are same as that before the kernel call. The values of tree however are correctly reflected after the kernel call is over.
Yes I am passing a pointer to host memory. The data structure is arranged as a tree. The dp is a call to do a dominant pass over one tree. I am attaching the .cu file if that can help. The troublesome kernel call is in line 207 and the kernel code starts from line 124. The weird thing is that a very similar data structure in the code (int *** tree) is getting correctly updated.
My problem is quite simple as I now see it. Can someone please explain as to why pointer p is not getting updated in debug mode? *p is getting updated in emudebug mode but is not happening in debug mode. Thank you.
#include <stdio.h>
#include <stdlib.h>
#include <cuda_runtime.h>
#include <conio.h>
char *p;
__global__ void updatep(char *p1)
{
*p1='e';
}
int main(int argc, char** argv)
{
p=(char *)malloc(sizeof(char));
*p='a';
printf("%c",*p);
// Here you need to allocate global memory on gpu, copy p to that allocated memory.
updatep<<<1,1>>>(p);
// Here you need to copy global memory from gpu back to the host.
printf("\n%c",*p);
getch();
return 0;
}
I want to thank you for your patience for helping me solve my mistakes. I had to modify my code to make everything work in one dimension. I am happy that now the code is running fine. Thanks for your time.