Skip to content

Commit 581805c

Browse files
Move OsContext id setting to constructor.
Change-Id: I1b809befc02536257800e3667307b8deabd5c95d
1 parent 8e33ec0 commit 581805c

15 files changed

+39
-27
lines changed

runtime/device/device.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ bool Device::createDeviceImpl(const HardwareInfo *pHwInfo, Device &outDevice) {
131131
}
132132
executionEnvironment->initializeMemoryManager(outDevice.getEnabled64kbPages(), outDevice.getHardwareCapabilities().localMemorySupported, outDevice.getDeviceIndex());
133133

134-
outDevice.osContext = new OsContext(executionEnvironment->osInterface.get());
134+
outDevice.osContext = new OsContext(executionEnvironment->osInterface.get(), outDevice.getDeviceIndex());
135135
executionEnvironment->memoryManager->registerOsContext(outDevice.osContext);
136136

137137
outDevice.commandStreamReceiver = executionEnvironment->commandStreamReceivers[outDevice.getDeviceIndex()].get();

runtime/memory_manager/memory_manager.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -387,9 +387,12 @@ RequirementsStatus MemoryManager::checkAllocationsForOverlapping(AllocationRequi
387387
}
388388

389389
void MemoryManager::registerOsContext(OsContext *contextToRegister) {
390+
auto contextId = contextToRegister->getContextId();
391+
if (contextId + 1 > registeredOsContexts.size()) {
392+
registeredOsContexts.resize(contextId + 1);
393+
}
390394
contextToRegister->incRefInternal();
391-
contextToRegister->setContextId(static_cast<uint32_t>(registeredOsContexts.size()));
392-
registeredOsContexts.push_back(contextToRegister);
395+
registeredOsContexts[contextToRegister->getContextId()] = contextToRegister;
393396
}
394397

