Skip to content

Commit 5f10e53

Browse files
Baj, TomaszCompute-Runtime-Automation
authored andcommitted
fix: set ParentDevice for subDevice only
Related-To: GSD-6609 Signed-off-by: Baj, Tomasz <tomasz.baj@intel.com> Source: 28c6dbf
1 parent e09724c commit 5f10e53

File tree

5 files changed

+21
-13
lines changed

5 files changed

+21
-13
lines changed

opencl/source/cl_device/cl_device.cpp

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,15 @@ ClDevice::ClDevice(Device &device, ClDevice &rootClDevice, Platform *platform) :
4848
auto pClSubDevice = std::make_unique<ClDevice>(*subDevice, rootClDevice, platform);
4949
pClSubDevice->incRefInternal();
5050
pClSubDevice->decRefApi();
51-
52-
auto &deviceInfo = pClSubDevice->deviceInfo;
53-
deviceInfo.parentDevice = this;
54-
deviceInfo.partitionType[0] = CL_DEVICE_PARTITION_BY_AFFINITY_DOMAIN;
55-
deviceInfo.partitionType[1] = CL_DEVICE_AFFINITY_DOMAIN_NUMA;
56-
deviceInfo.partitionType[2] = 0;
51+
pClSubDevice->internalParentDevice = this;
52+
53+
if (!device.getExecutionEnvironment()->isExposingSubDevicesAsDevices()) {
54+
auto &deviceInfo = pClSubDevice->deviceInfo;
55+
deviceInfo.parentDevice = this;
56+
deviceInfo.partitionType[0] = CL_DEVICE_PARTITION_BY_AFFINITY_DOMAIN;
57+
deviceInfo.partitionType[1] = CL_DEVICE_AFFINITY_DOMAIN_NUMA;
58+
deviceInfo.partitionType[2] = 0;
59+
}
5760

5861
subDevices.push_back(std::move(pClSubDevice));
5962
}
@@ -70,33 +73,33 @@ ClDevice::~ClDevice() {
7073
}
7174

