added resetDevice function, removed MultiGpuManager

This commit is contained in:
Vladislav Vinogradov
2011-06-01 10:11:27 +00:00
parent b6c195d44c
commit f906c9b259
5 changed files with 31 additions and 215 deletions

View File

@@ -36,8 +36,6 @@ using namespace cv::gpu;
struct Worker { void operator()(int device_id) const; };
MultiGpuManager multi_gpu_mgr;
int main()
{
int num_devices = getCudaEnabledDeviceCount();
@@ -58,8 +56,6 @@ int main()
}
}
multi_gpu_mgr.init();
// Execute calculation in two threads using two GPUs
int devices[] = {0, 1};
parallel_do(devices, devices + 2, Worker());
@@ -70,7 +66,7 @@ int main()
void Worker::operator()(int device_id) const
{
multi_gpu_mgr.gpuOn(device_id);
setDevice(device_id);
Mat src(1000, 1000, CV_32F);
Mat dst;
@@ -95,8 +91,6 @@ void Worker::operator()(int device_id) const
// after context is extracted from the stack
d_src.release();
d_dst.release();
multi_gpu_mgr.gpuOff();
}
#endif

View File

@@ -38,8 +38,6 @@ using namespace cv::gpu;
struct Worker { void operator()(int device_id) const; };
MultiGpuManager multi_gpu_mgr;
// GPUs data
GpuMat d_left[2];
GpuMat d_right[2];
@@ -89,43 +87,37 @@ int main(int argc, char** argv)
return -1;
}
multi_gpu_mgr.init();
// Split source images for processing on the GPU #0
multi_gpu_mgr.gpuOn(0);
setDevice(0);
d_left[0].upload(left.rowRange(0, left.rows / 2));
d_right[0].upload(right.rowRange(0, right.rows / 2));
bm[0] = new StereoBM_GPU();
multi_gpu_mgr.gpuOff();
// Split source images for processing on the GPU #1
multi_gpu_mgr.gpuOn(1);
setDevice(1);
d_left[1].upload(left.rowRange(left.rows / 2, left.rows));
d_right[1].upload(right.rowRange(right.rows / 2, right.rows));
bm[1] = new StereoBM_GPU();
multi_gpu_mgr.gpuOff();
// Execute calculation in two threads using two GPUs
int devices[] = {0, 1};
parallel_do(devices, devices + 2, Worker());
// Release the first GPU resources
multi_gpu_mgr.gpuOn(0);
setDevice(0);
imshow("GPU #0 result", Mat(d_result[0]));
d_left[0].release();
d_right[0].release();
d_result[0].release();
delete bm[0];
multi_gpu_mgr.gpuOff();
// Release the second GPU resources
multi_gpu_mgr.gpuOn(1);
setDevice(1);
imshow("GPU #1 result", Mat(d_result[1]));
d_left[1].release();
d_right[1].release();
d_result[1].release();
delete bm[1];
multi_gpu_mgr.gpuOff();
waitKey();
return 0;
@@ -134,15 +126,13 @@ int main(int argc, char** argv)
void Worker::operator()(int device_id) const
{
multi_gpu_mgr.gpuOn(device_id);
setDevice(device_id);
bm[device_id]->operator()(d_left[device_id], d_right[device_id],
d_result[device_id]);
std::cout << "GPU #" << device_id << " (" << DeviceInfo().name()
<< "): finished\n";
multi_gpu_mgr.gpuOff();
}
#endif