From 51a7b47cf0773681dae6db312e3dde306094d2f8 Mon Sep 17 00:00:00 2001 From: Igor Venevtsev Date: Tue, 24 Dec 2019 13:51:39 +0100 Subject: [PATCH] GmmHelper::de/canonize to address width specified by HardwareInfo Related-To: NEO-2941 Change-Id: Ibe09c9812dc109c06df1a308f831447f82bad57a Signed-off-by: Igor Venevtsev --- core/gmm_helper/gmm_helper.cpp | 6 +++ core/gmm_helper/gmm_helper.h | 8 +-- unit_tests/gmm_helper/gmm_helper_tests.cpp | 58 +++++++++++++--------- 3 files changed, 44 insertions(+), 28 deletions(-) diff --git a/core/gmm_helper/gmm_helper.cpp b/core/gmm_helper/gmm_helper.cpp index 564724cb7b..f6e1882d80 100644 --- a/core/gmm_helper/gmm_helper.cpp +++ b/core/gmm_helper/gmm_helper.cpp @@ -15,8 +15,12 @@ #include "gmm_client_context.h" +#include + namespace NEO { +uint32_t GmmHelper::addressWidth = 48; + GmmClientContext *GmmHelper::getClientContext() const { return gmmClientContext.get(); } @@ -33,6 +37,8 @@ uint32_t GmmHelper::getMOCS(uint32_t type) { GmmHelper::GmmHelper(OSInterface *osInterface, const HardwareInfo *pHwInfo) : hwInfo(pHwInfo) { loadLib(); + auto hwInfoAddressWidth = Math::log2(hwInfo->capabilityTable.gpuAddressSpace + 1); + GmmHelper::addressWidth = std::max(hwInfoAddressWidth, GmmHelper::addressWidth); gmmClientContext = GmmHelper::createGmmContextWrapperFunc(osInterface, const_cast(pHwInfo), this->initGmmFunc, this->destroyGmmFunc); UNRECOVERABLE_IF(!gmmClientContext); } diff --git a/core/gmm_helper/gmm_helper.h b/core/gmm_helper/gmm_helper.h index 4f7f4fbaa8..c873132bfa 100644 --- a/core/gmm_helper/gmm_helper.h +++ b/core/gmm_helper/gmm_helper.h @@ -7,6 +7,7 @@ #pragma once #include "core/gmm_helper/gmm_lib.h" +#include "core/helpers/basic_math.h" #include "core/memory_manager/memory_constants.h" #include @@ -28,14 +29,12 @@ class GmmHelper { static constexpr uint64_t maxPossiblePitch = 2147483648; - template static uint64_t canonize(uint64_t address) { - return ((int64_t)(address << (64 - addressWidth))) >> (64 - addressWidth); + return static_cast(address << (64 - GmmHelper::addressWidth)) >> (64 - GmmHelper::addressWidth); } - template static uint64_t decanonize(uint64_t address) { - return (address & maxNBitValue(addressWidth)); + return (address & maxNBitValue(GmmHelper::addressWidth)); } GmmClientContext *getClientContext() const; @@ -45,6 +44,7 @@ class GmmHelper { protected: void loadLib(); + static uint32_t addressWidth; const HardwareInfo *hwInfo = nullptr; std::unique_ptr gmmLib; std::unique_ptr gmmClientContext; diff --git a/unit_tests/gmm_helper/gmm_helper_tests.cpp b/unit_tests/gmm_helper/gmm_helper_tests.cpp index 69a5c574da..941d26ff99 100644 --- a/unit_tests/gmm_helper/gmm_helper_tests.cpp +++ b/unit_tests/gmm_helper/gmm_helper_tests.cpp @@ -336,39 +336,49 @@ TEST_F(GmmTests, givenNonZeroRowPitchWhenQueryImgFromBufferParamsThenUseUserValu } TEST_F(GmmTests, canonize) { - uint64_t addr1 = 0x7777777777777777; - uint64_t addrExpected1 = 0x0000777777777777; - EXPECT_EQ(GmmHelper::canonize(addr1), addrExpected1); + HardwareInfo hwInfo; - uint64_t addr2 = 0x7FFFFFFFFFFFFFFF; - uint64_t addrExpected2 = 0xFFFFFFFFFFFFFFFF; - EXPECT_EQ(GmmHelper::canonize(addr2), addrExpected2); + // 48 bit - canonize to 48 bit + hwInfo.capabilityTable.gpuAddressSpace = maxNBitValue(48); // 0x0000FFFFFFFFFFFF; + auto gmmHelper = std::make_unique(nullptr, &hwInfo); - uint64_t addr3 = 0x7777777777777777; - uint64_t addrExpected3 = 0x0000000077777777; - EXPECT_EQ(GmmHelper::canonize<32>(addr3), addrExpected3); + uint64_t testAddr1 = 0x7777777777777777; + uint64_t goodAddr1 = 0x0000777777777777; + EXPECT_EQ(GmmHelper::canonize(testAddr1), goodAddr1); - uint64_t addr4 = 0x77777777FFFFFFFF; - uint64_t addrExpected4 = 0xFFFFFFFFFFFFFFFF; - EXPECT_EQ(GmmHelper::canonize<32>(addr4), addrExpected4); + uint64_t testAddr2 = 0x7FFFFFFFFFFFFFFF; + uint64_t goodAddr2 = 0xFFFFFFFFFFFFFFFF; + EXPECT_EQ(GmmHelper::canonize(testAddr2), goodAddr2); + + // 36 bit - also canonize to 48 bit + hwInfo.capabilityTable.gpuAddressSpace = maxNBitValue(36); // 0x0000000FFFFFFFFF; + gmmHelper = std::make_unique(nullptr, &hwInfo); + + EXPECT_EQ(GmmHelper::canonize(testAddr1), goodAddr1); + EXPECT_EQ(GmmHelper::canonize(testAddr2), goodAddr2); } TEST_F(GmmTests, decanonize) { - uint64_t addr1 = 0x7777777777777777; - uint64_t addrExpected1 = 0x0000777777777777; - EXPECT_EQ(GmmHelper::decanonize(addr1), addrExpected1); + HardwareInfo hwInfo; - uint64_t addr2 = 0x7FFFFFFFFFFFFFFF; - uint64_t addrExpected2 = 0x0000FFFFFFFFFFFF; - EXPECT_EQ(GmmHelper::decanonize(addr2), addrExpected2); + // 48 bit - decanonize to 48 bit + hwInfo.capabilityTable.gpuAddressSpace = maxNBitValue(48); //0x0000FFFFFFFFFFFF; + auto gmmHelper = std::make_unique(nullptr, &hwInfo); - uint64_t addr3 = 0x7777777777777777; - uint64_t addrExpected3 = 0x0000000077777777; - EXPECT_EQ(GmmHelper::decanonize<32>(addr3), addrExpected3); + uint64_t testAddr1 = 0x7777777777777777; + uint64_t goodAddr1 = 0x0000777777777777; + EXPECT_EQ(GmmHelper::decanonize(testAddr1), goodAddr1); - uint64_t addr4 = 0x7FFFFFFFFFFFFFFF; - uint64_t addrExpected4 = 0x00000000FFFFFFFF; - EXPECT_EQ(GmmHelper::decanonize<32>(addr4), addrExpected4); + uint64_t testAddr2 = 0x7FFFFFFFFFFFFFFF; + uint64_t goodAddr2 = 0x0000FFFFFFFFFFFF; + EXPECT_EQ(GmmHelper::decanonize(testAddr2), goodAddr2); + + // 36 bit - also decanonize to 48 bit + hwInfo.capabilityTable.gpuAddressSpace = maxNBitValue(36); // 0x0000000FFFFFFFFF; + gmmHelper = std::make_unique(nullptr, &hwInfo); + + EXPECT_EQ(GmmHelper::decanonize(testAddr1), goodAddr1); + EXPECT_EQ(GmmHelper::decanonize(testAddr2), goodAddr2); } TEST_F(GmmTests, givenMipmapedInputWhenAskedForHalingThenNonDefaultValueIsReturned) {