2014-02-24 50 views
1

我正在尝试在循环中编写我的内核。 每次我想改变我的网格大小和块大小.. 我已经写了这样的事情..我们可以重新初始化CUDA中的网格大小和块大小:

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 

所以......任何人都可以帮助我......?

回答

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>>>(); 
+0

你是救命恩人......! thnks – user3319055