diff --git a/opencl/source/kernel/kernel.cpp b/opencl/source/kernel/kernel.cpp index f6bde0d25b..a2b5e5aa47 100644 --- a/opencl/source/kernel/kernel.cpp +++ b/opencl/source/kernel/kernel.cpp @@ -2625,6 +2625,11 @@ bool Kernel::hasIndirectStatelessAccessToHostMemory() const { return true; } } + + if (unifiedMemoryControls.indirectHostAllocationsAllowed) { + return getContext().getSVMAllocsManager()->hasHostAllocations(); + } + return false; } 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 f61cd3f1c2..9ad5cfd49f 100644 --- a/opencl/test/unit_test/kernel/kernel_arg_buffer_tests.cpp +++ b/opencl/test/unit_test/kernel/kernel_arg_buffer_tests.cpp @@ -5,6 +5,8 @@ * */ +#include "shared/source/memory_manager/unified_memory_manager.h" +#include "shared/source/unified_memory/unified_memory.h" #include "shared/test/unit_test/helpers/debug_manager_state_restore.h" #include "opencl/source/kernel/kernel.h" @@ -462,6 +464,34 @@ TEST_F(KernelArgBufferTest, givenKernelWithIndirectStatelessAccessWhenHasIndirec } } +TEST_F(KernelArgBufferTest, givenKernelExecInfoWithIndirectStatelessAccessWhenHasIndirectStatelessAccessToHostMemoryIsCalledThenReturnTrueForHostMemoryAllocations) { + KernelInfo kernelInfo; + kernelInfo.hasIndirectStatelessAccess = true; + + MockKernel mockKernel(pProgram, MockKernel::toKernelInfoContainer(kernelInfo, 0)); + EXPECT_FALSE(mockKernel.unifiedMemoryControls.indirectHostAllocationsAllowed); + EXPECT_FALSE(mockKernel.hasIndirectStatelessAccessToHostMemory()); + + auto svmAllocationsManager = mockKernel.getContext().getSVMAllocsManager(); + if (svmAllocationsManager == nullptr) { + return; + } + + mockKernel.unifiedMemoryControls.indirectHostAllocationsAllowed = true; + EXPECT_FALSE(mockKernel.hasIndirectStatelessAccessToHostMemory()); + + auto deviceProperties = SVMAllocsManager::UnifiedMemoryProperties(InternalMemoryType::DEVICE_UNIFIED_MEMORY, mockKernel.getContext().getRootDeviceIndices(), mockKernel.getContext().getDeviceBitfields()); + auto unifiedDeviceMemoryAllocation = svmAllocationsManager->createUnifiedMemoryAllocation(4096u, deviceProperties); + EXPECT_FALSE(mockKernel.hasIndirectStatelessAccessToHostMemory()); + + auto hostProperties = SVMAllocsManager::UnifiedMemoryProperties(InternalMemoryType::HOST_UNIFIED_MEMORY, mockKernel.getContext().getRootDeviceIndices(), mockKernel.getContext().getDeviceBitfields()); + auto unifiedHostMemoryAllocation = svmAllocationsManager->createUnifiedMemoryAllocation(4096u, hostProperties); + EXPECT_TRUE(mockKernel.hasIndirectStatelessAccessToHostMemory()); + + svmAllocationsManager->freeSVMAlloc(unifiedDeviceMemoryAllocation); + svmAllocationsManager->freeSVMAlloc(unifiedHostMemoryAllocation); +} + TEST_F(KernelArgBufferTest, whenSettingAuxTranslationRequiredThenIsAuxTranslationRequiredReturnsCorrectValue) { for (auto auxTranslationRequired : {false, true}) { pKernel->setAuxTranslationRequired(auxTranslationRequired); diff --git a/shared/source/memory_manager/unified_memory_manager.cpp b/shared/source/memory_manager/unified_memory_manager.cpp index f88b4d9854..7e04ee0f79 100644 --- a/shared/source/memory_manager/unified_memory_manager.cpp +++ b/shared/source/memory_manager/unified_memory_manager.cpp @@ -421,6 +421,16 @@ void SVMAllocsManager::freeSvmAllocationWithDeviceStorage(SvmAllocationData *svm memoryManager->freeGraphicsMemory(cpuAllocation); } +bool SVMAllocsManager::hasHostAllocations() { + std::unique_lock lock(mtx); + for (auto &allocation : this->SVMAllocs.allocations) { + if (allocation.second.memoryType == InternalMemoryType::HOST_UNIFIED_MEMORY) { + return true; + } + } + return false; +} + SvmMapOperation *SVMAllocsManager::getSvmMapOperation(const void *ptr) { std::unique_lock lock(mtx); return svmMapOperations.get(ptr); diff --git a/shared/source/memory_manager/unified_memory_manager.h b/shared/source/memory_manager/unified_memory_manager.h index db2697874f..6b6930122b 100644 --- a/shared/source/memory_manager/unified_memory_manager.h +++ b/shared/source/memory_manager/unified_memory_manager.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017-2020 Intel Corporation + * Copyright (C) 2017-2021 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -139,6 +139,7 @@ class SVMAllocsManager { void makeInternalAllocationsResident(CommandStreamReceiver &commandStreamReceiver, uint32_t requestedTypesMask); void *createUnifiedAllocationWithDeviceStorage(size_t size, const SvmAllocationProperties &svmProperties, const UnifiedMemoryProperties &unifiedMemoryProperties); void freeSvmAllocationWithDeviceStorage(SvmAllocationData *svmData); + bool hasHostAllocations(); protected: void *createZeroCopySvmAllocation(size_t size, const SvmAllocationProperties &svmProperties,