fix: set ParentDevice for subDevice only

Related-To: GSD-6609

Signed-off-by: Baj, Tomasz <tomasz.baj@intel.com>
This commit is contained in:
Baj, Tomasz 2023-10-30 16:06:20 +00:00 committed by Compute-Runtime-Automation
parent 9c7f31620a
commit 28c6dbf8c1
5 changed files with 20 additions and 12 deletions

View File

@ -48,12 +48,15 @@ ClDevice::ClDevice(Device &device, ClDevice &rootClDevice, Platform *platform) :
auto pClSubDevice = std::make_unique<ClDevice>(*subDevice, rootClDevice, platform);
pClSubDevice->incRefInternal();
pClSubDevice->decRefApi();
pClSubDevice->internalParentDevice = this;
auto &deviceInfo = pClSubDevice->deviceInfo;
deviceInfo.parentDevice = this;
deviceInfo.partitionType[0] = CL_DEVICE_PARTITION_BY_AFFINITY_DOMAIN;
deviceInfo.partitionType[1] = CL_DEVICE_AFFINITY_DOMAIN_NUMA;
deviceInfo.partitionType[2] = 0;
if (!device.getExecutionEnvironment()->isExposingSubDevicesAsDevices()) {
auto &deviceInfo = pClSubDevice->deviceInfo;
deviceInfo.parentDevice = this;
deviceInfo.partitionType[0] = CL_DEVICE_PARTITION_BY_AFFINITY_DOMAIN;
deviceInfo.partitionType[1] = CL_DEVICE_AFFINITY_DOMAIN_NUMA;
deviceInfo.partitionType[2] = 0;
}
subDevices.push_back(std::move(pClSubDevice));
}
@ -70,25 +73,25 @@ ClDevice::~ClDevice() {
}
void ClDevice::incRefInternal() {
if (deviceInfo.parentDevice == nullptr) {
if (internalParentDevice == nullptr) {
BaseObject<_cl_device_id>::incRefInternal();
return;
}
auto pParentDevice = static_cast<ClDevice *>(deviceInfo.parentDevice);
auto pParentDevice = static_cast<ClDevice *>(internalParentDevice);
pParentDevice->incRefInternal();
}
unique_ptr_if_unused<ClDevice> ClDevice::decRefInternal() {
if (deviceInfo.parentDevice == nullptr) {
if (internalParentDevice == nullptr) {
return BaseObject<_cl_device_id>::decRefInternal();
}
auto pParentDevice = static_cast<ClDevice *>(deviceInfo.parentDevice);
auto pParentDevice = static_cast<ClDevice *>(internalParentDevice);
return pParentDevice->decRefInternal();
}
void ClDevice::retainApi() {
auto parentDeviceId = deviceInfo.parentDevice;
if ((parentDeviceId && !getExecutionEnvironment()->isExposingSubDevicesAsDevices())) {
if (parentDeviceId) {
auto pParentClDevice = static_cast<ClDevice *>(parentDeviceId);
pParentClDevice->incRefInternal();
this->incRefApi();
@ -96,7 +99,7 @@ void ClDevice::retainApi() {
};
unique_ptr_if_unused<ClDevice> ClDevice::releaseApi() {
auto parentDeviceId = deviceInfo.parentDevice;
if (!parentDeviceId || getExecutionEnvironment()->isExposingSubDevicesAsDevices()) {
if (!parentDeviceId) {
return unique_ptr_if_unused<ClDevice>(this, false);
}
auto pParentClDevice = static_cast<ClDevice *>(parentDeviceId);

View File

@ -148,6 +148,7 @@ class ClDevice : public BaseObject<_cl_device_id> {
Device &device;
ClDevice &rootClDevice;
std::vector<std::unique_ptr<ClDevice>> subDevices;
cl_device_id internalParentDevice = nullptr;
cl_platform_id platformId;
std::string name;
std::unique_ptr<DriverInfo> driverInfo;

View File

@ -136,7 +136,7 @@ TEST_F(ClCreateSubDevicesTests, GivenValidInputWhenCreatingSubDevicesThenDeviceA
TEST_F(ClCreateSubDevicesTests, GivenValidInputAndReturnSubDevicesAsApiDevicesIsSetWhenCreatingSubDevicesThenDeviceApiReferenceCountIsNotIncreased) {
std::unordered_map<std::string, std::string> mockableEnvs = {{"ZE_FLAT_DEVICE_HIERARCHY", "COMPOSITE"}};
VariableBackup<std::unordered_map<std::string, std::string> *> mockableEnvValuesBackup(&IoFunctions::mockableEnvValues, &mockableEnvs);
DebugManager.flags.ReturnSubDevicesAsApiDevices.set(1);
DebugManager.flags.ReturnSubDevicesAsApiDevices.set(true);
setup(2);
EXPECT_EQ(0, device->getSubDevice(0)->getRefApiCount());
@ -189,6 +189,7 @@ struct ClCreateSubDevicesDeviceInfoTests : ClCreateSubDevicesTests {
};
TEST_F(ClCreateSubDevicesDeviceInfoTests, WhenGettingSubDeviceRelatedDeviceInfoThenCorrectValuesAreSet) {
DebugManager.flags.ReturnSubDevicesAsApiDevices.set(false);
setup(4);
auto &rootDeviceInfo = device->getDeviceInfo();
@ -260,6 +261,7 @@ TEST_F(ClCreateSubDevicesDeviceInfoTests, GivenRootDeviceWithoutSubDevicesWhenGe
}
TEST_F(ClCreateSubDevicesDeviceInfoTests, WhenGettingSubDeviceRelatedDeviceInfoViaApiThenCorrectValuesAreSet) {
DebugManager.flags.ReturnSubDevicesAsApiDevices.set(false);
setup(4);
size_t partitionPropertiesReturnValueSize = 0;

View File

@ -170,6 +170,7 @@ TEST(SubDevicesTest, givenDeviceWithSubDevicesWhenSubDeviceInternalRefCountsAreC
TEST(SubDevicesTest, givenClDeviceWithSubDevicesWhenSubDeviceInternalRefCountsAreChangedThenChangeIsPropagatedToRootDevice) {
DebugManagerStateRestore restorer;
DebugManager.flags.CreateMultipleSubDevices.set(2);
DebugManager.flags.ReturnSubDevicesAsApiDevices.set(false);
VariableBackup<bool> mockDeviceFlagBackup(&MockDevice::createSingleDevice, false);
auto device = std::make_unique<MockClDevice>(MockDevice::createWithNewExecutionEnvironment<MockDevice>(defaultHwInfo.get()));
device->incRefInternal();

View File

@ -29,6 +29,7 @@ UltDeviceFactory::UltDeviceFactory(uint32_t rootDevicesCount, uint32_t subDevice
VariableBackup<decltype(DeviceFactory::createRootDeviceFunc)> createRootDeviceFuncBackup{&DeviceFactory::createRootDeviceFunc};
VariableBackup<decltype(DeviceFactory::createMemoryManagerFunc)> createMemoryManagerFuncBackup{&DeviceFactory::createMemoryManagerFunc};
DebugManager.flags.ReturnSubDevicesAsApiDevices.set(false);
DebugManager.flags.CreateMultipleRootDevices.set(rootDevicesCount);
DebugManager.flags.CreateMultipleSubDevices.set(subDevicesCount);
createRootDeviceFuncBackup = [](ExecutionEnvironment &executionEnvironment, uint32_t rootDeviceIndex) -> std::unique_ptr<Device> {