【问题标题】:can we reinitialize grid size and block size in CUDA我们可以在 CUDA 中重新初始化网格大小和块大小吗
【发布时间】:2014-02-24 13:05:04
【问题描述】:

我试图在循环中编写我的内核。 每次我想改变我的网格大小和块大小.. 我写过这样的东西..

dim3 grid(1,1);
dim3 block(N,N);
kernel<<<grid, block>>>();
while(condition)
{
 //Here I want to change my grid and block size
  kernel<<<grid,block>>>();
}

我不能再次使用网格和块来初始化不同的 N 值。 它显示错误:

error: "grid" has already been declared in the current scope
error: "block" has already been declared in the current scope

所以...谁能帮帮我...??

【问题讨论】:

    标签: cuda


    【解决方案1】:

    您尝试重新声明的任何变量都会收到相同的错误消息。

    如果你有一个 int 变量,你不会这样做:

    int a = 7;
    int a = 5;
    

    你会这样做:

    int a = 7;
    a = 5;
    

    您对 blockgrid 执行相同的操作,只是每个组件最多包含三个组件:

    dim3 grid(1,1);
    dim3 block(N,N);
    kernel<<<grid, block>>>();
    while(condition)
    {
      grid.x = 2;  grid.y = 2;
      block.x = N/2; block.y = N/2;
      kernel<<<grid,block>>>();
    }
    

    dim3 是变量类型。 blockgrid 只是任意名称,您可以随意称呼它们,如下所示:

    dim3 foo;
    dim3 bar;
    foo.x = 5; foo.y = 10;
    bar.x = 2; bar.y = 4;
    kernel<<<bar, foo>>>();
    

    【讨论】:

      猜你喜欢
      • 2019-05-21
      • 2013-05-14
      • 2019-07-09
      • 2020-08-26
      • 2012-03-05
      • 1970-01-01
      • 1970-01-01
      • 2015-07-25
      • 2021-06-08
      相关资源
      最近更新 更多