parallel_do replaced by parallel_for_ in gpu/multi.cpp sample to get rid of cvconfig.h
This commit is contained in:
parent
840088e021
commit
e02418e904
@ -3,7 +3,6 @@
|
||||
#include <string>
|
||||
#include <ctype.h>
|
||||
|
||||
#include "cvconfig.h"
|
||||
#include "opencv2/core/core.hpp"
|
||||
#include "opencv2/highgui/highgui.hpp"
|
||||
#include "opencv2/gpu/gpu.hpp"
|
||||
|
@ -7,67 +7,19 @@
|
||||
#endif
|
||||
|
||||
#include <iostream>
|
||||
#include "cvconfig.h"
|
||||
#include "opencv2/core/core.hpp"
|
||||
#include "opencv2/gpu/gpu.hpp"
|
||||
|
||||
#if !defined(HAVE_CUDA) || !defined(HAVE_TBB)
|
||||
|
||||
int main()
|
||||
{
|
||||
#if !defined(HAVE_CUDA)
|
||||
std::cout << "CUDA support is required (CMake key 'WITH_CUDA' must be true).\n";
|
||||
#endif
|
||||
|
||||
#if !defined(HAVE_TBB)
|
||||
std::cout << "TBB support is required (CMake key 'WITH_TBB' must be true).\n";
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
#include "opencv2/core/internal.hpp" // For TBB wrappers
|
||||
|
||||
using namespace std;
|
||||
using namespace cv;
|
||||
using namespace cv::gpu;
|
||||
|
||||
struct Worker { void operator()(int device_id) const; };
|
||||
|
||||
int main()
|
||||
struct Worker: public ParallelLoopBody
|
||||
{
|
||||
int num_devices = getCudaEnabledDeviceCount();
|
||||
if (num_devices < 2)
|
||||
virtual void operator() (const Range& range) const
|
||||
{
|
||||
std::cout << "Two or more GPUs are required\n";
|
||||
return -1;
|
||||
}
|
||||
for (int i = 0; i < num_devices; ++i)
|
||||
for (int device_id = range.start; device_id != range.end; ++device_id)
|
||||
{
|
||||
cv::gpu::printShortCudaDeviceInfo(i);
|
||||
|
||||
DeviceInfo dev_info(i);
|
||||
if (!dev_info.isCompatible())
|
||||
{
|
||||
std::cout << "GPU module isn't built for GPU #" << i << " ("
|
||||
<< dev_info.name() << ", CC " << dev_info.majorVersion()
|
||||
<< dev_info.minorVersion() << "\n";
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
// Execute calculation in two threads using two GPUs
|
||||
int devices[] = {0, 1};
|
||||
parallel_do(devices, devices + 2, Worker());
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void Worker::operator()(int device_id) const
|
||||
{
|
||||
setDevice(device_id);
|
||||
|
||||
Mat src(1000, 1000, CV_32F);
|
||||
@ -93,6 +45,34 @@ void Worker::operator()(int device_id) const
|
||||
// after context is extracted from the stack
|
||||
d_src.release();
|
||||
d_dst.release();
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
int main()
|
||||
{
|
||||
int num_devices = getCudaEnabledDeviceCount();
|
||||
if (num_devices < 2)
|
||||
{
|
||||
std::cout << "Two or more GPUs are required\n";
|
||||
return -1;
|
||||
}
|
||||
for (int i = 0; i < num_devices; ++i)
|
||||
{
|
||||
cv::gpu::printShortCudaDeviceInfo(i);
|
||||
|
||||
DeviceInfo dev_info(i);
|
||||
if (!dev_info.isCompatible())
|
||||
{
|
||||
std::cout << "GPU module isn't built for GPU #" << i << " ("
|
||||
<< dev_info.name() << ", CC " << dev_info.majorVersion()
|
||||
<< dev_info.minorVersion() << "\n";
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
// Execute calculation in several threads, 1 GPU per thread
|
||||
parallel_for_(cv::Range(0, num_devices, Worker());
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
#include "cvconfig.h"
|
||||
#include "opencv2/core/core.hpp"
|
||||
#include "opencv2/imgproc/imgproc.hpp"
|
||||
#include "opencv2/highgui/highgui.hpp"
|
||||
|
Loading…
x
Reference in New Issue
Block a user