From a41394c8857492998aa2d7bdab1ddc2489378800 Mon Sep 17 00:00:00 2001 From: Alexander Alekhin Date: Thu, 18 Mar 2021 22:58:05 +0000 Subject: [PATCH] core(parallel): fix plugins handling if no filesystem available --- modules/core/CMakeLists.txt | 6 +++++- modules/core/src/parallel/parallel.cpp | 6 +++++- .../src/parallel/registry_parallel.impl.hpp | 18 ++++++++++++------ 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/modules/core/CMakeLists.txt b/modules/core/CMakeLists.txt index 3dcd019791..b2797ab31f 100644 --- a/modules/core/CMakeLists.txt +++ b/modules/core/CMakeLists.txt @@ -18,8 +18,12 @@ ocv_add_dispatched_file_force_all(test_intrin256 TEST AVX2 AVX512_SKX) ocv_add_dispatched_file_force_all(test_intrin512 TEST AVX512_SKX) +set(PARALLEL_ENABLE_PLUGINS_DEFAULT ON) +if(EMSCRIPTEN OR IOS OR WINRT) + set(PARALLEL_ENABLE_PLUGINS_DEFAULT OFF) +endif() # parallel backends configuration -set(PARALLEL_ENABLE_PLUGINS "ON" CACHE BOOL "Allow building parallel plugin support") +set(PARALLEL_ENABLE_PLUGINS "${PARALLEL_ENABLE_PLUGINS_DEFAULT}" CACHE BOOL "Allow building parallel plugin support") # TODO building plugins with OpenCV is not supported yet #set(PARALLEL_PLUGIN_LIST "" CACHE STRING "List of parallel backends to be compiled as plugins (tbb, openmp or special value 'all')") #string(REPLACE "," ";" PARALLEL_PLUGIN_LIST "${PARALLEL_PLUGIN_LIST}") # support comma-separated list (,) too diff --git a/modules/core/src/parallel/parallel.cpp b/modules/core/src/parallel/parallel.cpp index 67fea67cf2..29b482f5f3 100644 --- a/modules/core/src/parallel/parallel.cpp +++ b/modules/core/src/parallel/parallel.cpp @@ -63,7 +63,11 @@ std::shared_ptr createParallelForAPI() try { CV_LOG_DEBUG(NULL, "core(parallel): trying backend: " << info.name << " (priority=" << info.priority << ")"); - CV_Assert(info.backendFactory); + if (!info.backendFactory) + { + CV_LOG_DEBUG(NULL, "core(parallel): factory is not available (plugins require filesystem support): " << info.name); + continue; + } std::shared_ptr backend = info.backendFactory->create(); if (!backend) { diff --git a/modules/core/src/parallel/registry_parallel.impl.hpp b/modules/core/src/parallel/registry_parallel.impl.hpp index ef51437632..c8b57e7d6c 100644 --- a/modules/core/src/parallel/registry_parallel.impl.hpp +++ b/modules/core/src/parallel/registry_parallel.impl.hpp @@ -6,17 +6,23 @@ // Not a standalone header, part of parallel.cpp // +#include "opencv2/core/utils/filesystem.private.hpp" // OPENCV_HAVE_FILESYSTEM_SUPPORT + namespace cv { namespace parallel { +#if OPENCV_HAVE_FILESYSTEM_SUPPORT && defined(PARALLEL_ENABLE_PLUGINS) #define DECLARE_DYNAMIC_BACKEND(name) \ ParallelBackendInfo { \ 1000, name, createPluginParallelBackendFactory(name) \ -} +}, +#else +#define DECLARE_DYNAMIC_BACKEND(name) /* nothing */ +#endif #define DECLARE_STATIC_BACKEND(name, createBackendAPI) \ ParallelBackendInfo { \ 1000, name, std::make_shared([=] () -> std::shared_ptr { return createBackendAPI(); }) \ -} +}, static std::vector& getBuiltinParallelBackendsInfo() @@ -24,14 +30,14 @@ std::vector& getBuiltinParallelBackendsInfo() static std::vector g_backends { #ifdef HAVE_TBB - DECLARE_STATIC_BACKEND("TBB", createParallelBackendTBB), + DECLARE_STATIC_BACKEND("TBB", createParallelBackendTBB) #elif defined(PARALLEL_ENABLE_PLUGINS) - DECLARE_DYNAMIC_BACKEND("ONETBB"), // dedicated oneTBB plugin (interface >= 12000, binary incompatibe with TBB 2017-2020) - DECLARE_DYNAMIC_BACKEND("TBB"), // generic TBB plugins + DECLARE_DYNAMIC_BACKEND("ONETBB") // dedicated oneTBB plugin (interface >= 12000, binary incompatibe with TBB 2017-2020) + DECLARE_DYNAMIC_BACKEND("TBB") // generic TBB plugins #endif #ifdef HAVE_OPENMP - DECLARE_STATIC_BACKEND("OPENMP", createParallelBackendOpenMP), + DECLARE_STATIC_BACKEND("OPENMP", createParallelBackendOpenMP) #elif defined(PARALLEL_ENABLE_PLUGINS) DECLARE_DYNAMIC_BACKEND("OPENMP") // TODO Intel OpenMP? #endif