1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-29 15:23:05 +04:00

Merge pull request #11897 from Jakub-Golinowski:hpx_backend

* Add HPX backend for OpenCV implementation
Adds hpx backend for cv::parallel_for_() calls respecting the nstripes chunking parameter. C++ code for the backend is added to modules/core/parallel.cpp. Also, the necessary changes to cmake files are introduced.
Backend can operate in 2 versions (selectable by cmake build option WITH_HPX_STARTSTOP): hpx (runtime always on) and hpx_startstop (start and stop the backend for each cv::parallel_for_() call)

* WIP: Conditionally include hpx_main.hpp to tests in core module
Header hpx_main.hpp is included to both core/perf/perf_main.cpp and core/test/test_main.cpp.
The changes to cmake files for linking hpx library to above mentioned test executalbles are proposed but have issues.

* Add coditional iclusion of hpx_main.hpp to cpp cpu modules

* Remove start/stop version of hpx backend
This commit is contained in:
Jakub Golinowski
2018-08-31 15:23:26 +02:00
committed by Alexander Alekhin
parent 90f47eb952
commit 9f1218b00b
35 changed files with 188 additions and 0 deletions
+46
View File
@@ -79,6 +79,7 @@
/* IMPORTANT: always use the same order of defines
- HAVE_TBB - 3rdparty library, should be explicitly enabled
- HAVE_HPX - 3rdparty library, should be explicitly enabled
- HAVE_OPENMP - integrated to compiler, should be explicitly enabled
- HAVE_GCD - system wide, used automatically (APPLE only)
- WINRT - system wide, used automatically (Windows RT only)
@@ -95,6 +96,16 @@
#endif
#undef min
#undef max
#elif defined HAVE_HPX
#include <hpx/parallel/algorithms/for_loop.hpp>
#include <hpx/parallel/execution.hpp>
//
#include <hpx/hpx_start.hpp>
#include <hpx/hpx_suspend.hpp>
#include <hpx/include/apply.hpp>
#include <hpx/util/yield_while.hpp>
#include <hpx/include/threadmanager.hpp>
#elif defined HAVE_OPENMP
#include <omp.h>
#elif defined HAVE_GCD
@@ -109,6 +120,8 @@
#if defined HAVE_TBB
# define CV_PARALLEL_FRAMEWORK "tbb"
#elif defined HAVE_HPX
# define CV_PARALLEL_FRAMEWORK "hpx"
#elif defined HAVE_OPENMP
# define CV_PARALLEL_FRAMEWORK "openmp"
#elif defined HAVE_GCD
@@ -377,6 +390,26 @@ namespace
tbb::parallel_for(tbb::blocked_range<int>(range.start, range.end), *this);
}
};
#elif defined HAVE_HPX
class ProxyLoopBody : public ParallelLoopBodyWrapper
{
public:
ProxyLoopBody(ParallelLoopBodyWrapperContext& ctx_)
: ParallelLoopBodyWrapper(ctx_)
{}
void operator ()() const // run parallel job
{
cv::Range stripeRange = this->stripeRange();
hpx::parallel::for_loop(
hpx::parallel::execution::par,
stripeRange.start, stripeRange.end,
[&](const int &i) { ;
this->ParallelLoopBodyWrapper::operator()(
cv::Range(i, i + 1));
});
}
};
#elif defined HAVE_GCD
typedef ParallelLoopBodyWrapper ProxyLoopBody;
static void block_function(void* context, size_t index)
@@ -409,6 +442,8 @@ static int numThreads = -1;
#else
static tbb::task_scheduler_init tbbScheduler(tbb::task_scheduler_init::deferred);
#endif
#elif defined HAVE_HPX
// nothing for HPX
#elif defined HAVE_OPENMP
static int numThreadsMax = omp_get_max_threads();
#elif defined HAVE_GCD
@@ -508,6 +543,9 @@ static void parallel_for_impl(const cv::Range& range, const cv::ParallelLoopBody
pbody();
#endif
#elif defined HAVE_HPX
pbody();
#elif defined HAVE_OPENMP
#pragma omp parallel for schedule(dynamic) num_threads(numThreads > 0 ? numThreads : numThreadsMax)
@@ -579,6 +617,9 @@ int cv::getNumThreads(void)
: tbb::task_scheduler_init::default_num_threads();
#endif
#elif defined HAVE_HPX
return numThreads;
#elif defined HAVE_OPENMP
return numThreads > 0
@@ -653,6 +694,9 @@ void cv::setNumThreads( int threads_ )
if(threads > 0) tbbScheduler.initialize(threads);
#endif
#elif defined HAVE_HPX
return; // nothing needed as numThreads is used
#elif defined HAVE_OPENMP
return; // nothing needed as num_threads clause is used in #pragma omp parallel for
@@ -702,6 +746,8 @@ int cv::getThreadNum(void)
#else
return 0;
#endif
#elif defined HAVE_HPX
return (int)(hpx::get_num_worker_threads());
#elif defined HAVE_OPENMP
return omp_get_thread_num();
#elif defined HAVE_GCD