Initial implementation of CacheSettingsHelper

Signed-off-by: Bartosz Dunajski <bartosz.dunajski@intel.com>
This commit is contained in:
Bartosz Dunajski
2022-02-04 13:50:19 +00:00
committed by Compute-Runtime-Automation
parent c88fce0def
commit a95198521e
41 changed files with 250 additions and 163 deletions

View File

@@ -1,5 +1,5 @@
#
# Copyright (C) 2019-2021 Intel Corporation
# Copyright (C) 2019-2022 Intel Corporation
#
# SPDX-License-Identifier: MIT
#
@@ -9,6 +9,8 @@ set(NEO_CORE_GMM_HELPER
${CMAKE_CURRENT_SOURCE_DIR}${BRANCH_DIR_SUFFIX}resource_info_${DRIVER_MODEL}.cpp
${CMAKE_CURRENT_SOURCE_DIR}/client_context/gmm_client_context.cpp
${CMAKE_CURRENT_SOURCE_DIR}/client_context/gmm_client_context.h
${CMAKE_CURRENT_SOURCE_DIR}/cache_settings_helper.cpp
${CMAKE_CURRENT_SOURCE_DIR}/cache_settings_helper.h
${CMAKE_CURRENT_SOURCE_DIR}/gmm.cpp
${CMAKE_CURRENT_SOURCE_DIR}/gmm.h
${CMAKE_CURRENT_SOURCE_DIR}/gmm_helper.cpp

View File

@@ -0,0 +1,28 @@
/*
* Copyright (C) 2022 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "shared/source/gmm_helper/cache_settings_helper.h"
#include "shared/source/memory_manager/allocation_type.h"
namespace NEO {
namespace CacheSettingsHelper {
GMM_RESOURCE_USAGE_TYPE_ENUM getGmmUsageType(AllocationType allocationType, bool forceUncached) {
if (forceUncached) {
return (allocationType == AllocationType::PREEMPTION) ? GMM_RESOURCE_USAGE_OCL_BUFFER_CSR_UC
: GMM_RESOURCE_USAGE_OCL_BUFFER_CACHELINE_MISALIGNED;
}
if (allocationType == AllocationType::IMAGE) {
return GMM_RESOURCE_USAGE_OCL_IMAGE;
}
return GMM_RESOURCE_USAGE_OCL_BUFFER;
}
} // namespace CacheSettingsHelper
} // namespace NEO

View File

@@ -0,0 +1,17 @@
/*
* Copyright (C) 2022 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#pragma once
#include "shared/source/gmm_helper/gmm_lib.h"
namespace NEO {
enum class AllocationType;
namespace CacheSettingsHelper {
GMM_RESOURCE_USAGE_TYPE_ENUM getGmmUsageType(AllocationType allocationType, bool forceUncached);
}
} // namespace NEO

View File

@@ -7,6 +7,7 @@
#include "shared/source/gmm_helper/gmm.h"
#include "shared/source/gmm_helper/cache_settings_helper.h"
#include "shared/source/gmm_helper/client_context/gmm_client_context.h"
#include "shared/source/gmm_helper/gmm_helper.h"
#include "shared/source/gmm_helper/resource_info.h"
@@ -16,9 +17,11 @@
#include "shared/source/helpers/hw_info.h"
#include "shared/source/helpers/ptr_math.h"
#include "shared/source/helpers/surface_format_info.h"
#include "shared/source/memory_manager/allocation_type.h"
namespace NEO {
Gmm::Gmm(GmmClientContext *clientContext, const void *alignedPtr, size_t alignedSize, size_t alignment, bool uncacheable, bool preferCompressed, StorageInfo storageInfo, bool allowLargePages) : clientContext(clientContext) {
Gmm::Gmm(GmmClientContext *clientContext, const void *alignedPtr, size_t alignedSize, size_t alignment, GMM_RESOURCE_USAGE_TYPE_ENUM gmmResourceUsage,
bool preferCompressed, StorageInfo storageInfo, bool allowLargePages) : clientContext(clientContext) {
resourceParams.Type = RESOURCE_BUFFER;
resourceParams.Format = GMM_FORMAT_GENERIC_8BIT;
resourceParams.BaseWidth64 = static_cast<uint64_t>(alignedSize);
@@ -32,11 +35,7 @@ Gmm::Gmm(GmmClientContext *clientContext, const void *alignedPtr, size_t aligned
}
}
if (!uncacheable) {
resourceParams.Usage = GMM_RESOURCE_USAGE_OCL_BUFFER;
} else {
resourceParams.Usage = GMM_RESOURCE_USAGE_OCL_BUFFER_CSR_UC;
}
resourceParams.Usage = gmmResourceUsage;
resourceParams.Flags.Info.Linear = 1;
resourceParams.Flags.Info.Cacheable = 1;
resourceParams.Flags.Gpu.Texture = 1;
@@ -118,7 +117,7 @@ void Gmm::setupImageResourceParams(ImageInfo &imgInfo, bool preferCompressed) {
resourceParams.NoGfxMemory = 1; // dont allocate, only query for params
resourceParams.Usage = GMM_RESOURCE_USAGE_TYPE::GMM_RESOURCE_USAGE_OCL_IMAGE;
resourceParams.Usage = CacheSettingsHelper::getGmmUsageType(AllocationType::IMAGE, false);
resourceParams.Format = imgInfo.surfaceFormat->GMMSurfaceFormat;
resourceParams.Flags.Gpu.Texture = 1;

View File

@@ -25,7 +25,8 @@ class Gmm {
virtual ~Gmm();
Gmm() = delete;
Gmm(GmmClientContext *clientContext, ImageInfo &inputOutputImgInfo, StorageInfo storageInfo, bool preferCompressed);
Gmm(GmmClientContext *clientContext, const void *alignedPtr, size_t alignedSize, size_t alignment, bool uncacheable, bool preferCompressed, StorageInfo storageInfo, bool allowLargePages);
Gmm(GmmClientContext *clientContext, const void *alignedPtr, size_t alignedSize, size_t alignment,
GMM_RESOURCE_USAGE_TYPE_ENUM gmmResourceUsage, bool preferCompressed, StorageInfo storageInfo, bool allowLargePages);
Gmm(GmmClientContext *clientContext, GMM_RESOURCE_INFO *inputGmm);
void queryImageParams(ImageInfo &inputOutputImgInfo);

View File

@@ -11,6 +11,7 @@
#include "shared/source/aub/aub_helper.h"
#include "shared/source/execution_environment/execution_environment.h"
#include "shared/source/execution_environment/root_device_environment.h"
#include "shared/source/gmm_helper/cache_settings_helper.h"
#include "shared/source/gmm_helper/gmm.h"
#include "shared/source/gmm_helper/gmm_helper.h"
#include "shared/source/gmm_helper/resource_info.h"
@@ -110,7 +111,7 @@ GraphicsAllocation *OsAgnosticMemoryManager::allocateGraphicsMemoryWithAlignment
allocationData.hostPtr,
sizeAligned,
alignment,
allocationData.flags.uncacheable,
CacheSettingsHelper::getGmmUsageType(memoryAllocation->getAllocationType(), !!allocationData.flags.uncacheable),
true,
allocationData.storageInfo,
true);
@@ -161,7 +162,7 @@ GraphicsAllocation *OsAgnosticMemoryManager::allocateGraphicsMemory64kb(const Al
allocationData.hostPtr,
allocationDataAlign.size,
allocationDataAlign.alignment,
allocationData.flags.uncacheable,
CacheSettingsHelper::getGmmUsageType(memoryAllocation->getAllocationType(), !!allocationData.flags.uncacheable),
allocationData.flags.preferCompressed,
allocationData.storageInfo, true);
memoryAllocation->setDefaultGmm(gmm.release());
@@ -348,7 +349,8 @@ void OsAgnosticMemoryManager::cleanOsHandles(OsHandleStorage &handleStorage, uin
GraphicsAllocation *OsAgnosticMemoryManager::allocateMemoryByKMD(const AllocationData &allocationData) {
auto gmm = std::make_unique<Gmm>(executionEnvironment.rootDeviceEnvironments[allocationData.rootDeviceIndex]->getGmmClientContext(), allocationData.hostPtr,
allocationData.size, 0u, false, allocationData.flags.preferCompressed, allocationData.storageInfo, true);
allocationData.size, 0u, CacheSettingsHelper::getGmmUsageType(allocationData.type, allocationData.flags.uncacheable),
allocationData.flags.preferCompressed, allocationData.storageInfo, true);
GraphicsAllocation *alloc = nullptr;
@@ -480,7 +482,7 @@ GraphicsAllocation *OsAgnosticMemoryManager::allocateGraphicsMemoryInDevicePool(
allocationData.hostPtr,
sizeAligned64k,
MemoryConstants::pageSize64k,
allocationData.flags.uncacheable,
CacheSettingsHelper::getGmmUsageType(allocationData.type, allocationData.flags.uncacheable),
true,
allocationData.storageInfo,
true);

View File

@@ -10,6 +10,7 @@
#include "shared/source/command_stream/command_stream_receiver.h"
#include "shared/source/execution_environment/execution_environment.h"
#include "shared/source/execution_environment/root_device_environment.h"
#include "shared/source/gmm_helper/cache_settings_helper.h"
#include "shared/source/gmm_helper/gmm.h"
#include "shared/source/gmm_helper/gmm_helper.h"
#include "shared/source/gmm_helper/resource_info.h"
@@ -483,7 +484,7 @@ DrmAllocation *DrmMemoryManager::allocateGraphicsMemory64kb(const AllocationData
GraphicsAllocation *DrmMemoryManager::allocateMemoryByKMD(const AllocationData &allocationData) {
StorageInfo systemMemoryStorageInfo = {};
auto gmm = std::make_unique<Gmm>(executionEnvironment.rootDeviceEnvironments[allocationData.rootDeviceIndex]->getGmmClientContext(), allocationData.hostPtr,
allocationData.size, 0u, false, false, systemMemoryStorageInfo, true);
allocationData.size, 0u, CacheSettingsHelper::getGmmUsageType(allocationData.type, allocationData.flags.uncacheable), false, systemMemoryStorageInfo, true);
size_t bufferSize = allocationData.size;
uint64_t gpuRange = acquireGpuRange(bufferSize, allocationData.rootDeviceIndex, HeapIndex::HEAP_STANDARD64KB);
@@ -1196,7 +1197,7 @@ void createColouredGmms(GmmClientContext *clientContext, DrmAllocation &allocati
nullptr,
currentSize,
0u,
false,
CacheSettingsHelper::getGmmUsageType(allocation.getAllocationType(), false),
compression,
limitedStorageInfo,
true);
@@ -1210,7 +1211,7 @@ void fillGmmsInAllocation(GmmClientContext *clientContext, DrmAllocation *alloca
StorageInfo limitedStorageInfo = storageInfo;
limitedStorageInfo.memoryBanks &= 1u << handleId;
limitedStorageInfo.pageTablesVisibility &= 1u << handleId;
auto gmm = new Gmm(clientContext, nullptr, alignedSize, 0u, false, false, limitedStorageInfo, true);
auto gmm = new Gmm(clientContext, nullptr, alignedSize, 0u, CacheSettingsHelper::getGmmUsageType(allocation->getAllocationType(), false), false, limitedStorageInfo, true);
allocation->setGmm(gmm, handleId);
}
}
@@ -1279,7 +1280,7 @@ GraphicsAllocation *DrmMemoryManager::allocateGraphicsMemoryInDevicePool(const A
nullptr,
sizeAligned,
0u,
allocationData.flags.uncacheable,
CacheSettingsHelper::getGmmUsageType(allocationData.type, !!allocationData.flags.uncacheable),
allocationData.flags.preferCompressed,
allocationData.storageInfo,
true);

View File

@@ -9,6 +9,7 @@
#include "shared/source/command_stream/command_stream_receiver_hw.h"
#include "shared/source/execution_environment/root_device_environment.h"
#include "shared/source/gmm_helper/cache_settings_helper.h"
#include "shared/source/gmm_helper/gmm.h"
#include "shared/source/gmm_helper/gmm_helper.h"
#include "shared/source/gmm_helper/page_table_mngr.h"
@@ -71,7 +72,7 @@ GraphicsAllocation *WddmMemoryManager::allocateMemoryByKMD(const AllocationData
}
StorageInfo systemMemoryStorageInfo = {};
auto gmm = std::make_unique<Gmm>(executionEnvironment.rootDeviceEnvironments[allocationData.rootDeviceIndex]->getGmmClientContext(), allocationData.hostPtr, allocationData.size, 0u,
false, false, systemMemoryStorageInfo, true);
CacheSettingsHelper::getGmmUsageType(allocationData.type, !!allocationData.flags.uncacheable), false, systemMemoryStorageInfo, true);
auto allocation = std::make_unique<WddmAllocation>(allocationData.rootDeviceIndex,
1u, // numGmms
allocationData.type, nullptr, allocationData.size, nullptr,
@@ -122,7 +123,7 @@ GraphicsAllocation *WddmMemoryManager::allocateGraphicsMemoryUsingKmdAndMapItToC
auto gmm = new Gmm(executionEnvironment.rootDeviceEnvironments[allocationData.rootDeviceIndex]->getGmmClientContext(), nullptr,
sizeAligned, 0u,
allocationData.flags.uncacheable,
CacheSettingsHelper::getGmmUsageType(wddmAllocation->getAllocationType(), !!allocationData.flags.uncacheable),
allocationData.flags.preferCompressed,
allocationData.storageInfo,
allowLargePages);
@@ -188,7 +189,8 @@ GraphicsAllocation *WddmMemoryManager::allocateHugeGraphicsMemory(const Allocati
for (auto gmmId = 0u; gmmId < numGmms; ++gmmId) {
auto size = sizeRemaining > chunkSize ? chunkSize : sizeRemaining;
auto gmm = new Gmm(executionEnvironment.rootDeviceEnvironments[allocationData.rootDeviceIndex]->getGmmClientContext(),
static_cast<char *>(alignedPtr) + gmmId * chunkSize, size, 0u, uncacheable, false, {}, true);
static_cast<char *>(alignedPtr) + gmmId * chunkSize, size, 0u,
CacheSettingsHelper::getGmmUsageType(wddmAllocation->getAllocationType(), !!uncacheable), false, {}, true);
wddmAllocation->setGmm(gmm, gmmId);
sizeRemaining -= size;
}
@@ -242,7 +244,7 @@ GraphicsAllocation *WddmMemoryManager::allocateSystemMemoryAndCreateGraphicsAllo
wddmAllocation->setDriverAllocatedCpuPtr(pSysMem);
gmm = new Gmm(executionEnvironment.rootDeviceEnvironments[allocationData.rootDeviceIndex]->getGmmClientContext(), pSysMem, sizeAligned, 0u,
allocationData.flags.uncacheable, allocationData.flags.preferCompressed, allocationData.storageInfo, true);
CacheSettingsHelper::getGmmUsageType(wddmAllocation->getAllocationType(), !!allocationData.flags.uncacheable), allocationData.flags.preferCompressed, allocationData.storageInfo, true);
wddmAllocation->setDefaultGmm(gmm);
void *mapPtr = wddmAllocation->getAlignedCpuPtr();
@@ -286,7 +288,8 @@ GraphicsAllocation *WddmMemoryManager::allocateGraphicsMemoryForNonSvmHostPtr(co
auto offsetInPage = ptrDiff(allocationData.hostPtr, alignedPtr);
wddmAllocation->setAllocationOffset(offsetInPage);
auto gmm = new Gmm(executionEnvironment.rootDeviceEnvironments[allocationData.rootDeviceIndex]->getGmmClientContext(), alignedPtr, alignedSize, 0u, false, false, {}, true);
auto gmm = new Gmm(executionEnvironment.rootDeviceEnvironments[allocationData.rootDeviceIndex]->getGmmClientContext(), alignedPtr, alignedSize, 0u,
CacheSettingsHelper::getGmmUsageType(wddmAllocation->getAllocationType(), !!allocationData.flags.uncacheable), false, {}, true);
wddmAllocation->setDefaultGmm(gmm);
@@ -322,7 +325,8 @@ GraphicsAllocation *WddmMemoryManager::allocateGraphicsMemoryWithHostPtr(const A
maxOsContextCount);
allocation->setAllocationOffset(offset);
Gmm *gmm = new Gmm(executionEnvironment.rootDeviceEnvironments[allocationData.rootDeviceIndex]->getGmmClientContext(), ptrAligned, sizeAligned, 0u, false, false, {}, true);
Gmm *gmm = new Gmm(executionEnvironment.rootDeviceEnvironments[allocationData.rootDeviceIndex]->getGmmClientContext(), ptrAligned, sizeAligned, 0u,
CacheSettingsHelper::getGmmUsageType(allocation->getAllocationType(), !!allocationData.flags.uncacheable), false, {}, true);
allocation->setDefaultGmm(gmm);
if (createWddmAllocation(allocation, reserve)) {
return allocation;
@@ -366,7 +370,8 @@ GraphicsAllocation *WddmMemoryManager::allocate32BitGraphicsMemoryImpl(const All
wddmAllocation->setAllocationOffset(offset);
wddmAllocation->allocInFrontWindowPool = allocationData.flags.use32BitFrontWindow;
gmm = new Gmm(executionEnvironment.rootDeviceEnvironments[allocationData.rootDeviceIndex]->getGmmClientContext(), ptrAligned, sizeAligned, 0u, false, false, {}, true);
gmm = new Gmm(executionEnvironment.rootDeviceEnvironments[allocationData.rootDeviceIndex]->getGmmClientContext(), ptrAligned, sizeAligned, 0u,
CacheSettingsHelper::getGmmUsageType(wddmAllocation->getAllocationType(), !!allocationData.flags.uncacheable), false, {}, true);
wddmAllocation->setDefaultGmm(gmm);
if (!createWddmAllocation(wddmAllocation.get(), nullptr)) {
@@ -596,7 +601,8 @@ MemoryManager::AllocationStatus WddmMemoryManager::populateOsHandles(OsHandleSto
handleStorage.fragmentStorageData[i].residency = new ResidencyData(maxOsContextCount);
osHandle->gmm = new Gmm(executionEnvironment.rootDeviceEnvironments[rootDeviceIndex]->getGmmClientContext(), handleStorage.fragmentStorageData[i].cpuPtr,
handleStorage.fragmentStorageData[i].fragmentSize, 0u, false, false, {}, true);
handleStorage.fragmentStorageData[i].fragmentSize, 0u,
CacheSettingsHelper::getGmmUsageType(AllocationType::EXTERNAL_HOST_PTR, false), false, {}, true);
allocatedFragmentIndexes[allocatedFragmentsCounter] = i;
allocatedFragmentsCounter++;
}
@@ -919,7 +925,7 @@ void createColouredGmms(GmmClientContext *clientContext, WddmAllocation &allocat
nullptr,
currentSize,
0u,
false,
CacheSettingsHelper::getGmmUsageType(allocation.getAllocationType(), false),
compression,
limitedStorageInfo, true);
allocation.setGmm(gmm, handleId);
@@ -931,7 +937,7 @@ void fillGmmsInAllocation(GmmClientContext *clientContext, WddmAllocation *alloc
StorageInfo limitedStorageInfo = storageInfo;
limitedStorageInfo.memoryBanks &= static_cast<uint32_t>(1u << handleId);
limitedStorageInfo.pageTablesVisibility &= static_cast<uint32_t>(1u << handleId);
auto gmm = new Gmm(clientContext, nullptr, allocation->getAlignedSize(), 0u, false, false, limitedStorageInfo, true);
auto gmm = new Gmm(clientContext, nullptr, allocation->getAlignedSize(), 0u, CacheSettingsHelper::getGmmUsageType(allocation->getAllocationType(), false), false, limitedStorageInfo, true);
allocation->setGmm(gmm, handleId);
}
}
@@ -940,7 +946,7 @@ void splitGmmsInAllocation(GmmClientContext *clientContext, WddmAllocation *wddm
auto sizeRemaining = wddmAllocation->getAlignedSize();
for (auto gmmId = 0u; gmmId < wddmAllocation->getNumGmms(); ++gmmId) {
auto size = sizeRemaining > chunkSize ? chunkSize : sizeRemaining;
auto gmm = new Gmm(clientContext, nullptr, size, alignment, false, false, storageInfo, true);
auto gmm = new Gmm(clientContext, nullptr, size, alignment, CacheSettingsHelper::getGmmUsageType(wddmAllocation->getAllocationType(), false), false, storageInfo, true);
wddmAllocation->setGmm(gmm, gmmId);
sizeRemaining -= size;
}
@@ -988,7 +994,7 @@ GraphicsAllocation *WddmMemoryManager::allocateGraphicsMemoryInDevicePool(const
nullptr,
sizeAligned,
alignment,
allocationData.flags.uncacheable,
CacheSettingsHelper::getGmmUsageType(allocationData.type, !!allocationData.flags.uncacheable),
allocationData.flags.preferCompressed,
allocationData.storageInfo,
true);