2022-02-17 05:55:56 +08:00
|
|
|
// This file is part of OpenCV project.
|
|
|
|
// It is subject to the license terms in the LICENSE file found in the top-level directory
|
|
|
|
// of this distribution and at http://opencv.org/license.html.
|
|
|
|
|
|
|
|
#include "precomp.hpp"
|
|
|
|
|
|
|
|
#include "op_halide.hpp"
|
|
|
|
#include "op_inf_engine.hpp"
|
|
|
|
#include "ie_ngraph.hpp"
|
|
|
|
#include "op_vkcom.hpp"
|
|
|
|
#include "op_cuda.hpp"
|
|
|
|
#include "op_webnn.hpp"
|
2022-04-01 05:42:11 +08:00
|
|
|
#include "op_timvx.hpp"
|
2022-12-21 14:04:41 +08:00
|
|
|
#include "op_cann.hpp"
|
2022-02-17 05:55:56 +08:00
|
|
|
|
|
|
|
#include "halide_scheduler.hpp"
|
|
|
|
|
2022-03-18 14:19:30 +08:00
|
|
|
#include "backend.hpp"
|
|
|
|
#include "factory.hpp"
|
2022-02-17 05:55:56 +08:00
|
|
|
|
|
|
|
namespace cv {
|
|
|
|
namespace dnn {
|
|
|
|
CV__DNN_INLINE_NS_BEGIN
|
|
|
|
|
|
|
|
|
|
|
|
class BackendRegistry
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
typedef std::vector< std::pair<Backend, Target> > BackendsList;
|
|
|
|
const BackendsList & getBackends() const { return backends; }
|
|
|
|
static BackendRegistry & getRegistry()
|
|
|
|
{
|
|
|
|
static BackendRegistry impl;
|
|
|
|
return impl;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
BackendRegistry()
|
|
|
|
{
|
|
|
|
#ifdef HAVE_HALIDE
|
|
|
|
backends.push_back(std::make_pair(DNN_BACKEND_HALIDE, DNN_TARGET_CPU));
|
|
|
|
#ifdef HAVE_OPENCL
|
|
|
|
if (cv::ocl::useOpenCL())
|
|
|
|
backends.push_back(std::make_pair(DNN_BACKEND_HALIDE, DNN_TARGET_OPENCL));
|
|
|
|
#endif
|
|
|
|
#endif // HAVE_HALIDE
|
|
|
|
|
2022-03-18 14:19:30 +08:00
|
|
|
bool haveBackendOpenVINO = false;
|
2022-02-17 05:55:56 +08:00
|
|
|
#ifdef HAVE_INF_ENGINE
|
2022-03-18 14:19:30 +08:00
|
|
|
haveBackendOpenVINO = true;
|
|
|
|
#elif defined(ENABLE_PLUGINS)
|
2022-02-17 05:55:56 +08:00
|
|
|
{
|
2022-03-18 14:19:30 +08:00
|
|
|
auto factory = dnn_backend::createPluginDNNBackendFactory("openvino");
|
|
|
|
if (factory)
|
|
|
|
{
|
|
|
|
auto backend = factory->createNetworkBackend();
|
|
|
|
if (backend)
|
|
|
|
haveBackendOpenVINO = true;
|
|
|
|
}
|
|
|
|
}
|
2022-02-17 05:55:56 +08:00
|
|
|
#endif
|
2022-03-18 14:19:30 +08:00
|
|
|
|
|
|
|
if (haveBackendOpenVINO && openvino::checkTarget(DNN_TARGET_CPU))
|
|
|
|
{
|
|
|
|
backends.push_back(std::make_pair(DNN_BACKEND_INFERENCE_ENGINE_NGRAPH, DNN_TARGET_CPU));
|
2022-02-17 05:55:56 +08:00
|
|
|
}
|
2022-03-18 14:19:30 +08:00
|
|
|
if (haveBackendOpenVINO && openvino::checkTarget(DNN_TARGET_MYRIAD))
|
2022-02-17 05:55:56 +08:00
|
|
|
{
|
|
|
|
backends.push_back(std::make_pair(DNN_BACKEND_INFERENCE_ENGINE_NGRAPH, DNN_TARGET_MYRIAD));
|
|
|
|
}
|
2022-03-18 14:19:30 +08:00
|
|
|
if (haveBackendOpenVINO && openvino::checkTarget(DNN_TARGET_HDDL))
|
2022-02-17 05:55:56 +08:00
|
|
|
{
|
|
|
|
backends.push_back(std::make_pair(DNN_BACKEND_INFERENCE_ENGINE_NGRAPH, DNN_TARGET_HDDL));
|
|
|
|
}
|
|
|
|
#ifdef HAVE_OPENCL
|
|
|
|
if (cv::ocl::useOpenCL() && ocl::Device::getDefault().isIntel())
|
|
|
|
{
|
2022-03-18 14:19:30 +08:00
|
|
|
if (haveBackendOpenVINO && openvino::checkTarget(DNN_TARGET_OPENCL))
|
2022-02-17 05:55:56 +08:00
|
|
|
{
|
|
|
|
backends.push_back(std::make_pair(DNN_BACKEND_INFERENCE_ENGINE_NGRAPH, DNN_TARGET_OPENCL));
|
|
|
|
}
|
2022-03-18 14:19:30 +08:00
|
|
|
if (haveBackendOpenVINO && openvino::checkTarget(DNN_TARGET_OPENCL_FP16))
|
2022-02-17 05:55:56 +08:00
|
|
|
{
|
|
|
|
backends.push_back(std::make_pair(DNN_BACKEND_INFERENCE_ENGINE_NGRAPH, DNN_TARGET_OPENCL_FP16));
|
|
|
|
}
|
|
|
|
}
|
2022-03-18 14:19:30 +08:00
|
|
|
#endif // HAVE_OPENCL
|
2022-02-17 05:55:56 +08:00
|
|
|
|
|
|
|
#ifdef HAVE_WEBNN
|
|
|
|
if (haveWebnn())
|
|
|
|
{
|
|
|
|
backends.push_back(std::make_pair(DNN_BACKEND_WEBNN, DNN_TARGET_CPU));
|
|
|
|
}
|
|
|
|
#endif // HAVE_WEBNN
|
|
|
|
|
|
|
|
#ifdef HAVE_OPENCL
|
|
|
|
if (cv::ocl::useOpenCL())
|
|
|
|
{
|
|
|
|
backends.push_back(std::make_pair(DNN_BACKEND_OPENCV, DNN_TARGET_OPENCL));
|
|
|
|
backends.push_back(std::make_pair(DNN_BACKEND_OPENCV, DNN_TARGET_OPENCL_FP16));
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
backends.push_back(std::make_pair(DNN_BACKEND_OPENCV, DNN_TARGET_CPU));
|
|
|
|
|
|
|
|
#ifdef HAVE_VULKAN
|
|
|
|
if (haveVulkan())
|
|
|
|
backends.push_back(std::make_pair(DNN_BACKEND_VKCOM, DNN_TARGET_VULKAN));
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_CUDA
|
|
|
|
if (haveCUDA())
|
|
|
|
{
|
|
|
|
backends.push_back(std::make_pair(DNN_BACKEND_CUDA, DNN_TARGET_CUDA));
|
|
|
|
backends.push_back(std::make_pair(DNN_BACKEND_CUDA, DNN_TARGET_CUDA_FP16));
|
|
|
|
}
|
|
|
|
#endif
|
2022-04-01 05:42:11 +08:00
|
|
|
|
|
|
|
#ifdef HAVE_TIMVX
|
|
|
|
if (haveTimVX())
|
|
|
|
{
|
|
|
|
backends.push_back(std::make_pair(DNN_BACKEND_TIMVX, DNN_TARGET_NPU));
|
|
|
|
}
|
|
|
|
#endif
|
2022-12-21 14:04:41 +08:00
|
|
|
|
|
|
|
#ifdef HAVE_CANN
|
|
|
|
backends.push_back(std::make_pair(DNN_BACKEND_CANN, DNN_TARGET_NPU));
|
|
|
|
#endif
|
2022-02-17 05:55:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
BackendsList backends;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
std::vector<std::pair<Backend, Target>> getAvailableBackends()
|
|
|
|
{
|
|
|
|
return BackendRegistry::getRegistry().getBackends();
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<Target> getAvailableTargets(Backend be)
|
|
|
|
{
|
|
|
|
if (be == DNN_BACKEND_DEFAULT)
|
|
|
|
be = (Backend)getParam_DNN_BACKEND_DEFAULT();
|
2022-03-18 14:19:30 +08:00
|
|
|
|
2022-02-17 05:55:56 +08:00
|
|
|
if (be == DNN_BACKEND_INFERENCE_ENGINE)
|
|
|
|
be = DNN_BACKEND_INFERENCE_ENGINE_NGRAPH;
|
|
|
|
|
|
|
|
std::vector<Target> result;
|
|
|
|
const BackendRegistry::BackendsList all_backends = getAvailableBackends();
|
|
|
|
for (BackendRegistry::BackendsList::const_iterator i = all_backends.begin(); i != all_backends.end(); ++i)
|
|
|
|
{
|
|
|
|
if (i->first == be)
|
|
|
|
result.push_back(i->second);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
CV__DNN_INLINE_NS_END
|
|
|
|
}} // namespace cv::dnn
|