mirror of
https://github.com/intel/compute-runtime.git
synced 2026-01-05 18:06:32 +08:00
fix: set ParentDevice for subDevice only
Related-To: GSD-6609 Signed-off-by: Baj, Tomasz <tomasz.baj@intel.com>
This commit is contained in:
committed by
Compute-Runtime-Automation
parent
9c7f31620a
commit
28c6dbf8c1
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user