From 71bae7c23ff5ef190ea50174125bef3ae0081a08 Mon Sep 17 00:00:00 2001 From: Alexander Alekhin Date: Thu, 29 Apr 2021 12:37:14 +0300 Subject: [PATCH] dnn(ie): implicit usage of IE::GPU OpenCL kernels cache --- modules/dnn/src/ie_ngraph.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/modules/dnn/src/ie_ngraph.cpp b/modules/dnn/src/ie_ngraph.cpp index aa3be70..3b87243 100644 --- a/modules/dnn/src/ie_ngraph.cpp +++ b/modules/dnn/src/ie_ngraph.cpp @@ -20,6 +20,9 @@ #include #include +#include "opencv2/core/utils/filesystem.hpp" +#include "opencv2/core/utils/filesystem.private.hpp" + namespace cv { namespace dnn { #ifdef HAVE_DNN_NGRAPH @@ -681,6 +684,23 @@ void InfEngineNgraphNet::initPlugin(InferenceEngine::CNNNetwork& net) InferenceEngine::PluginConfigParams::KEY_CPU_THREADS_NUM, format("%d", getNumThreads()), }}, device_name); #endif +#if INF_ENGINE_VER_MAJOR_GE(INF_ENGINE_RELEASE_2021_2) + if (device_name.find("GPU") == 0) + { +#if OPENCV_HAVE_FILESYSTEM_SUPPORT + std::string cache_path = utils::fs::getCacheDirectory((std::string("dnn_ie_cache_") + device_name).c_str(), "OPENCV_DNN_IE_GPU_CACHE_DIR"); +#else + std::string cache_path = utils::getConfigurationParameterString("OPENCV_DNN_IE_GPU_CACHE_DIR", ""); +#endif + if (!cache_path.empty() && cache_path != "disabled") + { + CV_LOG_INFO(NULL, "OpenCV/nGraph: using GPU kernels cache: " << cache_path); + ie.SetConfig({{ + InferenceEngine::PluginConfigParams::KEY_CACHE_DIR, cache_path, + }}, device_name); + } + } +#endif } std::map config; if (device_name == "MYRIAD") { -- 2.7.4