395398
bool MemoryManager::getAllocationData(AllocationData &allocationData, bool allocateMemory, const void *hostPtr, size_t size, GraphicsAllocation::AllocationType type) {

runtime/os_interface/linux/os_context_linux.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
namespace OCLRT {
2626
class OsContext::OsContextImpl {};
27-
OsContext::OsContext(OSInterface *osInterface) {
27+
OsContext::OsContext(OSInterface *osInterface, uint32_t contextId) : contextId(contextId) {
2828
osContextImpl = std::make_unique<OsContext::OsContextImpl>();
2929
}
3030

runtime/os_interface/os_context.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,12 @@ class OSInterface;
2929
class OsContext : public ReferenceTrackedObject<OsContext> {
3030
public:
3131
class OsContextImpl;
32-
OsContext(OSInterface *osInterface);
32+
OsContext(OSInterface *osInterface, uint32_t contextId);
3333
~OsContext() override;
3434
OsContextImpl *get() const {
3535
return osContextImpl.get();
3636
};
3737

38-
void setContextId(uint32_t inputContextId) { contextId = inputContextId; }
3938
uint32_t getContextId() { return contextId; }
4039

4140
protected:

runtime/os_interface/windows/os_context_win.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ void OsContextWin::resetMonitoredFenceParams(D3DKMT_HANDLE &handle, uint64_t *cp
5353
monitoredFence.gpuAddress = gpuAddress;
5454
}
5555

56-
OsContext::OsContext(OSInterface *osInterface) {
56+
OsContext::OsContext(OSInterface *osInterface, uint32_t contextId) : contextId(contextId) {
5757
if (osInterface) {
5858
osContextImpl = std::make_unique<OsContextWin>(*osInterface->get()->getWddm());
5959
}

unit_tests/command_stream/command_stream_receiver_with_aub_dump_tests.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ HWTEST_P(CommandStreamReceiverWithAubDumpTest, givenCommandStreamReceiverWithAub
147147
BatchBuffer batchBuffer{cs.getGraphicsAllocation(), 0, 0, nullptr, false, false, QueueThrottle::MEDIUM, cs.getUsed(), &cs};
148148
auto engineType = OCLRT::ENGINE_RCS;
149149

150-
OsContext osContext(nullptr);
150+
OsContext osContext(nullptr, 0u);
151151

152152
ResidencyContainer allocationsForResidency;
153153
FlushStamp flushStamp = csrWithAubDump->flush(batchBuffer, engineType, &allocationsForResidency, osContext);
@@ -190,7 +190,7 @@ HWTEST_P(CommandStreamReceiverWithAubDumpTest, givenCommandStreamReceiverWithAub
190190
ASSERT_NE(nullptr, gfxAllocation);
191191

192192
ResidencyContainer allocationsForResidency = {gfxAllocation};
193-
OsContext osContext(nullptr);
193+
OsContext osContext(nullptr, 0u);
194194
csrWithAubDump->processResidency(&allocationsForResidency, osContext);
195195

196196
EXPECT_TRUE(csrWithAubDump->processResidencyParameterization.wasCalled);

unit_tests/memory_manager/memory_manager_tests.cpp

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1825,23 +1825,33 @@ TEST(GraphicsAllocation, givenSharedHandleBasedConstructorWhenGraphicsAllocation
18251825
}
18261826

18271827
TEST(ResidencyDataTest, givenOsContextWhenItIsRegisteredToMemoryManagerThenRefCountIncreases) {
1828-
auto osContext = new OsContext(nullptr);
1828+
auto osContext = new OsContext(nullptr, 0u);
18291829
OsAgnosticMemoryManager memoryManager;
18301830
memoryManager.registerOsContext(osContext);
18311831
EXPECT_EQ(1u, memoryManager.getOsContextCount());
18321832
EXPECT_EQ(1, osContext->getRefInternalCount());
18331833
}
18341834

1835+
TEST(ResidencyDataTest, givenTwoOsContextsWhenTheyAreRegistredFromHigherToLowerThenProperSizeIsReturned) {
1836+
auto osContext2 = new OsContext(nullptr, 1u);
1837+
auto osContext = new OsContext(nullptr, 0u);
1838+
OsAgnosticMemoryManager memoryManager;
1839+
memoryManager.registerOsContext(osContext2);
1840+
memoryManager.registerOsContext(osContext);
1841+
EXPECT_EQ(2u, memoryManager.getOsContextCount());
1842+
EXPECT_EQ(1, osContext->getRefInternalCount());
1843+
EXPECT_EQ(1, osContext2->getRefInternalCount());
1844+
}
1845+
18351846
TEST(ResidencyDataTest, givenResidencyDataWhenUpdateCompletionDataIsCalledThenItIsProperlyUpdated) {
18361847
struct mockResidencyData : public ResidencyData {
18371848
using ResidencyData::completionData;
18381849
};
18391850

18401851
mockResidencyData residency;
18411852

1842-
OsContext osContext(nullptr);
1843-
OsContext osContext2(nullptr);
1844-
osContext2.setContextId(1u);
1853+
OsContext osContext(nullptr, 0u);
1854+
OsContext osContext2(nullptr, 1u);
18451855

18461856
auto lastFenceValue = 45llu;
18471857
auto lastFenceValue2 = 23llu;

unit_tests/os_interface/linux/drm_command_stream_tests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class DrmCommandStreamFixture {
5757
const int mockFd = 33;
5858

5959
void SetUp() {
60-
osContext = std::make_unique<OsContext>(nullptr);
60+
osContext = std::make_unique<OsContext>(nullptr, 0u);
6161
this->dbgState = new DebugManagerStateRestore();
6262
//make sure this is disabled, we don't want test this now
6363
DebugManager.flags.EnableForcePin.set(false);

unit_tests/os_interface/linux/os_interface_linux_tests.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ TEST(OsInterfaceTest, GivenLinuxOsInterfaceWhenDeviceHandleQueriedthenZeroIsRetu
3737

3838
TEST(OsContextTest, WhenOsContextIsCreatedThenImplIsAvailable) {
3939
OSInterface osInterface;
40-
auto osContext = std::make_unique<OsContext>(&osInterface);
40+
auto osContext = std::make_unique<OsContext>(&osInterface, 0u);
4141
EXPECT_NE(nullptr, osContext->get());
4242
}
43-
} // namespace OCLRT
43+
} // namespace OCLRT

unit_tests/os_interface/windows/device_command_stream_tests.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ TEST(WddmPreemptionHeaderTests, givenWddmCommandStreamReceiverWhenPreemptionIsOf
279279
LinearStream cs(commandBuffer);
280280

281281
BatchBuffer batchBuffer{cs.getGraphicsAllocation(), 0, 0, nullptr, false, false, QueueThrottle::MEDIUM, cs.getUsed(), &cs};
282-
OsContext *osContext = new OsContext(executionEnvironment.osInterface.get());
282+
OsContext *osContext = new OsContext(executionEnvironment.osInterface.get(), 0u);
283283
osContext->incRefInternal();
284284
executionEnvironment.commandStreamReceivers[0u]->flush(batchBuffer, EngineType::ENGINE_RCS, &executionEnvironment.commandStreamReceivers[0u]->getResidencyAllocations(), *osContext);
285285
auto commandHeader = wddm->submitResult.commandHeaderSubmitted;
@@ -306,7 +306,7 @@ TEST(WddmPreemptionHeaderTests, givenWddmCommandStreamReceiverWhenPreemptionIsOn
306306
LinearStream cs(commandBuffer);
307307

308308
BatchBuffer batchBuffer{cs.getGraphicsAllocation(), 0, 0, nullptr, false, false, QueueThrottle::MEDIUM, cs.getUsed(), &cs};
309-
OsContext *osContext = new OsContext(executionEnvironment.osInterface.get());
309+
OsContext *osContext = new OsContext(executionEnvironment.osInterface.get(), 0u);
310310
osContext->incRefInternal();
311311
executionEnvironment.commandStreamReceivers[0u]->flush(batchBuffer, EngineType::ENGINE_RCS, &executionEnvironment.commandStreamReceivers[0u]->getResidencyAllocations(), *osContext);
312312
auto commandHeader = wddm->submitResult.commandHeaderSubmitted;

unit_tests/os_interface/windows/os_interface_win_tests.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,21 +44,21 @@ TEST(OsContextTest, givenWddmWhenCreateOsContextBeforeInitWddmThenOsContextIsNot
4444
auto wddm = new WddmMock;
4545
OSInterface osInterface;
4646
osInterface.get()->setWddm(wddm);
47-
EXPECT_THROW(auto osContext = std::make_unique<OsContext>(&osInterface), std::exception);
47+
EXPECT_THROW(auto osContext = std::make_unique<OsContext>(&osInterface, 0u), std::exception);
4848
}
4949

5050
TEST(OsContextTest, givenWddmWhenCreateOsContextAfterInitWddmThenOsContextIsInitialized) {
5151
auto wddm = new WddmMock;
5252
OSInterface osInterface;
5353
osInterface.get()->setWddm(wddm);
5454
wddm->init();
55-
auto osContext = std::make_unique<OsContext>(&osInterface);
55+
auto osContext = std::make_unique<OsContext>(&osInterface, 0u);
5656
EXPECT_NE(nullptr, osContext->get());
5757
EXPECT_TRUE(osContext->get()->isInitialized());
5858
EXPECT_EQ(osContext->get()->getWddm(), wddm);
5959
}
6060

6161
TEST(OsContextTest, whenCreateOsContextWithoutOsInterfaceThenOsContextImplIsNotAvailable) {
62-
auto osContext = std::make_unique<OsContext>(nullptr);
62+
auto osContext = std::make_unique<OsContext>(nullptr, 0u);
6363
EXPECT_EQ(nullptr, osContext->get());
6464
}

unit_tests/os_interface/windows/wddm23_tests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ struct Wddm23TestsWithoutWddmInit : public ::testing::Test, GdiDllFixture, publi
4949

5050
void init() {
5151
EXPECT_TRUE(wddm->init());
52-
osContext = std::make_unique<OsContext>(osInterface.get());
52+
osContext = std::make_unique<OsContext>(osInterface.get(), 0u);
5353
osContextWin = osContext->get();
5454
}
5555

unit_tests/os_interface/windows/wddm_fixture.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ struct WddmFixture : public GmmEnvironmentFixture {
4141
gdi = new MockGdi();
4242
wddm->gdi.reset(gdi);
4343
wddm->init();
44-
osContext = std::make_unique<OsContext>(osInterface.get());
44+
osContext = std::make_unique<OsContext>(osInterface.get(), 0u);
4545
osContextWin = osContext->get();
4646
ASSERT_TRUE(wddm->isInitialized());
4747
}
@@ -69,7 +69,7 @@ struct WddmFixtureWithMockGdiDll : public GmmEnvironmentFixture, public GdiDllFi
6969

7070
void init() {
7171
EXPECT_TRUE(wddm->init());
72-
osContext = std::make_unique<OsContext>(osInterface.get());
72+
osContext = std::make_unique<OsContext>(osInterface.get(), 0u);
7373
osContextWin = osContext->get();
7474
ASSERT_TRUE(wddm->isInitialized());
7575
}

unit_tests/os_interface/windows/wddm_memory_manager_tests.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ class MockWddmMemoryManagerFixture : public GmmEnvironmentFixture {
6464
gdi = new MockGdi();
6565
wddm->gdi.reset(gdi);
6666
EXPECT_TRUE(wddm->init());
67-
osContext = new OsContext(osInterface.get());
67+
osContext = new OsContext(osInterface.get(), 0u);
6868
osContext->incRefInternal();
6969
uint64_t heap32Base = (uint64_t)(0x800000000000);
7070
if (sizeof(uintptr_t) == 4) {
@@ -130,7 +130,7 @@ class WddmMemoryManagerFixtureWithGmockWddm : public GmmEnvironmentFixture {
130130
ASSERT_NE(nullptr, wddm);
131131
EXPECT_TRUE(wddm->init());
132132
osInterface->get()->setWddm(wddm);
133-
osContext = new OsContext(osInterface.get());
133+
osContext = new OsContext(osInterface.get(), 0u);
134134
osContext->incRefInternal();
135135
wddm->init();
136136
memoryManager = new (std::nothrow) MockWddmMemoryManager(wddm);

unit_tests/os_interface/windows/wddm_preemption_tests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class WddmPreemptionTests : public Test<WddmFixtureWithMockGdiDll> {
5151
PreemptionMode preemptionMode = PreemptionHelper::getDefaultPreemptionMode(hwInfoTest);
5252
wddm->setPreemptionMode(preemptionMode);
5353
wddm->init();
54-
osContext = std::make_unique<OsContext>(osInterface.get());
54+
osContext = std::make_unique<OsContext>(osInterface.get(), 0u);
5555
osContextWin = osContext->get();
5656
}
5757

0 commit comments

Comments
 (0)