Cuda gridDim和blockDim [英] Cuda gridDim and blockDim

查看:327
本文介绍了Cuda gridDim和blockDim的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我得到了 blockDim 是什么,但是我对 gridDim有问题。 Blockdim 给出块的大小,但是 gridDim 是什么?在互联网上,它说 gridDim.x 给出x坐标中的块数。

I get what blockDim is, but I have a problem with gridDim. Blockdim gives the size of the block, but what is gridDim? On the Internet it says gridDim.x gives the number of blocks in the x coordinate.

我怎么知道 blockDim.x * gridDim.x 给出什么?

我怎么知道有多少 gridDim.x 值是否在x行中?

How can I know that how many gridDim.x values are there in the x line?

例如,请考虑以下代码:

For example, consider the code below:

int tid = threadIdx.x + blockIdx.x * blockDim.x;
double temp = a[tid];
tid += blockDim.x * gridDim.x;

while (tid < count)
{
    if (a[tid] > temp)
    {
       temp = a[tid];
    }
    tid += blockDim.x * gridDim.x;
}

我知道 tid 从0开始。然后,代码具有 tid + = blockDim.x * gridDim.x 。完成此操作后, tid 是什么?

I know that tid starts with 0. The code then has tid+=blockDim.x * gridDim.x. What is tid now after this operation?

推荐答案


  • blockDim.x,y,z 给出一个块中线程的数量,在
    特定方向上

  • gridDim.x,y,z 给出网格中特定于
    方向的块数

  • blockDim.x * gridDim.x 给出网格中的线程数(在本例中为x方向)

    • blockDim.x,y,z gives the number of threads in a block, in the particular direction
    • gridDim.x,y,z gives the number of blocks in a grid, in the particular direction
    • blockDim.x * gridDim.x gives the number of threads in a grid (in the x direction, in this case)
    • 块和网格变量可以是1维,2维或3维。处理一维数据以仅创建一维块和网格是一种常见做法。

      block and grid variables can be 1, 2, or 3 dimensional. It's common practice when handling 1-D data to only create 1-D blocks and grids.

      在CUDA文档中,这些变量定义为此处

      In the CUDA documentation, these variables are defined here

      特别是,当x维度中的总线程( gridDim.x * blockDim.x 小于大小时在我要处理的数组中,通常的做法是创建一个循环并使线程网格在整个数组中移动。在这种情况下,在处理了一个循环迭代之后,每个线程都必须移至下一个未处理的位置,该位置由 tid + = blockDim.x * gridDim.x; 给出,则整个线程网格都将遍历一维数据数组,一次是一个网格宽度。此主题有时称为网格跨越循环,在此博客文章

      In particular, when the total threads in the x-dimension (gridDim.x*blockDim.x) is less than the size of the array I wish to process, then it's common practice to create a loop and have the grid of threads move through the entire array. In this case, after processing one loop iteration, each thread must then move to the next unprocessed location, which is given by tid+=blockDim.x*gridDim.x; In effect, the entire grid of threads is jumping through the 1-D array of data, a grid-width at a time. This topic, sometimes called a "grid-striding loop", is further discussed in this blog article.

      您可能要考虑参加 NVIDIA网络研讨会页面。例如,这些2:

      You might want to consider taking a couple of the introductory CUDA webinars available on the NVIDIA webinar page. For example, these 2:


      • 使用CUDA C进行GPU计算–简介(2010)简介
        GPU基础知识使用CUDA C进行计算。概念将通过代码示例演练来说明。不需要先前的GPU计算
        经验

      • 使用CUDA C进行GPU计算–高级1(2010)一级
        优化技术,例如全局内存优化和
        处理器利用率。将使用实际代码
        示例来说明概念。

      如果您想了解这些概念,那将花费2个小时更好。

      It would be 2 hours well spent, if you want to understand these concepts better.

      关于网格跨越循环的一般主题已详细介绍此处

      The general topic of grid-striding loops is covered in some detail here.

      这篇关于Cuda gridDim和blockDim的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