//
C code(hello.c):
typedef
struct
g_states_t 
...
{
int i;
struct g_states_t *pnext;
}
g_state;
typedef
struct
ST
...
{
g_states_t **cur;
g_states_t *ctx[4];
}
ST;
void
setstates(ST
*
ps, g_states_t states[
4
])
...
{
for (int i = 0; i < 4 ; i++)
...{
ps->ctx[i] = &states[i];
}
}

void
main(
int
argc,
char
*
argv[])
...
{
g_states_t states[4] = 
...{
...{400, &states[1]},
...{401, &states[2]},
...{402, &states[3]},
...{403, &states[0]}
};
ST s1, *ps1;
ps1 = &s1;
setstates(ps1, states);
ps1->ctx[2]->i = 123;
ps1->ctx[2]->pnext = &states[0];
ps1->ctx[3]->pnext->i = 456;
printf("%d ", ps1->ctx[2]->i);//ok,output:123
printf("%d ", ps1->ctx[2]->pnext->i);//ok,output:456
printf("%d ", ps1->ctx[3]->pnext->i);/**/////ok,output:456
printf("hello");
}


/**/
/////////////////////////////////////////////
GPU code(kernel.cu):
typedef
struct
g_states_t 
...
{
int i;
struct g_states_t *pnext;
}
g_state;
typedef
struct
ST
...
{
g_states_t **cur;
g_states_t *ctx[4];
}
ST;

__device__
void
setstates(ST
*
ps, g_states_t states[
4
])
...
{
for (int i = 0; i < 4 ; i++)
...{
ps->ctx[i] = &states[i];
}
}


__global__
void
kernel()
...
{
g_states_t states[4] = 
...{
...{400, &states[1]},
...{401, &states[2]},
...{402, &states[3]},
...{403, &states[0]}
};
ST s1, *ps1;
ps1 = &s1;
setstates(ps1, states);
ps1->ctx[2]->i = 123;//err
ps1->ctx[2]->pnext = &states[0];//err
ps1->ctx[3]->pnext->i = 456;//err
}
////////////////////////////////////
When compile the GPU code in Release mode,prompt:
1>正在执行自定义生成步骤
1>cu_host.cu
1>tmpxft_00001ae8_00000000-3.gpu
1>tmpxft_00001ae8_00000000-7.gpu
1>"E:/MYWIND~1/TEMP/tmpxft_00001ae8_00000000-8.i", line 43: Advisory: Cannot tell what pointer points to, assuming global memory space
1>"E:/MYWIND~1/TEMP/tmpxft_00001ae8_00000000-8.i", line 44: Advisory: Cannot tell what pointer points to, assuming global memory space
1>"E:/MYWIND~1/TEMP/tmpxft_00001ae8_00000000-8.i", line 45: Advisory: Cannot tell what pointer points to, assuming global memory space
1>"E:/MYWIND~1/TEMP/tmpxft_00001ae8_00000000-8.i", line 45: Advisory: Cannot tell what pointer points to, assuming global memory space
1>tmpxft_00001ae8_00000000-3.c
1>tmpxft_00001ae8_00000000-12.i
What's the reason?
Advisory: Cannot tell what pointer points to, assuming global memory space
////
Would you please explain the reason of the problem?
And how to implement the state machine in device code?
Can you tell me the restrict in operation of device memory,such as pointer:
"ps1->ctx[3]->pnext->i"
is this usage legal?
Please read my code in:
http://forums.nvidia.com/index.php?showtopic=61188
本文探讨了在C和GPU代码中实现状态机的方法,并针对GPU代码在编译时出现的警告进行了详细解析。文中提供了具体的代码示例,展示了如何定义状态结构体及状态之间的转换。

2757

被折叠的 条评论
为什么被折叠?



