From: Krzysztof Bruniecki Date: Mon, 19 Oct 2020 09:21:01 +0000 (+0200) Subject: Improve GNA MT sychronization (#2553) X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=e1428ecf1d74d6b1fb88c610a49b39b7eba5f2f8;p=platform%2Fupstream%2Fdldt.git Improve GNA MT sychronization (#2553) * Sync GNA lib calls to avoid multi threads and plugins crash * Remove TODO * Enable sync for GNA1 * Fix GNA1 sync * Add core_threading_tests to GNA Plugin to address story 31709 * Disable and change test description --- diff --git a/inference-engine/src/gna_plugin/gna_device.cpp b/inference-engine/src/gna_plugin/gna_device.cpp index 97d4026..ce15f2b 100644 --- a/inference-engine/src/gna_plugin/gna_device.cpp +++ b/inference-engine/src/gna_plugin/gna_device.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include #if GNA_LIB_VER == 2 @@ -24,6 +25,8 @@ #include "details/ie_exception.hpp" #include "gna_plugin_log.hpp" +std::mutex GNADeviceHelper::acrossPluginsSync{}; + uint8_t* GNADeviceHelper::alloc(uint32_t size_requested, uint32_t *size_granted) { void * memPtr = nullptr; #if GNA_LIB_VER == 1 @@ -62,6 +65,7 @@ uint32_t GNADeviceHelper::propagate(const intel_nnet_type_t *pNeuralNetwork, return reqId; } #else + void GNADeviceHelper::setUpActiveList(const uint32_t requestConfigId, uint32_t layerIndex, uint32_t* ptr_active_indices, uint32_t num_active_indices) { const auto status = Gna2RequestConfigEnableActiveList(requestConfigId, layerIndex, num_active_indices, ptr_active_indices); checkGna2Status(status); @@ -363,6 +367,7 @@ void GNADeviceHelper::checkStatus() const { #endif void GNADeviceHelper::open(uint8_t n_threads) { + std::unique_lock lockGnaCalls{ acrossPluginsSync }; #if GNA_LIB_VER == 1 nGNAHandle = GNADeviceOpenSetThreads(&nGNAStatus, n_threads); checkStatus(); @@ -379,6 +384,7 @@ void GNADeviceHelper::open(uint8_t n_threads) { } void GNADeviceHelper::close() { + std::unique_lock lockGnaCalls{ acrossPluginsSync }; #if GNA_LIB_VER == 1 GNADeviceClose(nGNAHandle); nGNAHandle = 0; @@ -398,6 +404,7 @@ void GNADeviceHelper::close() { } void GNADeviceHelper::setOMPThreads(uint8_t const n_threads) { + std::unique_lock lockGnaCalls{ acrossPluginsSync }; #if GNA_LIB_VER == 1 gmmSetThreads(n_threads); #else diff --git a/inference-engine/src/gna_plugin/gna_device.hpp b/inference-engine/src/gna_plugin/gna_device.hpp index 7b35f3c..0f71772 100644 --- a/inference-engine/src/gna_plugin/gna_device.hpp +++ b/inference-engine/src/gna_plugin/gna_device.hpp @@ -6,6 +6,7 @@ #include #include +#include #include #include #include @@ -37,6 +38,7 @@ enum GnaWaitStatus : int { * holds gna - style handle in RAII way */ class GNADeviceHelper { + static std::mutex acrossPluginsSync; #if GNA_LIB_VER == 1 intel_gna_status_t nGNAStatus = GNA_NOERROR; intel_gna_handle_t nGNAHandle = 0; @@ -168,6 +170,7 @@ public: void setOMPThreads(uint8_t const n_threads); void initGnaPerfCounters() { + std::unique_lock lockGnaCalls{ acrossPluginsSync }; #if GNA_LIB_VER == 1 nGNAPerfResults = {{0, 0, 0, 0, 0, 0, 0}, {0, 0}, {0, 0, 0}, {0, 0}}; nGNAPerfResultsTotal = {{0, 0, 0, 0, 0, 0, 0}, {0, 0}, {0, 0, 0}, {0, 0}}; diff --git a/inference-engine/tests/functional/inference_engine/core_threading_tests.cpp b/inference-engine/tests/functional/inference_engine/core_threading_tests.cpp index 576f112..2271ddd 100644 --- a/inference-engine/tests/functional/inference_engine/core_threading_tests.cpp +++ b/inference-engine/tests/functional/inference_engine/core_threading_tests.cpp @@ -117,7 +117,7 @@ TEST_F(CoreThreadingTests, RegisterPlugins) { } // tested function: GetAvailableDevices, UnregisterPlugin -// TODO: some plugins initialization (e.g. GNA) failed during such stress-test scenario +// TODO: some initialization (e.g. thread/dlopen) sporadically fails during such stress-test scenario TEST_F(CoreThreadingTests, DISABLED_GetAvailableDevices) { InferenceEngine::Core ie; runParallel([&] () { diff --git a/inference-engine/tests/functional/plugin/gna/shared_tests_instances/behavior/core_threading_tests.cpp b/inference-engine/tests/functional/plugin/gna/shared_tests_instances/behavior/core_threading_tests.cpp new file mode 100644 index 0000000..139bd9f --- /dev/null +++ b/inference-engine/tests/functional/plugin/gna/shared_tests_instances/behavior/core_threading_tests.cpp @@ -0,0 +1,23 @@ +// Copyright (C) 2020 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include + +namespace { + +Params params[] = { + std::tuple{ CommonTestUtils::DEVICE_GNA, {{ CONFIG_KEY(PERF_COUNT), CONFIG_VALUE(YES) }}}, + std::tuple{ CommonTestUtils::DEVICE_HETERO, {{ "TARGET_FALLBACK", CommonTestUtils::DEVICE_GNA }}}, + std::tuple{ CommonTestUtils::DEVICE_MULTI, {{ MULTI_CONFIG_KEY(DEVICE_PRIORITIES), CommonTestUtils::DEVICE_GNA }}}, +}; + +} // namespace + +INSTANTIATE_TEST_CASE_P(GNA, CoreThreadingTests, testing::ValuesIn(params), CoreThreadingTests::getTestCaseName); + +INSTANTIATE_TEST_CASE_P(DISABLED_GNA, CoreThreadingTestsWithIterations, + testing::Combine(testing::ValuesIn(params), + testing::Values(2), + testing::Values(2)), + CoreThreadingTestsWithIterations::getTestCaseName);