parallel_do replaced by parallel_for_ in gpu/multi.cpp sample to get rid of cvconfig.h

pull/3604/head
Alexander Smorkalov 10 years ago
parent 840088e021
commit e02418e904
  1. 1
      samples/gpu/brox_optical_flow.cpp
  2. 84
      samples/gpu/multi.cpp
  3. 1
      samples/gpu/pyrlk_optical_flow.cpp

@ -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,66 +7,18 @@
#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)
{
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
for (int device_id = range.start; device_id != range.end; ++device_id)
{
setDevice(device_id);
@ -94,5 +46,33 @@ void Worker::operator()(int device_id) const
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…
Cancel
Save