diff --git a/level_zero/core/source/cmdlist/cmdlist_imp.cpp b/level_zero/core/source/cmdlist/cmdlist_imp.cpp index cb11ec7e62..5a20afa1ce 100644 --- a/level_zero/core/source/cmdlist/cmdlist_imp.cpp +++ b/level_zero/core/source/cmdlist/cmdlist_imp.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020-2024 Intel Corporation + * Copyright (C) 2020-2025 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -292,7 +292,7 @@ void CommandListImp::enableCopyOperationOffload(uint32_t productFamily, Device * void CommandListImp::setStreamPropertiesDefaultSettings(NEO::StreamProperties &streamProperties) { if (this->stateComputeModeTracking) { - streamProperties.stateComputeMode.setPropertiesCoherencyDevicePreemption(cmdListDefaultCoherency, this->commandListPreemptionMode, true); + streamProperties.stateComputeMode.setPropertiesPerContext(cmdListDefaultCoherency, this->commandListPreemptionMode, true); } streamProperties.frontEndState.setPropertiesDisableOverdispatch(cmdListDefaultDisableOverdispatch, true); diff --git a/shared/source/command_stream/definitions/stream_properties.inl b/shared/source/command_stream/definitions/stream_properties.inl index 73b4d1ab7d..599ffadc3e 100644 --- a/shared/source/command_stream/definitions/stream_properties.inl +++ b/shared/source/command_stream/definitions/stream_properties.inl @@ -35,8 +35,8 @@ struct StateComputeModeProperties { void resetState(); void setPropertiesAll(bool requiresCoherency, uint32_t numGrfRequired, int32_t threadArbitrationPolicy, PreemptionMode devicePreemptionMode); + void setPropertiesPerContext(bool requiresCoherency, PreemptionMode devicePreemptionMode, bool clearDirtyState); void setPropertiesGrfNumberThreadArbitration(uint32_t numGrfRequired, int32_t threadArbitrationPolicy); - void setPropertiesCoherencyDevicePreemption(bool requiresCoherency, PreemptionMode devicePreemptionMode, bool clearDirtyState); void copyPropertiesAll(const StateComputeModeProperties &properties); void copyPropertiesGrfNumberThreadArbitration(const StateComputeModeProperties &properties); @@ -45,6 +45,7 @@ struct StateComputeModeProperties { void clearIsDirty(); protected: + void clearIsDirtyPerContext(); void clearIsDirtyExtraPerContext(); bool isDirtyExtra() const; void resetStateExtra(); diff --git a/shared/source/command_stream/stream_properties.cpp b/shared/source/command_stream/stream_properties.cpp index 9e68d51e91..a087499af7 100644 --- a/shared/source/command_stream/stream_properties.cpp +++ b/shared/source/command_stream/stream_properties.cpp @@ -20,7 +20,6 @@ void StateComputeModeProperties::setPropertiesAll(bool requiresCoherency, uint32 DEBUG_BREAK_IF(!this->propertiesSupportLoaded); clearIsDirty(); - setCoherencyProperty(requiresCoherency); setGrfNumberProperty(numGrfRequired); setThreadArbitrationProperty(threadArbitrationPolicy); @@ -39,7 +38,6 @@ void StateComputeModeProperties::setPropertiesAll(bool requiresCoherency, uint32 if (pixelAsyncComputeThreadLimit != -1 && this->scmPropertiesSupport.pixelAsyncComputeThreadLimit) { this->pixelAsyncComputeThreadLimit.set(pixelAsyncComputeThreadLimit); } - setDevicePreemptionProperty(devicePreemptionMode); int32_t memoryAllocationForScratchAndMidthreadPreemptionBuffers = -1; if (debugManager.flags.ForceScratchAndMTPBufferSizeMode.get() != -1) { @@ -49,7 +47,7 @@ void StateComputeModeProperties::setPropertiesAll(bool requiresCoherency, uint32 this->memoryAllocationForScratchAndMidthreadPreemptionBuffers.set(memoryAllocationForScratchAndMidthreadPreemptionBuffers); } - setPropertiesExtraPerContext(); + setPropertiesPerContext(requiresCoherency, devicePreemptionMode, false); } void StateComputeModeProperties::copyPropertiesAll(const StateComputeModeProperties &properties) { @@ -77,19 +75,30 @@ void StateComputeModeProperties::copyPropertiesGrfNumberThreadArbitration(const } bool StateComputeModeProperties::isDirty() const { - return isCoherencyRequired.isDirty || largeGrfMode.isDirty || zPassAsyncComputeThreadLimit.isDirty || - pixelAsyncComputeThreadLimit.isDirty || threadArbitrationPolicy.isDirty || devicePreemptionMode.isDirty || memoryAllocationForScratchAndMidthreadPreemptionBuffers.isDirty || isDirtyExtra(); + return isCoherencyRequired.isDirty || + largeGrfMode.isDirty || + zPassAsyncComputeThreadLimit.isDirty || + pixelAsyncComputeThreadLimit.isDirty || + threadArbitrationPolicy.isDirty || + devicePreemptionMode.isDirty || + memoryAllocationForScratchAndMidthreadPreemptionBuffers.isDirty || + isDirtyExtra(); } void StateComputeModeProperties::clearIsDirty() { - isCoherencyRequired.isDirty = false; largeGrfMode.isDirty = false; zPassAsyncComputeThreadLimit.isDirty = false; pixelAsyncComputeThreadLimit.isDirty = false; threadArbitrationPolicy.isDirty = false; - devicePreemptionMode.isDirty = false; memoryAllocationForScratchAndMidthreadPreemptionBuffers.isDirty = false; + clearIsDirtyPerContext(); +} + +void StateComputeModeProperties::clearIsDirtyPerContext() { + isCoherencyRequired.isDirty = false; + devicePreemptionMode.isDirty = false; + clearIsDirtyExtraPerContext(); } @@ -152,21 +161,17 @@ void StateComputeModeProperties::resetState() { resetStateExtra(); } -void StateComputeModeProperties::setPropertiesCoherencyDevicePreemption(bool requiresCoherency, PreemptionMode devicePreemptionMode, bool clearDirtyState) { +void StateComputeModeProperties::setPropertiesPerContext(bool requiresCoherency, PreemptionMode devicePreemptionMode, bool clearDirtyState) { DEBUG_BREAK_IF(!this->propertiesSupportLoaded); if (!clearDirtyState) { - this->isCoherencyRequired.isDirty = false; - this->devicePreemptionMode.isDirty = false; - clearIsDirtyExtraPerContext(); + clearIsDirtyPerContext(); } setCoherencyProperty(requiresCoherency); setDevicePreemptionProperty(devicePreemptionMode); setPropertiesExtraPerContext(); if (clearDirtyState) { - this->isCoherencyRequired.isDirty = false; - this->devicePreemptionMode.isDirty = false; - clearIsDirtyExtraPerContext(); + clearIsDirtyPerContext(); } } diff --git a/shared/test/unit_test/command_stream/stream_properties_tests_common.cpp b/shared/test/unit_test/command_stream/stream_properties_tests_common.cpp index d2b5dd0464..ebb7aaa716 100644 --- a/shared/test/unit_test/command_stream/stream_properties_tests_common.cpp +++ b/shared/test/unit_test/command_stream/stream_properties_tests_common.cpp @@ -293,62 +293,87 @@ TEST(StreamPropertiesTests, givenOtherPipelineSelectPropertiesStructWhenSetPrope verifySettingPropertiesFromOtherStruct(); } -TEST(StreamPropertiesTests, givenCoherencyStateAndDevicePreemptionComputeModePropertiesWhenSettingPropertyAndCheckIfSupportedThenExpectCorrectState) { +TEST(StreamPropertiesTests, givenVariousDevicePreemptionComputeModesWhenSettingPropertyPerContextAndCheckIfSupportedThenExpectCorrectState) { bool clearDirtyState = false; MockStateComputeModeProperties scmProperties{}; scmProperties.propertiesSupportLoaded = true; - scmProperties.scmPropertiesSupport.coherencyRequired = false; scmProperties.scmPropertiesSupport.devicePreemptionMode = false; bool coherencyRequired = false; PreemptionMode devicePreemptionMode = PreemptionMode::Disabled; - scmProperties.setPropertiesCoherencyDevicePreemption(coherencyRequired, devicePreemptionMode, clearDirtyState); + scmProperties.setPropertiesPerContext(coherencyRequired, devicePreemptionMode, clearDirtyState); EXPECT_FALSE(scmProperties.isDirty()); - EXPECT_EQ(-1, scmProperties.isCoherencyRequired.value); EXPECT_EQ(-1, scmProperties.devicePreemptionMode.value); - scmProperties.scmPropertiesSupport.coherencyRequired = true; scmProperties.scmPropertiesSupport.devicePreemptionMode = true; - scmProperties.setPropertiesCoherencyDevicePreemption(coherencyRequired, devicePreemptionMode, clearDirtyState); + scmProperties.setPropertiesPerContext(coherencyRequired, devicePreemptionMode, clearDirtyState); EXPECT_TRUE(scmProperties.isDirty()); - EXPECT_EQ(0, scmProperties.isCoherencyRequired.value); EXPECT_EQ(static_cast(devicePreemptionMode), scmProperties.devicePreemptionMode.value); devicePreemptionMode = PreemptionMode::Initial; scmProperties.setPropertiesAll(coherencyRequired, -1, -1, devicePreemptionMode); EXPECT_TRUE(scmProperties.isDirty()); - EXPECT_EQ(0, scmProperties.isCoherencyRequired.value); EXPECT_EQ(static_cast(devicePreemptionMode), scmProperties.devicePreemptionMode.value); - scmProperties.setPropertiesCoherencyDevicePreemption(coherencyRequired, devicePreemptionMode, clearDirtyState); + scmProperties.setPropertiesPerContext(coherencyRequired, devicePreemptionMode, clearDirtyState); EXPECT_FALSE(scmProperties.isDirty()); - EXPECT_EQ(0, scmProperties.isCoherencyRequired.value); EXPECT_EQ(static_cast(devicePreemptionMode), scmProperties.devicePreemptionMode.value); - scmProperties.setPropertiesCoherencyDevicePreemption(coherencyRequired, devicePreemptionMode, clearDirtyState); - EXPECT_FALSE(scmProperties.isDirty()); - EXPECT_EQ(0, scmProperties.isCoherencyRequired.value); - EXPECT_EQ(static_cast(devicePreemptionMode), scmProperties.devicePreemptionMode.value); - - coherencyRequired = true; devicePreemptionMode = PreemptionMode::MidThread; - scmProperties.setPropertiesCoherencyDevicePreemption(coherencyRequired, devicePreemptionMode, clearDirtyState); + scmProperties.setPropertiesPerContext(coherencyRequired, devicePreemptionMode, clearDirtyState); EXPECT_TRUE(scmProperties.isDirty()); - EXPECT_EQ(1, scmProperties.isCoherencyRequired.value); EXPECT_EQ(static_cast(devicePreemptionMode), scmProperties.devicePreemptionMode.value); - scmProperties.setPropertiesCoherencyDevicePreemption(coherencyRequired, devicePreemptionMode, clearDirtyState); + scmProperties.setPropertiesPerContext(coherencyRequired, devicePreemptionMode, clearDirtyState); EXPECT_FALSE(scmProperties.isDirty()); - EXPECT_EQ(1, scmProperties.isCoherencyRequired.value); EXPECT_EQ(static_cast(devicePreemptionMode), scmProperties.devicePreemptionMode.value); clearDirtyState = true; - coherencyRequired = false; devicePreemptionMode = PreemptionMode::ThreadGroup; - scmProperties.setPropertiesCoherencyDevicePreemption(coherencyRequired, devicePreemptionMode, clearDirtyState); + scmProperties.setPropertiesPerContext(coherencyRequired, devicePreemptionMode, clearDirtyState); + EXPECT_FALSE(scmProperties.isDirty()); + EXPECT_EQ(static_cast(devicePreemptionMode), scmProperties.devicePreemptionMode.value); +} + +TEST(StreamPropertiesTests, givenVariousCoherencyRequirementsWhenSettingPropertyPerContextAndCheckIfSupportedThenExpectCorrectState) { + bool clearDirtyState = false; + MockStateComputeModeProperties scmProperties{}; + scmProperties.propertiesSupportLoaded = true; + scmProperties.scmPropertiesSupport.coherencyRequired = false; + + bool coherencyRequired = false; + PreemptionMode devicePreemptionMode = PreemptionMode::Disabled; + scmProperties.setPropertiesPerContext(coherencyRequired, devicePreemptionMode, clearDirtyState); + EXPECT_FALSE(scmProperties.isDirty()); + EXPECT_EQ(-1, scmProperties.isCoherencyRequired.value); + + scmProperties.scmPropertiesSupport.coherencyRequired = true; + scmProperties.setPropertiesPerContext(coherencyRequired, devicePreemptionMode, clearDirtyState); + EXPECT_TRUE(scmProperties.isDirty()); + EXPECT_EQ(0, scmProperties.isCoherencyRequired.value); + + scmProperties.setPropertiesAll(coherencyRequired, -1, -1, devicePreemptionMode); + EXPECT_FALSE(scmProperties.isDirty()); + EXPECT_EQ(0, scmProperties.isCoherencyRequired.value); + + scmProperties.setPropertiesPerContext(coherencyRequired, devicePreemptionMode, clearDirtyState); + EXPECT_FALSE(scmProperties.isDirty()); + EXPECT_EQ(0, scmProperties.isCoherencyRequired.value); + + coherencyRequired = true; + scmProperties.setPropertiesPerContext(coherencyRequired, devicePreemptionMode, clearDirtyState); + EXPECT_TRUE(scmProperties.isDirty()); + EXPECT_EQ(1, scmProperties.isCoherencyRequired.value); + + scmProperties.setPropertiesPerContext(coherencyRequired, devicePreemptionMode, clearDirtyState); + EXPECT_FALSE(scmProperties.isDirty()); + EXPECT_EQ(1, scmProperties.isCoherencyRequired.value); + + clearDirtyState = true; + coherencyRequired = false; + scmProperties.setPropertiesPerContext(coherencyRequired, devicePreemptionMode, clearDirtyState); EXPECT_FALSE(scmProperties.isDirty()); EXPECT_EQ(0, scmProperties.isCoherencyRequired.value); - EXPECT_EQ(static_cast(devicePreemptionMode), scmProperties.devicePreemptionMode.value); } TEST(StreamPropertiesTests, givenGrfNumberAndThreadArbitrationStateComputeModePropertiesWhenSettingPropertyAndCheckIfSupportedThenExpectCorrectState) {