Skip to content

Commit 036b8f3

Browse files
fix: Taking into account variable ReturnSubDevicesAsApiDevices
Taking into account variable ReturnSubDevicesAsApiDevices during Retain and Release Device Related-To: NEO-8161 Signed-off-by: Andrzej Koska <[email protected]> Source: 0a3b135
1 parent 70f508d commit 036b8f3

File tree

5 files changed

+73
-2
lines changed

5 files changed

+73
-2
lines changed

opencl/source/cl_device/cl_device.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "shared/source/debug_settings/debug_settings_manager.h"
1212
#include "shared/source/device/device.h"
1313
#include "shared/source/device/sub_device.h"
14+
#include "shared/source/execution_environment/execution_environment.h"
1415
#include "shared/source/execution_environment/root_device_environment.h"
1516
#include "shared/source/helpers/basic_math.h"
1617
#include "shared/source/helpers/gfx_core_helper.h"
@@ -98,15 +99,15 @@ unique_ptr_if_unused<ClDevice> ClDevice::decRefInternal() {
9899

99100
void ClDevice::retainApi() {
100101
auto parentDeviceId = deviceInfo.parentDevice;
101-
if (parentDeviceId) {
102+
if ((parentDeviceId && !getExecutionEnvironment()->isExposingSubDevicesAsDevices())) {
102103
auto pParentClDevice = static_cast<ClDevice *>(parentDeviceId);
103104
pParentClDevice->incRefInternal();
104105
this->incRefApi();
105106
}
106107
};
107108
unique_ptr_if_unused<ClDevice> ClDevice::releaseApi() {
108109
auto parentDeviceId = deviceInfo.parentDevice;
109-
if (!parentDeviceId) {
110+
if (!parentDeviceId || getExecutionEnvironment()->isExposingSubDevicesAsDevices()) {
110111
return unique_ptr_if_unused<ClDevice>(this, false);
111112
}
112113
auto pParentClDevice = static_cast<ClDevice *>(parentDeviceId);

opencl/test/unit_test/api/cl_create_sub_devices_tests.inl

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,24 @@ TEST_F(ClCreateSubDevicesTests, GivenValidInputWhenCreatingSubDevicesThenDeviceA
130130
EXPECT_EQ(2, device->getSubDevice(1)->getRefApiCount());
131131
}
132132

133+
TEST_F(ClCreateSubDevicesTests, GivenValidInputAndReturnSubDevicesAsApiDevicesIsSetWhenCreatingSubDevicesThenDeviceApiReferenceCountIsNotIncreased) {
134+
DebugManager.flags.ReturnSubDevicesAsApiDevices.set(1);
135+
setup(2);
136+
137+
EXPECT_EQ(0, device->getSubDevice(0)->getRefApiCount());
138+
EXPECT_EQ(0, device->getSubDevice(1)->getRefApiCount());
139+
140+
auto retVal = clCreateSubDevices(device.get(), properties, outDevicesCount, outDevices, nullptr);
141+
EXPECT_EQ(CL_SUCCESS, retVal);
142+
EXPECT_EQ(0, device->getSubDevice(0)->getRefApiCount());
143+
EXPECT_EQ(0, device->getSubDevice(1)->getRefApiCount());
144+
145+
retVal = clCreateSubDevices(device.get(), properties, outDevicesCount, outDevices, nullptr);
146+
EXPECT_EQ(CL_SUCCESS, retVal);
147+
EXPECT_EQ(0, device->getSubDevice(0)->getRefApiCount());
148+
EXPECT_EQ(0, device->getSubDevice(1)->getRefApiCount());
149+
}
150+
133151
struct ClCreateSubDevicesDeviceInfoTests : ClCreateSubDevicesTests {
134152
void setup(int numberOfDevices) {
135153
ClCreateSubDevicesTests::setup(numberOfDevices);

opencl/test/unit_test/device/sub_device_tests.cpp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,42 @@ TEST(SubDevicesTest, givenDeviceWithSubDevicesWhenSubDeviceApiRefCountsAreChange
100100
EXPECT_EQ(baseDefaultDeviceInternalRefCount, defaultDevice->getRefInternalCount());
101101
}
102102

103+
TEST(SubDevicesTest, givenDeviceWithSubDevicesAndSubDevicesAsDevicesIsSetWhenSubDeviceApiRefCountsAreChangedThenChangeIsNotPropagatedToRootDevice) {
104+
DebugManagerStateRestore restorer;
105+
DebugManager.flags.CreateMultipleSubDevices.set(2);
106+
VariableBackup<bool> mockDeviceFlagBackup(&MockDevice::createSingleDevice, false);
107+
initPlatform();
108+
platform()->peekExecutionEnvironment()->setExposeSubDevicesAsDevices(1);
109+
auto nonDefaultPlatform = std::make_unique<MockPlatform>(*platform()->peekExecutionEnvironment());
110+
nonDefaultPlatform->initializeWithNewDevices();
111+
auto device = nonDefaultPlatform->getClDevice(0);
112+
auto defaultDevice = platform()->getClDevice(0);
113+
114+
auto subDevice = device->getSubDevice(1);
115+
auto baseDeviceApiRefCount = device->getRefApiCount();
116+
auto baseDeviceInternalRefCount = device->getRefInternalCount();
117+
auto baseSubDeviceApiRefCount = subDevice->getRefApiCount();
118+
auto baseSubDeviceInternalRefCount = subDevice->getRefInternalCount();
119+
auto baseDefaultDeviceApiRefCount = defaultDevice->getRefApiCount();
120+
auto baseDefaultDeviceInternalRefCount = defaultDevice->getRefInternalCount();
121+
122+
subDevice->retainApi();
123+
EXPECT_EQ(baseDeviceApiRefCount, device->getRefApiCount());
124+
EXPECT_EQ(baseDeviceInternalRefCount, device->getRefInternalCount());
125+
EXPECT_EQ(baseSubDeviceApiRefCount, subDevice->getRefApiCount());
126+
EXPECT_EQ(baseSubDeviceInternalRefCount, subDevice->getRefInternalCount());
127+
EXPECT_EQ(baseDefaultDeviceApiRefCount, defaultDevice->getRefApiCount());
128+
EXPECT_EQ(baseDefaultDeviceInternalRefCount, defaultDevice->getRefInternalCount());
129+
130+
subDevice->releaseApi();
131+
EXPECT_EQ(baseDeviceApiRefCount, device->getRefApiCount());
132+
EXPECT_EQ(baseDeviceInternalRefCount, device->getRefInternalCount());
133+
EXPECT_EQ(baseSubDeviceApiRefCount, subDevice->getRefApiCount());
134+
EXPECT_EQ(baseSubDeviceInternalRefCount, subDevice->getRefInternalCount());
135+
EXPECT_EQ(baseDefaultDeviceApiRefCount, defaultDevice->getRefApiCount());
136+
EXPECT_EQ(baseDefaultDeviceInternalRefCount, defaultDevice->getRefInternalCount());
137+
}
138+
103139
TEST(SubDevicesTest, givenDeviceWithSubDevicesWhenSubDeviceInternalRefCountsAreChangedThenChangeIsPropagatedToRootDevice) {
104140
DebugManagerStateRestore restorer;
105141
DebugManager.flags.CreateMultipleSubDevices.set(2);

shared/source/execution_environment/execution_environment.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,10 @@ void ExecutionEnvironment::configureNeoEnvironment() {
330330
if (strcmp(hierarchyModel.c_str(), "FLAT") == 0) {
331331
setExposeSubDevicesAsDevices(true);
332332
}
333+
334+
if (NEO::DebugManager.flags.ReturnSubDevicesAsApiDevices.get() == 1) {
335+
setExposeSubDevicesAsDevices(true);
336+
}
333337
}
334338

335339
bool ExecutionEnvironment::comparePciIdBusNumber(std::unique_ptr<RootDeviceEnvironment> &rootDeviceEnvironment1, std::unique_ptr<RootDeviceEnvironment> &rootDeviceEnvironment2) {

shared/test/unit_test/execution_environment/execution_environment_tests.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,18 @@ TEST(ExecutionEnvironment, givenDefaultConstructorWhenItIsCalledThenExecutionEnv
4141
EXPECT_EQ(0, environment.getRefApiCount());
4242
}
4343

44+
TEST(ExecutionEnvironment, givenDefaultConstructorWhenItIsCalledThenSubDevicesAsDevicesIsFalse) {
45+
ExecutionEnvironment environment;
46+
EXPECT_FALSE(environment.isExposingSubDevicesAsDevices());
47+
}
48+
49+
TEST(ExecutionEnvironment, givenDefaultConstructoWhenItIsCalledAndReturnSubDevicesAsApiDevicesIsSetThenSubDevicesAsDevicesIsTrue) {
50+
DebugManagerStateRestore dbgRestore;
51+
DebugManager.flags.ReturnSubDevicesAsApiDevices.set(1);
52+
ExecutionEnvironment environment;
53+
EXPECT_TRUE(environment.isExposingSubDevicesAsDevices());
54+
}
55+
4456
TEST(ExecutionEnvironment, WhenCreatingDevicesThenThoseDevicesAddRefcountsToExecutionEnvironment) {
4557
auto executionEnvironment = new ExecutionEnvironment();
4658

0 commit comments

Comments
 (0)