Skip to content

Commit fd9fb3e

Browse files
Remove isInitialized() method from OsContext
We can fail early, instead of constructing an invalid object Signed-off-by: Maciej Dziuban <[email protected]>
1 parent 5f9dbef commit fd9fb3e

File tree

8 files changed

+18
-37
lines changed

8 files changed

+18
-37
lines changed

opencl/test/unit_test/os_interface/os_context_tests.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ using namespace NEO;
1313

1414
TEST(OSContext, whenCreatingDefaultOsContextThenExpectInitializedAlways) {
1515
OsContext *osContext = OsContext::create(nullptr, 0, 0, EngineTypeUsage{aub_stream::ENGINE_RCS, EngineUsage::Regular}, PreemptionMode::Disabled, false);
16-
EXPECT_TRUE(osContext->isInitialized());
1716
EXPECT_FALSE(osContext->isLowPriority());
1817
EXPECT_FALSE(osContext->isInternalEngine());
1918
EXPECT_FALSE(osContext->isRootDevice());

opencl/test/unit_test/os_interface/windows/os_context_win_tests.cpp

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,36 +26,30 @@ struct OsContextWinTest : public WddmTestWithMockGdiDll {
2626
};
2727

2828
TEST_F(OsContextWinTest, givenWddm20WhenCreatingOsContextThenOsContextIsInitialized) {
29-
osContext = std::make_unique<OsContextWin>(*osInterface->get()->getWddm(), 0u, 1, engineTypeUsage, preemptionMode, false);
30-
EXPECT_TRUE(osContext->isInitialized());
29+
EXPECT_NO_THROW(osContext = std::make_unique<OsContextWin>(*osInterface->get()->getWddm(), 0u, 1, engineTypeUsage, preemptionMode, false));
30+
EXPECT_NE(nullptr, osContext);
3131
}
3232

33-
TEST_F(OsContextWinTest, givenWddm20WhenCreatingWddmContextFailThenOsContextIsNotInitialized) {
33+
TEST_F(OsContextWinTest, givenWddm20WhenCreatingWddmContextFailThenOsContextCreationFails) {
3434
wddm->device = INVALID_HANDLE;
35-
36-
osContext = std::make_unique<OsContextWin>(*osInterface->get()->getWddm(), 0u, 1, engineTypeUsage, preemptionMode, false);
37-
EXPECT_FALSE(osContext->isInitialized());
35+
EXPECT_ANY_THROW(osContext = std::make_unique<OsContextWin>(*osInterface->get()->getWddm(), 0u, 1, engineTypeUsage, preemptionMode, false));
3836
}
3937

40-
TEST_F(OsContextWinTest, givenWddm20WhenCreatingWddmMonitorFenceFailThenOsContextIsNotInitialized) {
38+
TEST_F(OsContextWinTest, givenWddm20WhenCreatingWddmMonitorFenceFailThenOsContextCreationFails) {
4139
*getCreateSynchronizationObject2FailCallFcn() = true;
42-
43-
osContext = std::make_unique<OsContextWin>(*osInterface->get()->getWddm(), 0u, 1, engineTypeUsage, preemptionMode, false);
44-
EXPECT_FALSE(osContext->isInitialized());
40+
EXPECT_ANY_THROW(osContext = std::make_unique<OsContextWin>(*osInterface->get()->getWddm(), 0u, 1, engineTypeUsage, preemptionMode, false));
4541
}
4642

47-
TEST_F(OsContextWinTest, givenWddm20WhenRegisterTrimCallbackFailThenOsContextIsNotInitialized) {
43+
TEST_F(OsContextWinTest, givenWddm20WhenRegisterTrimCallbackFailThenOsContextCreationFails) {
4844
*getRegisterTrimNotificationFailCallFcn() = true;
49-
50-
osContext = std::make_unique<OsContextWin>(*osInterface->get()->getWddm(), 0u, 1, engineTypeUsage, preemptionMode, false);
51-
EXPECT_FALSE(osContext->isInitialized());
45+
EXPECT_ANY_THROW(osContext = std::make_unique<OsContextWin>(*osInterface->get()->getWddm(), 0u, 1, engineTypeUsage, preemptionMode, false));
5246
}
5347

5448
TEST_F(OsContextWinTest, givenWddm20WhenRegisterTrimCallbackIsDisabledThenOsContextIsInitialized) {
5549
DebugManagerStateRestore stateRestore;
5650
DebugManager.flags.DoNotRegisterTrimCallback.set(true);
5751
*getRegisterTrimNotificationFailCallFcn() = true;
5852

59-
osContext = std::make_unique<OsContextWin>(*osInterface->get()->getWddm(), 0u, 1, engineTypeUsage, preemptionMode, false);
60-
EXPECT_TRUE(osContext->isInitialized());
53+
EXPECT_NO_THROW(osContext = std::make_unique<OsContextWin>(*osInterface->get()->getWddm(), 0u, 1, engineTypeUsage, preemptionMode, false));
54+
EXPECT_NE(nullptr, osContext);
6155
}

opencl/test/unit_test/os_interface/windows/os_interface_win_tests.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ TEST(OsContextTest, givenWddmWhenCreateOsContextAfterInitWddmThenOsContextIsInit
3434
auto osContext = std::make_unique<OsContextWin>(*wddm, 0u, 1,
3535
HwHelper::get(defaultHwInfo->platform.eRenderCoreFamily).getGpgpuEngineInstances(*defaultHwInfo)[0],
3636
preemptionMode, false);
37-
EXPECT_TRUE(osContext->isInitialized());
3837
EXPECT_EQ(osContext->getWddm(), wddm);
3938
EXPECT_EQ(1u, wddm->registerTrimCallbackResult.called);
4039
}

opencl/test/unit_test/os_interface/windows/wddm23_tests.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -217,8 +217,7 @@ TEST_F(Wddm23TestsWithoutWddmInit, whenInitCalledThenInitializeNewGdiDDIsAndCall
217217

218218
TEST_F(Wddm23TestsWithoutWddmInit, whenCreateHwQueueFailedThenReturnFalseFromInit) {
219219
wddmMockInterface->forceCreateHwQueueFail = true;
220-
init();
221-
EXPECT_FALSE(osContext->isInitialized());
220+
EXPECT_ANY_THROW(init());
222221
}
223222

224223
TEST_F(Wddm23TestsWithoutWddmInit, givenFailureOnGdiInitializationWhenCreatingHwQueueThenReturnFailure) {
@@ -229,8 +228,7 @@ TEST_F(Wddm23TestsWithoutWddmInit, givenFailureOnGdiInitializationWhenCreatingHw
229228
};
230229
auto myMockGdi = new MyMockGdi();
231230
wddm->resetGdi(myMockGdi);
232-
init();
233-
EXPECT_FALSE(osContext->isInitialized());
231+
EXPECT_ANY_THROW(init());
234232
EXPECT_EQ(1u, wddmMockInterface->createHwQueueCalled);
235233
EXPECT_FALSE(wddmMockInterface->createHwQueueResult);
236234
}

shared/source/memory_manager/memory_manager.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,6 @@ OsContext *MemoryManager::createAndRegisterOsContext(CommandStreamReceiver *comm
258258
auto contextId = ++latestContextId;
259259
auto osContext = OsContext::create(peekExecutionEnvironment().rootDeviceEnvironments[commandStreamReceiver->getRootDeviceIndex()]->osInterface.get(),
260260
contextId, deviceBitfield, typeUsage, preemptionMode, rootDevice);
261-
UNRECOVERABLE_IF(!osContext->isInitialized());
262261
osContext->incRefInternal();
263262

264263
registeredEngines.emplace_back(commandStreamReceiver, osContext);

shared/source/os_interface/os_context.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ class OsContext : public ReferenceTrackedObject<OsContext> {
3535
bool isLowPriority() const { return engineUsage == EngineUsage::LowPriority; }
3636
bool isInternalEngine() const { return engineUsage == EngineUsage::Internal; }
3737
bool isRootDevice() const { return rootDevice; }
38-
virtual bool isInitialized() const { return true; }
3938
virtual bool isDirectSubmissionSupported(const HardwareInfo &hwInfo) const { return false; }
4039
bool isDefaultContext() const { return defaultContext; }
4140
void setDefaultContext(bool value) { defaultContext = value; }

shared/source/os_interface/windows/os_context_win.cpp

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,22 +28,17 @@ OsContextWin::OsContextWin(Wddm &wddm, uint32_t contextId, DeviceBitfield device
2828
residencyController(wddm, contextId) {
2929

3030
auto wddmInterface = wddm.getWddmInterface();
31-
if (!wddm.createContext(*this)) {
32-
return;
33-
}
31+
UNRECOVERABLE_IF(!wddm.createContext(*this));
32+
3433
if (wddmInterface->hwQueuesSupported()) {
35-
if (!wddmInterface->createHwQueue(*this)) {
36-
return;
37-
}
34+
UNRECOVERABLE_IF(!wddmInterface->createHwQueue(*this));
3835
}
39-
initialized = wddmInterface->createMonitoredFence(*this);
36+
UNRECOVERABLE_IF(!wddmInterface->createMonitoredFence(*this));
37+
4038
residencyController.registerCallback();
39+
UNRECOVERABLE_IF(!residencyController.isInitialized());
4140
};
4241

43-
bool OsContextWin::isInitialized() const {
44-
return (initialized && residencyController.isInitialized());
45-
}
46-
4742
OsContextWin::~OsContextWin() {
4843
wddm.getWddmInterface()->destroyHwQueue(hardwareQueue.handle);
4944
wddm.getWddmInterface()->destroyMonitorFence(residencyController.getMonitoredFence());

shared/source/os_interface/windows/os_context_win.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,10 @@ class OsContextWin : public OsContext {
3232
void setWddmContextHandle(D3DKMT_HANDLE wddmContextHandle) { this->wddmContextHandle = wddmContextHandle; }
3333
HardwareQueue getHwQueue() const { return hardwareQueue; }
3434
void setHwQueue(HardwareQueue hardwareQueue) { this->hardwareQueue = hardwareQueue; }
35-
bool isInitialized() const override;
3635
Wddm *getWddm() const { return &wddm; }
3736
MOCKABLE_VIRTUAL WddmResidencyController &getResidencyController() { return residencyController; }
3837

3938
protected:
40-
bool initialized = false;
4139
D3DKMT_HANDLE wddmContextHandle = 0;
4240
HardwareQueue hardwareQueue;
4341
Wddm &wddm;

0 commit comments

Comments
 (0)