Advisory: Cannot tell what pointer points to, assuming global memory space

本文探讨了在C和GPU代码中实现状态机的方法,并针对GPU代码在编译时出现的警告进行了详细解析。文中提供了具体的代码示例,展示了如何定义状态结构体及状态之间的转换。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

// 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]->= 123;
    ps1
->ctx[2]->pnext = &states[0];
    ps1
->ctx[3]->pnext->= 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]->= 123;//err    
    ps1->ctx[2]->pnext = &states[0];//err
    ps1->ctx[3]->pnext->= 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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值