mirror of
https://github.com/intel/compute-runtime.git
synced 2025-12-18 13:54:58 +08:00
fix(ocl): do not reuse usm for globals export
Allocating global surface is expecting that the usm allocation is zeroed out. Reusing allocations can be filled with junk data and this caused errors. Resolves: HSD-18038551036, HSD-18038551766, HSD-18038551957, HSD-18038552252 Signed-off-by: Dominik Dabek <dominik.dabek@intel.com>
This commit is contained in:
committed by
Compute-Runtime-Automation
parent
3890f21600
commit
c9758216fc
@@ -297,7 +297,8 @@ void *SVMAllocsManager::createUnifiedMemoryAllocation(size_t size,
|
||||
|
||||
if (memoryProperties.memoryType == InternalMemoryType::deviceUnifiedMemory) {
|
||||
unifiedMemoryProperties.flags.isUSMDeviceAllocation = true;
|
||||
if (this->usmDeviceAllocationsCacheEnabled) {
|
||||
if (this->usmDeviceAllocationsCacheEnabled &&
|
||||
false == memoryProperties.needZeroedOutAllocation) {
|
||||
void *allocationFromCache = this->usmDeviceAllocationsCache.get(size, memoryProperties, this);
|
||||
if (allocationFromCache) {
|
||||
return allocationFromCache;
|
||||
|
||||
@@ -138,6 +138,7 @@ class SVMAllocsManager {
|
||||
const RootDeviceIndicesContainer &rootDeviceIndices;
|
||||
const std::map<uint32_t, DeviceBitfield> &subdeviceBitfields;
|
||||
AllocationType requestedAllocationType = AllocationType::unknown;
|
||||
bool needZeroedOutAllocation = false;
|
||||
};
|
||||
|
||||
struct SvmCacheAllocationInfo {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2020-2023 Intel Corporation
|
||||
* Copyright (C) 2020-2024 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
@@ -38,6 +38,7 @@ GraphicsAllocation *allocateGlobalsSurface(NEO::SVMAllocsManager *const svmAlloc
|
||||
NEO::SVMAllocsManager::UnifiedMemoryProperties unifiedMemoryProperties(InternalMemoryType::deviceUnifiedMemory, 1, rootDeviceIndices, subDeviceBitfields);
|
||||
unifiedMemoryProperties.device = &device;
|
||||
unifiedMemoryProperties.requestedAllocationType = allocationType;
|
||||
unifiedMemoryProperties.needZeroedOutAllocation = true;
|
||||
auto ptr = svmAllocManager->createUnifiedMemoryAllocation(totalSize, unifiedMemoryProperties);
|
||||
DEBUG_BREAK_IF(ptr == nullptr);
|
||||
if (ptr == nullptr) {
|
||||
|
||||
@@ -32,6 +32,12 @@ struct MockSVMAllocsManager : public SVMAllocsManager {
|
||||
prefetchMemoryCalled = true;
|
||||
}
|
||||
bool prefetchMemoryCalled = false;
|
||||
|
||||
void *createUnifiedMemoryAllocation(size_t size, const UnifiedMemoryProperties &memoryProperties) override {
|
||||
requestedZeroedOutAllocation = memoryProperties.needZeroedOutAllocation;
|
||||
return SVMAllocsManager::createUnifiedMemoryAllocation(size, memoryProperties);
|
||||
}
|
||||
bool requestedZeroedOutAllocation = false;
|
||||
};
|
||||
|
||||
template <bool enableLocalMemory>
|
||||
|
||||
@@ -519,6 +519,36 @@ TEST_F(SvmDeviceAllocationCacheTest, givenDeviceOutOfMemoryWhenAllocatingThenCac
|
||||
ASSERT_EQ(svmManager->usmDeviceAllocationsCache.allocations.size(), 0u);
|
||||
}
|
||||
|
||||
TEST_F(SvmDeviceAllocationCacheTest, givenAllocationWithNeedZeroedOutAllocationWhenAllocatingAfterFreeThenDoNotReuseAllocation) {
|
||||
std::unique_ptr<UltDeviceFactory> deviceFactory(new UltDeviceFactory(1, 1));
|
||||
RootDeviceIndicesContainer rootDeviceIndices = {mockRootDeviceIndex};
|
||||
std::map<uint32_t, DeviceBitfield> deviceBitfields{{mockRootDeviceIndex, mockDeviceBitfield}};
|
||||
DebugManagerStateRestore restore;
|
||||
debugManager.flags.ExperimentalEnableDeviceAllocationCache.set(1);
|
||||
auto device = deviceFactory->rootDevices[0];
|
||||
auto svmManager = std::make_unique<MockSVMAllocsManager>(device->getMemoryManager(), false);
|
||||
svmManager->initUsmAllocationsCaches(*device);
|
||||
EXPECT_TRUE(svmManager->usmDeviceAllocationsCacheEnabled);
|
||||
svmManager->usmDeviceAllocationsCache.maxSize = 1 * MemoryConstants::gigaByte;
|
||||
|
||||
SVMAllocsManager::UnifiedMemoryProperties unifiedMemoryProperties(InternalMemoryType::deviceUnifiedMemory, 1, rootDeviceIndices, deviceBitfields);
|
||||
unifiedMemoryProperties.device = device;
|
||||
auto allocation = svmManager->createUnifiedMemoryAllocation(10u, unifiedMemoryProperties);
|
||||
EXPECT_NE(allocation, nullptr);
|
||||
svmManager->freeSVMAlloc(allocation);
|
||||
EXPECT_EQ(svmManager->usmDeviceAllocationsCache.allocations.size(), 1u);
|
||||
|
||||
unifiedMemoryProperties.needZeroedOutAllocation = true;
|
||||
auto testedAllocation = svmManager->createUnifiedMemoryAllocation(10u, unifiedMemoryProperties);
|
||||
EXPECT_EQ(svmManager->usmDeviceAllocationsCache.allocations.size(), 1u);
|
||||
auto svmData = svmManager->getSVMAlloc(testedAllocation);
|
||||
EXPECT_NE(nullptr, svmData);
|
||||
|
||||
svmManager->freeSVMAlloc(testedAllocation);
|
||||
|
||||
svmManager->trimUSMDeviceAllocCache();
|
||||
}
|
||||
|
||||
using SvmHostAllocationCacheTest = Test<SvmAllocationCacheTestFixture>;
|
||||
|
||||
TEST_F(SvmHostAllocationCacheTest, givenAllocationCacheDefaultWhenCheckingIfEnabledThenItIsDisabled) {
|
||||
|
||||
@@ -93,6 +93,7 @@ TEST(AllocateGlobalSurfaceTest, GivenSvmAllocsManagerWhenGlobalsAreExportedThenM
|
||||
EXPECT_EQ(InternalMemoryType::deviceUnifiedMemory, svmAllocsManager.getSVMAlloc(reinterpret_cast<void *>(alloc->getGpuAddress()))->memoryType);
|
||||
EXPECT_EQ(AllocationType::constantSurface, alloc->getAllocationType());
|
||||
EXPECT_FALSE(alloc->getDefaultGmm()->resourceParams.Flags.Info.NotLockable);
|
||||
EXPECT_TRUE(svmAllocsManager.requestedZeroedOutAllocation);
|
||||
svmAllocsManager.freeSVMAlloc(reinterpret_cast<void *>(static_cast<uintptr_t>(alloc->getGpuAddress())));
|
||||
|
||||
alloc = allocateGlobalsSurface(&svmAllocsManager, device, initData.size(), 0u, true /* constant */, &linkerInputExportGlobalVariables, initData.data());
|
||||
|
||||
Reference in New Issue
Block a user