diff --git a/opencl/source/kernel/kernel.cpp b/opencl/source/kernel/kernel.cpp index bc86050b44..f6bde0d25b 100644 --- a/opencl/source/kernel/kernel.cpp +++ b/opencl/source/kernel/kernel.cpp @@ -2615,6 +2615,19 @@ bool Kernel::hasDirectStatelessAccessToHostMemory() const { return false; } +bool Kernel::hasIndirectStatelessAccessToHostMemory() const { + if (!getDefaultKernelInfo().hasIndirectStatelessAccess) { + return false; + } + + for (auto gfxAllocation : kernelUnifiedMemoryGfxAllocations) { + if (gfxAllocation->getAllocationType() == GraphicsAllocation::AllocationType::BUFFER_HOST_MEMORY) { + return true; + } + } + return false; +} + void Kernel::getAllocationsForCacheFlush(CacheFlushAllocationsVec &out, uint32_t rootDeviceIndex) const { if (false == HwHelper::cacheFlushAfterWalkerSupported(getHardwareInfo(rootDeviceIndex))) { return; diff --git a/opencl/source/kernel/kernel.h b/opencl/source/kernel/kernel.h index 5fb6be1b99..62d5ee77b7 100644 --- a/opencl/source/kernel/kernel.h +++ b/opencl/source/kernel/kernel.h @@ -501,6 +501,7 @@ class Kernel : public BaseObject<_cl_kernel> { void reconfigureKernel(uint32_t rootDeviceIndex); bool hasDirectStatelessAccessToHostMemory() const; + bool hasIndirectStatelessAccessToHostMemory() const; void addAllocationToCacheFlushVector(uint32_t argIndex, GraphicsAllocation *argAllocation); bool allocationForCacheFlush(GraphicsAllocation *argAllocation) const; diff --git a/opencl/test/unit_test/kernel/kernel_arg_buffer_tests.cpp b/opencl/test/unit_test/kernel/kernel_arg_buffer_tests.cpp index adfd92a11a..f61cd3f1c2 100644 --- a/opencl/test/unit_test/kernel/kernel_arg_buffer_tests.cpp +++ b/opencl/test/unit_test/kernel/kernel_arg_buffer_tests.cpp @@ -432,6 +432,36 @@ TEST_F(KernelArgBufferTest, givenInvalidKernelObjWhenHasDirectStatelessAccessToH EXPECT_FALSE(pKernel->hasDirectStatelessAccessToHostMemory()); } +TEST_F(KernelArgBufferTest, givenKernelWithIndirectStatelessAccessWhenHasIndirectStatelessAccessToHostMemoryIsCalledThenReturnTrueForHostMemoryAllocations) { + KernelInfo kernelInfo; + EXPECT_FALSE(kernelInfo.hasIndirectStatelessAccess); + + MockKernel kernelWithNoIndirectStatelessAccess(pProgram, MockKernel::toKernelInfoContainer(kernelInfo, 0)); + EXPECT_FALSE(kernelWithNoIndirectStatelessAccess.hasIndirectStatelessAccessToHostMemory()); + + kernelInfo.hasIndirectStatelessAccess = true; + + MockKernel kernelWithNoIndirectHostAllocations(pProgram, MockKernel::toKernelInfoContainer(kernelInfo, 0)); + EXPECT_FALSE(kernelWithNoIndirectHostAllocations.hasIndirectStatelessAccessToHostMemory()); + + const auto allocationTypes = {GraphicsAllocation::AllocationType::BUFFER, + GraphicsAllocation::AllocationType::BUFFER_COMPRESSED, + GraphicsAllocation::AllocationType::BUFFER_HOST_MEMORY}; + + MockKernel kernelWithIndirectUnifiedMemoryAllocation(pProgram, MockKernel::toKernelInfoContainer(kernelInfo, 0)); + MockGraphicsAllocation gfxAllocation; + for (const auto type : allocationTypes) { + gfxAllocation.setAllocationType(type); + kernelWithIndirectUnifiedMemoryAllocation.setUnifiedMemoryExecInfo(&gfxAllocation); + if (type == GraphicsAllocation::AllocationType::BUFFER_HOST_MEMORY) { + EXPECT_TRUE(kernelWithIndirectUnifiedMemoryAllocation.hasIndirectStatelessAccessToHostMemory()); + } else { + EXPECT_FALSE(kernelWithIndirectUnifiedMemoryAllocation.hasIndirectStatelessAccessToHostMemory()); + } + kernelWithIndirectUnifiedMemoryAllocation.clearUnifiedMemoryExecInfo(); + } +} + TEST_F(KernelArgBufferTest, whenSettingAuxTranslationRequiredThenIsAuxTranslationRequiredReturnsCorrectValue) { for (auto auxTranslationRequired : {false, true}) { pKernel->setAuxTranslationRequired(auxTranslationRequired); diff --git a/opencl/test/unit_test/mocks/mock_kernel.h b/opencl/test/unit_test/mocks/mock_kernel.h index 0126847808..b6522777cb 100644 --- a/opencl/test/unit_test/mocks/mock_kernel.h +++ b/opencl/test/unit_test/mocks/mock_kernel.h @@ -63,6 +63,7 @@ class MockKernel : public Kernel { using Kernel::containsStatelessWrites; using Kernel::executionType; using Kernel::hasDirectStatelessAccessToHostMemory; + using Kernel::hasIndirectStatelessAccessToHostMemory; using Kernel::isSchedulerKernel; using Kernel::kernelArgHandlers; using Kernel::kernelArgRequiresCacheFlush;