Handle multiple GNA devices and modes HW/SW (#2720)
* Introduce Gna2DeviceGetCount * Check for the number of GNA devices * Add Gna2DeviceGetCount() mock
This commit is contained in:
committed by
GitHub
parent
d79263fcd0
commit
6a2c209e58
@@ -132,6 +132,22 @@ uint32_t GNADeviceHelper::createRequestConfig(const uint32_t model_id) {
|
||||
return reqConfId;
|
||||
}
|
||||
|
||||
uint32_t GNADeviceHelper::getNumberOfGnaDevices() {
|
||||
std::unique_lock<std::mutex> lockGnaCalls{ acrossPluginsSync };
|
||||
uint32_t numberOfGnaDevices = 0;
|
||||
auto status = Gna2DeviceGetCount(&numberOfGnaDevices);
|
||||
checkGna2Status(status);
|
||||
return numberOfGnaDevices;
|
||||
}
|
||||
|
||||
uint32_t GNADeviceHelper::selectGnaDevice() {
|
||||
const auto deviceCount = getNumberOfGnaDevices();
|
||||
if (deviceCount != 1) {
|
||||
THROW_GNA_EXCEPTION << "Unsupported number of GNA devices detected = " << deviceCount;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void GNADeviceHelper::checkGna2Status(Gna2Status status, const Gna2Model& gnaModel) {
|
||||
if (!Gna2StatusIsSuccessful(status)) {
|
||||
std::vector<char> gna2StatusBuffer(1024);
|
||||
|
||||
@@ -69,12 +69,13 @@ public:
|
||||
bool isPerformanceMeasuring = false) :
|
||||
isPerformanceMeasuring(isPerformanceMeasuring) {
|
||||
#else
|
||||
explicit GNADeviceHelper(Gna2DeviceVersion gna2HwConsistency = Gna2DeviceVersionSoftwareEmulation,
|
||||
explicit GNADeviceHelper(Gna2DeviceVersion gna2HwConsistency = Gna2DeviceVersionSoftwareEmulation,
|
||||
uint8_t lib_async_n_threads = 1,
|
||||
bool use_openmp = false,
|
||||
bool isPerformanceMeasuring = false) :
|
||||
gna2HwConsistency(gna2HwConsistency),
|
||||
isPerformanceMeasuring(isPerformanceMeasuring) {
|
||||
isPerformanceMeasuring(isPerformanceMeasuring),
|
||||
nGnaDeviceIndex{selectGnaDevice()} {
|
||||
#endif
|
||||
open(lib_async_n_threads);
|
||||
initGnaPerfCounters();
|
||||
@@ -116,6 +117,8 @@ public:
|
||||
#endif
|
||||
void releaseModel(const uint32_t model_id);
|
||||
uint32_t createRequestConfig(const uint32_t model_id);
|
||||
static uint32_t getNumberOfGnaDevices();
|
||||
static uint32_t selectGnaDevice();
|
||||
bool hasGnaHw() const {
|
||||
return Gna2DeviceVersionSoftwareEmulation != detectedGnaDevVersion;
|
||||
}
|
||||
|
||||
@@ -36,8 +36,8 @@ Parameter GNAPlugin::GetMetric(const std::string& name, const std::map<std::stri
|
||||
}
|
||||
|
||||
if (!options.count(KEY_DEVICE_ID)) {
|
||||
if (availableDevices.size() == 1) {
|
||||
return availableDevices[0];
|
||||
if (availableDevices.size() == 1 || availableDevices.size() == 2) {
|
||||
return availableDevices.back(); // detection order is GNA_SW, GNA_HW
|
||||
} else {
|
||||
THROW_GNA_EXCEPTION << "KEY_DEVICE_ID not set in request for FULL_DEVICE_NAME";
|
||||
}
|
||||
|
||||
@@ -60,6 +60,14 @@ GNA2_API Gna2Status Gna2DeviceClose(
|
||||
return Gna2StatusSuccess;
|
||||
}
|
||||
|
||||
GNA2_API Gna2Status Gna2DeviceGetCount(
|
||||
uint32_t* numberOfDevices) {
|
||||
if (numberOfDevices != nullptr) {
|
||||
*numberOfDevices = 1;
|
||||
}
|
||||
return Gna2StatusSuccess;
|
||||
}
|
||||
|
||||
GNA2_API enum Gna2Status Gna2MemoryFree(
|
||||
void * memory) {
|
||||
return Gna2StatusSuccess;
|
||||
|
||||
@@ -69,6 +69,14 @@ GNA2_API Gna2Status Gna2DeviceClose(
|
||||
return Gna2StatusSuccess;
|
||||
}
|
||||
|
||||
GNA2_API Gna2Status Gna2DeviceGetCount(
|
||||
uint32_t * numberOfDevices) {
|
||||
if (numberOfDevices != nullptr) {
|
||||
*numberOfDevices = 1;
|
||||
}
|
||||
return Gna2StatusSuccess;
|
||||
}
|
||||
|
||||
GNA2_API enum Gna2Status Gna2MemoryFree(
|
||||
void * memory) {
|
||||
if (current != nullptr) {
|
||||
|
||||
@@ -102,6 +102,9 @@ class GNACppApi {
|
||||
MOCK_METHOD1(Gna2DeviceClose, Gna2Status (
|
||||
uint32_t deviceIndex));
|
||||
|
||||
MOCK_METHOD1(Gna2DeviceGetCount, Gna2Status (
|
||||
uint32_t * numberOfDevices));
|
||||
|
||||
MOCK_METHOD1(Gna2MemoryFree, Gna2Status (
|
||||
void * memory));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user