SWDEV-291787 - Fix persistent direct map

Change-Id: Ic1507cc6d63e9ed574e8e169bce7bf56f4792c19


[ROCm/clr commit: 84b971c7c1]
Этот коммит содержится в:
jujiang
2021-07-13 19:44:02 -04:00
коммит произвёл Maneesh Gupta
родитель f19e3f0a13
Коммит f0ec01f657
6 изменённых файлов: 32 добавлений и 11 удалений
+2 -1
Просмотреть файл
@@ -841,7 +841,8 @@ class Memory : public amd::HeapObject {
SubMemoryObject = 0x00000008, //!< Memory is sub-memory
HostMemoryRegistered = 0x00000010, //!< Host memory was registered
MemoryCpuUncached = 0x00000020, //!< Memory is uncached on CPU access(slow read)
AllowedPeerAccess = 0x00000040 //!< Memory can be accessed from peer
AllowedPeerAccess = 0x00000040, //!< Memory can be accessed from peer
PersistentMap = 0x00000080 //!< Map Peristent memory
};
uint flags_; //!< Memory object flags
+10 -4
Просмотреть файл
@@ -786,12 +786,16 @@ void* Memory::allocMapTarget(const amd::Coord3D& origin, const amd::Coord3D& reg
mapAddress = reinterpret_cast<address>(owner()->getHostMem());
}
// If resource is a persistent allocation, we can use it directly
else if (isPersistentDirectMap()) {
else if ((isPersistentDirectMap(mapFlags & CL_MAP_WRITE) && (getMapCount() == 0)) ||
isPersistentMapped()) {
if (nullptr == map(nullptr)) {
LogError("Could not map target persistent resource");
decIndMapCount();
return nullptr;
}
if (getMapCount() == 1) {
setPersistentMapFlag(true);
}
mapAddress = data();
}
// Otherwise we can use a remote resource:
@@ -1046,14 +1050,17 @@ void* Image::allocMapTarget(const amd::Coord3D& origin, const amd::Coord3D& regi
//! runtime can't use it directly,
//! because CAL volume map doesn't work properly.
//! @todo arrays can be added for persistent lock with some CAL changes
else if (isPersistentDirectMap()) {
else if((isPersistentDirectMap(mapFlags & CL_MAP_WRITE) && (getMapCount() == 0)) ||
isPersistentMapped()) {
if (nullptr == map(nullptr)) {
useRemoteResource = true;
LogError("Could not map target persistent resource, try remote resource");
} else {
useRemoteResource = false;
mapAddress = data();
if (getMapCount() == 1) {
setPersistentMapFlag(true);
}
// Calculate the offset in bytes
offset *= elementSize();
@@ -1075,7 +1082,6 @@ void* Image::allocMapTarget(const amd::Coord3D& origin, const amd::Coord3D& regi
const static bool SysMem = true;
bool failed = false;
amd::Memory* memory;
// Search for a possible indirect resource
memory = dev().findMapTarget(owner()->getSize());
+10
Просмотреть файл
@@ -97,6 +97,16 @@ class Memory : public device::Memory, public Resource {
size_t* slicePitch = NULL //!< Slice for the mapped memory
);
virtual bool isPersistentMapped() const { return (flags_ & PersistentMap) ? true : false; }
virtual void setPersistentMapFlag(bool persistentMapped) {
if (persistentMapped == true) {
flags_ |= PersistentMap;
}
else {
flags_ &= ~PersistentMap;
}
}
//! Pins system memory associated with this memory object
virtual bool pinSystemMemory(void* hostPtr, //!< System memory address
size_t size //!< Size of allocated system memory
+3 -3
Просмотреть файл
@@ -1824,9 +1824,9 @@ bool Resource::isMemoryType(MemoryType memType) const {
}
// ================================================================================================
bool Resource::isPersistentDirectMap() const {
bool directMap =
((memoryType() == Resource::Persistent) && (desc().dimSize_ < 3) && !desc().imageArray_);
bool Resource::isPersistentDirectMap(bool writeMap) const {
bool directMap = ((memoryType() == Resource::Persistent) &&
(desc().dimSize_ < 3) && !desc().imageArray_ && writeMap);
// If direct map is possible, then validate it with the current tiling
if (directMap && desc().tiled_) {
+2 -1
Просмотреть файл
@@ -296,7 +296,8 @@ class Resource : public amd::HeapObject {
bool mipMapped() const { return (desc().mipLevels_ > 1) ? true : false; }
//! Checks if persistent memory can have a direct map
bool isPersistentDirectMap() const;
bool isPersistentDirectMap(bool writeMap = true) const;
int getMapCount() const { return mapCount_; }
/*! \brief Locks the resource and returns a physical pointer
*
+5 -2
Просмотреть файл
@@ -1620,7 +1620,7 @@ void VirtualGPU::submitMapMemory(amd::MapMemoryCommand& vcmd) {
// Add memory to VA cache, so rutnime can detect direct access to VA
dev().addVACache(memory);
} else if (memory->isPersistentDirectMap()) {
} else if (memory->isPersistentMapped()) {
// Nothing to do here
} else if (memory->mapMemory() != nullptr) {
// Target is a remote resource, so copy
@@ -1721,10 +1721,13 @@ void VirtualGPU::submitUnmapMemory(amd::UnmapMemoryCommand& vcmd) {
}
// data check was added for persistent memory that failed to get aperture
// and therefore are treated like a remote resource
else if (memory->isPersistentDirectMap() && (memory->data() != nullptr)) {
else if (memory->isPersistentMapped()) {
// Map/unmap must be serialized
amd::ScopedLock lock(owner->lockMemoryOps());
memory->unmap(this);
if (memory->getMapount() == 0) {
memory->setPersistentMapFlag(false);
}
} else if (memory->mapMemory() != nullptr) {
if (writeMapInfo->isUnmapWrite()) {
amd::Coord3D srcOrigin(0, 0, 0);