Commit e02418e9 authored by Alexander Smorkalov's avatar Alexander Smorkalov

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

parent 840088e0
...@@ -3,7 +3,6 @@ ...@@ -3,7 +3,6 @@
#include <string> #include <string>
#include <ctype.h> #include <ctype.h>
#include "cvconfig.h"
#include "opencv2/core/core.hpp" #include "opencv2/core/core.hpp"
#include "opencv2/highgui/highgui.hpp" #include "opencv2/highgui/highgui.hpp"
#include "opencv2/gpu/gpu.hpp" #include "opencv2/gpu/gpu.hpp"
......
...@@ -7,34 +7,47 @@ ...@@ -7,34 +7,47 @@
#endif #endif
#include <iostream> #include <iostream>
#include "cvconfig.h"
#include "opencv2/core/core.hpp" #include "opencv2/core/core.hpp"
#include "opencv2/gpu/gpu.hpp" #include "opencv2/gpu/gpu.hpp"
#if !defined(HAVE_CUDA) || !defined(HAVE_TBB) using namespace std;
using namespace cv;
using namespace cv::gpu;
int main() struct Worker: public ParallelLoopBody
{ {
#if !defined(HAVE_CUDA) virtual void operator() (const Range& range) const
std::cout << "CUDA support is required (CMake key 'WITH_CUDA' must be true).\n"; {
#endif for (int device_id = range.start; device_id != range.end; ++device_id)
{
setDevice(device_id);
#if !defined(HAVE_TBB) Mat src(1000, 1000, CV_32F);
std::cout << "TBB support is required (CMake key 'WITH_TBB' must be true).\n"; Mat dst;
#endif
return 0; RNG rng(0);
} rng.fill(src, RNG::UNIFORM, 0, 1);
#else // CPU works
transpose(src, dst);
#include "opencv2/core/internal.hpp" // For TBB wrappers // GPU works
GpuMat d_src(src);
GpuMat d_dst;
transpose(d_src, d_dst);
using namespace std; // Check results
using namespace cv; bool passed = norm(dst - Mat(d_dst), NORM_INF) < 1e-3;
using namespace cv::gpu; std::cout << "GPU #" << device_id << " (" << DeviceInfo().name() << "): "
<< (passed ? "passed" : "FAILED") << endl;
struct Worker { void operator()(int device_id) const; }; // Deallocate data here, otherwise deallocation will be performed
// after context is extracted from the stack
d_src.release();
d_dst.release();
}
}
};
int main() int main()
{ {
...@@ -58,41 +71,8 @@ int main() ...@@ -58,41 +71,8 @@ int main()
} }
} }
// Execute calculation in two threads using two GPUs // Execute calculation in several threads, 1 GPU per thread
int devices[] = {0, 1}; parallel_for_(cv::Range(0, num_devices, Worker());
parallel_do(devices, devices + 2, Worker());
return 0; return 0;
} }
void Worker::operator()(int device_id) const
{
setDevice(device_id);
Mat src(1000, 1000, CV_32F);
Mat dst;
RNG rng(0);
rng.fill(src, RNG::UNIFORM, 0, 1);
// CPU works
transpose(src, dst);
// GPU works
GpuMat d_src(src);
GpuMat d_dst;
transpose(d_src, d_dst);
// Check results
bool passed = norm(dst - Mat(d_dst), NORM_INF) < 1e-3;
std::cout << "GPU #" << device_id << " (" << DeviceInfo().name() << "): "
<< (passed ? "passed" : "FAILED") << endl;
// Deallocate data here, otherwise deallocation will be performed
// after context is extracted from the stack
d_src.release();
d_dst.release();
}
#endif
#include <iostream> #include <iostream>
#include <vector> #include <vector>
#include "cvconfig.h"
#include "opencv2/core/core.hpp" #include "opencv2/core/core.hpp"
#include "opencv2/imgproc/imgproc.hpp" #include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp" #include "opencv2/highgui/highgui.hpp"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment