Defer Sysman Scheduler and Memory Initialization

With this change, init for sysman Scheduler/Memory API would
not be done during zeInit.
init and thereby Scheduler/Memory API handle creation would be done
only when user explicitly requests to enumerate handles
using zesDeviceEnumSchedulers/zesDeviceEnumMemory.

Related-To: LOCI-3127

Signed-off-by: Kulkarni, Ashwin Kumar <ashwin.kumar.kulkarni@intel.com>
This commit is contained in:
Kulkarni, Ashwin Kumar
2022-07-26 09:31:22 +00:00
committed by Compute-Runtime-Automation
parent 4967e053b8
commit 1898a82317
10 changed files with 21 additions and 10 deletions

View File

@@ -10,6 +10,7 @@
#include "level_zero/core/source/device/device.h"
#include "level_zero/tools/source/sysman/memory/memory_imp.h"
#include "level_zero/tools/source/sysman/os_sysman.h"
namespace L0 {
@@ -36,6 +37,9 @@ ze_result_t MemoryHandleContext::init(std::vector<ze_device_handle_t> &deviceHan
}
ze_result_t MemoryHandleContext::memoryGet(uint32_t *pCount, zes_mem_handle_t *phMemory) {
std::call_once(initMemoryOnce, [this]() {
this->init(pOsSysman->getDeviceHandles());
});
uint32_t handleListSize = static_cast<uint32_t>(handleList.size());
uint32_t numToCopy = std::min(*pCount, handleListSize);
if (0 == *pCount || *pCount > handleListSize) {

View File

@@ -9,6 +9,7 @@
#include "level_zero/core/source/device/device.h"
#include <level_zero/zes_api.h>
#include <mutex>
#include <vector>
struct _zes_mem_handle_t {
@@ -46,6 +47,7 @@ struct MemoryHandleContext {
private:
void createHandle(ze_device_handle_t deviceHandle);
std::once_flag initMemoryOnce;
};
} // namespace L0

View File

@@ -8,6 +8,7 @@
#include "shared/source/helpers/basic_math.h"
#include "shared/source/helpers/debug_helpers.h"
#include "level_zero/tools/source/sysman/os_sysman.h"
#include "level_zero/tools/source/sysman/scheduler/scheduler_imp.h"
class OsScheduler;
@@ -39,6 +40,9 @@ void SchedulerHandleContext::init(std::vector<ze_device_handle_t> &deviceHandles
}
ze_result_t SchedulerHandleContext::schedulerGet(uint32_t *pCount, zes_sched_handle_t *phScheduler) {
std::call_once(initSchedulerOnce, [this]() {
this->init(pOsSysman->getDeviceHandles());
});
uint32_t handleListSize = static_cast<uint32_t>(handleList.size());
uint32_t numToCopy = std::min(*pCount, handleListSize);
if (0 == *pCount || *pCount > handleListSize) {

View File

@@ -12,6 +12,7 @@
#include <level_zero/zes_api.h>
#include <map>
#include <mutex>
#include <string>
#include <vector>
@@ -51,6 +52,7 @@ struct SchedulerHandleContext : NEO::NonCopyableOrMovableClass {
private:
void createHandle(zes_engine_type_flag_t engineType, std::vector<std::string> &listOfEngines, ze_device_handle_t deviceHandle);
std::once_flag initSchedulerOnce;
};
} // namespace L0

View File

@@ -100,12 +100,6 @@ ze_result_t SysmanDeviceImp::init() {
if (pEngineHandleContext) {
pEngineHandleContext->init();
}
if (pSchedulerHandleContext) {
pSchedulerHandleContext->init(deviceHandles);
}
if (pMemoryHandleContext) {
pMemoryHandleContext->init(deviceHandles);
}
return result;
}

View File

@@ -46,7 +46,7 @@ class SysmanDeviceMemoryFixture : public SysmanDeviceFixture {
deviceHandles.resize(subDeviceCount, nullptr);
Device::fromHandle(device->toHandle())->getSubDevices(&subDeviceCount, deviceHandles.data());
}
pSysmanDeviceImp->pMemoryHandleContext->init(deviceHandles);
getMemoryHandles(0);
}
void TearDown() override {

View File

@@ -58,7 +58,7 @@ class SysmanDeviceMemoryFixture : public SysmanDeviceFixture {
deviceHandles.resize(subDeviceCount, nullptr);
Device::fromHandle(device->toHandle())->getSubDevices(&subDeviceCount, deviceHandles.data());
}
pSysmanDeviceImp->pMemoryHandleContext->init(deviceHandles);
getMemoryHandles(0);
}
void TearDown() override {

View File

@@ -56,7 +56,7 @@ class SysmanDeviceMemoryFixture : public SysmanDeviceFixture {
deviceHandles.resize(subDeviceCount, nullptr);
Device::fromHandle(device->toHandle())->getSubDevices(&subDeviceCount, deviceHandles.data());
}
pSysmanDeviceImp->pMemoryHandleContext->init(deviceHandles);
getMemoryHandles(0);
}
void TearDown() override {

View File

@@ -43,6 +43,11 @@ TEST_F(SysmanDevicePowerFixture, GivenComponentCountZeroWhenEnumeratingPowerDoma
EXPECT_EQ(zesDeviceEnumPowerDomains(device->toHandle(), &count, nullptr), ZE_RESULT_SUCCESS);
EXPECT_EQ(count, powerHandleComponentCount);
}
TEST_F(SysmanDeviceFixture, GivenComponentCountZeroWhenEnumeratingPowerDomainsWhenhwmonInterfaceDoesNotExistThenZeroCountIsReturnedAndVerifySysmanPowerGetCallSucceeds) {
uint32_t count = 0;
EXPECT_EQ(zesDeviceEnumPowerDomains(device->toHandle(), &count, nullptr), ZE_RESULT_SUCCESS);
EXPECT_EQ(count, 0u);
}
TEST_F(SysmanDevicePowerFixture, GivenInvalidComponentCountWhenEnumeratingPowerDomainsWhenhwmonInterfaceExistsThenValidCountIsReturnedAndVerifySysmanPowerGetCallSucceeds) {
uint32_t count = 0;

View File

@@ -84,7 +84,7 @@ class SysmanDeviceSchedulerFixture : public SysmanDeviceFixture {
deviceHandles.resize(subDeviceCount, nullptr);
Device::fromHandle(device->toHandle())->getSubDevices(&subDeviceCount, deviceHandles.data());
}
pSysmanDeviceImp->pSchedulerHandleContext->init(deviceHandles);
getSchedHandles(0);
}
void TearDown() override {