Commit d1a81710 authored by Maxim Kostin's avatar Maxim Kostin

Added WinRT concurrency support.

parent baf191fa
...@@ -69,7 +69,7 @@ ...@@ -69,7 +69,7 @@
#define HAVE_GCD #define HAVE_GCD
#endif #endif
#if defined _MSC_VER && _MSC_VER >= 1600 && !defined(WINRT) #if defined _MSC_VER && _MSC_VER >= 1600
#define HAVE_CONCURRENCY #define HAVE_CONCURRENCY
#endif #endif
...@@ -78,7 +78,8 @@ ...@@ -78,7 +78,8 @@
2. HAVE_CSTRIPES - 3rdparty library, should be explicitly enabled 2. HAVE_CSTRIPES - 3rdparty library, should be explicitly enabled
3. HAVE_OPENMP - integrated to compiler, should be explicitly enabled 3. HAVE_OPENMP - integrated to compiler, should be explicitly enabled
4. HAVE_GCD - system wide, used automatically (APPLE only) 4. HAVE_GCD - system wide, used automatically (APPLE only)
5. HAVE_CONCURRENCY - part of runtime, used automatically (Windows only - MSVS 10, MSVS 11) 5. WINRT - system wide, used automatically (Windows RT only)
6. HAVE_CONCURRENCY - part of runtime, used automatically (Windows only - MSVS 10, MSVS 11)
*/ */
#if defined HAVE_TBB #if defined HAVE_TBB
...@@ -105,6 +106,8 @@ ...@@ -105,6 +106,8 @@
#elif defined HAVE_GCD #elif defined HAVE_GCD
#include <dispatch/dispatch.h> #include <dispatch/dispatch.h>
#include <pthread.h> #include <pthread.h>
#elif defined WINRT
#include <ppltasks.h>
#elif defined HAVE_CONCURRENCY #elif defined HAVE_CONCURRENCY
#include <ppl.h> #include <ppl.h>
#endif #endif
...@@ -118,6 +121,8 @@ ...@@ -118,6 +121,8 @@
# define CV_PARALLEL_FRAMEWORK "openmp" # define CV_PARALLEL_FRAMEWORK "openmp"
#elif defined HAVE_GCD #elif defined HAVE_GCD
# define CV_PARALLEL_FRAMEWORK "gcd" # define CV_PARALLEL_FRAMEWORK "gcd"
#elif defined WINRT
# define CV_PARALLEL_FRAMEWORK "winrt-concurrency"
#elif defined HAVE_CONCURRENCY #elif defined HAVE_CONCURRENCY
# define CV_PARALLEL_FRAMEWORK "ms-concurrency" # define CV_PARALLEL_FRAMEWORK "ms-concurrency"
#endif #endif
...@@ -179,7 +184,7 @@ namespace ...@@ -179,7 +184,7 @@ namespace
ProxyLoopBody* ptr_body = static_cast<ProxyLoopBody*>(context); ProxyLoopBody* ptr_body = static_cast<ProxyLoopBody*>(context);
(*ptr_body)(cv::Range((int)index, (int)index + 1)); (*ptr_body)(cv::Range((int)index, (int)index + 1));
} }
#elif defined HAVE_CONCURRENCY #elif defined WINRT || defined HAVE_CONCURRENCY
class ProxyLoopBody : public ParallelLoopBodyWrapper class ProxyLoopBody : public ParallelLoopBodyWrapper
{ {
public: public:
...@@ -206,7 +211,10 @@ static tbb::task_scheduler_init tbbScheduler(tbb::task_scheduler_init::deferred) ...@@ -206,7 +211,10 @@ static tbb::task_scheduler_init tbbScheduler(tbb::task_scheduler_init::deferred)
static int numThreadsMax = omp_get_max_threads(); static int numThreadsMax = omp_get_max_threads();
#elif defined HAVE_GCD #elif defined HAVE_GCD
// nothing for GCD // nothing for GCD
#elif defined WINRT
// nothing for WINRT
#elif defined HAVE_CONCURRENCY #elif defined HAVE_CONCURRENCY
class SchedPtr class SchedPtr
{ {
Concurrency::Scheduler* sched_; Concurrency::Scheduler* sched_;
...@@ -224,6 +232,7 @@ public: ...@@ -224,6 +232,7 @@ public:
~SchedPtr() { *this = 0; } ~SchedPtr() { *this = 0; }
}; };
static SchedPtr pplScheduler; static SchedPtr pplScheduler;
#endif #endif
#endif // CV_PARALLEL_FRAMEWORK #endif // CV_PARALLEL_FRAMEWORK
...@@ -272,6 +281,10 @@ void cv::parallel_for_(const cv::Range& range, const cv::ParallelLoopBody& body, ...@@ -272,6 +281,10 @@ void cv::parallel_for_(const cv::Range& range, const cv::ParallelLoopBody& body,
dispatch_queue_t concurrent_queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0); dispatch_queue_t concurrent_queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
dispatch_apply_f(stripeRange.end - stripeRange.start, concurrent_queue, &pbody, block_function); dispatch_apply_f(stripeRange.end - stripeRange.start, concurrent_queue, &pbody, block_function);
#elif defined WINRT
Concurrency::parallel_for(stripeRange.start, stripeRange.end, pbody);
#elif defined HAVE_CONCURRENCY #elif defined HAVE_CONCURRENCY
if(!pplScheduler || pplScheduler->Id() == Concurrency::CurrentScheduler::Id()) if(!pplScheduler || pplScheduler->Id() == Concurrency::CurrentScheduler::Id())
...@@ -330,6 +343,10 @@ int cv::getNumThreads(void) ...@@ -330,6 +343,10 @@ int cv::getNumThreads(void)
return 512; // the GCD thread pool limit return 512; // the GCD thread pool limit
#elif defined WINRT
return 0;
#elif defined HAVE_CONCURRENCY #elif defined HAVE_CONCURRENCY
return 1 + (pplScheduler == 0 return 1 + (pplScheduler == 0
...@@ -371,6 +388,10 @@ void cv::setNumThreads( int threads ) ...@@ -371,6 +388,10 @@ void cv::setNumThreads( int threads )
// unsupported // unsupported
// there is only private dispatch_queue_set_width() and only for desktop // there is only private dispatch_queue_set_width() and only for desktop
#elif defined WINRT
return;
#elif defined HAVE_CONCURRENCY #elif defined HAVE_CONCURRENCY
if (threads <= 0) if (threads <= 0)
...@@ -407,6 +428,8 @@ int cv::getThreadNum(void) ...@@ -407,6 +428,8 @@ int cv::getThreadNum(void)
return omp_get_thread_num(); return omp_get_thread_num();
#elif defined HAVE_GCD #elif defined HAVE_GCD
return (int)(size_t)(void*)pthread_self(); // no zero-based indexing return (int)(size_t)(void*)pthread_self(); // no zero-based indexing
#elif defined WINRT
return 0;
#elif defined HAVE_CONCURRENCY #elif defined HAVE_CONCURRENCY
return std::max(0, (int)Concurrency::Context::VirtualProcessorId()); // zero for master thread, unique number for others but not necessary 1,2,3,... return std::max(0, (int)Concurrency::Context::VirtualProcessorId()); // zero for master thread, unique number for others but not necessary 1,2,3,...
#else #else
......
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