Add function to check for USM host allocations in SVM Allocs Manager

Signed-off-by: Slawomir Milczarek <slawomir.milczarek@intel.com>
This commit is contained in:
Slawomir Milczarek 2021-01-11 17:42:33 +00:00 committed by Compute-Runtime-Automation
parent 90fd102fe5
commit 068cb09c90
4 changed files with 47 additions and 1 deletions

View File

@ -2625,6 +2625,11 @@ bool Kernel::hasIndirectStatelessAccessToHostMemory() const {
return true;
}
}
if (unifiedMemoryControls.indirectHostAllocationsAllowed) {
return getContext().getSVMAllocsManager()->hasHostAllocations();
}
return false;
}

View File

@ -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);

View File

@ -421,6 +421,16 @@ void SVMAllocsManager::freeSvmAllocationWithDeviceStorage(SvmAllocationData *svm
memoryManager->freeGraphicsMemory(cpuAllocation);
}
bool SVMAllocsManager::hasHostAllocations() {
std::unique_lock<SpinLock> 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<SpinLock> lock(mtx);
return svmMapOperations.get(ptr);

View File

@ -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,