Cuda未能在街区上跑,但在网格上没问题

时间:2016-10-14 09:12:35

标签: cuda

以下是来自cs344的cuda代码的一部分: 将rgb中的图片转换为灰色是一项任务。 代码现在运行正常。 但是当我在评论中使用代码时。它失败了。

__global__
void rgba_to_greyscale(const uchar4* const rgbaImage,
                       unsigned char* const greyImage,
                       int numRows, int numCols)
{
  //int x = threadIdx.x ;
  //int y = threadIdx.y ;      
  int x = blockIdx.x ;
  int y = blockIdx.y ;

  if (x<numCols && y<numRows)
  {
    uchar4 rgba = rgbaImage[y*numCols+x] ;
    float channelSum = .299f * rgba.x + .587f * rgba.y + .114f * rgba.z;
    greyImage[y*numCols+x] = channelSum;
  }
}    


void your_rgba_to_greyscale(const uchar4 * const h_rgbaImage, 
                            uchar4 * const d_rgbaImage, unsigned char* const d_greyImage, 
                            size_t numRows, size_t numCols)
{
  // const dim3 blockSize(numCols,numRows , 1);  //TODO
  // const dim3 gridSize( 1, 1, 1);  //TODO
  const dim3 blockSize(1,1 , 1);  //TODO
  const dim3 gridSize( numCols,numRows , 1);  //TODO
  std::cout << numCols << " " << numRows << std::endl ; // numCols=557 numRows=313
  rgba_to_greyscale<<<gridSize, blockSize>>>(d_rgbaImage, d_greyImage, numRows, numCols);
  cudaDeviceSynchronize(); 
  checkCudaErrors(cudaGetLastError());
}

当我使用带注释的代码时,代码无法运行,错误:

CUDA error at: /home/yc/cuda_prj/cs344_bak/Problem Sets/Problem Set 1/student_func.cu:90
invalid configuration argument cudaGetLastError()

这是我的deviceQuery报告:

Detected 1 CUDA Capable device(s)

Device 0: "GeForce GTX 1080"
  CUDA Driver Version / Runtime Version          8.0 / 8.0
  CUDA Capability Major/Minor version number:    6.1
  Total amount of global memory:                 8110 MBytes (8504279040 bytes)
  (20) Multiprocessors, (128) CUDA Cores/MP:     2560 CUDA Cores
  GPU Max Clock rate:                            1823 MHz (1.82 GHz)
  Memory Clock rate:                             5005 Mhz
  Memory Bus Width:                              256-bit
  L2 Cache Size:                                 2097152 bytes
  Maximum Texture Dimension Size (x,y,z)         1D=(131072), 2D=(131072, 65536), 3D=(16384, 16384, 16384)
  Maximum Layered 1D Texture Size, (num) layers  1D=(32768), 2048 layers
  Maximum Layered 2D Texture Size, (num) layers  2D=(32768, 32768), 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: 65536
  Warp size:                                     32
  Maximum number of threads per multiprocessor:  2048
  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): (2147483647, 65535, 65535)
  Maximum memory pitch:                          2147483647 bytes
  Texture alignment:                             512 bytes
  Concurrent copy and kernel execution:          Yes with 2 copy engine(s)
  Run time limit on kernels:                     Yes
  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) >

  deviceQuery, CUDA Driver = CUDART, CUDA Driver Version = 8.0, CUDA Runtime Version = 8.0, NumDevs = 1, Device0 = GeForce GTX 1080

谁能告诉我为什么?

1 个答案:

答案 0 :(得分:1)

罗伯特发布了解决问题的答案:

  

每个块的总线程数是维度的乘积。如果您的尺寸为numCols = 557 numRows = 313,则其产品超过150,000。设备上每个块的总线程数限制为1024,它位于deviceQuery输出中:每个块的最大线程数:1024