From 90034d4173951bd99f6cebd4706c5f551f807ed5 Mon Sep 17 00:00:00 2001 From: Andrzej Koska Date: Thu, 17 Nov 2022 14:27:52 +0000 Subject: [PATCH] Added scratch size check Related-To: NEO-7508 Signed-off-by: Andrzej Koska --- level_zero/core/source/kernel/kernel_imp.cpp | 3 + .../test/unit_tests/fixtures/module_fixture.h | 28 +++++++++ .../unit_tests/sources/kernel/test_kernel.cpp | 17 ++++++ opencl/source/kernel/kernel.cpp | 3 + opencl/test/unit_test/kernel/kernel_tests.cpp | 15 +++++ ...cratch_space_controller_xehp_and_later.cpp | 4 +- shared/source/helpers/hw_helper.h | 2 + .../helpers/hw_helper_bdw_and_later.inl | 5 ++ .../helpers/hw_helper_xehp_and_later.inl | 4 ++ shared/source/helpers/kernel_helpers.cpp | 6 ++ shared/source/helpers/kernel_helpers.h | 3 +- .../helpers/kernel_helpers_tests.cpp | 57 +++++++++++++++++-- .../unit_test/xe_hpg_core/dg2/CMakeLists.txt | 1 + .../xe_hpg_core/dg2/sampler_tests_dg2.cpp | 42 ++++++++++++++ 14 files changed, 183 insertions(+), 7 deletions(-) create mode 100644 shared/test/unit_test/xe_hpg_core/dg2/sampler_tests_dg2.cpp diff --git a/level_zero/core/source/kernel/kernel_imp.cpp b/level_zero/core/source/kernel/kernel_imp.cpp index 2492a9e289..6aea6b13c3 100644 --- a/level_zero/core/source/kernel/kernel_imp.cpp +++ b/level_zero/core/source/kernel/kernel_imp.cpp @@ -803,6 +803,9 @@ ze_result_t KernelImp::initialize(const ze_kernel_desc_t *desc) { const auto &hwInfoConfig = *NEO::HwInfoConfig::get(hwInfo.platform.eProductFamily); auto &kernelDescriptor = kernelImmData->getDescriptor(); auto ret = NEO::KernelHelper::checkIfThereIsSpaceForScratchOrPrivate(kernelDescriptor.kernelAttributes, neoDevice); + if (ret == NEO::KernelHelper::ErrorCode::INVALID_KERNEL) { + return ZE_RESULT_ERROR_INVALID_NATIVE_BINARY; + } if (ret == NEO::KernelHelper::ErrorCode::OUT_OF_DEVICE_MEMORY) { return ZE_RESULT_ERROR_OUT_OF_DEVICE_MEMORY; } diff --git a/level_zero/core/test/unit_tests/fixtures/module_fixture.h b/level_zero/core/test/unit_tests/fixtures/module_fixture.h index eca32e276f..12acbbb0c6 100644 --- a/level_zero/core/test/unit_tests/fixtures/module_fixture.h +++ b/level_zero/core/test/unit_tests/fixtures/module_fixture.h @@ -77,7 +77,35 @@ struct ModuleImmutableDataFixture : public DeviceFixture { canonizedGpuAddress)); kernelInfo->kernelAllocation = isaGraphicsAllocation.get(); } + MockImmutableData(uint32_t perHwThreadPrivateMemorySize, uint32_t perThreadScratchSize, uint32_t perThreaddPrivateScratchSize) { + mockKernelDescriptor = new NEO::KernelDescriptor; + mockKernelDescriptor->kernelAttributes.perHwThreadPrivateMemorySize = perHwThreadPrivateMemorySize; + mockKernelDescriptor->kernelAttributes.perThreadScratchSize[0] = perThreadScratchSize; + mockKernelDescriptor->kernelAttributes.perThreadScratchSize[1] = perThreaddPrivateScratchSize; + kernelDescriptor = mockKernelDescriptor; + mockKernelInfo = new NEO::KernelInfo; + mockKernelInfo->heapInfo.pKernelHeap = kernelHeap; + mockKernelInfo->heapInfo.KernelHeapSize = MemoryConstants::pageSize; + kernelInfo = mockKernelInfo; + + if (getIsaGraphicsAllocation() != nullptr) { + device->getNEODevice()->getMemoryManager()->freeGraphicsMemory(&*isaGraphicsAllocation); + isaGraphicsAllocation.release(); + } + auto ptr = reinterpret_cast(0x1234); + auto gmmHelper = std::make_unique(nullptr, defaultHwInfo.get()); + auto canonizedGpuAddress = gmmHelper->canonize(castToUint64(ptr)); + isaGraphicsAllocation.reset(new NEO::MockGraphicsAllocation(0, + NEO::AllocationType::KERNEL_ISA, + ptr, + 0x1000, + 0u, + MemoryPool::System4KBPages, + MemoryManager::maxOsContextCount, + canonizedGpuAddress)); + kernelInfo->kernelAllocation = isaGraphicsAllocation.get(); + } void setDevice(L0::Device *inDevice) { device = inDevice; } diff --git a/level_zero/core/test/unit_tests/sources/kernel/test_kernel.cpp b/level_zero/core/test/unit_tests/sources/kernel/test_kernel.cpp index c36c415cd1..7bc37662c2 100644 --- a/level_zero/core/test/unit_tests/sources/kernel/test_kernel.cpp +++ b/level_zero/core/test/unit_tests/sources/kernel/test_kernel.cpp @@ -78,6 +78,23 @@ TEST_F(KernelInitTest, givenKernelToInitWhenItHasTooBigPrivateSizeThenOutOfMemor EXPECT_EQ(kernel->initialize(&desc), ZE_RESULT_ERROR_OUT_OF_DEVICE_MEMORY); } +TEST_F(KernelInitTest, givenKernelToInitWhenItHasTooBigScratchSizeThenInvalidBinaryIsRetutned) { + auto globalSize = device->getNEODevice()->getRootDevice()->getGlobalMemorySize(static_cast(device->getNEODevice()->getDeviceBitfield().to_ulong())); + uint32_t perHwThreadPrivateMemorySizeRequested = (static_cast((globalSize + device->getNEODevice()->getDeviceInfo().computeUnitsUsedForScratch) / device->getNEODevice()->getDeviceInfo().computeUnitsUsedForScratch)) / 2; + auto &hwHelper = NEO::HwHelper::get(device->getHwInfo().platform.eRenderCoreFamily); + uint32_t maxScratchSize = hwHelper.getMaxScratchSize(); + std::unique_ptr mockKernelImmData = + std::make_unique(perHwThreadPrivateMemorySizeRequested, maxScratchSize + 1, 0x100); + + createModuleFromMockBinary(perHwThreadPrivateMemorySizeRequested, false, mockKernelImmData.get()); + std::unique_ptr kernel; + kernel = std::make_unique(module.get()); + ze_kernel_desc_t desc = {}; + desc.pKernelName = kernelName.c_str(); + mockKernelImmData->resizeExplicitArgs(1); + EXPECT_EQ(kernel->initialize(&desc), ZE_RESULT_ERROR_INVALID_NATIVE_BINARY); +} + using KernelBaseAddressTests = Test; TEST_F(KernelBaseAddressTests, whenQueryingKernelBaseAddressThenCorrectAddressIsReturned) { uint32_t perHwThreadPrivateMemorySizeRequested = 32u; diff --git a/opencl/source/kernel/kernel.cpp b/opencl/source/kernel/kernel.cpp index af61524cd0..f913cf1af8 100644 --- a/opencl/source/kernel/kernel.cpp +++ b/opencl/source/kernel/kernel.cpp @@ -158,6 +158,9 @@ cl_int Kernel::initialize() { pImplicitArgs->simdWidth = maxSimdSize; } auto ret = KernelHelper::checkIfThereIsSpaceForScratchOrPrivate(kernelDescriptor.kernelAttributes, &pClDevice->getDevice()); + if (ret == NEO::KernelHelper::ErrorCode::INVALID_KERNEL) { + return CL_INVALID_KERNEL; + } if (ret == NEO::KernelHelper::ErrorCode::OUT_OF_DEVICE_MEMORY) { return CL_OUT_OF_RESOURCES; } diff --git a/opencl/test/unit_test/kernel/kernel_tests.cpp b/opencl/test/unit_test/kernel/kernel_tests.cpp index 97daf67c84..1ed57ce4d6 100644 --- a/opencl/test/unit_test/kernel/kernel_tests.cpp +++ b/opencl/test/unit_test/kernel/kernel_tests.cpp @@ -786,6 +786,21 @@ TEST_F(KernelPrivateSurfaceTest, GivenKernelWhenPrivateSurfaceTooBigAndGpuPointe EXPECT_EQ(CL_OUT_OF_RESOURCES, kernel->patchPrivateSurface()); } +TEST_F(KernelPrivateSurfaceTest, GivenKernelWhenScratchSizeIsGreaterThanMaxScratchSizeThenReturnInvalidKernel) { + auto &hwHelper = NEO::HwHelper::get(pDevice->getHardwareInfo().platform.eRenderCoreFamily); + uint32_t maxScratchSize = hwHelper.getMaxScratchSize(); + + auto pKernelInfo = std::make_unique(); + pKernelInfo->kernelDescriptor.kernelAttributes.simdSize = 32; + pKernelInfo->setPrivateMemory(0x100, false, 0, 0, 0); + pKernelInfo->setPerThreadScratchSize(maxScratchSize + 100, 0); + + MockContext context; + MockProgram program(&context, false, toClDeviceVector(*pClDevice)); + std::unique_ptr kernel(new MockKernel(&program, *pKernelInfo, *pClDevice)); + EXPECT_EQ(CL_INVALID_KERNEL, kernel->initialize()); +} + TEST_F(KernelPrivateSurfaceTest, GivenKernelWhenPrivateSurfaceTooBigAndGpuPointerSize4And32BitAllocationsThenReturnOutOfResources) { auto pKernelInfo = std::make_unique(); pKernelInfo->kernelDescriptor.kernelAttributes.simdSize = 32; diff --git a/shared/source/command_stream/scratch_space_controller_xehp_and_later.cpp b/shared/source/command_stream/scratch_space_controller_xehp_and_later.cpp index 3978c45df2..afe8329e4d 100644 --- a/shared/source/command_stream/scratch_space_controller_xehp_and_later.cpp +++ b/shared/source/command_stream/scratch_space_controller_xehp_and_later.cpp @@ -158,7 +158,7 @@ void ScratchSpaceControllerXeHPAndLater::prepareScratchAllocation(uint32_t requi bool &scratchSurfaceDirty, bool &vfeStateDirty) { uint32_t requiredPerThreadScratchSizeAlignedUp = alignUp(requiredPerThreadScratchSize, 64); - size_t requiredScratchSizeInBytes = requiredPerThreadScratchSizeAlignedUp * computeUnitsUsedForScratch; + size_t requiredScratchSizeInBytes = static_cast(requiredPerThreadScratchSizeAlignedUp) * computeUnitsUsedForScratch; scratchSurfaceDirty = false; auto multiTileCapable = osContext.getNumSupportedDevices() > 1; if (scratchSizeBytes < requiredScratchSizeInBytes) { @@ -174,7 +174,7 @@ void ScratchSpaceControllerXeHPAndLater::prepareScratchAllocation(uint32_t requi } if (privateScratchSpaceSupported) { uint32_t requiredPerThreadPrivateScratchSizeAlignedUp = alignUp(requiredPerThreadPrivateScratchSize, 64); - size_t requiredPrivateScratchSizeInBytes = requiredPerThreadPrivateScratchSizeAlignedUp * computeUnitsUsedForScratch; + size_t requiredPrivateScratchSizeInBytes = static_cast(requiredPerThreadPrivateScratchSizeAlignedUp) * computeUnitsUsedForScratch; if (privateScratchSizeBytes < requiredPrivateScratchSizeInBytes) { if (privateScratchAllocation) { privateScratchAllocation->updateTaskCount(currentTaskCount, osContext.getContextId()); diff --git a/shared/source/helpers/hw_helper.h b/shared/source/helpers/hw_helper.h index d5e7d24a2f..ee862b3983 100644 --- a/shared/source/helpers/hw_helper.h +++ b/shared/source/helpers/hw_helper.h @@ -136,6 +136,7 @@ class HwHelper { virtual size_t getSamplerStateSize() const = 0; virtual bool preferInternalBcsEngine() const = 0; virtual bool isScratchSpaceSurfaceStateAccessible() const = 0; + virtual uint32_t getMaxScratchSize() const = 0; virtual uint64_t getRenderSurfaceStateBaseAddress(void *renderSurfaceState) const = 0; virtual uint32_t getRenderSurfaceStatePitch(void *renderSurfaceState) const = 0; virtual size_t getMax3dImageWidthOrHeight() const = 0; @@ -354,6 +355,7 @@ class HwHelperHw : public HwHelper { void adjustPreemptionSurfaceSize(size_t &csrSize) const override; bool isScratchSpaceSurfaceStateAccessible() const override; + uint32_t getMaxScratchSize() const override; bool preferInternalBcsEngine() const override; size_t getMax3dImageWidthOrHeight() const override; uint64_t getMaxMemAllocSize() const override; diff --git a/shared/source/helpers/hw_helper_bdw_and_later.inl b/shared/source/helpers/hw_helper_bdw_and_later.inl index c8556fc09d..17fc93cb56 100644 --- a/shared/source/helpers/hw_helper_bdw_and_later.inl +++ b/shared/source/helpers/hw_helper_bdw_and_later.inl @@ -145,6 +145,11 @@ bool HwHelperHw::isScratchSpaceSurfaceStateAccessible() const { return false; } +template +uint32_t HwHelperHw::getMaxScratchSize() const { + return 2 * MB; +} + template inline bool HwHelperHw::platformSupportsImplicitScaling(const NEO::HardwareInfo &hwInfo) const { return false; diff --git a/shared/source/helpers/hw_helper_xehp_and_later.inl b/shared/source/helpers/hw_helper_xehp_and_later.inl index f1497435cf..aeafdff002 100644 --- a/shared/source/helpers/hw_helper_xehp_and_later.inl +++ b/shared/source/helpers/hw_helper_xehp_and_later.inl @@ -202,6 +202,10 @@ template bool HwHelperHw::isScratchSpaceSurfaceStateAccessible() const { return true; } +template +uint32_t HwHelperHw::getMaxScratchSize() const { + return 256 * KB; +} template inline bool HwHelperHw::platformSupportsImplicitScaling(const NEO::HardwareInfo &hwInfo) const { diff --git a/shared/source/helpers/kernel_helpers.cpp b/shared/source/helpers/kernel_helpers.cpp index 30c9957bb5..f46c087e02 100644 --- a/shared/source/helpers/kernel_helpers.cpp +++ b/shared/source/helpers/kernel_helpers.cpp @@ -11,6 +11,7 @@ #include "shared/source/device/device.h" #include "shared/source/helpers/basic_math.h" #include "shared/source/helpers/debug_helpers.h" +#include "shared/source/helpers/hw_helper.h" #include @@ -48,6 +49,11 @@ uint32_t KernelHelper::getMaxWorkGroupCount(uint32_t simd, uint32_t availableThr } KernelHelper::ErrorCode KernelHelper::checkIfThereIsSpaceForScratchOrPrivate(KernelDescriptor::KernelAttributes attributes, Device *device) { + auto &coreHelper = device->getRootDeviceEnvironment().getHelper(); + uint32_t maxScratchSize = coreHelper.getMaxScratchSize(); + if ((attributes.perThreadScratchSize[0] > maxScratchSize) || (attributes.perThreadScratchSize[1] > maxScratchSize)) { + return KernelHelper::ErrorCode::INVALID_KERNEL; + } auto globalMemorySize = device->getDeviceInfo().globalMemSize; uint32_t sizes[] = {attributes.perHwThreadPrivateMemorySize, attributes.perThreadScratchSize[0], diff --git a/shared/source/helpers/kernel_helpers.h b/shared/source/helpers/kernel_helpers.h index c796253785..ec55d153f1 100644 --- a/shared/source/helpers/kernel_helpers.h +++ b/shared/source/helpers/kernel_helpers.h @@ -18,7 +18,8 @@ class Device; struct KernelHelper { enum class ErrorCode { SUCCESS = 0, - OUT_OF_DEVICE_MEMORY = 1 + OUT_OF_DEVICE_MEMORY = 1, + INVALID_KERNEL = 2 }; static uint32_t getMaxWorkGroupCount(uint32_t simd, uint32_t availableThreadCount, uint32_t dssCount, uint32_t availableSlmSize, uint32_t usedSlmSize, uint32_t maxBarrierCount, uint32_t numberOfBarriers, uint32_t workDim, diff --git a/shared/test/unit_test/helpers/kernel_helpers_tests.cpp b/shared/test/unit_test/helpers/kernel_helpers_tests.cpp index ef479847cb..1d82ef7f20 100644 --- a/shared/test/unit_test/helpers/kernel_helpers_tests.cpp +++ b/shared/test/unit_test/helpers/kernel_helpers_tests.cpp @@ -7,6 +7,7 @@ #include "shared/source/helpers/basic_math.h" #include "shared/source/helpers/constants.h" +#include "shared/source/helpers/hw_helper.h" #include "shared/source/helpers/kernel_helpers.h" #include "shared/test/common/fixtures/device_fixture.h" #include "shared/test/common/helpers/debug_manager_state_restore.h" @@ -94,14 +95,24 @@ TEST_F(KernelHelperTest, GivenScratchSizeGreaterThanGlobalSizeWhenCheckingIfTher auto globalSize = pDevice->getDeviceInfo().globalMemSize; KernelDescriptor::KernelAttributes attributes = {}; attributes.perThreadScratchSize[0] = (static_cast((globalSize + pDevice->getDeviceInfo().computeUnitsUsedForScratch) / pDevice->getDeviceInfo().computeUnitsUsedForScratch)) + 100; - EXPECT_EQ(KernelHelper::checkIfThereIsSpaceForScratchOrPrivate(attributes, pDevice), KernelHelper::ErrorCode::OUT_OF_DEVICE_MEMORY); + auto &hwHelper = NEO::HwHelper::get(pDevice->getHardwareInfo().platform.eRenderCoreFamily); + if (attributes.perThreadScratchSize[0] > hwHelper.getMaxScratchSize()) { + EXPECT_EQ(KernelHelper::checkIfThereIsSpaceForScratchOrPrivate(attributes, pDevice), KernelHelper::ErrorCode::INVALID_KERNEL); + } else { + EXPECT_EQ(KernelHelper::checkIfThereIsSpaceForScratchOrPrivate(attributes, pDevice), KernelHelper::ErrorCode::OUT_OF_DEVICE_MEMORY); + } } TEST_F(KernelHelperTest, GivenScratchPrivateSizeGreaterThanGlobalSizeWhenCheckingIfThereIsEnaughSpaceThenOutOfMemReturned) { auto globalSize = pDevice->getDeviceInfo().globalMemSize; KernelDescriptor::KernelAttributes attributes = {}; attributes.perThreadScratchSize[1] = (static_cast((globalSize + pDevice->getDeviceInfo().computeUnitsUsedForScratch) / pDevice->getDeviceInfo().computeUnitsUsedForScratch)) + 100; - EXPECT_EQ(KernelHelper::checkIfThereIsSpaceForScratchOrPrivate(attributes, pDevice), KernelHelper::ErrorCode::OUT_OF_DEVICE_MEMORY); + auto &hwHelper = NEO::HwHelper::get(pDevice->getHardwareInfo().platform.eRenderCoreFamily); + if (attributes.perThreadScratchSize[1] > hwHelper.getMaxScratchSize()) { + EXPECT_EQ(KernelHelper::checkIfThereIsSpaceForScratchOrPrivate(attributes, pDevice), KernelHelper::ErrorCode::INVALID_KERNEL); + } else { + EXPECT_EQ(KernelHelper::checkIfThereIsSpaceForScratchOrPrivate(attributes, pDevice), KernelHelper::ErrorCode::OUT_OF_DEVICE_MEMORY); + } } TEST_F(KernelHelperTest, GivenScratchAndPrivateSizeLessThanGlobalSizeWhenCheckingIfThereIsEnaughSpaceThenSuccessReturned) { @@ -109,7 +120,45 @@ TEST_F(KernelHelperTest, GivenScratchAndPrivateSizeLessThanGlobalSizeWhenCheckin KernelDescriptor::KernelAttributes attributes = {}; auto size = (static_cast((globalSize + pDevice->getDeviceInfo().computeUnitsUsedForScratch) / pDevice->getDeviceInfo().computeUnitsUsedForScratch)) - 100; attributes.perHwThreadPrivateMemorySize = size; - attributes.perThreadScratchSize[0] = size; - attributes.perThreadScratchSize[1] = size; + auto &coreHelper = pDevice->getRootDeviceEnvironment().getHelper(); + uint32_t maxScratchSize = coreHelper.getMaxScratchSize(); + attributes.perThreadScratchSize[0] = (size > maxScratchSize) ? maxScratchSize : size; + attributes.perThreadScratchSize[1] = (size > maxScratchSize) ? maxScratchSize : size; + EXPECT_EQ(KernelHelper::checkIfThereIsSpaceForScratchOrPrivate(attributes, pDevice), KernelHelper::ErrorCode::SUCCESS); +} + +TEST_F(KernelHelperTest, GivenScratchSizeGreaterThanMaxScratchSizeWhenCheckingIfThereIsEnaughSpaceThenInvalidKernelIsReturned) { + KernelDescriptor::KernelAttributes attributes = {}; + auto &coreHelper = pDevice->getRootDeviceEnvironment().getHelper(); + uint32_t maxScratchSize = coreHelper.getMaxScratchSize(); + attributes.perHwThreadPrivateMemorySize = 0x10; + attributes.perThreadScratchSize[0] = maxScratchSize + 1; + attributes.perThreadScratchSize[1] = 0x10; + EXPECT_EQ(KernelHelper::checkIfThereIsSpaceForScratchOrPrivate(attributes, pDevice), KernelHelper::ErrorCode::INVALID_KERNEL); +} + +TEST_F(KernelHelperTest, GivenScratchPrivateSizeGreaterThanMaxScratchSizeWhenCheckingIfThereIsEnaughSpaceThenInvalidKernelIsReturned) { + KernelDescriptor::KernelAttributes attributes = {}; + auto &coreHelper = pDevice->getRootDeviceEnvironment().getHelper(); + uint32_t maxScratchSize = coreHelper.getMaxScratchSize(); + attributes.perHwThreadPrivateMemorySize = 0x10; + attributes.perThreadScratchSize[0] = 0x10; + attributes.perThreadScratchSize[1] = maxScratchSize + 1; + EXPECT_EQ(KernelHelper::checkIfThereIsSpaceForScratchOrPrivate(attributes, pDevice), KernelHelper::ErrorCode::INVALID_KERNEL); +} + +TEST_F(KernelHelperTest, GivenScratchAndEqualsZeroWhenCheckingIfThereIsEnaughSpaceThenSuccessIsReturned) { + KernelDescriptor::KernelAttributes attributes = {}; + attributes.perHwThreadPrivateMemorySize = 0; + attributes.perThreadScratchSize[0] = 0; + attributes.perThreadScratchSize[1] = 0; + EXPECT_EQ(KernelHelper::checkIfThereIsSpaceForScratchOrPrivate(attributes, pDevice), KernelHelper::ErrorCode::SUCCESS); +} + +TEST_F(KernelHelperTest, GivenScratchEqualsZeroAndPrivetGreaterThanZeroWhenCheckingIfThereIsEnaughSpaceThenSuccessIsReturned) { + KernelDescriptor::KernelAttributes attributes = {}; + attributes.perHwThreadPrivateMemorySize = 0x10; + attributes.perThreadScratchSize[0] = 0; + attributes.perThreadScratchSize[1] = 0; EXPECT_EQ(KernelHelper::checkIfThereIsSpaceForScratchOrPrivate(attributes, pDevice), KernelHelper::ErrorCode::SUCCESS); } \ No newline at end of file diff --git a/shared/test/unit_test/xe_hpg_core/dg2/CMakeLists.txt b/shared/test/unit_test/xe_hpg_core/dg2/CMakeLists.txt index 8399dbf3bc..b6d7b25f3e 100644 --- a/shared/test/unit_test/xe_hpg_core/dg2/CMakeLists.txt +++ b/shared/test/unit_test/xe_hpg_core/dg2/CMakeLists.txt @@ -19,6 +19,7 @@ if(TESTS_DG2) ${CMAKE_CURRENT_SOURCE_DIR}/hw_info_config_tests_dg2.cpp ${CMAKE_CURRENT_SOURCE_DIR}/memory_manager_tests_dg2.cpp ${CMAKE_CURRENT_SOURCE_DIR}/product_config_helper_tests_dg2.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/sampler_tests_dg2.cpp ${CMAKE_CURRENT_SOURCE_DIR}/test_encode_dg2.cpp ${CMAKE_CURRENT_SOURCE_DIR}/test_encode_dispatch_kernel_dg2.cpp ${CMAKE_CURRENT_SOURCE_DIR}/test_hw_helper_dg2.cpp diff --git a/shared/test/unit_test/xe_hpg_core/dg2/sampler_tests_dg2.cpp b/shared/test/unit_test/xe_hpg_core/dg2/sampler_tests_dg2.cpp new file mode 100644 index 0000000000..12d843d38d --- /dev/null +++ b/shared/test/unit_test/xe_hpg_core/dg2/sampler_tests_dg2.cpp @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2022 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "shared/source/debug_settings/debug_settings_manager.h" +#include "shared/source/os_interface/hw_info_config.h" +#include "shared/test/common/helpers/debug_manager_state_restore.h" +#include "shared/test/common/helpers/default_hw_info.h" +#include "shared/test/common/test_macros/hw_test.h" + +#include + +using namespace NEO; + +using SamplerTestDG2 = ::testing::Test; + +HWTEST2_F(SamplerTestDG2, givenDG2SamplerWhenUsingDefaultFilteringAndAppendSamplerStateParamsThenDisableLowQualityFilter, IsDG2) { + EXPECT_FALSE(DebugManager.flags.ForceSamplerLowFilteringPrecision.get()); + typedef typename FamilyType::SAMPLER_STATE SAMPLER_STATE; + + auto state = FamilyType::cmdInitSamplerState; + + EXPECT_EQ(SAMPLER_STATE::LOW_QUALITY_FILTER_DISABLE, state.getLowQualityFilter()); + HwInfoConfig::get(defaultHwInfo->platform.eProductFamily)->adjustSamplerState(&state, *defaultHwInfo); + EXPECT_EQ(SAMPLER_STATE::LOW_QUALITY_FILTER_DISABLE, state.getLowQualityFilter()); +} + +HWTEST2_F(SamplerTestDG2, giveDG2SamplerWhenForcingLowQualityFilteringAndAppendSamplerStateParamsThenEnableLowQualityFilter, IsDG2) { + DebugManagerStateRestore dbgRestore; + DebugManager.flags.ForceSamplerLowFilteringPrecision.set(true); + EXPECT_TRUE(DebugManager.flags.ForceSamplerLowFilteringPrecision.get()); + typedef typename FamilyType::SAMPLER_STATE SAMPLER_STATE; + + auto state = FamilyType::cmdInitSamplerState; + + EXPECT_EQ(SAMPLER_STATE::LOW_QUALITY_FILTER_DISABLE, state.getLowQualityFilter()); + HwInfoConfig::get(defaultHwInfo->platform.eProductFamily)->adjustSamplerState(&state, *defaultHwInfo); + EXPECT_EQ(SAMPLER_STATE::LOW_QUALITY_FILTER_ENABLE, state.getLowQualityFilter()); +}