MULTI-DIMENSIONAL THREADS

Each CUDA kernel is executed by a grid, which contains

  • a 3d thread blocks
  • a 3d threads

image.png
Each thread executes the same program

  • on distinct data inputs
  • single program multipul data model (SPMD)

image.png
like the operation system:

  • cooperation happens within a block.
  • threads in different block cooperate less

    MAPPING THREADS TO MULTIDIMENSIONAL DATA

    How to calculate the gird?

    image.png
    每个block中的thread 处理一个图片中的像素

    How to deal with the idle threads

    image.png

    如何计算当前thread对应在图像中的行数和列数

    image.png
    而当前的如果是灰度图,拿到的就是真实的下标,而RGB图片有三个通道,并且张量形式为(width,height,channels),每个像素都有三个分量,需要乘以3才是当前图像中像素的位置在张量中的下标
    image.png