7275
void ClDevice::incRefInternal() {
73-
if (deviceInfo.parentDevice == nullptr) {
76+
if (internalParentDevice == nullptr) {
7477
BaseObject<_cl_device_id>::incRefInternal();
7578
return;
7679
}
77-
auto pParentDevice = static_cast<ClDevice *>(deviceInfo.parentDevice);
80+
auto pParentDevice = static_cast<ClDevice *>(internalParentDevice);
7881
pParentDevice->incRefInternal();
7982
}
8083

8184
unique_ptr_if_unused<ClDevice> ClDevice::decRefInternal() {
82-
if (deviceInfo.parentDevice == nullptr) {
85+
if (internalParentDevice == nullptr) {
8386
return BaseObject<_cl_device_id>::decRefInternal();
8487
}
85-
auto pParentDevice = static_cast<ClDevice *>(deviceInfo.parentDevice);
88+
auto pParentDevice = static_cast<ClDevice *>(internalParentDevice);
8689
return pParentDevice->decRefInternal();
8790
}
8891

8992
void ClDevice::retainApi() {
9093
auto parentDeviceId = deviceInfo.parentDevice;
91-
if ((parentDeviceId && !getExecutionEnvironment()->isExposingSubDevicesAsDevices())) {
94+
if (parentDeviceId) {
9295
auto pParentClDevice = static_cast<ClDevice *>(parentDeviceId);
9396
pParentClDevice->incRefInternal();
9497
this->incRefApi();
9598
}
9699
};
97100
unique_ptr_if_unused<ClDevice> ClDevice::releaseApi() {
98101
auto parentDeviceId = deviceInfo.parentDevice;
99-
if (!parentDeviceId || getExecutionEnvironment()->isExposingSubDevicesAsDevices()) {
102+
if (!parentDeviceId) {
100103
return unique_ptr_if_unused<ClDevice>(this, false);
101104
}
102105
auto pParentClDevice = static_cast<ClDevice *>(parentDeviceId);

opencl/source/cl_device/cl_device.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ class ClDevice : public BaseObject<_cl_device_id> {
148148
Device &device;
149149
ClDevice &rootClDevice;
150150
std::vector<std::unique_ptr<ClDevice>> subDevices;
151+
cl_device_id internalParentDevice = nullptr;
151152
cl_platform_id platformId;
152153
std::string name;
153154
std::unique_ptr<DriverInfo> driverInfo;

opencl/test/unit_test/api/cl_create_sub_devices_tests.inl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ TEST_F(ClCreateSubDevicesTests, GivenValidInputWhenCreatingSubDevicesThenDeviceA
136136
TEST_F(ClCreateSubDevicesTests, GivenValidInputAndReturnSubDevicesAsApiDevicesIsSetWhenCreatingSubDevicesThenDeviceApiReferenceCountIsNotIncreased) {
137137
std::unordered_map<std::string, std::string> mockableEnvs = {{"ZE_FLAT_DEVICE_HIERARCHY", "COMPOSITE"}};
138138
VariableBackup<std::unordered_map<std::string, std::string> *> mockableEnvValuesBackup(&IoFunctions::mockableEnvValues, &mockableEnvs);
139-
DebugManager.flags.ReturnSubDevicesAsApiDevices.set(1);
139+
DebugManager.flags.ReturnSubDevicesAsApiDevices.set(true);
140140
setup(2);
141141

142142
EXPECT_EQ(0, device->getSubDevice(0)->getRefApiCount());
@@ -189,6 +189,7 @@ struct ClCreateSubDevicesDeviceInfoTests : ClCreateSubDevicesTests {
189189
};
190190

191191
TEST_F(ClCreateSubDevicesDeviceInfoTests, WhenGettingSubDeviceRelatedDeviceInfoThenCorrectValuesAreSet) {
192+
DebugManager.flags.ReturnSubDevicesAsApiDevices.set(false);
192193
setup(4);
193194

194195
auto &rootDeviceInfo = device->getDeviceInfo();
@@ -260,6 +261,7 @@ TEST_F(ClCreateSubDevicesDeviceInfoTests, GivenRootDeviceWithoutSubDevicesWhenGe
260261
}
261262

262263
TEST_F(ClCreateSubDevicesDeviceInfoTests, WhenGettingSubDeviceRelatedDeviceInfoViaApiThenCorrectValuesAreSet) {
264+
DebugManager.flags.ReturnSubDevicesAsApiDevices.set(false);
263265
setup(4);
264266

265267
size_t partitionPropertiesReturnValueSize = 0;

opencl/test/unit_test/device/sub_device_tests.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ TEST(SubDevicesTest, givenDeviceWithSubDevicesWhenSubDeviceInternalRefCountsAreC
170170
TEST(SubDevicesTest, givenClDeviceWithSubDevicesWhenSubDeviceInternalRefCountsAreChangedThenChangeIsPropagatedToRootDevice) {
171171
DebugManagerStateRestore restorer;
172172
DebugManager.flags.CreateMultipleSubDevices.set(2);
173+
DebugManager.flags.ReturnSubDevicesAsApiDevices.set(false);
173174
VariableBackup<bool> mockDeviceFlagBackup(&MockDevice::createSingleDevice, false);
174175
auto device = std::make_unique<MockClDevice>(MockDevice::createWithNewExecutionEnvironment<MockDevice>(defaultHwInfo.get()));
175176
device->incRefInternal();

shared/test/common/mocks/ult_device_factory.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ UltDeviceFactory::UltDeviceFactory(uint32_t rootDevicesCount, uint32_t subDevice
2929
VariableBackup<decltype(DeviceFactory::createRootDeviceFunc)> createRootDeviceFuncBackup{&DeviceFactory::createRootDeviceFunc};
3030
VariableBackup<decltype(DeviceFactory::createMemoryManagerFunc)> createMemoryManagerFuncBackup{&DeviceFactory::createMemoryManagerFunc};
3131

32+
DebugManager.flags.ReturnSubDevicesAsApiDevices.set(false);
3233
DebugManager.flags.CreateMultipleRootDevices.set(rootDevicesCount);
3334
DebugManager.flags.CreateMultipleSubDevices.set(subDevicesCount);
3435
createRootDeviceFuncBackup = [](ExecutionEnvironment &executionEnvironment, uint32_t rootDeviceIndex) -> std::unique_ptr<Device> {

0 commit comments

Comments
 (0)