我有这样的代码:
for(int i =0; i<2; i++)
{
//initialization of memory and some variables
........
........
RunDll(input image, output image); //function that calls kernel
}
上述循环中的每次迭代都是独立的。我想同时运行它们。所以,我尝试了这个:
for(int i =0; i<num_devices; i++)
{
cudaSetDevice(i);
//initialization of memory and some variables
........
........
RunDll(input image, output image);
{
RunBasicFBP_CUDA(parameters); //function that calls kernel 1
xSegmentMetal(parameters); //CPU function
RunBasicFP_CUDA(parameters); //function that uses output of kernel 1 as input for kernel 2
for (int idx_view = 0; idx_view < param.fbp.num_view; idx_view++)
{
for (int idx_bin = 1; idx_bin < param.fbp.num_bin-1; idx_bin++)
{
sino_diff[idx_view][idx_bin] = sino_org[idx_view][idx_bin] - sino_mask[idx_view][idx_bin];
}
}
RunBasicFP_CUDA(parameters);
if(some condition)
{
xInterpolateSinoLinear(parameters); //CPU function
}
else
{
xInterpolateSinoPoly(parameters); //CPU function
}
RunBasicFBP_CUDA( parameters );
}
}
我正在使用 2 GTX 680,我想同时使用这两个设备。使用上面的代码,我没有得到任何加速。处理时间几乎与在单个 GPU 上运行时相同。
如何在两个可用设备上实现并发执行?