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
This commit is contained in:
parent
3c5aefb427
commit
e1428ecf1d
@ -7,6 +7,7 @@
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <cstring>
|
||||
#include <mutex>
|
||||
#include <vector>
|
||||
|
||||
#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<std::mutex> 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<std::mutex> 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<std::mutex> lockGnaCalls{ acrossPluginsSync };
|
||||
#if GNA_LIB_VER == 1
|
||||
gmmSetThreads(n_threads);
|
||||
#else
|
||||
|
@ -6,6 +6,7 @@
|
||||
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include <vector>
|
||||
@ -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<std::mutex> 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}};
|
||||
|
@ -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([&] () {
|
||||
|
@ -0,0 +1,23 @@
|
||||
// Copyright (C) 2020 Intel Corporation
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
||||
#include <behavior/core_threading_tests.hpp>
|
||||
|
||||
namespace {
|
||||
|
||||
Params params[] = {
|
||||
std::tuple<Device, Config>{ CommonTestUtils::DEVICE_GNA, {{ CONFIG_KEY(PERF_COUNT), CONFIG_VALUE(YES) }}},
|
||||
std::tuple<Device, Config>{ CommonTestUtils::DEVICE_HETERO, {{ "TARGET_FALLBACK", CommonTestUtils::DEVICE_GNA }}},
|
||||
std::tuple<Device, Config>{ 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);
|
Loading…
Reference in New Issue
Block a user