diff --git a/runtime/dll/linux/drm_neo_create.cpp b/runtime/dll/linux/drm_neo_create.cpp index ebcf83600a..8f80e8fbdb 100644 --- a/runtime/dll/linux/drm_neo_create.cpp +++ b/runtime/dll/linux/drm_neo_create.cpp @@ -25,6 +25,7 @@ #include "runtime/helpers/options.h" #include "runtime/os_interface/linux/drm_neo.h" #include "runtime/os_interface/linux/drm_null_device.h" +#include "runtime/gmm_helper/gmm_helper.h" #include "drm/i915_drm.h" #include "runtime/os_interface/debug_settings_manager.h" #include @@ -212,6 +213,8 @@ Drm *Drm::create(int32_t deviceOrdinal) { // Activate the Turbo Boost Frequency feature ret = drmObject->enableTurboBoost(); if (ret != 0) { + //turbo patch not present, we are not on custom Kernel, switch to simplified Mocs selection + Gmm::useSimplifiedMocsTable = true; printDebugString(DebugManager.flags.PrintDebugMessages.get(), stderr, "%s", "WARNING: Failed to request OCL Turbo Boost\n"); } diff --git a/runtime/gmm_helper/gmm_helper.cpp b/runtime/gmm_helper/gmm_helper.cpp index e78abd3846..8c3159d4c7 100644 --- a/runtime/gmm_helper/gmm_helper.cpp +++ b/runtime/gmm_helper/gmm_helper.cpp @@ -78,6 +78,14 @@ bool Gmm::initContext(const PLATFORM *pPlatform, } uint32_t Gmm::getMOCS(uint32_t type) { + if (useSimplifiedMocsTable) { + if (type == GMM_RESOURCE_USAGE_OCL_BUFFER_CACHELINE_MISALIGNED) { + return cacheDisabledIndex; + } else { + return cacheEnabledIndex; + } + } + MEMORY_OBJECT_CONTROL_STATE mocs = pGmmGlobalContext->GetCachePolicyObj()->CachePolicyGetMemoryObject(nullptr, static_cast(type)); @@ -385,4 +393,7 @@ uint8_t Gmm::resourceCopyBlt(void *sys, void *gpu, uint32_t pitch, uint32_t heig return this->gmmResourceInfo->cpuBlt(&gmmResourceCopyBLT); } + +bool Gmm::useSimplifiedMocsTable = false; + } // namespace OCLRT diff --git a/runtime/gmm_helper/gmm_helper.h b/runtime/gmm_helper/gmm_helper.h index 5d23332d31..a545d61cc9 100644 --- a/runtime/gmm_helper/gmm_helper.h +++ b/runtime/gmm_helper/gmm_helper.h @@ -49,6 +49,9 @@ enum OCLPlane { PLANE_UV }; +constexpr uint32_t cacheDisabledIndex = 0; +constexpr uint32_t cacheEnabledIndex = 4; + class Gmm { public: static const uint32_t maxPossiblePitch = 2147483648; @@ -93,5 +96,6 @@ class Gmm { std::unique_ptr gmmResourceInfo; bool isRenderCompressed = false; + static bool useSimplifiedMocsTable; }; } // namespace OCLRT diff --git a/unit_tests/gmm_helper/gmm_helper_tests.cpp b/unit_tests/gmm_helper/gmm_helper_tests.cpp index 0a7228ffae..193b1a17cb 100644 --- a/unit_tests/gmm_helper/gmm_helper_tests.cpp +++ b/unit_tests/gmm_helper/gmm_helper_tests.cpp @@ -560,4 +560,21 @@ TEST_F(GmmTests, copyResourceBlt) { EXPECT_EQ(1u, retVal); EXPECT_TRUE(memcmp(&expectedCpuBlt, &requestedCpuBlt, sizeof(GMM_RES_COPY_BLT)) == 0); } + +TEST(GmmSimplifiedCacheSelectionPolicy, givenGmmInSimplifiedCacheSelectionPolicyWhenItIsAskedForUncachedIndexThen0IsReturned) { + Gmm::useSimplifiedMocsTable = true; + auto index = Gmm::getMOCS(GMM_RESOURCE_USAGE_OCL_BUFFER_CACHELINE_MISALIGNED); + auto expectedIndex = cacheDisabledIndex; + EXPECT_EQ(expectedIndex, index); + Gmm::useSimplifiedMocsTable = false; +} + +TEST(GmmSimplifiedCacheSelectionPolicy, givenGmmInSimplifiedCacheSelectionPolicyWhenItIsAskedForCachedIndexThen4IsReturned) { + Gmm::useSimplifiedMocsTable = true; + auto index = Gmm::getMOCS(GMM_RESOURCE_USAGE_OCL_BUFFER); + auto expectedIndex = cacheEnabledIndex; + EXPECT_EQ(expectedIndex, index); + Gmm::useSimplifiedMocsTable = false; +} + } // namespace OCLRT diff --git a/unit_tests/linux/main_linux_dll.cpp b/unit_tests/linux/main_linux_dll.cpp index bc52d4058e..d1c6e753b3 100644 --- a/unit_tests/linux/main_linux_dll.cpp +++ b/unit_tests/linux/main_linux_dll.cpp @@ -21,6 +21,7 @@ */ #include "mock_os_layer.h" +#include "runtime/gmm_helper/gmm_helper.h" #include "unit_tests/custom_event_listener.h" #include "test.h" @@ -202,6 +203,21 @@ TEST_F(DrmTests, failOnParamBoost) { EXPECT_NE(ptr, nullptr); } +TEST_F(DrmTests, givenKernelNotSupportingTurboPatchWhenDeviceIsCreatedThenGmmSwitchesToSimplifiedMocsSelection) { + Gmm::useSimplifiedMocsTable = false; + failOnParamBoost = -1; + auto ptr = DrmWrap::createDrm(0); + EXPECT_NE(ptr, nullptr); + EXPECT_TRUE(Gmm::useSimplifiedMocsTable); + Gmm::useSimplifiedMocsTable = false; +} + +TEST_F(DrmTests, givenKernelSupportingTurboPatchWhenDeviceIsCreatedThenSimplifiedMocsSelectionIsFalse) { + auto ptr = DrmWrap::createDrm(0); + EXPECT_NE(ptr, nullptr); + EXPECT_FALSE(Gmm::useSimplifiedMocsTable); +} + #if defined(I915_PARAM_HAS_PREEMPTION) TEST_F(DrmTests, checkPreemption) { auto ptr = DrmWrap::createDrm(0);