[Sysman] Replace normal pointers with smart pointers (11/n)

Replacing normal pointers by smart pointers in memory module
of LO sysman(zesinit).

Related-To: LOCI-2810

Signed-off-by: Singh, Prasoon <prasoon.singh@intel.com>
This commit is contained in:
Singh, Prasoon
2023-04-05 10:30:57 +00:00
committed by Compute-Runtime-Automation
parent d1393e08d3
commit afe99d7dbc
12 changed files with 25 additions and 61 deletions

View File

@@ -42,9 +42,9 @@ ze_result_t LinuxMemoryImp::getState(zes_mem_state_t *pState) {
return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE;
}
OsMemory *OsMemory::create(OsSysman *pOsSysman, ze_bool_t onSubdevice, uint32_t subdeviceId) {
LinuxMemoryImp *pLinuxMemoryImp = new LinuxMemoryImp(pOsSysman, onSubdevice, subdeviceId);
return static_cast<OsMemory *>(pLinuxMemoryImp);
std::unique_ptr<OsMemory> OsMemory::create(OsSysman *pOsSysman, ze_bool_t onSubdevice, uint32_t subdeviceId) {
std::unique_ptr<LinuxMemoryImp> pLinuxMemoryImp = std::make_unique<LinuxMemoryImp>(pOsSysman, onSubdevice, subdeviceId);
return pLinuxMemoryImp;
}
} // namespace Sysman

View File

@@ -69,9 +69,9 @@ ze_result_t LinuxMemoryImp::getState(zes_mem_state_t *pState) {
return ZE_RESULT_SUCCESS;
}
OsMemory *OsMemory::create(OsSysman *pOsSysman, ze_bool_t onSubdevice, uint32_t subdeviceId) {
LinuxMemoryImp *pLinuxMemoryImp = new LinuxMemoryImp(pOsSysman, onSubdevice, subdeviceId);
return static_cast<OsMemory *>(pLinuxMemoryImp);
std::unique_ptr<OsMemory> OsMemory::create(OsSysman *pOsSysman, ze_bool_t onSubdevice, uint32_t subdeviceId) {
std::unique_ptr<LinuxMemoryImp> pLinuxMemoryImp = std::make_unique<LinuxMemoryImp>(pOsSysman, onSubdevice, subdeviceId);
return pLinuxMemoryImp;
}
} // namespace Sysman

View File

@@ -329,9 +329,9 @@ ze_result_t LinuxMemoryImp::getState(zes_mem_state_t *pState) {
return ZE_RESULT_SUCCESS;
}
OsMemory *OsMemory::create(OsSysman *pOsSysman, ze_bool_t onSubdevice, uint32_t subdeviceId) {
LinuxMemoryImp *pLinuxMemoryImp = new LinuxMemoryImp(pOsSysman, onSubdevice, subdeviceId);
return static_cast<OsMemory *>(pLinuxMemoryImp);
std::unique_ptr<OsMemory> OsMemory::create(OsSysman *pOsSysman, ze_bool_t onSubdevice, uint32_t subdeviceId) {
std::unique_ptr<LinuxMemoryImp> pLinuxMemoryImp = std::make_unique<LinuxMemoryImp>(pOsSysman, onSubdevice, subdeviceId);
return pLinuxMemoryImp;
}
} // namespace Sysman

View File

