mirror of
https://github.com/intel/compute-runtime.git
synced 2025-09-15 13:01:45 +08:00
Add memoryPool to GraphicsAllocation
- new ExtendableEnum struct that serves as enum but can be extended with values - decrease dependencies on graphics_allocation.h header - use forward class declaration when possible - memoryPool indicates what kind of memory is allocated for a given GraphicsAllocation Change-Id: I7a707c28dc4544cc73abc5f0ed5263ba5be17452
This commit is contained in:

committed by
sys_ocldev

parent
4a6be207cd
commit
407227959a
@ -23,6 +23,7 @@
|
||||
#include "runtime/command_stream/command_stream_receiver_hw.h"
|
||||
#include "runtime/command_stream/experimental_command_buffer.h"
|
||||
#include "runtime/command_stream/linear_stream.h"
|
||||
#include "runtime/memory_manager/graphics_allocation.h"
|
||||
|
||||
namespace OCLRT {
|
||||
|
||||
|
@ -23,12 +23,12 @@
|
||||
#pragma once
|
||||
#include "runtime/helpers/debug_helpers.h"
|
||||
#include "runtime/helpers/ptr_math.h"
|
||||
#include "runtime/memory_manager/graphics_allocation.h"
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <atomic>
|
||||
|
||||
namespace OCLRT {
|
||||
class GraphicsAllocation;
|
||||
|
||||
class LinearStream {
|
||||
public:
|
||||
|
@ -21,6 +21,7 @@
|
||||
*/
|
||||
#include "submissions_aggregator.h"
|
||||
#include "runtime/helpers/flush_stamp.h"
|
||||
#include "runtime/memory_manager/graphics_allocation.h"
|
||||
|
||||
void OCLRT::SubmissionAggregator::recordCommandBuffer(CommandBuffer *commandBuffer) {
|
||||
this->cmdBuffers.pushTailOne(*commandBuffer);
|
||||
|
@ -20,15 +20,16 @@
|
||||
* OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
#pragma once
|
||||
#include "runtime/memory_manager/graphics_allocation.h"
|
||||
#include "runtime/utilities/idlist.h"
|
||||
#include "runtime/utilities/stackvec.h"
|
||||
#include "runtime/command_stream/linear_stream.h"
|
||||
#include "runtime/helpers/properties_helper.h"
|
||||
#include "runtime/memory_manager/residency_container.h"
|
||||
#include <vector>
|
||||
namespace OCLRT {
|
||||
class Event;
|
||||
class FlushStampTracker;
|
||||
class GraphicsAllocation;
|
||||
|
||||
struct BatchBuffer {
|
||||
BatchBuffer(GraphicsAllocation *commandBufferAllocation,
|
||||
|
@ -43,6 +43,7 @@ set(RUNTIME_SRCS_HELPERS_BASE
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/enable_product.inl
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/engine_node.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/error_mappers.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/extendable_enum.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/file_io.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/file_io.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/flat_batch_buffer_helper.h
|
||||
|
35
runtime/helpers/extendable_enum.h
Normal file
35
runtime/helpers/extendable_enum.h
Normal file
@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright (c) 2018, Intel Corporation
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included
|
||||
* in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
||||
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
* OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
struct ExtendableEnum {
|
||||
constexpr operator uint32_t() const {
|
||||
return value;
|
||||
}
|
||||
|
||||
protected:
|
||||
constexpr ExtendableEnum(uint32_t val) : value(val) {}
|
||||
uint32_t value;
|
||||
};
|
@ -21,6 +21,7 @@
|
||||
*/
|
||||
|
||||
#include "runtime/helpers/flat_batch_buffer_helper.h"
|
||||
#include "runtime/memory_manager/graphics_allocation.h"
|
||||
|
||||
namespace OCLRT {
|
||||
|
||||
|
@ -21,6 +21,7 @@
|
||||
*/
|
||||
|
||||
#include "indirect_heap.h"
|
||||
#include "runtime/memory_manager/graphics_allocation.h"
|
||||
|
||||
namespace OCLRT {
|
||||
|
||||
@ -32,4 +33,5 @@ IndirectHeap::IndirectHeap(GraphicsAllocation *gfxAllocation, bool canBeUtilized
|
||||
|
||||
IndirectHeap::IndirectHeap(void *buffer, size_t bufferSize) : BaseClass(buffer, bufferSize) {
|
||||
}
|
||||
|
||||
} // namespace OCLRT
|
||||
|
@ -25,6 +25,7 @@
|
||||
#include "runtime/helpers/aligned_memory.h"
|
||||
#include "runtime/helpers/ptr_math.h"
|
||||
#include "runtime/helpers/basic_math.h"
|
||||
#include "runtime/memory_manager/graphics_allocation.h"
|
||||
#include "runtime/memory_manager/memory_constants.h"
|
||||
|
||||
namespace OCLRT {
|
||||
@ -66,20 +67,7 @@ inline void IndirectHeap::align(size_t alignment) {
|
||||
auto address = alignUp(ptrOffset(buffer, sizeUsed), alignment);
|
||||
sizeUsed = ptrDiff(address, buffer);
|
||||
}
|
||||
inline uint64_t IndirectHeap::getHeapGpuStartOffset() const {
|
||||
if (this->canBeUtilizedAs4GbHeap) {
|
||||
return this->graphicsAllocation->getGpuAddressToPatch();
|
||||
} else {
|
||||
return 0llu;
|
||||
}
|
||||
}
|
||||
inline uint64_t IndirectHeap::getHeapGpuBase() const {
|
||||
if (this->canBeUtilizedAs4GbHeap) {
|
||||
return this->graphicsAllocation->gpuBaseAddress;
|
||||
} else {
|
||||
return this->graphicsAllocation->getGpuAddress();
|
||||
}
|
||||
}
|
||||
|
||||
inline uint32_t IndirectHeap::getHeapSizeInPages() const {
|
||||
if (this->canBeUtilizedAs4GbHeap) {
|
||||
return MemoryConstants::sizeOf4GBinPageEntities;
|
||||
@ -87,4 +75,20 @@ inline uint32_t IndirectHeap::getHeapSizeInPages() const {
|
||||
return (static_cast<uint32_t>(getMaxAvailableSpace()) + MemoryConstants::pageMask) / MemoryConstants::pageSize;
|
||||
}
|
||||
}
|
||||
|
||||
inline uint64_t IndirectHeap::getHeapGpuStartOffset() const {
|
||||
if (this->canBeUtilizedAs4GbHeap) {
|
||||
return this->graphicsAllocation->getGpuAddressToPatch();
|
||||
} else {
|
||||
return 0llu;
|
||||
}
|
||||
}
|
||||
|
||||
inline uint64_t IndirectHeap::getHeapGpuBase() const {
|
||||
if (this->canBeUtilizedAs4GbHeap) {
|
||||
return this->graphicsAllocation->gpuBaseAddress;
|
||||
} else {
|
||||
return this->graphicsAllocation->getGpuAddress();
|
||||
}
|
||||
}
|
||||
} // namespace OCLRT
|
||||
|
@ -33,10 +33,12 @@ set(RUNTIME_SRCS_MEMORY_MANAGER
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/memory_constants.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/memory_manager.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/memory_manager.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/memory_pool.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/os_agnostic_memory_manager.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/os_agnostic_memory_manager.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/page_table.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/page_table.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/residency_container.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/surface.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/svm_memory_manager.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/svm_memory_manager.h
|
||||
|
@ -28,6 +28,8 @@
|
||||
#include "runtime/helpers/debug_helpers.h"
|
||||
#include "runtime/helpers/ptr_math.h"
|
||||
#include "runtime/memory_manager/host_ptr_defines.h"
|
||||
#include "runtime/memory_manager/memory_pool.h"
|
||||
#include "runtime/memory_manager/residency_container.h"
|
||||
#include "runtime/utilities/idlist.h"
|
||||
|
||||
namespace OCLRT {
|
||||
@ -52,8 +54,18 @@ class GraphicsAllocation : public IDNode<GraphicsAllocation> {
|
||||
bool locked = false;
|
||||
uint32_t reuseCount = 0; // GraphicsAllocation can be reused by shared resources
|
||||
bool evictable = true;
|
||||
MemoryPool::Type memoryPool = MemoryPool::MemoryNull;
|
||||
|
||||
public:
|
||||
uint32_t taskCount = ObjectNotUsed;
|
||||
OsHandleStorage fragmentsStorage;
|
||||
bool is32BitAllocation = false;
|
||||
uint64_t gpuBaseAddress = 0;
|
||||
Gmm *gmm = nullptr;
|
||||
uint64_t allocationOffset = 0u;
|
||||
int residencyTaskCount = ObjectNotResident;
|
||||
bool cpuPtrAllocated = false; // flag indicating if cpuPtr is driver-allocated
|
||||
|
||||
enum AllocationType {
|
||||
UNKNOWN = 0,
|
||||
BUFFER,
|
||||
@ -132,16 +144,7 @@ class GraphicsAllocation : public IDNode<GraphicsAllocation> {
|
||||
void clearTypeAubNonWritable() { this->allocationType &= ~GraphicsAllocation::AllocationType::NON_AUB_WRITABLE; }
|
||||
bool isTypeAubNonWritable() const { return !!(this->allocationType & GraphicsAllocation::AllocationType::NON_AUB_WRITABLE); }
|
||||
|
||||
uint32_t taskCount = ObjectNotUsed;
|
||||
OsHandleStorage fragmentsStorage;
|
||||
bool isL3Capable();
|
||||
bool is32BitAllocation = false;
|
||||
uint64_t gpuBaseAddress = 0;
|
||||
Gmm *gmm = nullptr;
|
||||
uint64_t allocationOffset = 0u;
|
||||
|
||||
int residencyTaskCount = ObjectNotResident;
|
||||
|
||||
void setEvictable(bool evictable) { this->evictable = evictable; }
|
||||
bool peekEvictable() const { return evictable; }
|
||||
|
||||
@ -152,7 +155,9 @@ class GraphicsAllocation : public IDNode<GraphicsAllocation> {
|
||||
void incReuseCount() { reuseCount++; }
|
||||
void decReuseCount() { reuseCount--; }
|
||||
uint32_t peekReuseCount() const { return reuseCount; }
|
||||
bool cpuPtrAllocated = false; // flag indicating if cpuPtr is driver-allocated
|
||||
MemoryPool::Type getMemoryPool() {
|
||||
return memoryPool;
|
||||
}
|
||||
|
||||
protected:
|
||||
//this variable can only be modified from SubmissionAggregator
|
||||
@ -162,7 +167,4 @@ class GraphicsAllocation : public IDNode<GraphicsAllocation> {
|
||||
private:
|
||||
uint32_t allocationType;
|
||||
};
|
||||
|
||||
using ResidencyContainer = std::vector<GraphicsAllocation *>;
|
||||
|
||||
} // namespace OCLRT
|
||||
|
37
runtime/memory_manager/memory_pool.h
Normal file
37
runtime/memory_manager/memory_pool.h
Normal file
@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright (c) 2018, Intel Corporation
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included
|
||||
* in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
||||
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
* OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "runtime/helpers/extendable_enum.h"
|
||||
|
||||
namespace MemoryPool {
|
||||
struct Type : ExtendableEnum {
|
||||
constexpr Type(uint32_t val) : ExtendableEnum(val) {}
|
||||
};
|
||||
constexpr Type MemoryNull{0};
|
||||
constexpr Type System4KBPages{1};
|
||||
constexpr Type System64KBPages{2};
|
||||
constexpr Type System4KBPagesWith32BitGpuAddressing{3};
|
||||
constexpr Type System64KBPagesWith32BitGpuAddressing{4};
|
||||
constexpr Type SystemCpuInaccessible{5};
|
||||
} // namespace MemoryPool
|
@ -45,14 +45,14 @@ GraphicsAllocation *OsAgnosticMemoryManager::allocateGraphicsMemory(size_t size,
|
||||
MemoryAllocation *memoryAllocation = nullptr;
|
||||
|
||||
if (fakeBigAllocations && size > bigAllocation) {
|
||||
memoryAllocation = new MemoryAllocation(true, (void *)dummyAddress, static_cast<uint64_t>(dummyAddress), size, counter);
|
||||
memoryAllocation = new MemoryAllocation(true, (void *)dummyAddress, static_cast<uint64_t>(dummyAddress), size, counter, MemoryPool::System4KBPages);
|
||||
counter++;
|
||||
memoryAllocation->uncacheable = uncacheable;
|
||||
return memoryAllocation;
|
||||
}
|
||||
auto ptr = allocateSystemMemory(sizeAligned, alignment ? alignUp(alignment, MemoryConstants::pageSize) : MemoryConstants::pageSize);
|
||||
if (ptr != nullptr) {
|
||||
memoryAllocation = new MemoryAllocation(true, ptr, reinterpret_cast<uint64_t>(ptr), size, counter);
|
||||
memoryAllocation = new MemoryAllocation(true, ptr, reinterpret_cast<uint64_t>(ptr), size, counter, MemoryPool::System4KBPages);
|
||||
if (!memoryAllocation) {
|
||||
alignedFreeWrapper(ptr);
|
||||
return nullptr;
|
||||
@ -64,7 +64,11 @@ GraphicsAllocation *OsAgnosticMemoryManager::allocateGraphicsMemory(size_t size,
|
||||
}
|
||||
|
||||
GraphicsAllocation *OsAgnosticMemoryManager::allocateGraphicsMemory64kb(size_t size, size_t alignment, bool forcePin) {
|
||||
return allocateGraphicsMemory(alignUp(size, MemoryConstants::pageSize64k), MemoryConstants::pageSize64k, forcePin, false);
|
||||
auto memoryAllocation = allocateGraphicsMemory(alignUp(size, MemoryConstants::pageSize64k), MemoryConstants::pageSize64k, forcePin, false);
|
||||
if (memoryAllocation) {
|
||||
reinterpret_cast<MemoryAllocation *>(memoryAllocation)->overrideMemoryPool(MemoryPool::System64KBPages);
|
||||
}
|
||||
return memoryAllocation;
|
||||
}
|
||||
|
||||
GraphicsAllocation *OsAgnosticMemoryManager::allocate32BitGraphicsMemory(size_t size, const void *ptr, AllocationOrigin allocationOrigin) {
|
||||
@ -75,7 +79,7 @@ GraphicsAllocation *OsAgnosticMemoryManager::allocate32BitGraphicsMemory(size_t
|
||||
return nullptr;
|
||||
}
|
||||
uint64_t offset = static_cast<uint64_t>(reinterpret_cast<uintptr_t>(ptr) & MemoryConstants::pageMask);
|
||||
MemoryAllocation *memAlloc = new MemoryAllocation(false, const_cast<void *>(ptr), GmmHelper::canonize(gpuVirtualAddress + offset), size, counter);
|
||||
MemoryAllocation *memAlloc = new MemoryAllocation(false, const_cast<void *>(ptr), GmmHelper::canonize(gpuVirtualAddress + offset), size, counter, MemoryPool::System4KBPagesWith32BitGpuAddressing);
|
||||
memAlloc->is32BitAllocation = true;
|
||||
memAlloc->gpuBaseAddress = GmmHelper::canonize(allocator32Bit->getBase());
|
||||
memAlloc->sizeToFree = allocationSize;
|
||||
@ -93,7 +97,7 @@ GraphicsAllocation *OsAgnosticMemoryManager::allocate32BitGraphicsMemory(size_t
|
||||
|
||||
MemoryAllocation *memoryAllocation = nullptr;
|
||||
if (ptrAlloc != nullptr) {
|
||||
memoryAllocation = new MemoryAllocation(true, ptrAlloc, GmmHelper::canonize(gpuAddress), size, counter);
|
||||
memoryAllocation = new MemoryAllocation(true, ptrAlloc, GmmHelper::canonize(gpuAddress), size, counter, MemoryPool::System4KBPagesWith32BitGpuAddressing);
|
||||
memoryAllocation->is32BitAllocation = true;
|
||||
memoryAllocation->gpuBaseAddress = GmmHelper::canonize(allocator32Bit->getBase());
|
||||
memoryAllocation->sizeToFree = allocationSize;
|
||||
@ -104,7 +108,7 @@ GraphicsAllocation *OsAgnosticMemoryManager::allocate32BitGraphicsMemory(size_t
|
||||
}
|
||||
|
||||
GraphicsAllocation *OsAgnosticMemoryManager::createGraphicsAllocationFromSharedHandle(osHandle handle, bool requireSpecificBitness, bool reuseBO) {
|
||||
auto graphicsAllocation = new MemoryAllocation(false, reinterpret_cast<void *>(1), 1, 4096u, static_cast<uint64_t>(handle));
|
||||
auto graphicsAllocation = new MemoryAllocation(false, reinterpret_cast<void *>(1), 1, 4096u, static_cast<uint64_t>(handle), MemoryPool::SystemCpuInaccessible);
|
||||
graphicsAllocation->setSharedHandle(handle);
|
||||
graphicsAllocation->is32BitAllocation = requireSpecificBitness;
|
||||
return graphicsAllocation;
|
||||
@ -171,7 +175,7 @@ uint64_t OsAgnosticMemoryManager::getInternalHeapBaseAddress() {
|
||||
}
|
||||
|
||||
GraphicsAllocation *OsAgnosticMemoryManager::createGraphicsAllocation(OsHandleStorage &handleStorage, size_t hostPtrSize, const void *hostPtr) {
|
||||
auto allocation = new MemoryAllocation(false, const_cast<void *>(hostPtr), reinterpret_cast<uint64_t>(hostPtr), hostPtrSize, counter++);
|
||||
auto allocation = new MemoryAllocation(false, const_cast<void *>(hostPtr), reinterpret_cast<uint64_t>(hostPtr), hostPtrSize, counter++, MemoryPool::System4KBPages);
|
||||
allocation->fragmentsStorage = handleStorage;
|
||||
return allocation;
|
||||
}
|
||||
|
@ -26,7 +26,6 @@
|
||||
#include <map>
|
||||
|
||||
namespace OCLRT {
|
||||
|
||||
constexpr size_t bigAllocation = 1 * MB;
|
||||
constexpr uintptr_t dummyAddress = 0xFFFFF000u;
|
||||
class MemoryAllocation : public GraphicsAllocation {
|
||||
@ -37,9 +36,14 @@ class MemoryAllocation : public GraphicsAllocation {
|
||||
|
||||
void setSharedHandle(osHandle handle) { this->sharedHandle = handle; }
|
||||
|
||||
MemoryAllocation(bool cpuPtrAllocated, void *pMem, uint64_t gpuAddress, size_t memSize, uint64_t count) : GraphicsAllocation(pMem, gpuAddress, 0u, memSize),
|
||||
id(count) {
|
||||
MemoryAllocation(bool cpuPtrAllocated, void *pMem, uint64_t gpuAddress, size_t memSize, uint64_t count, MemoryPool::Type pool) : GraphicsAllocation(pMem, gpuAddress, 0u, memSize),
|
||||
id(count) {
|
||||
this->cpuPtrAllocated = cpuPtrAllocated;
|
||||
this->memoryPool = pool;
|
||||
}
|
||||
|
||||
void overrideMemoryPool(MemoryPool::Type pool) {
|
||||
memoryPool = pool;
|
||||
}
|
||||
};
|
||||
|
||||
|
30
runtime/memory_manager/residency_container.h
Normal file
30
runtime/memory_manager/residency_container.h
Normal file
@ -0,0 +1,30 @@
|
||||
/*
|
||||
* Copyright (c) 2018, Intel Corporation
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included
|
||||
* in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
||||
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
* OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <vector>
|
||||
|
||||
namespace OCLRT {
|
||||
class GraphicsAllocation;
|
||||
using ResidencyContainer = std::vector<GraphicsAllocation *>;
|
||||
|
||||
} // namespace OCLRT
|
@ -32,11 +32,14 @@ struct OsHandle {
|
||||
|
||||
class DrmAllocation : public GraphicsAllocation {
|
||||
public:
|
||||
DrmAllocation(BufferObject *bo, void *ptrIn, size_t sizeIn) : GraphicsAllocation(ptrIn, sizeIn), bo(bo) {
|
||||
DrmAllocation(BufferObject *bo, void *ptrIn, size_t sizeIn, MemoryPool::Type pool) : GraphicsAllocation(ptrIn, sizeIn), bo(bo) {
|
||||
this->memoryPool = pool;
|
||||
}
|
||||
DrmAllocation(BufferObject *bo, void *ptrIn, size_t sizeIn, osHandle sharedHandle) : GraphicsAllocation(ptrIn, sizeIn, sharedHandle), bo(bo) {
|
||||
DrmAllocation(BufferObject *bo, void *ptrIn, size_t sizeIn, osHandle sharedHandle, MemoryPool::Type pool) : GraphicsAllocation(ptrIn, sizeIn, sharedHandle), bo(bo) {
|
||||
this->memoryPool = pool;
|
||||
}
|
||||
DrmAllocation(BufferObject *bo, void *ptrIn, uint64_t gpuAddress, size_t sizeIn) : GraphicsAllocation(ptrIn, gpuAddress, 0, sizeIn), bo(bo) {
|
||||
DrmAllocation(BufferObject *bo, void *ptrIn, uint64_t gpuAddress, size_t sizeIn, MemoryPool::Type pool) : GraphicsAllocation(ptrIn, gpuAddress, 0, sizeIn), bo(bo) {
|
||||
this->memoryPool = pool;
|
||||
}
|
||||
|
||||
BufferObject *getBO() const {
|
||||
|
@ -162,7 +162,7 @@ OCLRT::BufferObject *DrmMemoryManager::allocUserptr(uintptr_t address, size_t si
|
||||
}
|
||||
|
||||
DrmAllocation *DrmMemoryManager::createGraphicsAllocation(OsHandleStorage &handleStorage, size_t hostPtrSize, const void *hostPtr) {
|
||||
auto allocation = new DrmAllocation(nullptr, const_cast<void *>(hostPtr), hostPtrSize);
|
||||
auto allocation = new DrmAllocation(nullptr, const_cast<void *>(hostPtr), hostPtrSize, MemoryPool::System4KBPages);
|
||||
allocation->fragmentsStorage = handleStorage;
|
||||
return allocation;
|
||||
}
|
||||
@ -170,6 +170,7 @@ DrmAllocation *DrmMemoryManager::createGraphicsAllocation(OsHandleStorage &handl
|
||||
DrmAllocation *DrmMemoryManager::allocateGraphicsMemory(size_t size, size_t alignment, bool forcePin, bool uncacheable) {
|
||||
const size_t minAlignment = MemoryConstants::allocationAlignment;
|
||||
size_t cAlignment = alignUp(std::max(alignment, minAlignment), minAlignment);
|
||||
DrmAllocation *allocation = nullptr;
|
||||
// When size == 0 allocate allocationAlignment
|
||||
// It's needed to prevent overlapping pages with user pointers
|
||||
size_t cSize = std::max(alignUp(size, minAlignment), minAlignment);
|
||||
@ -190,8 +191,8 @@ DrmAllocation *DrmMemoryManager::allocateGraphicsMemory(size_t size, size_t alig
|
||||
if (forcePinEnabled && pinBB != nullptr && forcePin && size >= this->pinThreshold) {
|
||||
pinBB->pin(&bo, 1);
|
||||
}
|
||||
|
||||
return new DrmAllocation(bo, res, cSize);
|
||||
allocation = new DrmAllocation(bo, res, cSize, MemoryPool::System4KBPages);
|
||||
return allocation;
|
||||
}
|
||||
|
||||
DrmAllocation *DrmMemoryManager::allocateGraphicsMemory(size_t size, const void *ptr, bool forcePin) {
|
||||
@ -242,7 +243,7 @@ GraphicsAllocation *DrmMemoryManager::allocateGraphicsMemoryForImage(ImageInfo &
|
||||
|
||||
bo->setUnmapSize(imgInfo.size);
|
||||
|
||||
auto allocation = new DrmAllocation(bo, nullptr, (uint64_t)gpuRange, imgInfo.size);
|
||||
auto allocation = new DrmAllocation(bo, nullptr, (uint64_t)gpuRange, imgInfo.size, MemoryPool::SystemCpuInaccessible);
|
||||
bo->setAllocationType(MMAP_ALLOCATOR);
|
||||
allocation->gmm = gmm;
|
||||
return allocation;
|
||||
@ -275,7 +276,7 @@ DrmAllocation *DrmMemoryManager::allocate32BitGraphicsMemory(size_t size, const
|
||||
uintptr_t offset = (uintptr_t)bo->address;
|
||||
bo->softPin((uint64_t)offset);
|
||||
bo->setAllocationType(allocatorType);
|
||||
auto drmAllocation = new DrmAllocation(bo, (void *)ptr, (uint64_t)ptrOffset(gpuVirtualAddress, inputPointerOffset), allocationSize);
|
||||
auto drmAllocation = new DrmAllocation(bo, (void *)ptr, (uint64_t)ptrOffset(gpuVirtualAddress, inputPointerOffset), allocationSize, MemoryPool::System4KBPagesWith32BitGpuAddressing);
|
||||
drmAllocation->is32BitAllocation = true;
|
||||
drmAllocation->gpuBaseAddress = allocatorToUse->getBase();
|
||||
return drmAllocation;
|
||||
@ -307,7 +308,7 @@ DrmAllocation *DrmMemoryManager::allocate32BitGraphicsMemory(size_t size, const
|
||||
|
||||
bo->setAllocationType(allocatorType);
|
||||
|
||||
auto drmAllocation = new DrmAllocation(bo, reinterpret_cast<void *>(res), alignedAllocationSize);
|
||||
auto drmAllocation = new DrmAllocation(bo, reinterpret_cast<void *>(res), alignedAllocationSize, MemoryPool::System4KBPagesWith32BitGpuAddressing);
|
||||
drmAllocation->is32BitAllocation = true;
|
||||
drmAllocation->gpuBaseAddress = allocatorToUse->getBase();
|
||||
return drmAllocation;
|
||||
@ -383,17 +384,17 @@ GraphicsAllocation *DrmMemoryManager::createGraphicsAllocationFromSharedHandle(o
|
||||
}
|
||||
}
|
||||
|
||||
auto drmAllocation = new DrmAllocation(bo, bo->address, bo->size, handle);
|
||||
auto drmAllocation = new DrmAllocation(bo, bo->address, bo->size, handle, MemoryPool::SystemCpuInaccessible);
|
||||
|
||||
if (requireSpecificBitness && this->force32bitAllocations) {
|
||||
drmAllocation->is32BitAllocation = true;
|
||||
drmAllocation->gpuBaseAddress = allocator32Bit->getBase();
|
||||
}
|
||||
|
||||
return drmAllocation;
|
||||
}
|
||||
|
||||
GraphicsAllocation *DrmMemoryManager::createPaddedAllocation(GraphicsAllocation *inputGraphicsAllocation, size_t sizeWithPadding) {
|
||||
DrmAllocation *drmAllocation = nullptr;
|
||||
void *gpuRange = mmapFunction(nullptr, sizeWithPadding, PROT_NONE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_NORESERVE, -1, 0);
|
||||
|
||||
auto srcPtr = inputGraphicsAllocation->getUnderlyingBuffer();
|
||||
@ -410,7 +411,8 @@ GraphicsAllocation *DrmMemoryManager::createPaddedAllocation(GraphicsAllocation
|
||||
bo->softPin(reinterpret_cast<uint64_t>(gpuRange));
|
||||
bo->setUnmapSize(sizeWithPadding);
|
||||
bo->setAllocationType(MMAP_ALLOCATOR);
|
||||
return new DrmAllocation(bo, (void *)srcPtr, (uint64_t)ptrOffset(gpuRange, offset), sizeWithPadding);
|
||||
drmAllocation = new DrmAllocation(bo, (void *)srcPtr, (uint64_t)ptrOffset(gpuRange, offset), sizeWithPadding, inputGraphicsAllocation->getMemoryPool());
|
||||
return drmAllocation;
|
||||
}
|
||||
|
||||
void DrmMemoryManager::addAllocationToHostPtrManager(GraphicsAllocation *gfxAllocation) {
|
||||
|
@ -45,7 +45,7 @@ class WddmAllocation : public GraphicsAllocation {
|
||||
D3DKMT_HANDLE resourceHandle = 0u; // used by shared resources
|
||||
|
||||
D3DGPU_VIRTUAL_ADDRESS gpuPtr; // set by mapGpuVA
|
||||
WddmAllocation(void *cpuPtrIn, size_t sizeIn, void *alignedCpuPtr, size_t alignedSize, void *reservedAddr)
|
||||
WddmAllocation(void *cpuPtrIn, size_t sizeIn, void *alignedCpuPtr, size_t alignedSize, void *reservedAddr, MemoryPool::Type pool)
|
||||
: GraphicsAllocation(cpuPtrIn, sizeIn),
|
||||
handle(0),
|
||||
gpuPtr(0),
|
||||
@ -53,22 +53,21 @@ class WddmAllocation : public GraphicsAllocation {
|
||||
alignedSize(alignedSize) {
|
||||
trimListPosition = trimListUnusedPosition;
|
||||
reservedAddressSpace = reservedAddr;
|
||||
this->memoryPool = pool;
|
||||
}
|
||||
|
||||
WddmAllocation(void *cpuPtrIn, size_t sizeIn, osHandle sharedHandle) : GraphicsAllocation(cpuPtrIn, sizeIn, sharedHandle),
|
||||
handle(0),
|
||||
gpuPtr(0),
|
||||
alignedCpuPtr(nullptr),
|
||||
alignedSize(sizeIn) {
|
||||
WddmAllocation(void *cpuPtrIn, size_t sizeIn, osHandle sharedHandle, MemoryPool::Type pool) : GraphicsAllocation(cpuPtrIn, sizeIn, sharedHandle),
|
||||
handle(0),
|
||||
gpuPtr(0),
|
||||
alignedCpuPtr(nullptr),
|
||||
alignedSize(sizeIn) {
|
||||
trimListPosition = trimListUnusedPosition;
|
||||
reservedAddressSpace = nullptr;
|
||||
this->memoryPool = pool;
|
||||
}
|
||||
|
||||
WddmAllocation(void *alignedCpuPtr, size_t sizeIn, void *reservedAddress)
|
||||
: WddmAllocation(alignedCpuPtr, sizeIn, alignedCpuPtr, sizeIn, reservedAddress) {
|
||||
}
|
||||
|
||||
WddmAllocation() : WddmAllocation(nullptr, 0, nullptr, 0, nullptr) {
|
||||
WddmAllocation(void *alignedCpuPtr, size_t sizeIn, void *reservedAddress, MemoryPool::Type pool)
|
||||
: WddmAllocation(alignedCpuPtr, sizeIn, alignedCpuPtr, sizeIn, reservedAddress, pool) {
|
||||
}
|
||||
|
||||
void *getAlignedCpuPtr() const {
|
||||
|
@ -65,7 +65,7 @@ GraphicsAllocation *WddmMemoryManager::allocateGraphicsMemoryForImage(ImageInfo
|
||||
delete gmm;
|
||||
return allocateGraphicsMemory(imgInfo.size);
|
||||
}
|
||||
auto allocation = new WddmAllocation(nullptr, imgInfo.size, nullptr);
|
||||
auto allocation = new WddmAllocation(nullptr, imgInfo.size, nullptr, MemoryPool::SystemCpuInaccessible);
|
||||
allocation->gmm = gmm;
|
||||
|
||||
if (!WddmMemoryManager::createWddmAllocation(allocation, AllocationOrigin::EXTERNAL_ALLOCATION)) {
|
||||
@ -79,7 +79,7 @@ GraphicsAllocation *WddmMemoryManager::allocateGraphicsMemory64kb(size_t size, s
|
||||
size_t sizeAligned = alignUp(size, MemoryConstants::pageSize64k);
|
||||
Gmm *gmm = nullptr;
|
||||
|
||||
auto wddmAllocation = new WddmAllocation(nullptr, sizeAligned, nullptr, sizeAligned, nullptr);
|
||||
auto wddmAllocation = new WddmAllocation(nullptr, sizeAligned, nullptr, sizeAligned, nullptr, MemoryPool::System64KBPages);
|
||||
|
||||
gmm = new Gmm(nullptr, sizeAligned, false);
|
||||
wddmAllocation->gmm = gmm;
|
||||
@ -112,7 +112,7 @@ GraphicsAllocation *WddmMemoryManager::allocateGraphicsMemory(size_t size, size_
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto wddmAllocation = new WddmAllocation(pSysMem, sizeAligned, pSysMem, sizeAligned, nullptr);
|
||||
auto wddmAllocation = new WddmAllocation(pSysMem, sizeAligned, pSysMem, sizeAligned, nullptr, MemoryPool::System4KBPages);
|
||||
wddmAllocation->cpuPtrAllocated = true;
|
||||
|
||||
gmm = new Gmm(pSysMem, sizeAligned, uncacheable);
|
||||
@ -125,7 +125,6 @@ GraphicsAllocation *WddmMemoryManager::allocateGraphicsMemory(size_t size, size_
|
||||
freeSystemMemory(pSysMem);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return wddmAllocation;
|
||||
}
|
||||
|
||||
@ -147,7 +146,7 @@ GraphicsAllocation *WddmMemoryManager::allocateGraphicsMemory(size_t size, const
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto allocation = new WddmAllocation(ptr, size, ptrAligned, sizeAligned, reserve);
|
||||
auto allocation = new WddmAllocation(ptr, size, ptrAligned, sizeAligned, reserve, MemoryPool::System4KBPages);
|
||||
allocation->allocationOffset = offset;
|
||||
|
||||
Gmm *gmm = new Gmm(ptrAligned, sizeAligned, false);
|
||||
@ -184,7 +183,7 @@ GraphicsAllocation *WddmMemoryManager::allocate32BitGraphicsMemory(size_t size,
|
||||
cpuPtrAllocated = true;
|
||||
}
|
||||
|
||||
auto wddmAllocation = new WddmAllocation(const_cast<void *>(ptrAligned), sizeAligned, const_cast<void *>(ptrAligned), sizeAligned, nullptr);
|
||||
auto wddmAllocation = new WddmAllocation(const_cast<void *>(ptrAligned), sizeAligned, const_cast<void *>(ptrAligned), sizeAligned, nullptr, MemoryPool::System4KBPagesWith32BitGpuAddressing);
|
||||
wddmAllocation->cpuPtrAllocated = cpuPtrAllocated;
|
||||
wddmAllocation->is32BitAllocation = true;
|
||||
wddmAllocation->allocationOffset = offset;
|
||||
@ -207,7 +206,7 @@ GraphicsAllocation *WddmMemoryManager::allocate32BitGraphicsMemory(size_t size,
|
||||
}
|
||||
|
||||
GraphicsAllocation *WddmMemoryManager::createAllocationFromHandle(osHandle handle, bool requireSpecificBitness, bool ntHandle) {
|
||||
auto allocation = new WddmAllocation(nullptr, 0, handle);
|
||||
auto allocation = new WddmAllocation(nullptr, 0, handle, MemoryPool::SystemCpuInaccessible);
|
||||
bool is32BitAllocation = false;
|
||||
|
||||
bool status = ntHandle ? wddm->openNTHandle((HANDLE)((UINT_PTR)handle), allocation)
|
||||
@ -237,7 +236,6 @@ GraphicsAllocation *WddmMemoryManager::createAllocationFromHandle(osHandle handl
|
||||
status = wddm->mapGpuVirtualAddress(allocation, ptr, is32BitAllocation, false, false);
|
||||
DEBUG_BREAK_IF(!status);
|
||||
allocation->setGpuAddress(allocation->gpuPtr);
|
||||
|
||||
return allocation;
|
||||
}
|
||||
|
||||
@ -430,7 +428,7 @@ void WddmMemoryManager::obtainGpuAddresFromFragments(WddmAllocation *allocation,
|
||||
}
|
||||
|
||||
GraphicsAllocation *WddmMemoryManager::createGraphicsAllocation(OsHandleStorage &handleStorage, size_t hostPtrSize, const void *hostPtr) {
|
||||
auto allocation = new WddmAllocation(const_cast<void *>(hostPtr), hostPtrSize, const_cast<void *>(hostPtr), hostPtrSize, nullptr);
|
||||
auto allocation = new WddmAllocation(const_cast<void *>(hostPtr), hostPtrSize, const_cast<void *>(hostPtr), hostPtrSize, nullptr, MemoryPool::System4KBPages);
|
||||
allocation->fragmentsStorage = handleStorage;
|
||||
obtainGpuAddresFromFragments(allocation, handleStorage);
|
||||
return allocation;
|
||||
|
Reference in New Issue
Block a user