Download modules/gapi/src/backends/ie/giebackend/giewrapper.cpp from tgollogly/test: direct link, hf CLI and curl.
- Browser
- Download file 5.26 kB
-
https://huggingface.co/tgollogly/test/resolve/main/modules/gapi/src/backends/ie/giebackend/giewrapper.cpp
- Command line
-
hf download hf://tgollogly/test/modules/gapi/src/backends/ie/giebackend/giewrapper.cpp
-
curl -L -o giewrapper.cpp https://huggingface.co/tgollogly/test/resolve/main/modules/gapi/src/backends/ie/giebackend/giewrapper.cpp
5.26 kB
| // 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. | |
| // | |
| // Copyright (C) 2020-2024 Intel Corporation | |
| namespace IE = InferenceEngine; | |
| namespace giewrap = cv::gimpl::ie::wrap; | |
| using GIEParam = cv::gapi::ie::detail::ParamDesc; | |
| // Load extensions (taken from DNN module) | |
| std::vector<std::string> giewrap::getExtensions(const GIEParam& params) { | |
| std::vector<std::string> candidates; | |
| if (params.device_id == "CPU" || params.device_id == "FPGA") | |
| { | |
| const std::string suffixes[] = { "_avx2", "_sse4", ""}; | |
| const bool haveFeature[] = { | |
| cv::checkHardwareSupport(CPU_AVX2), | |
| cv::checkHardwareSupport(CPU_SSE4_2), | |
| true | |
| }; | |
| for (auto &&it : ade::util::zip(ade::util::toRange(suffixes), | |
| ade::util::toRange(haveFeature))) | |
| { | |
| std::string suffix; | |
| bool available = false; | |
| std::tie(suffix, available) = it; | |
| if (!available) continue; | |
| candidates.push_back("cpu_extension" + suffix + ".dll"); | |
| candidates.push_back("libcpu_extension" + suffix + ".so"); // built as loadable module | |
| candidates.push_back("libcpu_extension" + suffix + ".dylib"); // built as shared library | |
| candidates.push_back("libcpu_extension" + suffix + ".so"); | |
| } | |
| } | |
| return candidates; | |
| } | |
| IE::CNNNetwork giewrap::readNetwork(const GIEParam& params) { | |
| IE::CNNNetReader reader; | |
| reader.ReadNetwork(params.model_path); | |
| reader.ReadWeights(params.weights_path); | |
| return reader.getNetwork(); | |
| } | |
| std::vector<std::string> giewrap::getExtensions(const GIEParam&) { | |
| return std::vector<std::string>(); | |
| } | |
| IE::CNNNetwork giewrap::readNetwork(const GIEParam& params) { | |
| auto core = giewrap::getCore(); | |
| return core.ReadNetwork(params.model_path, params.weights_path); | |
| } | |
| IE::InferencePlugin giewrap::getPlugin(const GIEParam& params) { | |
| auto plugin = IE::PluginDispatcher().getPluginByDevice(params.device_id); | |
| if (params.device_id == "CPU" || params.device_id == "FPGA") | |
| { | |
| for (auto &&extlib : giewrap::getExtensions(params)) | |
| { | |
| try | |
| { | |
| plugin.AddExtension(IE::make_so_pointer<IE::IExtension>(extlib)); | |
| CV_LOG_INFO(NULL, "DNN-IE: Loaded extension plugin: " << extlib); | |
| break; | |
| } | |
| catch(...) | |
| { | |
| CV_LOG_INFO(NULL, "Failed to load IE extension: " << extlib); | |
| } | |
| } | |
| } | |
| return plugin; | |
| } | |
| // NB: Some of IE plugins fail during IE::Core destroying in specific cases. | |
| // Solution is allocate IE::Core in heap and doesn't destroy it, which cause | |
| // leak, but fixes tests on CI. This behaviour is configurable by using | |
| // OPENCV_GAPI_INFERENCE_ENGINE_CORE_LIFETIME_WORKAROUND=0 | |
| static IE::Core create_IE_Core_pointer() { | |
| // NB: 'delete' is never called | |
| static IE::Core* core = new IE::Core(); | |
| return *core; | |
| } | |
| static IE::Core create_IE_Core_instance() { | |
| static IE::Core core; | |
| return core; | |
| } | |
| IE::Core giewrap::getCore() { | |
| // NB: to make happy memory leak tools use: | |
| // - OPENCV_GAPI_INFERENCE_ENGINE_CORE_LIFETIME_WORKAROUND=0 | |
| static bool param_GAPI_INFERENCE_ENGINE_CORE_LIFETIME_WORKAROUND = | |
| utils::getConfigurationParameterBool( | |
| "OPENCV_GAPI_INFERENCE_ENGINE_CORE_LIFETIME_WORKAROUND", | |
| true | |
| false | |
| ); | |
| return param_GAPI_INFERENCE_ENGINE_CORE_LIFETIME_WORKAROUND | |
| ? create_IE_Core_pointer() : create_IE_Core_instance(); | |
| } | |
| IE::Core giewrap::getPlugin(const GIEParam& params) { | |
| auto plugin = giewrap::getCore(); | |
| if (params.device_id == "CPU" || params.device_id == "FPGA") | |
| { | |
| for (auto &&extlib : giewrap::getExtensions(params)) | |
| { | |
| try | |
| { | |
| plugin.AddExtension(std::make_shared<IE::Extension>(extlib), params.device_id); | |
| plugin.AddExtension(IE::make_so_pointer<IE::IExtension>(extlib), params.device_id); | |
| CV_LOG_INFO(NULL, "DNN-IE: Loaded extension plugin: " << extlib); | |
| break; | |
| } | |
| catch(...) | |
| { | |
| CV_LOG_INFO(NULL, "Failed to load IE extension: " << extlib); | |
| } | |
| } | |
| } | |
| return plugin; | |
| } | |