@@ -14,18 +14,12 @@
namespace L0 {
namespace Sysman {
MemoryHandleContext::~MemoryHandleContext() {
for (Memory *pMemory : handleList) {
delete pMemory;
}
}
MemoryHandleContext::~MemoryHandleContext() = default;
void MemoryHandleContext::createHandle(bool onSubdevice, uint32_t subDeviceId) {
Memory *pMemory = new MemoryImp(pOsSysman, onSubdevice, subDeviceId);
std::unique_ptr<Memory> pMemory = std::make_unique<MemoryImp>(pOsSysman, onSubdevice, subDeviceId);
if (pMemory->initSuccess == true) {
handleList.push_back(pMemory);
} else {
delete pMemory;
handleList.push_back(std::move(pMemory));
}
}

View File

@@ -9,6 +9,7 @@
#include "level_zero/api/sysman/zes_handles_struct.h"
#include <level_zero/zes_api.h>
#include <memory>
#include <mutex>
#include <vector>
@@ -39,7 +40,7 @@ struct MemoryHandleContext {
ze_result_t memoryGet(uint32_t *pCount, zes_mem_handle_t *phMemory);
OsSysman *pOsSysman = nullptr;
std::vector<Memory *> handleList = {};
std::vector<std::unique_ptr<Memory>> handleList = {};
private:
void createHandle(bool onSubdevice, uint32_t subDeviceId);

View File

@@ -35,11 +35,7 @@ MemoryImp::MemoryImp(OsSysman *pOsSysman, bool onSubdevice, uint32_t subDeviceId
init();
}
MemoryImp::~MemoryImp() {
if (nullptr != pOsMemory) {
delete pOsMemory;
}
}
MemoryImp::~MemoryImp() = default;
} // namespace Sysman
} // namespace L0

View File

@@ -26,7 +26,7 @@ class MemoryImp : public Memory, NEO::NonCopyableOrMovableClass {
MemoryImp() = default;
void init();
OsMemory *pOsMemory = nullptr;
std::unique_ptr<OsMemory> pOsMemory;
private:
zes_mem_properties_t memoryProperties = {};

View File

@@ -9,6 +9,8 @@
#include <level_zero/zes_api.h>
#include <memory>
namespace L0 {
namespace Sysman {
@@ -19,7 +21,7 @@ class OsMemory {
virtual ze_result_t getBandwidth(zes_mem_bandwidth_t *pBandwidth) = 0;
virtual ze_result_t getState(zes_mem_state_t *pState) = 0;
virtual bool isMemoryModuleSupported() = 0;
static OsMemory *create(OsSysman *pOsSysman, ze_bool_t onSubdevice, uint32_t subdeviceId);
static std::unique_ptr<OsMemory> create(OsSysman *pOsSysman, ze_bool_t onSubdevice, uint32_t subdeviceId);
virtual ~OsMemory() {}
};

View File

@@ -9,9 +9,9 @@
namespace L0 {
namespace Sysman {
OsMemory *OsMemory::create(OsSysman *pOsSysman, ze_bool_t onSubdevice, uint32_t subdeviceId) {
WddmMemoryImp *pWddmMemoryImp = new WddmMemoryImp(pOsSysman, onSubdevice, subdeviceId);
return static_cast<OsMemory *>(pWddmMemoryImp);
std::unique_ptr<OsMemory> OsMemory::create(OsSysman *pOsSysman, ze_bool_t onSubdevice, uint32_t subdeviceId) {
std::unique_ptr<WddmMemoryImp> pWddmMemoryImp = std::make_unique<WddmMemoryImp>(pOsSysman, onSubdevice, subdeviceId);
return pWddmMemoryImp;
}
} // namespace Sysman

View File

@@ -20,9 +20,6 @@ class SysmanDeviceMemoryFixture : public SysmanDeviceFixture {
void SetUp() override {
DebugManager.flags.EnableLocalMemory.set(1);
SysmanDeviceFixture::SetUp();
for (auto handle : pSysmanDeviceImp->pMemoryHandleContext->handleList) {
delete handle;
}
pSysmanDeviceImp->pMemoryHandleContext->handleList.clear();
device = pSysmanDeviceImp;
@@ -36,9 +33,6 @@ class SysmanDeviceMemoryFixture : public SysmanDeviceFixture {
void setLocalSupportedAndReinit(bool supported) {
DebugManager.flags.EnableLocalMemory.set(supported == true ? 1 : 0);
for (auto handle : pSysmanDeviceImp->pMemoryHandleContext->handleList) {
delete handle;
}
pSysmanDeviceImp->pMemoryHandleContext->handleList.clear();
pSysmanDeviceImp->pMemoryHandleContext->init(pOsSysman->getSubDeviceCount());
@@ -136,11 +130,10 @@ TEST_F(SysmanMultiDeviceFixture, GivenValidDevicePointerWhenGettingMemoryPropert
zes_mem_properties_t properties = {};
ze_bool_t isSubdevice = pLinuxSysmanImp->getSubDeviceCount() == 0 ? false : true;
auto subDeviceId = std::max(0u, pLinuxSysmanImp->getSubDeviceCount() - 1);
L0::Sysman::LinuxMemoryImp *pLinuxMemoryImp = new L0::Sysman::LinuxMemoryImp(pOsSysman, isSubdevice, subDeviceId);
std::unique_ptr<L0::Sysman::LinuxMemoryImp> pLinuxMemoryImp = std::make_unique<L0::Sysman::LinuxMemoryImp>(pOsSysman, isSubdevice, subDeviceId);
EXPECT_EQ(ZE_RESULT_SUCCESS, pLinuxMemoryImp->getProperties(&properties));
EXPECT_EQ(properties.subdeviceId, subDeviceId);
EXPECT_EQ(properties.onSubdevice, isSubdevice);
delete pLinuxMemoryImp;
}
} // namespace ult

View File

@@ -27,10 +27,6 @@ class SysmanDeviceMemoryFixture : public SysmanDeviceFixture {
auto &osInterface = pSysmanDeviceImp->getRootDeviceEnvironment().osInterface;
osInterface->setDriverModel(std::make_unique<MockMemoryNeoDrm>(const_cast<NEO::RootDeviceEnvironment &>(pSysmanDeviceImp->getRootDeviceEnvironment())));
for (auto handle : pSysmanDeviceImp->pMemoryHandleContext->handleList) {
delete handle;
}
pSysmanDeviceImp->pMemoryHandleContext->handleList.clear();
getMemoryHandles(0);
}
@@ -43,9 +39,6 @@ class SysmanDeviceMemoryFixture : public SysmanDeviceFixture {
DebugManager.flags.EnableLocalMemory.set(supported == true ? 1 : 0);
for (auto handle : pSysmanDeviceImp->pMemoryHandleContext->handleList) {
delete handle;
}
pSysmanDeviceImp->pMemoryHandleContext->handleList.clear();
pSysmanDeviceImp->pMemoryHandleContext->init(pOsSysman->getSubDeviceCount());
}
@@ -202,11 +195,10 @@ TEST_F(SysmanMultiDeviceFixture, GivenValidDevicePointerWhenGettingMemoryPropert
zes_mem_properties_t properties = {};
ze_bool_t isSubdevice = pLinuxSysmanImp->getSubDeviceCount() == 0 ? false : true;
auto subDeviceId = std::max(0u, pLinuxSysmanImp->getSubDeviceCount() - 1);
L0::Sysman::LinuxMemoryImp *pLinuxMemoryImp = new L0::Sysman::LinuxMemoryImp(pOsSysman, isSubdevice, subDeviceId);
std::unique_ptr<L0::Sysman::LinuxMemoryImp> pLinuxMemoryImp = std::make_unique<L0::Sysman::LinuxMemoryImp>(pOsSysman, isSubdevice, subDeviceId);
EXPECT_EQ(ZE_RESULT_SUCCESS, pLinuxMemoryImp->getProperties(&properties));
EXPECT_EQ(properties.subdeviceId, subDeviceId);
EXPECT_EQ(properties.onSubdevice, isSubdevice);
delete pLinuxMemoryImp;
}
} // namespace ult

View File

@@ -52,9 +52,7 @@ class SysmanDeviceMemoryFixture : public SysmanDeviceFixture {
pLinuxSysmanImp->pFsAccess = pFsAccess.get();
pDrm->setMemoryType(INTEL_HWCONFIG_MEMORY_TYPE_HBM2e);
pDrm->ioctlHelper = static_cast<std::unique_ptr<NEO::IoctlHelper>>(std::make_unique<IoctlHelperPrelim20>(*pDrm));
for (auto handle : pSysmanDeviceImp->pMemoryHandleContext->handleList) {
delete handle;
}
pSysmanDeviceImp->pMemoryHandleContext->handleList.clear();
pmtMapOriginal = pLinuxSysmanImp->mapOfSubDeviceIdToPmtObject;
pLinuxSysmanImp->mapOfSubDeviceIdToPmtObject.clear();
@@ -86,10 +84,6 @@ class SysmanDeviceMemoryFixture : public SysmanDeviceFixture {
void setLocalSupportedAndReinit(bool supported) {
DebugManager.flags.EnableLocalMemory.set(supported == true ? 1 : 0);
for (auto handle : pSysmanDeviceImp->pMemoryHandleContext->handleList) {
delete handle;
}
pSysmanDeviceImp->pMemoryHandleContext->handleList.clear();
pSysmanDeviceImp->pMemoryHandleContext->init(pOsSysman->getSubDeviceCount());
}
@@ -758,10 +752,6 @@ class SysmanMultiDeviceMemoryFixture : public SysmanMultiDeviceFixture {
auto &osInterface = pSysmanDeviceImp->getRootDeviceEnvironment().osInterface;
osInterface->setDriverModel(std::unique_ptr<MockMemoryNeoDrm>(pDrm));
for (auto handle : pSysmanDeviceImp->pMemoryHandleContext->handleList) {
delete handle;
}
pSysmanDeviceImp->pMemoryHandleContext->handleList.clear();
device = pSysmanDeviceImp;
getMemoryHandles(0);
@@ -775,10 +765,6 @@ class SysmanMultiDeviceMemoryFixture : public SysmanMultiDeviceFixture {
void setLocalSupportedAndReinit(bool supported) {
DebugManager.flags.EnableLocalMemory.set(supported == true ? 1 : 0);
for (auto handle : pSysmanDeviceImp->pMemoryHandleContext->handleList) {
delete handle;
}
pSysmanDeviceImp->pMemoryHandleContext->handleList.clear();
pSysmanDeviceImp->pMemoryHandleContext->init(pOsSysman->getSubDeviceCount());
}