mirror of
https://github.com/intel/compute-runtime.git
synced 2026-01-03 06:49:52 +08:00
Add support for mem advise to set cache policy in buffer object
Signed-off-by: Milczarek, Slawomir <slawomir.milczarek@intel.com>
This commit is contained in:
committed by
Compute-Runtime-Automation
parent
45de13233a
commit
afa45bd9e7
29
shared/source/memory_manager/memadvise_flags.h
Normal file
29
shared/source/memory_manager/memadvise_flags.h
Normal file
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Copyright (C) 2021 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
namespace NEO {
|
||||
|
||||
typedef union {
|
||||
uint8_t memadvise_flags; /* all memadvise_flags */
|
||||
struct
|
||||
{
|
||||
uint8_t read_only : 1, /* ZE_MEMORY_ADVICE_SET_READ_MOSTLY or ZE_MEMORY_ADVICE_CLEAR_READ_MOSTLY */
|
||||
device_preferred_location : 1, /* ZE_MEMORY_ADVICE_SET_PREFERRED_LOCATION or ZE_MEMORY_ADVICE_CLEAR_PREFERRED_LOCATION */
|
||||
non_atomic : 1, /* ZE_MEMORY_ADVICE_SET_NON_ATOMIC_MOSTLY or ZE_MEMORY_ADVICE_CLEAR_NON_ATOMIC_MOSTLY */
|
||||
cached_memory : 1, /* ZE_MEMORY_ADVICE_BIAS_CACHED or ZE_MEMORY_ADVICE_BIAS_UNCACHED */
|
||||
cpu_migration_blocked : 1, /* ZE_MEMORY_ADVICE_SET_READ_MOSTLY and ZE_MEMORY_ADVICE_SET_PREFERRED_LOCATION */
|
||||
reserved2 : 1,
|
||||
reserved1 : 1,
|
||||
reserved0 : 1;
|
||||
};
|
||||
} MemAdviseFlags;
|
||||
|
||||
} // namespace NEO
|
||||
@@ -19,6 +19,7 @@
|
||||
#include "shared/source/memory_manager/graphics_allocation.h"
|
||||
#include "shared/source/memory_manager/host_ptr_defines.h"
|
||||
#include "shared/source/memory_manager/local_memory_usage.h"
|
||||
#include "shared/source/memory_manager/memadvise_flags.h"
|
||||
#include "shared/source/memory_manager/multi_graphics_allocation.h"
|
||||
#include "shared/source/os_interface/os_interface.h"
|
||||
#include "shared/source/page_fault_manager/cpu_page_fault_manager.h"
|
||||
@@ -208,6 +209,8 @@ class MemoryManager {
|
||||
virtual void registerSysMemAlloc(GraphicsAllocation *allocation){};
|
||||
virtual void registerLocalMemAlloc(GraphicsAllocation *allocation, uint32_t rootDeviceIndex){};
|
||||
|
||||
virtual void setMemAdvise(GraphicsAllocation *gfxAllocation, MemAdviseFlags flags){};
|
||||
|
||||
bool isExternalAllocation(GraphicsAllocation::AllocationType allocationType);
|
||||
LocalMemoryUsageBankSelector *getLocalMemoryUsageBankSelector(GraphicsAllocation::AllocationType allocationType, uint32_t rootDeviceIndex);
|
||||
|
||||
|
||||
@@ -12,6 +12,13 @@
|
||||
|
||||
namespace NEO {
|
||||
|
||||
enum class CachePolicy : uint32_t {
|
||||
Uncached = 0,
|
||||
WriteCombined = 1,
|
||||
WriteThrough = 2,
|
||||
WriteBack = 3,
|
||||
};
|
||||
|
||||
enum class CacheRegion : uint16_t {
|
||||
Default = 0,
|
||||
Region1,
|
||||
|
||||
@@ -29,6 +29,14 @@ uint64_t DrmAllocation::peekInternalHandle(MemoryManager *memoryManager) {
|
||||
return static_cast<uint64_t>((static_cast<DrmMemoryManager *>(memoryManager))->obtainFdFromHandle(getBO()->peekHandle(), this->rootDeviceIndex));
|
||||
}
|
||||
|
||||
void DrmAllocation::setCachePolicy(CachePolicy memType) {
|
||||
for (auto bo : bufferObjects) {
|
||||
if (bo != nullptr) {
|
||||
bo->setCachePolicy(memType);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool DrmAllocation::setCacheAdvice(Drm *drm, size_t regionSize, CacheRegion regionIndex) {
|
||||
if (!drm->getCacheInfo()->getCacheRegion(regionSize, regionIndex)) {
|
||||
return false;
|
||||
|
||||
@@ -13,6 +13,7 @@ namespace NEO {
|
||||
class BufferObject;
|
||||
class OsContext;
|
||||
class Drm;
|
||||
enum class CachePolicy : uint32_t;
|
||||
enum class CacheRegion : uint16_t;
|
||||
|
||||
struct OsHandleLinux : OsHandle {
|
||||
@@ -66,6 +67,7 @@ class DrmAllocation : public GraphicsAllocation {
|
||||
|
||||
bool setCacheRegion(Drm *drm, CacheRegion regionIndex);
|
||||
bool setCacheAdvice(Drm *drm, size_t regionSize, CacheRegion regionIndex);
|
||||
void setCachePolicy(CachePolicy memType);
|
||||
|
||||
void *getMmapPtr() { return this->mmapPtr; }
|
||||
void setMmapPtr(void *ptr) { this->mmapPtr = ptr; }
|
||||
|
||||
@@ -90,6 +90,9 @@ class BufferObject {
|
||||
void setCacheRegion(CacheRegion regionIndex) { cacheRegion = regionIndex; }
|
||||
CacheRegion peekCacheRegion() const { return cacheRegion; }
|
||||
|
||||
void setCachePolicy(CachePolicy memType) { cachePolicy = memType; }
|
||||
CachePolicy peekCachePolicy() const { return cachePolicy; }
|
||||
|
||||
protected:
|
||||
Drm *drm = nullptr;
|
||||
bool perContextVmsUsed = false;
|
||||
@@ -115,6 +118,7 @@ class BufferObject {
|
||||
uint64_t unmapSize = 0;
|
||||
|
||||
CacheRegion cacheRegion = CacheRegion::Default;
|
||||
CachePolicy cachePolicy = CachePolicy::WriteBack;
|
||||
|
||||
std::vector<std::array<bool, EngineLimits::maxHandleCount>> bindInfo;
|
||||
StackVec<uint32_t, 2> bindExtHandles;
|
||||
|
||||
@@ -201,6 +201,13 @@ bool DrmMemoryManager::isKmdMigrationAvailable(uint32_t rootDeviceIndex) {
|
||||
return useKmdMigration;
|
||||
}
|
||||
|
||||
void DrmMemoryManager::setMemAdvise(GraphicsAllocation *gfxAllocation, MemAdviseFlags flags) {
|
||||
DrmAllocation *drmAllocation = static_cast<DrmAllocation *>(gfxAllocation);
|
||||
|
||||
CachePolicy memType = flags.cached_memory ? CachePolicy::WriteBack : CachePolicy::Uncached;
|
||||
drmAllocation->setCachePolicy(memType);
|
||||
}
|
||||
|
||||
NEO::BufferObject *DrmMemoryManager::allocUserptr(uintptr_t address, size_t size, uint64_t flags, uint32_t rootDeviceIndex) {
|
||||
drm_i915_gem_userptr userptr = {};
|
||||
userptr.user_ptr = address;
|
||||
|
||||
@@ -65,6 +65,8 @@ class DrmMemoryManager : public MemoryManager {
|
||||
|
||||
bool isKmdMigrationAvailable(uint32_t rootDeviceIndex) override;
|
||||
|
||||
void setMemAdvise(GraphicsAllocation *gfxAllocation, MemAdviseFlags flags) override;
|
||||
|
||||
std::unique_lock<std::mutex> acquireAllocLock();
|
||||
std::vector<GraphicsAllocation *> &getSysMemAllocs();
|
||||
std::vector<GraphicsAllocation *> &getLocalMemAllocs(uint32_t rootDeviceIndex);
|
||||
|
||||
@@ -141,6 +141,11 @@ class MockMemoryManager : public MemoryManagerCreate<OsAgnosticMemoryManager> {
|
||||
}
|
||||
void forceLimitedRangeAllocator(uint32_t rootDeviceIndex, uint64_t range) { getGfxPartition(rootDeviceIndex)->init(range, 0, 0, gfxPartitions.size()); }
|
||||
|
||||
void setMemAdvise(GraphicsAllocation *gfxAllocation, MemAdviseFlags flags) override {
|
||||
memAdviseFlags = flags;
|
||||
MemoryManager::setMemAdvise(gfxAllocation, flags);
|
||||
}
|
||||
|
||||
uint32_t freeGraphicsMemoryCalled = 0u;
|
||||
uint32_t unlockResourceCalled = 0u;
|
||||
uint32_t lockResourceCalled = 0u;
|
||||
@@ -178,6 +183,7 @@ class MockMemoryManager : public MemoryManagerCreate<OsAgnosticMemoryManager> {
|
||||
std::unique_ptr<MockExecutionEnvironment> mockExecutionEnvironment;
|
||||
DeviceBitfield recentlyPassedDeviceBitfield{};
|
||||
std::unique_ptr<MultiGraphicsAllocation> waitAllocations = nullptr;
|
||||
MemAdviseFlags memAdviseFlags{};
|
||||
};
|
||||
|
||||
class GMockMemoryManager : public MockMemoryManager {
|
||||
|
||||
Reference in New Issue
Block a user