2015-07-10 117 views
1

我在代碼中隔離了一個錯誤,我無法理解我做錯了什麼。當我執行下面的代碼時,CUDA內核不會爲所有塊執行。cuda內核不能執行所有blockIdx

#include <stdio.h> 

__global__ 
void dummy_test_kernel() 
{ 
    printf("grid = (%i, %i, %i), block = (%i, %i, %i), 
    bid (%i,%i,%i), tid (%i, %i, %i)\n", 
    gridDim.x, gridDim.y, gridDim.z, 
    blockDim.x, blockDim.y, blockDim.z, 
    blockIdx.x, blockIdx.y, blockIdx.z, 
    threadIdx.x, threadIdx.y, threadIdx.z); 
} 

int main(int argc, char* argv[]) 
{ 
    (void)argc; 
    (void)argv; 
    dummy_test_kernel<<<62,256>>>(); 
    if(cudaDeviceSynchronize()) 
    printf("something went wrong in the kernel execution\n"); 
    return 0; 
} 

例如,我從來沒有看到有任何打印塊的blockIdx.x塊。在情況下,可能會幫助找出我的錯誤,這裏是CUDA樣品中發現由DEVICEQUERY返回的信息:

Device 0: "GeForce GTX 675M" 
    CUDA Driver Version/Runtime Version   7.5/7.0 
    CUDA Capability Major/Minor version number: 2.1 
    Total amount of global memory:     2048 MBytes (2147155968 bytes) 
    (8) Multiprocessors, (48) CUDA Cores/MP:  384 CUDA Cores 
    GPU Max Clock rate:       1240 MHz (1.24 GHz) 
    Memory Clock rate:        1500 Mhz 
    Memory Bus Width:        256-bit 
    L2 Cache Size:         524288 bytes 
    Maximum Texture Dimension Size (x,y,z)   1D=(65536), 2D=(65536, 65535), 3D=(2048, 2048, 2048) 
    Maximum Layered 1D Texture Size, (num) layers 1D=(16384), 2048 layers 
    Maximum Layered 2D Texture Size, (num) layers 2D=(16384, 16384), 2048 layers 
    Total amount of constant memory:    65536 bytes 
    Total amount of shared memory per block:  49152 bytes 
    Total number of registers available per block: 32768 
    Warp size:          32 
    Maximum number of threads per multiprocessor: 1536 
    Maximum number of threads per block:   1024 
    Max dimension size of a thread block (x,y,z): (1024, 1024, 64) 
    Max dimension size of a grid size (x,y,z): (65535, 65535, 65535) 
    Maximum memory pitch:       2147483647 bytes 
    Texture alignment:        512 bytes 
    Concurrent copy and kernel execution:   Yes with 1 copy engine(s) 
    Run time limit on kernels:      No 
    Integrated GPU sharing Host Memory:   No 
    Support host page-locked memory mapping:  Yes 
    Alignment requirement for Surfaces:   Yes 
    Device has ECC support:      Disabled 
    Device supports Unified Addressing (UVA):  Yes 
    Device PCI Domain ID/Bus ID/location ID: 0/1/0 
    Compute Mode: 
    < Default (multiple host threads can use ::cudaSetDevice() with device simultaneously) > 

誰能幫我解決這個問題?

+0

你可能只是溢出了內核printf緩衝區。運行時爲緩衝區分配一個固定的空間量。你的內核可能產生太多的輸出 – talonmies

+0

是的,那是一個溢出。通過在'printf'之前添加一個測試'if(blockIdx.x <20)',我可以看到具有較小x ids的塊。 –

回答

-1
  1. 嘗試打印由cudaDeviceSynchronize給出
  2. 嘗試CUDA-MEMCHECK ./program來執行你的代碼中的錯誤
  3. 如果2點)返回一個錯誤使用CUDA-GDB到調試它。
  4. 您正在啓動每個包含256個線程的62個線程塊的1D內核。我期望你的輸出是網格(62,1,1)塊(256,1,1)bid(b_x,1,1)tid(t_x,1,1)