2014-01-23 137 views
1

鑑於此CUDA代碼,我試圖執行位移操作,並且這些值的返回值爲零。這不應該發生。有誰知道如何解決這個問題?我是否缺少CUDA頭文件?CUDA中的移位運算符

代碼

 __device__ unsigned int FI(unsigned int in_data, unsigned int subkey, 
    unsigned int *KLi1, unsigned int *KLi2, unsigned int *KOi1, unsigned int *KOi2, 
    unsigned int *KOi3, unsigned int *KIi1, unsigned int *KIi2, unsigned int *KIi3) { 

     unsigned int nine, seven; 

     unsigned int S7[128] = {}; 

     unsigned int S9[512] = {}; 

     nine = (in_data>>7); 
     seven = (in_data&0x7F); 

     /* Now run the various operations */ 
     nine = (unsigned int)(S9[nine]^seven); 
     seven = (unsigned int)(S7[seven]^(nine & 0x7F)); 
     seven ^= (subkey>>9); 
     nine ^= (subkey&0x1FF); 
     nine = (unsigned int)(S9[nine]^seven); 
     seven = (unsigned int)(S7[seven]^(nine & 0x7F)); 
     in_data = (unsigned int)((seven<<9) + nine); 
     return(in_data); 
     } 

斷點分析

這裏是轉移一個unsigned int 7位到右側的代碼片段的例子。當我在指令中使用cuda-gdb命令和斷點時,我發現移位後的值在它不應該爲零時保持爲零。當我通常在cuda-gdb命令提示符中執行相同的操作時,我得到一個非零值。任何建議或提示?

根據in_data的值,變量9和7應該是非空的。

nine = (in_data>>7); 
    seven = (in_data&0x7F); 

    [Switching focus to CUDA kernel 0, grid 1, block (0,0,0), thread (1,0,0), device 0, sm 0, warp 0, lane 1] 
    Breakpoint 1, FI (KLi1=0x3fffae0, KLi2=0x3fffb00, KOi1=0x3fffb20, KOi2=0x3fffb40, KOi3=0x3fffb60, 
    KIi1=0x3fffb80, KIi2=0x3fffba0, KIi3=0x3fffbc0, in_data=461, subkey=0) at kasumiOp.cu:61 
    61 nine = (in_data>>7); 
    (cuda-gdb) p in_data 
    $1 = 461 
    (cuda-gdb) step 
    62 seven = (in_data&0x7F); 
    (cuda-gdb) p nine 
    $2 = 0 
    (cuda-gdb) step 
    65 nine = (unsigned int)(S9[nine]^seven); 
    (cuda-gdb) p seven 
    $3 = 0 
    (cuda-gdb) p 461 >> 7 
    $4 = 3 
    (cuda-gdb) cuda thread 
    thread (1,0,0) 
    (cuda-gdb) p 561 & 0x7f 
    $5 = 49 
    (cuda-gdb) p 461 & 0x7f 
    $6 = 77 

因此,in_data是一個值。我會嘗試一個微不足道的例子,看看我是否可以重現相同。

+3

CUDA中的移位運算符應該與C的工作方式相同。您可以發佈重現問題的最小大小示例而不是調試會話嗎?你確定'in_data'實際上包含你期望的值嗎? – JackOLantern

+1

你在調試調試版嗎? –

+0

這不是一個可編譯和可執行的完整代碼。只有'__device__'函數,我們不知道'in_data'是如何設置的。 – JackOLantern

回答

1

由於提供的信息有限(無碼)我可能會猜測:

CUDA-GDB documentation狀態:

The GDB print command has been extended to decipher the location of any program variable and can be used to display the contents of any CUDA program variable including: 
* data allocated via cudaMalloc() 
* data that resides in various GPU memory regions, such as shared, local, and global memory 
* special CUDA runtime variables, such as threadIdx 

如果IN_DATA是指一個特定的存儲區,那麼它可能是你'處理內存指針而不是實際數據。

雖然我只有兩分錢。