From 165d1e4e5548b9e8126061feb84460ef2481e51c Mon Sep 17 00:00:00 2001 From: "Venevtsev, Igor" Date: Thu, 18 Apr 2019 15:30:47 +0200 Subject: [PATCH] Use GfxPartition for GPU address range allocations [2/n] - OsAgnosticMemoryManager Related-To: NEO-2877 Change-Id: I887126362381ac960608a2150fae211631d3cd5b Signed-off-by: Venevtsev, Igor --- runtime/device/device.h | 2 +- runtime/dll/linux/allocator_helper.cpp | 6 + .../execution_environment.h | 2 +- runtime/memory_manager/gfx_partition.cpp | 129 ++++++++++++++---- runtime/memory_manager/gfx_partition.h | 24 ++-- runtime/memory_manager/memory_manager.h | 2 + .../os_agnostic_memory_manager.cpp | 115 ++++++++++------ .../os_agnostic_memory_manager.h | 23 ++-- runtime/os_interface/CMakeLists.txt | 1 + runtime/os_interface/linux/CMakeLists.txt | 1 + runtime/os_interface/linux/allocator_helper.h | 3 +- .../os_interface/linux/drm_memory_manager.cpp | 3 +- .../os_interface/linux/os_memory_linux.cpp | 23 ++++ runtime/os_interface/os_memory.h | 19 +++ runtime/os_interface/windows/CMakeLists.txt | 1 + .../os_interface/windows/os_memory_win.cpp | 22 +++ .../enqueue_read_buffer_aub_tests.cpp | 15 +- .../command_queue/enqueue_kernel_1_tests.cpp | 4 +- .../command_queue/enqueue_kernel_2_tests.cpp | 15 +- .../enqueue_kernel_two_walker_ioq_tests.cpp | 2 +- .../enqueue_svm_mem_copy_tests.cpp | 27 +++- .../command_queue/enqueue_svm_tests.cpp | 4 + .../gl/enqueue_kernel_gl_tests.cpp | 10 +- ...and_stream_receiver_flush_task_2_tests.cpp | 38 ++++-- .../command_stream_receiver_hw_tests.cpp | 21 ++- .../command_stream_receiver_tests.cpp | 4 +- .../device_queue/device_queue_hw_tests.cpp | 8 +- .../enqueue_execution_model_kernel_tests.cpp | 12 +- .../gen_commands_common_validation.h | 4 +- unit_tests/kernel/kernel_tests.cpp | 4 +- unit_tests/linux/main_linux_dll.cpp | 4 + unit_tests/mem_obj/image_set_arg_tests.cpp | 2 +- .../memory_manager/gfx_partition_tests.cpp | 30 +++- ..._manager_allocate_in_device_pool_tests.cpp | 6 +- .../memory_manager/memory_manager_tests.cpp | 91 +++--------- unit_tests/mocks/mock_gfx_partition.h | 8 ++ unit_tests/mocks/mock_graphics_allocation.h | 17 +-- unit_tests/os_interface/CMakeLists.txt | 1 + .../os_interface/linux/allocator_helper.cpp | 9 ++ .../linux/allocator_helper_tests.cpp | 5 + unit_tests/os_interface/os_memory_tests.cpp | 19 +++ unit_tests/program/program_tests.cpp | 7 +- 42 files changed, 501 insertions(+), 242 deletions(-) create mode 100644 runtime/os_interface/linux/os_memory_linux.cpp create mode 100644 runtime/os_interface/os_memory.h create mode 100644 runtime/os_interface/windows/os_memory_win.cpp create mode 100644 unit_tests/os_interface/os_memory_tests.cpp diff --git a/runtime/device/device.h b/runtime/device/device.h index 8cd423f1ed..7a77fc8062 100644 --- a/runtime/device/device.h +++ b/runtime/device/device.h @@ -115,7 +115,7 @@ class Device : public BaseObject<_cl_device_id> { const HardwareCapabilities &getHardwareCapabilities() const { return hardwareCapabilities; } uint32_t getDeviceIndex() const { return deviceIndex; } bool isFullRangeSvm() const { - return getHardwareInfo().capabilityTable.gpuAddressSpace == MemoryConstants::max48BitAddress; + return executionEnvironment->isFullRangeSvm(); } protected: diff --git a/runtime/dll/linux/allocator_helper.cpp b/runtime/dll/linux/allocator_helper.cpp index 2d0a71e23f..6ed7786572 100644 --- a/runtime/dll/linux/allocator_helper.cpp +++ b/runtime/dll/linux/allocator_helper.cpp @@ -11,7 +11,13 @@ #include "runtime/helpers/aligned_memory.h" namespace NEO { + size_t getSizeToMap() { return static_cast(alignUp(4 * GB - 8096, 4096)); } + +size_t getSizeToReserve() { + return maxNBitValue<47> / 4; +} + } // namespace NEO diff --git a/runtime/execution_environment/execution_environment.h b/runtime/execution_environment/execution_environment.h index 2738439f1f..9fd75147f1 100644 --- a/runtime/execution_environment/execution_environment.h +++ b/runtime/execution_environment/execution_environment.h @@ -54,7 +54,7 @@ class ExecutionEnvironment : public ReferenceTrackedObject const HardwareInfo *getHardwareInfo() const { return hwInfo.get(); } HardwareInfo *getMutableHardwareInfo() const { return hwInfo.get(); } bool isFullRangeSvm() const { - return hwInfo->capabilityTable.gpuAddressSpace == MemoryConstants::max48BitAddress; + return hwInfo->capabilityTable.gpuAddressSpace >= maxNBitValue<47>; } GmmHelper *getGmmHelper() const; diff --git a/runtime/memory_manager/gfx_partition.cpp b/runtime/memory_manager/gfx_partition.cpp index 362291d263..de5387e236 100644 --- a/runtime/memory_manager/gfx_partition.cpp +++ b/runtime/memory_manager/gfx_partition.cpp @@ -8,6 +8,7 @@ #include "runtime/memory_manager/gfx_partition.h" #include "runtime/helpers/aligned_memory.h" +#include "runtime/os_interface/os_memory.h" namespace NEO { @@ -16,33 +17,115 @@ const std::array GfxPartition::heap32Names{{HeapIndex::HEAP_INTERN HeapIndex::HEAP_EXTERNAL_DEVICE_MEMORY, HeapIndex::HEAP_EXTERNAL}}; -void GfxPartition::init(uint64_t gpuAddressSpace) { +const std::array GfxPartition::heapNonSvmNames{{HeapIndex::HEAP_INTERNAL_DEVICE_MEMORY, + HeapIndex::HEAP_INTERNAL, + HeapIndex::HEAP_EXTERNAL_DEVICE_MEMORY, + HeapIndex::HEAP_EXTERNAL, + HeapIndex::HEAP_STANDARD, + HeapIndex::HEAP_STANDARD64KB}}; +GfxPartition::~GfxPartition() { + if (reservedCpuAddressRange) { + OSMemory::releaseCpuAddressRange(reservedCpuAddressRange, reservedCpuAddressRangeSize); + } +} - // 1) Full Range SVM gfx layout: - // - // SVM H0 H1 H2 H3 STANDARD STANDARD64K - // |__________________________________|____|____|____|____|________________|______________| - // | | | | | | | | - // | gfxBase gfxTop - // 0x0 0x0000800000000000/0x10000000 for 32 bit 0x0000FFFFFFFFFFFFFFFF - // - // 2) Limited Range gfx layout (no SVM): - // - // H0 H1 H2 H3 STANDARD STANDARD64K - // |____|____|____|____|____________________|__________________| - // | | | | | | | - // gfxBase gfxTop - // 0x0 0xFFF...FFF < 48 bit +void GfxPartition::Heap::init(uint64_t base, uint64_t size) { + this->base = base; + this->size = size; - uint64_t gfxTop = gpuAddressSpace + 1; - uint64_t gfxBase = is64bit ? MemoryConstants::max64BitAppAddress + 1 : MemoryConstants::max32BitAddress + 1; - const uint64_t gfxHeap32Size = 4 * MemoryConstants::gigaByte; - - if (gpuAddressSpace < MemoryConstants::max48BitAddress) { - gfxBase = 0ull; + // Exclude very first and very last 64K from GPU address range allocation + if (size > 2 * GfxPartition::heapGranularity) { + size -= 2 * GfxPartition::heapGranularity; } - heapInit(HeapIndex::HEAP_SVM, 0ull, gfxBase); + alloc = std::make_unique(base + GfxPartition::heapGranularity, size); +} + +void GfxPartition::freeGpuAddressRange(uint64_t ptr, size_t size) { + for (auto heapName : GfxPartition::heapNonSvmNames) { + auto &heap = getHeap(heapName); + if ((ptr > heap.getBase()) && ((ptr + size) < heap.getLimit())) { + heap.free(ptr, size); + break; + } + } +} + +void GfxPartition::init(uint64_t gpuAddressSpace, size_t cpuAddressRangeSizeToReserve) { + + /* + * I. 64-bit builds: + * + * 1) 48-bit Full Range SVM gfx layout: + * + * SVM H0 H1 H2 H3 STANDARD STANDARD64K + * |__________________________________|____|____|____|____|________________|______________| + * | | | | | | | | + * | gfxBase gfxTop + * 0x0 0x0000800000000000 0x0000FFFFFFFFFFFF + * + * + * 2) 47-bit Full Range SVM gfx layout: + * + * gfxSize = 2^47 / 4 = 0x200000000000 + * ________________________________________________ + * / \ + * SVM / H0 H1 H2 H3 STANDARD STANDARD64K \ SVM + * |________________|____|____|____|____|________________|______________|_______________| + * | | | | | | | | | + * | gfxBase gfxTop | + * 0x0 reserveCpuAddressRange(gfxSize) 0x00007FFFFFFFFFFF + * \_____________________________________ SVM _________________________________________/ + * + * + * + * 3) Limited Range gfx layout (no SVM): + * + * H0 H1 H2 H3 STANDARD STANDARD64K + * |____|____|____|____|____________________|__________________| + * | | | | | | | + * gfxBase gfxTop + * 0x0 0xFFF...FFF < 47 bit + * + * + * II. 32-bit builds: + * + * 1) 32-bit Full Range SVM gfx layout: + * + * SVM H0 H1 H2 H3 STANDARD STANDARD64K + * |_______|____|____|____|____|________________|______________| + * | | | | | | | | + * | gfxBase gfxTop + * 0x0 0x100000000 gpuAddressSpace + */ + + uint64_t gfxTop = gpuAddressSpace + 1; + uint64_t gfxBase = 0x0ull; + const uint64_t gfxHeap32Size = 4 * MemoryConstants::gigaByte; + + if (is32bit) { + gfxBase = maxNBitValue<32> + 1; + heapInit(HeapIndex::HEAP_SVM, 0ull, gfxBase); + } else { + if (gpuAddressSpace == maxNBitValue<48>) { + gfxBase = maxNBitValue<48 - 1> + 1; + heapInit(HeapIndex::HEAP_SVM, 0ull, gfxBase); + } else if (gpuAddressSpace == maxNBitValue<47>) { + reservedCpuAddressRangeSize = cpuAddressRangeSizeToReserve; + UNRECOVERABLE_IF(reservedCpuAddressRangeSize == 0); + reservedCpuAddressRange = OSMemory::reserveCpuAddressRange(reservedCpuAddressRangeSize); + UNRECOVERABLE_IF(reservedCpuAddressRange == nullptr); + UNRECOVERABLE_IF(!isAligned(reservedCpuAddressRange)); + gfxBase = reinterpret_cast(reservedCpuAddressRange); + gfxTop = gfxBase + reservedCpuAddressRangeSize; + heapInit(HeapIndex::HEAP_SVM, 0ull, gpuAddressSpace + 1); + } else if (gpuAddressSpace < maxNBitValue<47>) { + gfxBase = 0ull; + heapInit(HeapIndex::HEAP_SVM, 0ull, 0ull); + } else { + UNRECOVERABLE_IF("Invalid GPU Address Range!"); + } + } for (auto heap : GfxPartition::heap32Names) { heapInit(heap, gfxBase, gfxHeap32Size); diff --git a/runtime/memory_manager/gfx_partition.h b/runtime/memory_manager/gfx_partition.h index 3695836e50..cb40e5cd12 100644 --- a/runtime/memory_manager/gfx_partition.h +++ b/runtime/memory_manager/gfx_partition.h @@ -31,8 +31,9 @@ constexpr auto internalHeapIndex = is32bit ? HeapIndex::HEAP_INTERNAL : HeapInde class GfxPartition { public: GfxPartition() {} + ~GfxPartition(); - void init(uint64_t gpuAddressSpace); + void init(uint64_t gpuAddressSpace, size_t cpuAddressRangeSizeToReserve); void heapInit(HeapIndex heapIndex, uint64_t base, uint64_t size) { getHeap(heapIndex).init(base, size); @@ -46,33 +47,35 @@ class GfxPartition { getHeap(heapIndex).free(ptr, size); } + void freeGpuAddressRange(uint64_t ptr, size_t size); + uint64_t getHeapBase(HeapIndex heapIndex) { return getHeap(heapIndex).getBase(); } uint64_t getHeapLimit(HeapIndex heapIndex) { - return getHeap(heapIndex).getBase() + getHeap(heapIndex).getSize() - 1; + return getHeap(heapIndex).getLimit(); } uint64_t getHeapMinimalAddress(HeapIndex heapIndex) { return getHeapBase(heapIndex) + heapGranularity; } + bool isLimitedRange() { return getHeap(HeapIndex::HEAP_SVM).getSize() == 0ull; } + static const uint64_t heapGranularity = MemoryConstants::pageSize64k; static const std::array heap32Names; + static const std::array heapNonSvmNames; protected: class Heap { public: Heap() = default; + void init(uint64_t base, uint64_t size); uint64_t getBase() const { return base; } uint64_t getSize() const { return size; } - void init(uint64_t base, uint64_t size) { - this->base = base; - this->size = size; - alloc = std::make_unique(base + heapGranularity, size ? size - heapGranularity : 0ull); - } + uint64_t getLimit() const { return base + size - 1; } uint64_t allocate(size_t &size) { return alloc->allocate(size); } void free(uint64_t ptr, size_t size) { alloc->free(ptr, size); } @@ -82,10 +85,13 @@ class GfxPartition { }; Heap &getHeap(HeapIndex heapIndex) { - return heap[static_cast(heapIndex)]; + return heaps[static_cast(heapIndex)]; } - std::array(HeapIndex::TOTAL_HEAPS)> heap; + std::array(HeapIndex::TOTAL_HEAPS)> heaps; + + void *reservedCpuAddressRange = nullptr; + size_t reservedCpuAddressRangeSize = 0; }; } // namespace NEO diff --git a/runtime/memory_manager/memory_manager.h b/runtime/memory_manager/memory_manager.h index ad474a1def..9e45727c4a 100644 --- a/runtime/memory_manager/memory_manager.h +++ b/runtime/memory_manager/memory_manager.h @@ -111,6 +111,8 @@ class MemoryManager { virtual uint64_t getExternalHeapBaseAddress() = 0; + bool isLimitedRange() { return gfxPartition.isLimitedRange(); } + bool peek64kbPagesEnabled() const { return enable64kbpages; } bool peekForce32BitAllocations() const { return force32bitAllocations; } virtual void setForce32BitAllocations(bool newValue); diff --git a/runtime/memory_manager/os_agnostic_memory_manager.cpp b/runtime/memory_manager/os_agnostic_memory_manager.cpp index 57a09be8c6..7e61edad7d 100644 --- a/runtime/memory_manager/os_agnostic_memory_manager.cpp +++ b/runtime/memory_manager/os_agnostic_memory_manager.cpp @@ -18,11 +18,20 @@ #include "runtime/helpers/options.h" #include "runtime/helpers/surface_formats.h" #include "runtime/memory_manager/host_ptr_manager.h" +#include "runtime/os_interface/os_memory.h" #include namespace NEO { +OsAgnosticMemoryManager::OsAgnosticMemoryManager(bool aubUsage, ExecutionEnvironment &executionEnvironment) : MemoryManager(executionEnvironment) { + auto gpuAddressSpace = executionEnvironment.getHardwareInfo()->capabilityTable.gpuAddressSpace; + + // 4 x sizeof(Heap32) + 2 x sizeof(Standard/Standard64k) + size_t reservedCpuAddressRangeSize = is64bit ? (4 * 4 + 2 * (aubUsage ? 32 : 4)) * GB : 0; + gfxPartition.init(gpuAddressSpace, reservedCpuAddressRangeSize); +} + OsAgnosticMemoryManager::~OsAgnosticMemoryManager() { applyCommonCleanup(); } @@ -35,22 +44,19 @@ GraphicsAllocation *OsAgnosticMemoryManager::allocateGraphicsMemoryWithAlignment MemoryAllocation *memoryAllocation = nullptr; if (fakeBigAllocations && allocationData.size > bigAllocation) { - memoryAllocation = new MemoryAllocation( + memoryAllocation = createMemoryAllocation( allocationData.type, nullptr, (void *)dummyAddress, static_cast(dummyAddress), allocationData.size, counter, MemoryPool::System4KBPages, allocationData.flags.multiOsContextCapable, allocationData.flags.uncacheable, - allocationData.flags.flushL3); + allocationData.flags.flushL3, false); counter++; return memoryAllocation; } auto ptr = allocateSystemMemory(sizeAligned, allocationData.alignment ? alignUp(allocationData.alignment, MemoryConstants::pageSize) : MemoryConstants::pageSize); if (ptr != nullptr) { - memoryAllocation = new MemoryAllocation(allocationData.type, ptr, ptr, reinterpret_cast(ptr), allocationData.size, - counter, MemoryPool::System4KBPages, allocationData.flags.multiOsContextCapable, - allocationData.flags.uncacheable, allocationData.flags.flushL3); - if (!memoryAllocation) { - alignedFreeWrapper(ptr); - return nullptr; - } + memoryAllocation = createMemoryAllocation(allocationData.type, ptr, ptr, reinterpret_cast(ptr), allocationData.size, + counter, MemoryPool::System4KBPages, allocationData.flags.multiOsContextCapable, + allocationData.flags.uncacheable, allocationData.flags.flushL3, false); + if (allocationData.type == GraphicsAllocation::AllocationType::SVM_CPU) { //add 2MB padding in case mapPtr is not 2MB aligned size_t reserveSize = sizeAligned + allocationData.alignment; @@ -73,11 +79,12 @@ GraphicsAllocation *OsAgnosticMemoryManager::allocateGraphicsMemoryForNonSvmHost auto alignedPtr = alignDown(allocationData.hostPtr, MemoryConstants::pageSize); auto offsetInPage = ptrDiff(allocationData.hostPtr, alignedPtr); - auto memoryAllocation = new MemoryAllocation(allocationData.type, nullptr, const_cast(allocationData.hostPtr), - reinterpret_cast(alignedPtr), allocationData.size, counter, - MemoryPool::System4KBPages, false, false, allocationData.flags.flushL3); + auto memoryAllocation = createMemoryAllocation(allocationData.type, nullptr, const_cast(allocationData.hostPtr), + reinterpret_cast(alignedPtr), allocationData.size, counter, + MemoryPool::System4KBPages, false, false, allocationData.flags.flushL3, false); memoryAllocation->setAllocationOffset(offsetInPage); + counter++; return memoryAllocation; } @@ -94,9 +101,10 @@ GraphicsAllocation *OsAgnosticMemoryManager::allocateGraphicsMemory64kb(const Al } GraphicsAllocation *OsAgnosticMemoryManager::allocate32BitGraphicsMemoryImpl(const AllocationData &allocationData) { + auto heap = useInternal32BitAllocator(allocationData.type) ? internalHeapIndex : HeapIndex::HEAP_EXTERNAL; if (allocationData.hostPtr) { auto allocationSize = alignSizeWholePage(allocationData.hostPtr, allocationData.size); - auto gpuVirtualAddress = allocator32Bit->allocate(allocationSize); + auto gpuVirtualAddress = gfxPartition.heapAllocate(heap, allocationSize); if (!gpuVirtualAddress) { return nullptr; } @@ -104,8 +112,9 @@ GraphicsAllocation *OsAgnosticMemoryManager::allocate32BitGraphicsMemoryImpl(con MemoryAllocation *memAlloc = new MemoryAllocation( allocationData.type, nullptr, const_cast(allocationData.hostPtr), GmmHelper::canonize(gpuVirtualAddress + offset), allocationData.size, counter, MemoryPool::System4KBPagesWith32BitGpuAddressing, false, false, false); + memAlloc->set32BitAllocation(true); - memAlloc->setGpuBaseAddress(GmmHelper::canonize(getExternalHeapBaseAddress())); + memAlloc->setGpuBaseAddress(GmmHelper::canonize(gfxPartition.getHeapBase(heap))); memAlloc->sizeToFree = allocationSize; counter++; @@ -114,7 +123,7 @@ GraphicsAllocation *OsAgnosticMemoryManager::allocate32BitGraphicsMemoryImpl(con auto allocationSize = alignUp(allocationData.size, MemoryConstants::pageSize); void *ptrAlloc = nullptr; - auto gpuAddress = allocator32Bit->allocate(allocationSize); + auto gpuAddress = gfxPartition.heapAllocate(heap, allocationSize); if (allocationData.size < 0xfffff000) { if (fakeBigAllocations) { @@ -129,8 +138,9 @@ GraphicsAllocation *OsAgnosticMemoryManager::allocate32BitGraphicsMemoryImpl(con memoryAllocation = new MemoryAllocation(allocationData.type, ptrAlloc, ptrAlloc, GmmHelper::canonize(gpuAddress), allocationData.size, counter, MemoryPool::System4KBPagesWith32BitGpuAddressing, false, false, false); + memoryAllocation->set32BitAllocation(true); - memoryAllocation->setGpuBaseAddress(GmmHelper::canonize(getExternalHeapBaseAddress())); + memoryAllocation->setGpuBaseAddress(GmmHelper::canonize(gfxPartition.getHeapBase(heap))); memoryAllocation->sizeToFree = allocationSize; } counter++; @@ -138,9 +148,9 @@ GraphicsAllocation *OsAgnosticMemoryManager::allocate32BitGraphicsMemoryImpl(con } GraphicsAllocation *OsAgnosticMemoryManager::createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness) { - auto graphicsAllocation = new MemoryAllocation(properties.allocationType, nullptr, reinterpret_cast(1), 1, - 4096u, static_cast(handle), MemoryPool::SystemCpuInaccessible, false, - false, false); + auto graphicsAllocation = createMemoryAllocation(properties.allocationType, nullptr, reinterpret_cast(1), 1, + 4096u, static_cast(handle), MemoryPool::SystemCpuInaccessible, false, + false, false, requireSpecificBitness); graphicsAllocation->setSharedHandle(handle); graphicsAllocation->set32BitAllocation(requireSpecificBitness); @@ -191,9 +201,12 @@ void OsAgnosticMemoryManager::freeGraphicsMemoryImpl(GraphicsAllocation *gfxAllo return; } - if (gfxAllocation->is32BitAllocation()) { - auto gpuAddressToFree = gfxAllocation->getGpuAddress() & ~MemoryConstants::pageMask; - allocator32Bit->free(gpuAddressToFree, static_cast(gfxAllocation)->sizeToFree); + auto memoryAllocation = static_cast(gfxAllocation); + auto sizeToFree = memoryAllocation->sizeToFree; + + if (sizeToFree) { + auto gpuAddressToFree = GmmHelper::decanonize(memoryAllocation->getGpuAddress()) & ~MemoryConstants::pageMask; + gfxPartition.freeGpuAddressRange(gpuAddressToFree, sizeToFree); } alignedFreeWrapper(gfxAllocation->getDriverAllocatedCpuPtr()); @@ -218,17 +231,22 @@ uint64_t OsAgnosticMemoryManager::getMaxApplicationAddress() { } uint64_t OsAgnosticMemoryManager::getInternalHeapBaseAddress() { - return this->allocator32Bit->getBase(); + return gfxPartition.getHeapBase(internalHeapIndex); } uint64_t OsAgnosticMemoryManager::getExternalHeapBaseAddress() { - return this->allocator32Bit->getBase(); + return gfxPartition.getHeapBase(HeapIndex::HEAP_EXTERNAL); +} + +void OsAgnosticMemoryManager::setForce32BitAllocations(bool newValue) { + force32bitAllocations = newValue; } GraphicsAllocation *OsAgnosticMemoryManager::createGraphicsAllocation(OsHandleStorage &handleStorage, const AllocationData &allocationData) { - auto allocation = new MemoryAllocation(allocationData.type, nullptr, const_cast(allocationData.hostPtr), - reinterpret_cast(allocationData.hostPtr), allocationData.size, counter++, - MemoryPool::System4KBPages, false, false, false); + auto allocation = createMemoryAllocation(allocationData.type, nullptr, const_cast(allocationData.hostPtr), + reinterpret_cast(allocationData.hostPtr), allocationData.size, counter++, + MemoryPool::System4KBPages, false, false, false, false); + allocation->fragmentsStorage = handleStorage; return allocation; } @@ -276,8 +294,8 @@ GraphicsAllocation *OsAgnosticMemoryManager::allocateGraphicsMemoryForImageImpl( auto ptr = allocateSystemMemory(alignUp(allocationData.imgInfo->size, MemoryConstants::pageSize), MemoryConstants::pageSize); if (ptr != nullptr) { - alloc = new MemoryAllocation(allocationData.type, ptr, ptr, reinterpret_cast(ptr), allocationData.imgInfo->size, - counter, MemoryPool::SystemCpuInaccessible, false, allocationData.flags.uncacheable, allocationData.flags.flushL3); + alloc = createMemoryAllocation(allocationData.type, ptr, ptr, reinterpret_cast(ptr), allocationData.imgInfo->size, + counter, MemoryPool::SystemCpuInaccessible, false, allocationData.flags.uncacheable, allocationData.flags.flushL3, false); counter++; } @@ -288,21 +306,6 @@ GraphicsAllocation *OsAgnosticMemoryManager::allocateGraphicsMemoryForImageImpl( return alloc; } -Allocator32bit *OsAgnosticMemoryManager::create32BitAllocator(bool aubUsage) { - uint64_t allocatorSize = MemoryConstants::gigaByte - 2 * 4096; - uint64_t heap32Base = 0x80000000000ul; - - if (is64bit && this->localMemorySupported && aubUsage) { - heap32Base = 0x40000000000ul; - } - - if (is32bit) { - heap32Base = 0x0; - } - - return new Allocator32bit(heap32Base, allocatorSize); -} - void *OsAgnosticMemoryManager::reserveCpuAddressRange(size_t size) { void *reservePtr = allocateSystemMemory(size, MemoryConstants::preferredAlignment); return reservePtr; @@ -311,4 +314,28 @@ void *OsAgnosticMemoryManager::reserveCpuAddressRange(size_t size) { void OsAgnosticMemoryManager::releaseReservedCpuAddressRange(void *reserved, size_t size) { alignedFreeWrapper(reserved); } + +MemoryAllocation *OsAgnosticMemoryManager::createMemoryAllocation(GraphicsAllocation::AllocationType allocationType, void *driverAllocatedCpuPointer, + void *pMem, uint64_t gpuAddress, size_t memSize, uint64_t count, + MemoryPool::Type pool, bool multiOsContextCapable, bool uncacheable, + bool flushL3Required, bool requireSpecificBitness) { + if (!isLimitedRange()) { + return new MemoryAllocation(allocationType, driverAllocatedCpuPointer, pMem, gpuAddress, memSize, + count, pool, multiOsContextCapable, uncacheable, flushL3Required); + } + + size_t alignedSize = alignSizeWholePage(pMem, memSize); + + auto heap = (force32bitAllocations || requireSpecificBitness) ? HeapIndex::HEAP_EXTERNAL : HeapIndex::HEAP_STANDARD; + + uint64_t limitedGpuAddress = gfxPartition.heapAllocate(heap, alignedSize); + + auto memoryAllocation = new MemoryAllocation(allocationType, driverAllocatedCpuPointer, pMem, limitedGpuAddress, memSize, + count, pool, multiOsContextCapable, uncacheable, flushL3Required); + + memoryAllocation->setGpuBaseAddress(GmmHelper::canonize(gfxPartition.getHeapBase(heap))); + memoryAllocation->sizeToFree = alignedSize; + + return memoryAllocation; +} } // namespace NEO diff --git a/runtime/memory_manager/os_agnostic_memory_manager.h b/runtime/memory_manager/os_agnostic_memory_manager.h index bce47a5559..2f6d6e2f96 100644 --- a/runtime/memory_manager/os_agnostic_memory_manager.h +++ b/runtime/memory_manager/os_agnostic_memory_manager.h @@ -7,8 +7,6 @@ #pragma once #include "core/helpers/basic_math.h" -#include "runtime/helpers/hw_info.h" -#include "runtime/helpers/options.h" #include "runtime/memory_manager/memory_manager.h" namespace NEO { @@ -22,6 +20,15 @@ class MemoryAllocation : public GraphicsAllocation { void setSharedHandle(osHandle handle) { sharingInfo.sharedHandle = handle; } + MemoryAllocation(AllocationType allocationType, void *cpuPtrIn, uint64_t gpuAddress, uint64_t baseAddress, size_t sizeIn, + MemoryPool::Type pool, bool multiOsContextCapable) + : GraphicsAllocation(allocationType, cpuPtrIn, gpuAddress, baseAddress, sizeIn, pool, multiOsContextCapable), + id(0), uncacheable(false) {} + + MemoryAllocation(AllocationType allocationType, void *cpuPtrIn, size_t sizeIn, osHandle sharedHandleIn, MemoryPool::Type pool, bool multiOsContextCapable) + : GraphicsAllocation(allocationType, cpuPtrIn, sizeIn, sharedHandleIn, pool, multiOsContextCapable), + id(0), uncacheable(false) {} + MemoryAllocation(AllocationType allocationType, void *driverAllocatedCpuPointer, void *pMem, uint64_t gpuAddress, size_t memSize, uint64_t count, MemoryPool::Type pool, bool multiOsContextCapable, bool uncacheable, bool flushL3Required) : GraphicsAllocation(allocationType, pMem, gpuAddress, 0u, memSize, pool, multiOsContextCapable), @@ -40,12 +47,7 @@ class OsAgnosticMemoryManager : public MemoryManager { using MemoryManager::allocateGraphicsMemory; OsAgnosticMemoryManager(ExecutionEnvironment &executionEnvironment) : OsAgnosticMemoryManager(false, executionEnvironment) {} - - OsAgnosticMemoryManager(bool aubUsage, ExecutionEnvironment &executionEnvironment) : MemoryManager(executionEnvironment) { - allocator32Bit.reset(create32BitAllocator(aubUsage)); - gfxPartition.init(platformDevices[0]->capabilityTable.gpuAddressSpace); - } - + OsAgnosticMemoryManager(bool aubUsage, ExecutionEnvironment &executionEnvironment); ~OsAgnosticMemoryManager() override; GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness) override; GraphicsAllocation *createGraphicsAllocationFromNTHandle(void *handle) override { return nullptr; } @@ -61,11 +63,10 @@ class OsAgnosticMemoryManager : public MemoryManager { uint64_t getMaxApplicationAddress() override; uint64_t getInternalHeapBaseAddress() override; uint64_t getExternalHeapBaseAddress() override; + void setForce32BitAllocations(bool newValue) override; void turnOnFakingBigAllocations(); - Allocator32bit *create32BitAllocator(bool enableLocalMemory); - void *reserveCpuAddressRange(size_t size) override; void releaseReservedCpuAddressRange(void *reserved, size_t size) override; @@ -80,6 +81,8 @@ class OsAgnosticMemoryManager : public MemoryManager { void unlockResourceImpl(GraphicsAllocation &graphicsAllocation) override {} GraphicsAllocation *allocate32BitGraphicsMemoryImpl(const AllocationData &allocationData) override; GraphicsAllocation *allocateGraphicsMemoryInDevicePool(const AllocationData &allocationData, AllocationStatus &status) override; + MemoryAllocation *createMemoryAllocation(GraphicsAllocation::AllocationType allocationType, void *driverAllocatedCpuPointer, void *pMem, uint64_t gpuAddress, size_t memSize, + uint64_t count, MemoryPool::Type pool, bool multiOsContextCapable, bool uncacheable, bool flushL3Required, bool requireSpecificBitness); private: unsigned long long counter = 0; diff --git a/runtime/os_interface/CMakeLists.txt b/runtime/os_interface/CMakeLists.txt index e5af34cab3..253c6b7e64 100644 --- a/runtime/os_interface/CMakeLists.txt +++ b/runtime/os_interface/CMakeLists.txt @@ -18,6 +18,7 @@ set(RUNTIME_SRCS_OS_INTERFACE_BASE ${CMAKE_CURRENT_SOURCE_DIR}/os_inc_base.h ${CMAKE_CURRENT_SOURCE_DIR}/os_interface.h ${CMAKE_CURRENT_SOURCE_DIR}/os_library.h + ${CMAKE_CURRENT_SOURCE_DIR}/os_memory.h ${CMAKE_CURRENT_SOURCE_DIR}/os_thread.h ${CMAKE_CURRENT_SOURCE_DIR}/os_time.cpp ${CMAKE_CURRENT_SOURCE_DIR}/os_time.h diff --git a/runtime/os_interface/linux/CMakeLists.txt b/runtime/os_interface/linux/CMakeLists.txt index c65b692dca..d8d6cb90ca 100644 --- a/runtime/os_interface/linux/CMakeLists.txt +++ b/runtime/os_interface/linux/CMakeLists.txt @@ -45,6 +45,7 @@ set(RUNTIME_SRCS_OS_INTERFACE_LINUX ${CMAKE_CURRENT_SOURCE_DIR}/os_interface.h ${CMAKE_CURRENT_SOURCE_DIR}/os_library.cpp ${CMAKE_CURRENT_SOURCE_DIR}/os_library.h + ${CMAKE_CURRENT_SOURCE_DIR}/os_memory_linux.cpp ${CMAKE_CURRENT_SOURCE_DIR}/os_thread_linux.cpp ${CMAKE_CURRENT_SOURCE_DIR}/os_thread_linux.h ${CMAKE_CURRENT_SOURCE_DIR}/os_time_linux.cpp diff --git a/runtime/os_interface/linux/allocator_helper.h b/runtime/os_interface/linux/allocator_helper.h index 02966e86d5..a1ed957333 100644 --- a/runtime/os_interface/linux/allocator_helper.h +++ b/runtime/os_interface/linux/allocator_helper.h @@ -10,4 +10,5 @@ namespace NEO { size_t getSizeToMap(); -} // namespace NEO \ No newline at end of file +size_t getSizeToReserve(); +} // namespace NEO diff --git a/runtime/os_interface/linux/drm_memory_manager.cpp b/runtime/os_interface/linux/drm_memory_manager.cpp index 4798b60fb8..457ed7655c 100644 --- a/runtime/os_interface/linux/drm_memory_manager.cpp +++ b/runtime/os_interface/linux/drm_memory_manager.cpp @@ -19,6 +19,7 @@ #include "runtime/helpers/surface_formats.h" #include "runtime/memory_manager/host_ptr_manager.h" #include "runtime/os_interface/32bit_memory.h" +#include "runtime/os_interface/linux/allocator_helper.h" #include "runtime/os_interface/linux/os_context_linux.h" #include "runtime/os_interface/linux/os_interface.h" #include "runtime/os_interface/linux/tiling_mode_helper.h" @@ -39,7 +40,7 @@ DrmMemoryManager::DrmMemoryManager(gemCloseWorkerMode mode, forcePinEnabled(forcePinAllowed), validateHostPtrMemory(validateHostPtrMemory) { supportsMultiStorageResources = false; - gfxPartition.init(platformDevices[0]->capabilityTable.gpuAddressSpace); + gfxPartition.init(platformDevices[0]->capabilityTable.gpuAddressSpace, getSizeToReserve()); MemoryManager::virtualPaddingAvailable = true; if (mode != gemCloseWorkerMode::gemCloseWorkerInactive) { gemCloseWorker.reset(new DrmGemCloseWorker(*this)); diff --git a/runtime/os_interface/linux/os_memory_linux.cpp b/runtime/os_interface/linux/os_memory_linux.cpp new file mode 100644 index 0000000000..eaa20230c9 --- /dev/null +++ b/runtime/os_interface/linux/os_memory_linux.cpp @@ -0,0 +1,23 @@ +/* + * Copyright (C) 2019 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "runtime/os_interface/os_memory.h" + +#include +#include + +namespace NEO { + +void *OSMemory::reserveCpuAddressRange(size_t sizeToReserve) { + return mmap(0, sizeToReserve, PROT_NONE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_NORESERVE | MAP_HUGETLB, open("/dev/null", O_RDONLY), 0); +} + +void OSMemory::releaseCpuAddressRange(void *reservedCpuAddressRange, size_t reservedSize) { + munmap(reservedCpuAddressRange, reservedSize); +} + +} // namespace NEO diff --git a/runtime/os_interface/os_memory.h b/runtime/os_interface/os_memory.h new file mode 100644 index 0000000000..2a0d18115a --- /dev/null +++ b/runtime/os_interface/os_memory.h @@ -0,0 +1,19 @@ +/* + * Copyright (C) 2019 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#pragma once +#include + +namespace NEO { + +struct OSMemory { + public: + static void *reserveCpuAddressRange(size_t sizeToReserve); + static void releaseCpuAddressRange(void *reservedCpuAddressRange, size_t reservedSize); +}; + +} // namespace NEO diff --git a/runtime/os_interface/windows/CMakeLists.txt b/runtime/os_interface/windows/CMakeLists.txt index cf92785b59..0b46a934c0 100644 --- a/runtime/os_interface/windows/CMakeLists.txt +++ b/runtime/os_interface/windows/CMakeLists.txt @@ -35,6 +35,7 @@ set(RUNTIME_SRCS_OS_INTERFACE_WINDOWS ${CMAKE_CURRENT_SOURCE_DIR}/os_interface.h ${CMAKE_CURRENT_SOURCE_DIR}/os_library.cpp ${CMAKE_CURRENT_SOURCE_DIR}/os_library.h + ${CMAKE_CURRENT_SOURCE_DIR}/os_memory_win.cpp ${CMAKE_CURRENT_SOURCE_DIR}/os_socket.h ${CMAKE_CURRENT_SOURCE_DIR}/os_thread_win.cpp ${CMAKE_CURRENT_SOURCE_DIR}/os_thread_win.h diff --git a/runtime/os_interface/windows/os_memory_win.cpp b/runtime/os_interface/windows/os_memory_win.cpp new file mode 100644 index 0000000000..b1609113eb --- /dev/null +++ b/runtime/os_interface/windows/os_memory_win.cpp @@ -0,0 +1,22 @@ +/* + * Copyright (C) 2019 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "runtime/os_interface/os_memory.h" + +#include + +namespace NEO { + +void *OSMemory::reserveCpuAddressRange(size_t sizeToReserve) { + return VirtualAlloc(0, sizeToReserve, MEM_RESERVE, PAGE_READWRITE); +} + +void OSMemory::releaseCpuAddressRange(void *reservedCpuAddressRange, size_t /* reservedSize */) { + VirtualFree(reservedCpuAddressRange, 0, MEM_RELEASE); +} + +} // namespace NEO diff --git a/unit_tests/aub_tests/command_queue/enqueue_read_buffer_aub_tests.cpp b/unit_tests/aub_tests/command_queue/enqueue_read_buffer_aub_tests.cpp index 3edddc3e18..0537a4d810 100644 --- a/unit_tests/aub_tests/command_queue/enqueue_read_buffer_aub_tests.cpp +++ b/unit_tests/aub_tests/command_queue/enqueue_read_buffer_aub_tests.cpp @@ -13,6 +13,7 @@ #include "unit_tests/aub_tests/aub_tests_configuration.h" #include "unit_tests/aub_tests/command_queue/command_enqueue_fixture.h" #include "unit_tests/mocks/mock_context.h" +#include "unit_tests/mocks/mock_graphics_allocation.h" #include @@ -115,13 +116,13 @@ HWTEST_F(AUBReadBuffer, reserveCanonicalGpuAddress) { cl_float srcMemory[] = {1.0f, 2.0f, 3.0f, 4.0f}; cl_float dstMemory[] = {0.0f, 0.0f, 0.0f, 0.0f}; - GraphicsAllocation *srcAlocation = new GraphicsAllocation(GraphicsAllocation::AllocationType::UNKNOWN, - srcMemory, - 0xFFFF800400001000, - 0xFFFF800400001000, - sizeof(srcMemory), - MemoryPool::MemoryNull, - false); + GraphicsAllocation *srcAlocation = new MockGraphicsAllocation(GraphicsAllocation::AllocationType::UNKNOWN, + srcMemory, + 0xFFFF800400001000, + 0xFFFF800400001000, + sizeof(srcMemory), + MemoryPool::MemoryNull, + false); std::unique_ptr srcBuffer(Buffer::createBufferHw(&context, CL_MEM_USE_HOST_PTR, diff --git a/unit_tests/command_queue/enqueue_kernel_1_tests.cpp b/unit_tests/command_queue/enqueue_kernel_1_tests.cpp index 6240c3ceac..ecf8bea7b1 100644 --- a/unit_tests/command_queue/enqueue_kernel_1_tests.cpp +++ b/unit_tests/command_queue/enqueue_kernel_1_tests.cpp @@ -370,7 +370,7 @@ HWTEST_F(EnqueueKernelTest, givenReducedAddressSpaceGraphicsAllocationForHostPtr std::unique_ptr device; std::unique_ptr cmdQ; auto hwInfoToModify = *platformDevices[0]; - hwInfoToModify.capabilityTable.gpuAddressSpace = MemoryConstants::max32BitAddress; + hwInfoToModify.capabilityTable.gpuAddressSpace = MemoryConstants::max36BitAddress; device.reset(MockDevice::createWithNewExecutionEnvironment(&hwInfoToModify)); auto mockCsr = new MockCsrHw2(*device->executionEnvironment); device->resetCommandStreamReceiver(mockCsr); @@ -394,7 +394,7 @@ HWTEST_F(EnqueueKernelTest, givenReducedAddressSpaceGraphicsAllocationForHostPtr std::unique_ptr device; std::unique_ptr cmdQ; auto hwInfoToModify = *platformDevices[0]; - hwInfoToModify.capabilityTable.gpuAddressSpace = MemoryConstants::max32BitAddress; + hwInfoToModify.capabilityTable.gpuAddressSpace = MemoryConstants::max36BitAddress; device.reset(MockDevice::createWithNewExecutionEnvironment(&hwInfoToModify)); auto mockCsr = new MockCsrHw2(*device->executionEnvironment); device->resetCommandStreamReceiver(mockCsr); diff --git a/unit_tests/command_queue/enqueue_kernel_2_tests.cpp b/unit_tests/command_queue/enqueue_kernel_2_tests.cpp index e00f5bbc93..20a77cd67f 100644 --- a/unit_tests/command_queue/enqueue_kernel_2_tests.cpp +++ b/unit_tests/command_queue/enqueue_kernel_2_tests.cpp @@ -324,13 +324,13 @@ HWCMDTEST_P(IGFX_GEN8_CORE, EnqueueScratchSpaceTests, GivenKernelRequiringScratc EXPECT_EQ(bitValue, cmd->getPerThreadScratchSpace()); EXPECT_EQ(bitValue, cmd->getStackSize()); auto graphicsAllocation = csr.getScratchAllocation(); - auto GSHaddress = (uintptr_t)sba->getGeneralStateBaseAddress(); + auto GSHaddress = sba->getGeneralStateBaseAddress(); if (is32bit) { EXPECT_NE(0u, cmd->getScratchSpaceBasePointer()); EXPECT_EQ(0u, GSHaddress); } else { EXPECT_EQ(HwHelperHw::get().getScratchSpaceOffsetFor64bit(), cmd->getScratchSpaceBasePointer()); - EXPECT_EQ(GSHaddress + HwHelperHw::get().getScratchSpaceOffsetFor64bit(), (uintptr_t)graphicsAllocation->getUnderlyingBuffer()); + EXPECT_EQ(GSHaddress + HwHelperHw::get().getScratchSpaceOffsetFor64bit(), graphicsAllocation->getGpuAddress()); } auto allocationSize = scratchSize * pDevice->getDeviceInfo().computeUnitsUsedForScratch; @@ -374,9 +374,9 @@ HWCMDTEST_P(IGFX_GEN8_CORE, EnqueueScratchSpaceTests, GivenKernelRequiringScratc auto graphicsAllocation2 = csr.getScratchAllocation(); if (is32bit) { - auto scratchBase = (uintptr_t)cmd2->getScratchSpaceBasePointer(); + auto scratchBase = cmd2->getScratchSpaceBasePointer(); EXPECT_NE(0u, scratchBase); - auto graphicsAddress = (uintptr_t)graphicsAllocation2->getUnderlyingBuffer(); + auto graphicsAddress = graphicsAllocation2->getGpuAddress(); EXPECT_EQ(graphicsAddress, scratchBase); } else { auto *sba2 = (STATE_BASE_ADDRESS *)*itorCmdForStateBase; @@ -403,7 +403,7 @@ HWCMDTEST_P(IGFX_GEN8_CORE, EnqueueScratchSpaceTests, GivenKernelRequiringScratc if (is32bit) { EXPECT_EQ(0u, GSBaddress); } else if (is64bit) { - EXPECT_EQ((uintptr_t)graphicsAllocation2->getUnderlyingBuffer(), GSBaddress + HwHelperHw::get().getScratchSpaceOffsetFor64bit()); + EXPECT_EQ(graphicsAllocation2->getGpuAddress(), GSBaddress + HwHelperHw::get().getScratchSpaceOffsetFor64bit()); } EXPECT_TRUE(csr.getAllocationsForReuse().peekIsEmpty()); @@ -489,7 +489,7 @@ HWCMDTEST_P(IGFX_GEN8_CORE, EnqueueKernelWithScratch, givenDeviceForcing32bitAll ASSERT_NE(itorCmdForStateBase, itorWalker); auto *sba = (STATE_BASE_ADDRESS *)*itorCmdForStateBase; - auto GSHaddress = (uintptr_t)sba->getGeneralStateBaseAddress(); + auto GSHaddress = sba->getGeneralStateBaseAddress(); EXPECT_EQ(memoryManager->getExternalHeapBaseAddress(), GSHaddress); @@ -595,7 +595,8 @@ HWTEST_P(EnqueueKernelPrintfTest, GivenKernelWithPrintfBlockedByEventWhenEventUn // In scenarios with 32bit allocator and 64 bit tests this code won't work // due to inability to retrieve original buffer pointer as it is done in this test. - if (!pDevice->getMemoryManager()->peekForce32BitAllocations()) { + auto memoryManager = pDevice->getMemoryManager(); + if (!memoryManager->peekForce32BitAllocations() && !memoryManager->isLimitedRange()) { testing::internal::CaptureStdout(); auto userEvent = make_releaseable(context); diff --git a/unit_tests/command_queue/enqueue_kernel_two_walker_ioq_tests.cpp b/unit_tests/command_queue/enqueue_kernel_two_walker_ioq_tests.cpp index c05c17af8e..4ed3cc9b18 100644 --- a/unit_tests/command_queue/enqueue_kernel_two_walker_ioq_tests.cpp +++ b/unit_tests/command_queue/enqueue_kernel_two_walker_ioq_tests.cpp @@ -61,6 +61,6 @@ HWTEST_F(IOQWithTwoWalkers, shouldHaveAPipecontrolBetweenWalkers2) { uint64_t addressPC = ((uint64_t)pipeControl->getAddressHigh() << 32) | pipeControl->getAddress(); // The PC address should match the CS tag address - EXPECT_EQ((uint64_t)commandStreamReceiver.getTagAddress(), addressPC); + EXPECT_EQ(commandStreamReceiver.getTagAllocation()->getGpuAddress(), addressPC); EXPECT_EQ(1u, pipeControl->getImmediateData()); } diff --git a/unit_tests/command_queue/enqueue_svm_mem_copy_tests.cpp b/unit_tests/command_queue/enqueue_svm_mem_copy_tests.cpp index fb659d71ac..7a19480ea2 100644 --- a/unit_tests/command_queue/enqueue_svm_mem_copy_tests.cpp +++ b/unit_tests/command_queue/enqueue_svm_mem_copy_tests.cpp @@ -24,6 +24,11 @@ struct EnqueueSvmMemCopyTest : public DeviceFixture, void SetUp() override { DeviceFixture::SetUp(); + + if (!pDevice->isFullRangeSvm()) { + return; + } + CommandQueueFixture::SetUp(pDevice, 0); srcSvmPtr = context->getSVMAllocsManager()->createSVMAlloc(256, {}); ASSERT_NE(nullptr, srcSvmPtr); @@ -40,9 +45,11 @@ struct EnqueueSvmMemCopyTest : public DeviceFixture, } void TearDown() override { - context->getSVMAllocsManager()->freeSVMAlloc(srcSvmPtr); - context->getSVMAllocsManager()->freeSVMAlloc(dstSvmPtr); - CommandQueueFixture::TearDown(); + if (pDevice->isFullRangeSvm()) { + context->getSVMAllocsManager()->freeSVMAlloc(srcSvmPtr); + context->getSVMAllocsManager()->freeSVMAlloc(dstSvmPtr); + CommandQueueFixture::TearDown(); + } DeviceFixture::TearDown(); } @@ -53,6 +60,10 @@ struct EnqueueSvmMemCopyTest : public DeviceFixture, }; HWTEST_F(EnqueueSvmMemCopyTest, givenEnqueueSVMMemcpyWhenUsingCopyBufferToBufferBuilderThenItConfiguredWithBuiltinOpsAndProducesDispatchInfo) { + if (!pDevice->isFullRangeSvm()) { + return; + } + auto &builtIns = *pCmdQ->getDevice().getExecutionEnvironment()->getBuiltIns(); // retrieve original builder @@ -125,6 +136,10 @@ HWTEST_F(EnqueueSvmMemCopyTest, givenEnqueueSVMMemcpyWhenUsingCopyBufferToBuffer } HWTEST_F(EnqueueSvmMemCopyTest, givenEnqueueSVMMemcpyWhenUsingCopyBufferToBufferBuilderAndSrcHostPtrThenItConfiguredWithBuiltinOpsAndProducesDispatchInfo) { + if (!pDevice->isFullRangeSvm()) { + return; + } + auto &builtIns = *pCmdQ->getDevice().getExecutionEnvironment()->getBuiltIns(); void *srcHostPtr = alignedMalloc(256, 64); @@ -199,6 +214,10 @@ HWTEST_F(EnqueueSvmMemCopyTest, givenEnqueueSVMMemcpyWhenUsingCopyBufferToBuffer } HWTEST_F(EnqueueSvmMemCopyTest, givenEnqueueSVMMemcpyWhenUsingCopyBufferToBufferBuilderAndDstHostPtrThenItConfiguredWithBuiltinOpsAndProducesDispatchInfo) { + if (!pDevice->isFullRangeSvm()) { + return; + } + auto &builtIns = *pCmdQ->getDevice().getExecutionEnvironment()->getBuiltIns(); auto dstHostPtr = alignedMalloc(256, 64); @@ -270,4 +289,4 @@ HWTEST_F(EnqueueSvmMemCopyTest, givenEnqueueSVMMemcpyWhenUsingCopyBufferToBuffer auto kernel = mdi->begin()->getKernel(); EXPECT_EQ("CopyBufferToBufferMiddle", kernel->getKernelInfo().name); alignedFree(dstHostPtr); -} \ No newline at end of file +} diff --git a/unit_tests/command_queue/enqueue_svm_tests.cpp b/unit_tests/command_queue/enqueue_svm_tests.cpp index 0f8d4d916e..3553f7c135 100644 --- a/unit_tests/command_queue/enqueue_svm_tests.cpp +++ b/unit_tests/command_queue/enqueue_svm_tests.cpp @@ -732,6 +732,10 @@ TEST_F(EnqueueSvmTest, enqueueSVMMigrateMem_Success) { } TEST(CreateSvmAllocTests, givenVariousSvmAllocationPropertiesWhenAllocatingSvmThenSvmIsCorrectlyAllocated) { + if (!platformDevices[0]->capabilityTable.ftrSvm) { + return; + } + DebugManagerStateRestore dbgRestore; SVMAllocsManager::SvmAllocationProperties svmAllocationProperties; diff --git a/unit_tests/command_queue/gl/enqueue_kernel_gl_tests.cpp b/unit_tests/command_queue/gl/enqueue_kernel_gl_tests.cpp index d3b7076216..d27522657d 100644 --- a/unit_tests/command_queue/gl/enqueue_kernel_gl_tests.cpp +++ b/unit_tests/command_queue/gl/enqueue_kernel_gl_tests.cpp @@ -44,7 +44,10 @@ TEST_F(EnqueueKernelTest, givenKernelWithSharedObjArgsWhenEnqueueIsCalledThenRes (uint32_t *)(pKernel->getCrossThreadData() + kernelInfo.kernelArgInfo[0].kernelArgPatchInfoVector[0].crossthreadOffset); auto address1 = static_cast(*pKernelArg); - EXPECT_EQ(sharedBuffer->getGraphicsAllocation()->getGpuAddress(), address1); + auto sharedBufferGpuAddress = + pKernel->isBuiltIn ? sharedBuffer->getGraphicsAllocation()->getGpuAddress() + : sharedBuffer->getGraphicsAllocation()->getGpuAddressToPatch(); + EXPECT_EQ(sharedBufferGpuAddress, address1); // update address glSharing.uploadDataToBufferInfo(1, 1); @@ -54,7 +57,10 @@ TEST_F(EnqueueKernelTest, givenKernelWithSharedObjArgsWhenEnqueueIsCalledThenRes auto address2 = static_cast(*pKernelArg); EXPECT_NE(address1, address2); - EXPECT_EQ(sharedBuffer->getGraphicsAllocation()->getGpuAddress(), address2); + sharedBufferGpuAddress = + pKernel->isBuiltIn ? sharedBuffer->getGraphicsAllocation()->getGpuAddress() + : sharedBuffer->getGraphicsAllocation()->getGpuAddressToPatch(); + EXPECT_EQ(sharedBufferGpuAddress, address2); delete sharedBuffer; delete nonSharedBuffer; diff --git a/unit_tests/command_stream/command_stream_receiver_flush_task_2_tests.cpp b/unit_tests/command_stream/command_stream_receiver_flush_task_2_tests.cpp index 6adeb720c7..b73cb17d5a 100644 --- a/unit_tests/command_stream/command_stream_receiver_flush_task_2_tests.cpp +++ b/unit_tests/command_stream/command_stream_receiver_flush_task_2_tests.cpp @@ -462,13 +462,14 @@ HWCMDTEST_F(IGFX_GEN8_CORE, CommandStreamReceiverFlushTaskTests, givenTwoConsecu EXPECT_EQ(false, kernel.mockKernel->isBuiltIn); - if (pDevice->getDeviceInfo().force32BitAddressess == true) { + auto deviceInfo = pDevice->getDeviceInfo(); + if (deviceInfo.force32BitAddressess) { EXPECT_FALSE(commandStreamReceiver->getGSBAFor32BitProgrammed()); } commandQueue.enqueueKernel(kernel, 1, nullptr, &GWS, nullptr, 0, nullptr, nullptr); - if (pDevice->getDeviceInfo().force32BitAddressess == true) { + if (deviceInfo.force32BitAddressess) { EXPECT_TRUE(commandStreamReceiver->getGSBAFor32BitProgrammed()); } @@ -490,9 +491,12 @@ HWCMDTEST_F(IGFX_GEN8_CORE, CommandStreamReceiverFlushTaskTests, givenTwoConsecu // Get address ( offset in 32 bit addressing ) of sratch graphicsAddress = (uint64_t)graphicsAllocationScratch->getGpuAddressToPatch(); - if (pDevice->getDeviceInfo().force32BitAddressess == true && is64bit) { + if (deviceInfo.force32BitAddressess && is64bit) { EXPECT_TRUE(graphicsAllocationScratch->is32BitAllocation()); - EXPECT_EQ((uint64_t)graphicsAllocationScratch->getGpuAddress() - GSHaddress, graphicsAddress); + EXPECT_EQ(GmmHelper::decanonize(graphicsAllocationScratch->getGpuAddress()) - GSHaddress, graphicsAddress); + } else if (!deviceInfo.svmCapabilities && is64bit) { + EXPECT_EQ(HwHelperHw::get().getScratchSpaceOffsetFor64bit(), mediaVfeState->getScratchSpaceBasePointer()); + EXPECT_EQ(GSHaddress + HwHelperHw::get().getScratchSpaceOffsetFor64bit(), graphicsAllocationScratch->getGpuAddressToPatch()); } else { EXPECT_EQ((uint64_t)graphicsAllocationScratch->getUnderlyingBuffer(), graphicsAddress); } @@ -503,7 +507,7 @@ HWCMDTEST_F(IGFX_GEN8_CORE, CommandStreamReceiverFlushTaskTests, givenTwoConsecu uint64_t scratchBaseLowPart = (uint64_t)mediaVfeState->getScratchSpaceBasePointer(); uint64_t scratchBaseHighPart = (uint64_t)mediaVfeState->getScratchSpaceBasePointerHigh(); - if (is64bit && !pDevice->getDeviceInfo().force32BitAddressess) { + if (is64bit && !deviceInfo.force32BitAddressess) { uint64_t expectedAddress = HwHelperHw::get().getScratchSpaceOffsetFor64bit(); EXPECT_EQ(expectedAddress, scratchBaseLowPart); EXPECT_EQ(0u, scratchBaseHighPart); @@ -512,7 +516,7 @@ HWCMDTEST_F(IGFX_GEN8_CORE, CommandStreamReceiverFlushTaskTests, givenTwoConsecu EXPECT_EQ(highPartGraphicsAddress, scratchBaseHighPart); } - if (pDevice->getDeviceInfo().force32BitAddressess == true) { + if (deviceInfo.force32BitAddressess) { EXPECT_EQ(pDevice->getMemoryManager()->getExternalHeapBaseAddress(), GSHaddress); } else { if (is64bit) { @@ -572,13 +576,14 @@ HWCMDTEST_F(IGFX_GEN8_CORE, CommandStreamReceiverFlushTaskTests, givenNDRangeKer EXPECT_EQ(false, kernel.mockKernel->isBuiltIn); - if (pDevice->getDeviceInfo().force32BitAddressess == true) { + auto deviceInfo = pDevice->getDeviceInfo(); + if (deviceInfo.force32BitAddressess) { EXPECT_FALSE(commandStreamReceiver->getGSBAFor32BitProgrammed()); } commandQueue.enqueueKernel(kernel, 1, nullptr, &GWS, nullptr, 0, nullptr, nullptr); - if (pDevice->getDeviceInfo().force32BitAddressess == true) { + if (deviceInfo.force32BitAddressess) { EXPECT_TRUE(commandStreamReceiver->getGSBAFor32BitProgrammed()); } @@ -600,9 +605,12 @@ HWCMDTEST_F(IGFX_GEN8_CORE, CommandStreamReceiverFlushTaskTests, givenNDRangeKer // Get address ( offset in 32 bit addressing ) of sratch graphicsAddress = (uint64_t)graphicsAllocationScratch->getGpuAddressToPatch(); - if (pDevice->getDeviceInfo().force32BitAddressess == true && is64bit) { + if (deviceInfo.force32BitAddressess && is64bit) { EXPECT_TRUE(graphicsAllocationScratch->is32BitAllocation()); - EXPECT_EQ((uint64_t)graphicsAllocationScratch->getGpuAddress() - GSHaddress, graphicsAddress); + EXPECT_EQ(GmmHelper::decanonize(graphicsAllocationScratch->getGpuAddress()) - GSHaddress, graphicsAddress); + } else if (!deviceInfo.svmCapabilities && is64bit) { + EXPECT_EQ(HwHelperHw::get().getScratchSpaceOffsetFor64bit(), mediaVfeState->getScratchSpaceBasePointer()); + EXPECT_EQ(GSHaddress + HwHelperHw::get().getScratchSpaceOffsetFor64bit(), graphicsAllocationScratch->getGpuAddressToPatch()); } else { EXPECT_EQ((uint64_t)graphicsAllocationScratch->getUnderlyingBuffer(), graphicsAddress); } @@ -613,7 +621,7 @@ HWCMDTEST_F(IGFX_GEN8_CORE, CommandStreamReceiverFlushTaskTests, givenNDRangeKer uint64_t scratchBaseLowPart = (uint64_t)mediaVfeState->getScratchSpaceBasePointer(); uint64_t scratchBaseHighPart = (uint64_t)mediaVfeState->getScratchSpaceBasePointerHigh(); - if (is64bit && !pDevice->getDeviceInfo().force32BitAddressess) { + if (is64bit && !deviceInfo.force32BitAddressess) { lowPartGraphicsAddress = HwHelperHw::get().getScratchSpaceOffsetFor64bit(); highPartGraphicsAddress = 0u; } @@ -621,7 +629,7 @@ HWCMDTEST_F(IGFX_GEN8_CORE, CommandStreamReceiverFlushTaskTests, givenNDRangeKer EXPECT_EQ(lowPartGraphicsAddress, scratchBaseLowPart); EXPECT_EQ(highPartGraphicsAddress, scratchBaseHighPart); - if (pDevice->getDeviceInfo().force32BitAddressess == true) { + if (deviceInfo.force32BitAddressess) { EXPECT_EQ(pDevice->getMemoryManager()->getExternalHeapBaseAddress(), GSHaddress); } else { if (is64bit) { @@ -644,7 +652,7 @@ HWCMDTEST_F(IGFX_GEN8_CORE, CommandStreamReceiverFlushTaskTests, givenNDRangeKer itorCmdForStateBase = find(itorWalker, cmdList.end()); - if (pDevice->getDeviceInfo().force32BitAddressess == true) { + if (deviceInfo.force32BitAddressess) { EXPECT_NE(itorWalker, itorCmdForStateBase); if (itorCmdForStateBase != cmdList.end()) { @@ -655,14 +663,14 @@ HWCMDTEST_F(IGFX_GEN8_CORE, CommandStreamReceiverFlushTaskTests, givenNDRangeKer EXPECT_NE(sba, sba2); EXPECT_EQ(0u, GSHaddress2); - if (pDevice->getDeviceInfo().force32BitAddressess == true) { + if (deviceInfo.force32BitAddressess) { EXPECT_FALSE(commandStreamReceiver->getGSBAFor32BitProgrammed()); } } } delete buffer; - if (pDevice->getDeviceInfo().force32BitAddressess == true) { + if (deviceInfo.force32BitAddressess) { // Asserts placed after restoring old CSR to avoid heap corruption ASSERT_NE(itorCmdForStateBase, cmdList.end()); } diff --git a/unit_tests/command_stream/command_stream_receiver_hw_tests.cpp b/unit_tests/command_stream/command_stream_receiver_hw_tests.cpp index c3a98dfba6..d0e5323d90 100644 --- a/unit_tests/command_stream/command_stream_receiver_hw_tests.cpp +++ b/unit_tests/command_stream/command_stream_receiver_hw_tests.cpp @@ -252,8 +252,9 @@ HWTEST_F(CommandStreamReceiverHwTest, WhenScratchSpaceIsRequiredThenCorrectAddre scratchController->setRequiredScratchSpace(surfaceHeap.get(), 0x1000u, 0u, 0u, stateBaseAddressDirty, cfeStateDirty); uint64_t expectedScratchAddress = 0xAAABBBCCCDDD000ull; - scratchController->getScratchSpaceAllocation()->setCpuPtrAndGpuAddress(scratchController->getScratchSpaceAllocation()->getUnderlyingBuffer(), expectedScratchAddress); - EXPECT_TRUE(UnitTestHelper::evaluateGshAddressForScratchSpace((expectedScratchAddress - MemoryConstants::pageSize), scratchController->calculateNewGSH())); + auto scratchAllocation = scratchController->getScratchSpaceAllocation(); + scratchAllocation->setCpuPtrAndGpuAddress(scratchAllocation->getUnderlyingBuffer(), expectedScratchAddress); + EXPECT_TRUE(UnitTestHelper::evaluateGshAddressForScratchSpace((scratchAllocation->getGpuAddress() - MemoryConstants::pageSize), scratchController->calculateNewGSH())); } HWTEST_F(CommandStreamReceiverHwTest, WhenScratchSpaceIsNotRequiredThenGshAddressZeroIsReturned) { @@ -591,7 +592,9 @@ HWTEST_F(BcsTests, givenBufferWhenBlitOperationCalledThenProgramCorrectGpuAddres auto bltCmd = genCmdCast(*hwParser.cmdList.begin()); EXPECT_NE(nullptr, bltCmd); - EXPECT_EQ(reinterpret_cast(hostPtr), bltCmd->getSourceBaseAddress()); + if (pDevice->isFullRangeSvm()) { + EXPECT_EQ(reinterpret_cast(hostPtr), bltCmd->getSourceBaseAddress()); + } EXPECT_EQ(buffer1->getGraphicsAllocation()->getGpuAddress(), bltCmd->getDestinationBaseAddress()); } { @@ -605,7 +608,9 @@ HWTEST_F(BcsTests, givenBufferWhenBlitOperationCalledThenProgramCorrectGpuAddres auto bltCmd = genCmdCast(*hwParser.cmdList.begin()); EXPECT_NE(nullptr, bltCmd); - EXPECT_EQ(reinterpret_cast(hostPtr), bltCmd->getDestinationBaseAddress()); + if (pDevice->isFullRangeSvm()) { + EXPECT_EQ(reinterpret_cast(hostPtr), bltCmd->getDestinationBaseAddress()); + } EXPECT_EQ(buffer1->getGraphicsAllocation()->getGpuAddress(), bltCmd->getSourceBaseAddress()); } { @@ -645,7 +650,9 @@ HWTEST_F(BcsTests, givenBufferWithOffsetWhenBlitOperationCalledThenProgramCorrec auto bltCmd = genCmdCast(*hwParser.cmdList.begin()); EXPECT_NE(nullptr, bltCmd); - EXPECT_EQ(reinterpret_cast(hostPtr), bltCmd->getSourceBaseAddress()); + if (pDevice->isFullRangeSvm()) { + EXPECT_EQ(reinterpret_cast(hostPtr), bltCmd->getSourceBaseAddress()); + } EXPECT_EQ(ptrOffset(buffer1->getGraphicsAllocation()->getGpuAddress(), buffer1Offset), bltCmd->getDestinationBaseAddress()); } { @@ -659,7 +666,9 @@ HWTEST_F(BcsTests, givenBufferWithOffsetWhenBlitOperationCalledThenProgramCorrec auto bltCmd = genCmdCast(*hwParser.cmdList.begin()); EXPECT_NE(nullptr, bltCmd); - EXPECT_EQ(reinterpret_cast(hostPtr), bltCmd->getDestinationBaseAddress()); + if (pDevice->isFullRangeSvm()) { + EXPECT_EQ(reinterpret_cast(hostPtr), bltCmd->getDestinationBaseAddress()); + } EXPECT_EQ(ptrOffset(buffer1->getGraphicsAllocation()->getGpuAddress(), buffer1Offset), bltCmd->getSourceBaseAddress()); } diff --git a/unit_tests/command_stream/command_stream_receiver_tests.cpp b/unit_tests/command_stream/command_stream_receiver_tests.cpp index a809d6307b..d29d62a580 100644 --- a/unit_tests/command_stream/command_stream_receiver_tests.cpp +++ b/unit_tests/command_stream/command_stream_receiver_tests.cpp @@ -340,8 +340,8 @@ TEST(CommandStreamReceiverSimpleTest, givenCSRWithTagAllocationSetWhenGetTagAllo } TEST(CommandStreamReceiverSimpleTest, givenCommandStreamReceiverWhenItIsDestroyedThenItDestroysTagAllocation) { - struct MockGraphicsAllocationWithDestructorTracing : public GraphicsAllocation { - using GraphicsAllocation::GraphicsAllocation; + struct MockGraphicsAllocationWithDestructorTracing : public MockGraphicsAllocation { + using MockGraphicsAllocation::MockGraphicsAllocation; ~MockGraphicsAllocationWithDestructorTracing() override { *destructorCalled = true; } bool *destructorCalled = nullptr; }; diff --git a/unit_tests/device_queue/device_queue_hw_tests.cpp b/unit_tests/device_queue/device_queue_hw_tests.cpp index a66a145659..60a0f0a5c9 100644 --- a/unit_tests/device_queue/device_queue_hw_tests.cpp +++ b/unit_tests/device_queue/device_queue_hw_tests.cpp @@ -322,7 +322,7 @@ HWCMDTEST_F(IGFX_GEN8_CORE, DeviceQueueSlb, cleanupSection) { hwParser.parseCommands(*slbCS, cleanupSectionOffsetToParse); hwParser.findHardwareCommands(); - uint64_t cleanUpSectionAddress = (uint64_t)slbCS->getCpuBase() + cleanupSectionOffset; + uint64_t cleanUpSectionAddress = mockDeviceQueueHw->getSlbBuffer()->getGpuAddress() + cleanupSectionOffset; EXPECT_EQ(cleanUpSectionAddress, igilCmdQueue->m_controls.m_CleanupSectionAddress); EXPECT_EQ(slbCS->getUsed() - cleanupSectionOffset, igilCmdQueue->m_controls.m_CleanupSectionSize); @@ -334,7 +334,7 @@ HWCMDTEST_F(IGFX_GEN8_CORE, DeviceQueueSlb, cleanupSection) { MI_BATCH_BUFFER_END *bbEnd = (MI_BATCH_BUFFER_END *)*bbEndItor; uint64_t bbEndAddres = (uint64_t)bbEnd; - EXPECT_LE(mockDeviceQueueHw->getSlbBuffer()->getGpuAddress() + cleanupSectionOffset, bbEndAddres); + EXPECT_LE((uint64_t)mockDeviceQueueHw->getSlbBuffer()->getUnderlyingBuffer() + cleanupSectionOffset, bbEndAddres); delete mockParentKernel; delete mockDeviceQueueHw; @@ -369,7 +369,7 @@ HWCMDTEST_F(IGFX_GEN8_CORE, DeviceQueueSlb, AddEMCleanupSectionWithProfiling) { hwParser.parseCommands(*slbCS, cleanupSectionOffsetToParse); hwParser.findHardwareCommands(); - uint64_t cleanUpSectionAddress = (uint64_t)slbCS->getCpuBase() + cleanupSectionOffset; + uint64_t cleanUpSectionAddress = mockDeviceQueueHw->getSlbBuffer()->getGpuAddress() + cleanupSectionOffset; EXPECT_EQ(cleanUpSectionAddress, igilCmdQueue->m_controls.m_CleanupSectionAddress); EXPECT_EQ(slbCS->getUsed() - cleanupSectionOffset, igilCmdQueue->m_controls.m_CleanupSectionSize); @@ -405,7 +405,7 @@ HWCMDTEST_F(IGFX_GEN8_CORE, DeviceQueueSlb, AddEMCleanupSectionWithProfiling) { MI_BATCH_BUFFER_END *bbEnd = (MI_BATCH_BUFFER_END *)*bbEndItor; uint64_t bbEndAddres = (uint64_t)bbEnd; - EXPECT_LE(mockDeviceQueueHw->getSlbBuffer()->getGpuAddress() + cleanupSectionOffset, bbEndAddres); + EXPECT_LE((uint64_t)mockDeviceQueueHw->getSlbBuffer()->getUnderlyingBuffer() + cleanupSectionOffset, bbEndAddres); delete mockParentKernel; delete mockDeviceQueueHw; diff --git a/unit_tests/execution_model/enqueue_execution_model_kernel_tests.cpp b/unit_tests/execution_model/enqueue_execution_model_kernel_tests.cpp index abc7d4b67a..0631246b3c 100644 --- a/unit_tests/execution_model/enqueue_execution_model_kernel_tests.cpp +++ b/unit_tests/execution_model/enqueue_execution_model_kernel_tests.cpp @@ -425,14 +425,14 @@ TEST_F(ParentKernelEnqueueFixture, GivenParentKernelWhenEnqueuedTheDefaultDevice auto patchLocation = ptrOffset(reinterpret_cast(parentKernel->getCrossThreadData()), patchInfo.pAllocateStatelessDefaultDeviceQueueSurface->DataParamOffset); - EXPECT_EQ(pDevQueue->getQueueBuffer()->getGpuAddress(), *patchLocation); + EXPECT_EQ(pDevQueue->getQueueBuffer()->getGpuAddressToPatch(), *patchLocation); } if (patchInfo.pAllocateStatelessEventPoolSurface) { auto patchLocation = ptrOffset(reinterpret_cast(parentKernel->getCrossThreadData()), patchInfo.pAllocateStatelessEventPoolSurface->DataParamOffset); - EXPECT_EQ(pDevQueue->getEventPoolBuffer()->getGpuAddress(), *patchLocation); + EXPECT_EQ(pDevQueue->getEventPoolBuffer()->getGpuAddressToPatch(), *patchLocation); } } } @@ -463,15 +463,15 @@ HWTEST_F(ParentKernelEnqueueFixture, GivenParentKernelWhenEnqueuedThenBlocksDSHO uint32_t offset = MockKernel::ReflectionSurfaceHelperPublic::getConstantBufferOffset(reflectionSurface, i); if (defaultQueueSize == sizeof(uint64_t)) { - EXPECT_EQ_VAL(pDevQueueHw->getQueueBuffer()->getGpuAddressToPatch(), *(uint64_t *)ptrOffset(reflectionSurface, offset + defaultQueueOffset)); + EXPECT_EQ_VAL(pDevQueueHw->getQueueBuffer()->getGpuAddress(), *(uint64_t *)ptrOffset(reflectionSurface, offset + defaultQueueOffset)); } else { - EXPECT_EQ((uint32_t)pDevQueueHw->getQueueBuffer()->getGpuAddressToPatch(), *(uint32_t *)ptrOffset(reflectionSurface, offset + defaultQueueOffset)); + EXPECT_EQ((uint32_t)pDevQueueHw->getQueueBuffer()->getGpuAddress(), *(uint32_t *)ptrOffset(reflectionSurface, offset + defaultQueueOffset)); } if (eventPoolSize == sizeof(uint64_t)) { - EXPECT_EQ_VAL(pDevQueueHw->getEventPoolBuffer()->getGpuAddressToPatch(), *(uint64_t *)ptrOffset(reflectionSurface, offset + eventPoolOffset)); + EXPECT_EQ_VAL(pDevQueueHw->getEventPoolBuffer()->getGpuAddress(), *(uint64_t *)ptrOffset(reflectionSurface, offset + eventPoolOffset)); } else { - EXPECT_EQ((uint32_t)pDevQueueHw->getEventPoolBuffer()->getGpuAddressToPatch(), *(uint32_t *)ptrOffset(reflectionSurface, offset + eventPoolOffset)); + EXPECT_EQ((uint32_t)pDevQueueHw->getEventPoolBuffer()->getGpuAddress(), *(uint32_t *)ptrOffset(reflectionSurface, offset + eventPoolOffset)); } } } diff --git a/unit_tests/gen_common/gen_commands_common_validation.h b/unit_tests/gen_common/gen_commands_common_validation.h index 3211c212fe..49f3ad0302 100644 --- a/unit_tests/gen_common/gen_commands_common_validation.h +++ b/unit_tests/gen_common/gen_commands_common_validation.h @@ -39,10 +39,10 @@ void validateStateBaseAddress(uint64_t internalHeapBase, IndirectHeap *pDSH, EXPECT_TRUE(cmd->getIndirectObjectBaseAddressModifyEnable()); EXPECT_TRUE(cmd->getInstructionBaseAddressModifyEnable()); - EXPECT_EQ(static_cast(reinterpret_cast(pDSH->getCpuBase())), cmd->getDynamicStateBaseAddress()); + EXPECT_EQ(pDSH->getGraphicsAllocation()->getGpuAddress(), cmd->getDynamicStateBaseAddress()); // Stateless accesses require GSH.base to be 0. EXPECT_EQ(expectedGeneralStateHeapBaseAddress, cmd->getGeneralStateBaseAddress()); - EXPECT_EQ(static_cast(reinterpret_cast(pSSH->getCpuBase())), cmd->getSurfaceStateBaseAddress()); + EXPECT_EQ(pSSH->getGraphicsAllocation()->getGpuAddress(), cmd->getSurfaceStateBaseAddress()); EXPECT_EQ(pIOH->getGraphicsAllocation()->getGpuBaseAddress(), cmd->getIndirectObjectBaseAddress()); EXPECT_EQ(internalHeapBase, cmd->getInstructionBaseAddress()); diff --git a/unit_tests/kernel/kernel_tests.cpp b/unit_tests/kernel/kernel_tests.cpp index 91d9a87730..27c02ce350 100644 --- a/unit_tests/kernel/kernel_tests.cpp +++ b/unit_tests/kernel/kernel_tests.cpp @@ -1362,7 +1362,7 @@ TEST_F(KernelEventPoolSurfaceTest, givenStatelessKernelWhenEventPoolIsPatchedThe pKernel->patchEventPool(pDevQueue); - EXPECT_EQ(pDevQueue->getEventPoolBuffer()->getGpuAddress(), *(uint64_t *)pKernel->getCrossThreadData()); + EXPECT_EQ(pDevQueue->getEventPoolBuffer()->getGpuAddressToPatch(), *(uint64_t *)pKernel->getCrossThreadData()); delete pKernel; } @@ -1572,7 +1572,7 @@ TEST_F(KernelDefaultDeviceQueueSurfaceTest, givenStatelessKernelWhenDefaultDevic pKernel->patchDefaultDeviceQueue(pDevQueue); - EXPECT_EQ(pDevQueue->getQueueBuffer()->getGpuAddress(), *(uint64_t *)pKernel->getCrossThreadData()); + EXPECT_EQ(pDevQueue->getQueueBuffer()->getGpuAddressToPatch(), *(uint64_t *)pKernel->getCrossThreadData()); delete pKernel; } diff --git a/unit_tests/linux/main_linux_dll.cpp b/unit_tests/linux/main_linux_dll.cpp index c90816e8a1..51dff5b209 100644 --- a/unit_tests/linux/main_linux_dll.cpp +++ b/unit_tests/linux/main_linux_dll.cpp @@ -361,6 +361,10 @@ TEST(AllocatorHelper, givenExpectedSizeToMapWhenGetSizetoMapCalledThenExpectedVa EXPECT_EQ((alignUp(4 * GB - 8096, 4096)), NEO::getSizeToMap()); } +TEST(AllocatorHelper, givenExpectedSizeToReserveWhenGetSizeToReserveCalledThenExpectedValueReturned) { + EXPECT_EQ(maxNBitValue<47> / 4, NEO::getSizeToReserve()); +} + TEST(DrmMemoryManagerCreate, whenCallCreateMemoryManagerThenDrmMemoryManagerIsCreated) { DrmMockSuccess mock; MockExecutionEnvironment executionEnvironment(*platformDevices); diff --git a/unit_tests/mem_obj/image_set_arg_tests.cpp b/unit_tests/mem_obj/image_set_arg_tests.cpp index ace7de0163..e92884b8c4 100644 --- a/unit_tests/mem_obj/image_set_arg_tests.cpp +++ b/unit_tests/mem_obj/image_set_arg_tests.cpp @@ -1101,7 +1101,7 @@ HWTEST_F(ImageSetArgTest, givenImageWithOffsetGreaterThan4GBWhenSurfaceStateIsPr srcImage->setSurfaceOffsets(surfaceOffset, 0, 0, 0); srcImage->setImageArg(&surfaceState, false, 0); - auto expectedAddress = srcImage->getGraphicsAllocation()->getGpuAddressToPatch() + surfaceOffset; + auto expectedAddress = srcImage->getGraphicsAllocation()->getGpuAddress() + surfaceOffset; auto surfaceAddress = surfaceState.getSurfaceBaseAddress(); EXPECT_EQ(expectedAddress, surfaceAddress); diff --git a/unit_tests/memory_manager/gfx_partition_tests.cpp b/unit_tests/memory_manager/gfx_partition_tests.cpp index 313e35756b..1af24073aa 100644 --- a/unit_tests/memory_manager/gfx_partition_tests.cpp +++ b/unit_tests/memory_manager/gfx_partition_tests.cpp @@ -5,8 +5,10 @@ * */ +#include "core/helpers/basic_math.h" #include "core/helpers/ptr_math.h" #include "runtime/helpers/aligned_memory.h" +#include "runtime/os_interface/os_memory.h" #include "unit_tests/mocks/mock_gfx_partition.h" #include "gtest/gtest.h" @@ -15,18 +17,27 @@ using namespace NEO; void testGfxPartition(uint64_t gpuAddressSpace) { MockGfxPartition gfxPartition; - gfxPartition.init(gpuAddressSpace); + size_t reservedCpuAddressRangeSize = is64bit ? (6 * 4 * GB) : 0; + gfxPartition.init(gpuAddressSpace, reservedCpuAddressRangeSize); uint64_t gfxTop = gpuAddressSpace + 1; uint64_t gfxBase = MemoryConstants::maxSvmAddress + 1; const uint64_t sizeHeap32 = 4 * MemoryConstants::gigaByte; - if (MemoryConstants::max48BitAddress == gpuAddressSpace) { - // Full range SVM + if (is32bit || maxNBitValue<48> == gpuAddressSpace) { + // Full range SVM 48/32-bit EXPECT_TRUE(gfxPartition.heapInitialized(HeapIndex::HEAP_SVM)); EXPECT_EQ(gfxPartition.getHeapBase(HeapIndex::HEAP_SVM), 0ull); EXPECT_EQ(gfxPartition.getHeapSize(HeapIndex::HEAP_SVM), gfxBase); EXPECT_EQ(gfxPartition.getHeapLimit(HeapIndex::HEAP_SVM), MemoryConstants::maxSvmAddress); + } else if (maxNBitValue<47> == gpuAddressSpace) { + // Full range SVM 47-bit + gfxBase = (uint64_t)gfxPartition.getReservedCpuAddressRange(); + gfxTop = gfxBase + gfxPartition.getReservedCpuAddressRangeSize(); + EXPECT_TRUE(gfxPartition.heapInitialized(HeapIndex::HEAP_SVM)); + EXPECT_EQ(gfxPartition.getHeapBase(HeapIndex::HEAP_SVM), 0ull); + EXPECT_EQ(gfxPartition.getHeapSize(HeapIndex::HEAP_SVM), is64bit ? gpuAddressSpace + 1 : gfxBase); + EXPECT_EQ(gfxPartition.getHeapLimit(HeapIndex::HEAP_SVM), MemoryConstants::maxSvmAddress); } else { // Limited range EXPECT_FALSE(gfxPartition.heapInitialized(HeapIndex::HEAP_SVM)); @@ -81,15 +92,20 @@ void testGfxPartition(uint64_t gpuAddressSpace) { auto ptrSmall = gfxPartition.heapAllocate(heap, sizeSmall); EXPECT_NE(ptrSmall, 0ull); EXPECT_LT(gfxPartition.getHeapBase(heap), ptrSmall); - EXPECT_EQ(ptrSmall, gfxPartition.getHeapBase(heap) + gfxPartition.getHeapSize(heap) - sizeSmall); + EXPECT_GT(gfxPartition.getHeapLimit(heap), ptrSmall); + EXPECT_EQ(ptrSmall, gfxPartition.getHeapBase(heap) + gfxPartition.getHeapSize(heap) - GfxPartition::heapGranularity - sizeSmall); gfxPartition.heapFree(heap, ptrSmall, sizeSmall); } } -TEST(GfxPartitionTest, testGfxPartitionFullRangeSVM) { - testGfxPartition(MemoryConstants::max48BitAddress); +TEST(GfxPartitionTest, testGfxPartitionFullRange48BitSVM) { + testGfxPartition(maxNBitValue<48>); +} + +TEST(GfxPartitionTest, testGfxPartitionFullRange47BitSVM) { + testGfxPartition(maxNBitValue<47>); } TEST(GfxPartitionTest, testGfxPartitionLimitedRange) { - testGfxPartition(maxNBitValue<48 - 1>); + testGfxPartition(maxNBitValue<47 - 1>); } diff --git a/unit_tests/memory_manager/memory_manager_allocate_in_device_pool_tests.cpp b/unit_tests/memory_manager/memory_manager_allocate_in_device_pool_tests.cpp index b8aae9492b..50a1f0d663 100644 --- a/unit_tests/memory_manager/memory_manager_allocate_in_device_pool_tests.cpp +++ b/unit_tests/memory_manager/memory_manager_allocate_in_device_pool_tests.cpp @@ -63,6 +63,10 @@ TEST(MemoryManagerTest, givenSvmGpuAllocationTypeWhenAllocationSystemMemoryFails } TEST(MemoryManagerTest, givenSvmGpuAllocationTypeWhenAllocationSucceedThenReturnGpuAddressAsHostPtr) { + if (platformDevices[0]->capabilityTable.gpuAddressSpace != maxNBitValue<48> && platformDevices[0]->capabilityTable.gpuAddressSpace != maxNBitValue<47>) { + return; + } + MockExecutionEnvironment executionEnvironment(*platformDevices); MockMemoryManager memoryManager(false, false, executionEnvironment); @@ -79,4 +83,4 @@ TEST(MemoryManagerTest, givenSvmGpuAllocationTypeWhenAllocationSucceedThenReturn EXPECT_NE(reinterpret_cast(allocation->getUnderlyingBuffer()), allocation->getGpuAddress()); memoryManager.freeGraphicsMemory(allocation); -} \ No newline at end of file +} diff --git a/unit_tests/memory_manager/memory_manager_tests.cpp b/unit_tests/memory_manager/memory_manager_tests.cpp index 7707af054d..5aaebae881 100644 --- a/unit_tests/memory_manager/memory_manager_tests.cpp +++ b/unit_tests/memory_manager/memory_manager_tests.cpp @@ -199,7 +199,9 @@ TEST_F(MemoryAllocatorTest, allocateGraphics) { EXPECT_EQ(Sharing::nonSharedResource, allocation->peekSharedHandle()); // Gpu address equal to cpu address - EXPECT_EQ(reinterpret_cast(allocation->getUnderlyingBuffer()), allocation->getGpuAddress()); + if (platformDevices[0]->capabilityTable.gpuAddressSpace == MemoryConstants::max48BitAddress) { + EXPECT_EQ(reinterpret_cast(allocation->getUnderlyingBuffer()), allocation->getGpuAddress()); + } memoryManager->freeGraphicsMemory(allocation); } @@ -374,21 +376,6 @@ TEST_F(MemoryAllocatorTest, GivenPointerAndSizeWhenAskedToCreateGrahicsAllocatio EXPECT_NE(&allocation->fragmentsStorage, &handleStorage); } -TEST_F(MemoryAllocatorTest, givenMemoryManagerWhensetForce32BitAllocationsIsCalledWithTrueMultipleTimesThenAllocatorIsReused) { - memoryManager->setForce32BitAllocations(true); - EXPECT_NE(nullptr, memoryManager->allocator32Bit.get()); - auto currentAllocator = memoryManager->allocator32Bit.get(); - memoryManager->setForce32BitAllocations(true); - EXPECT_EQ(memoryManager->allocator32Bit.get(), currentAllocator); -} - -TEST_F(MemoryAllocatorTest, givenMemoryManagerWhensetForce32BitAllocationsIsCalledWithFalseThenAllocatorIsNotDeleted) { - memoryManager->setForce32BitAllocations(true); - EXPECT_NE(nullptr, memoryManager->allocator32Bit.get()); - memoryManager->setForce32BitAllocations(false); - EXPECT_NE(nullptr, memoryManager->allocator32Bit.get()); -} - TEST_F(MemoryAllocatorTest, givenMemoryManagerWhenAskedFor32bitAllocationThen32bitGraphicsAllocationIsReturned) { size_t size = 10; auto allocation = memoryManager->allocate32BitGraphicsMemory(size, nullptr, GraphicsAllocation::AllocationType::BUFFER); @@ -834,6 +821,23 @@ TEST(OsAgnosticMemoryManager, givenDefaultMemoryManagerWhenCreateGraphicsAllocat memoryManager.freeGraphicsMemory(sharedAllocation); } +TEST(OsAgnosticMemoryManager, givenDefaultMemoryManagerWhenCreateGraphicsAllocationFromSharedObjectIsCalledWithSpecificBitnessThen32BitGraphicsAllocationIsReturned) { + MockExecutionEnvironment executionEnvironment(*platformDevices); + MemoryManagerCreate memoryManager(false, false, executionEnvironment); + osHandle handle = 1; + auto size = 4096u; + AllocationProperties properties(false, size, GraphicsAllocation::AllocationType::SHARED_BUFFER, false); + auto sharedAllocation = memoryManager.createGraphicsAllocationFromSharedHandle(handle, properties, true); + EXPECT_NE(nullptr, sharedAllocation); + EXPECT_TRUE(sharedAllocation->is32BitAllocation()); + EXPECT_FALSE(sharedAllocation->isCoherent()); + EXPECT_NE(nullptr, sharedAllocation->getUnderlyingBuffer()); + EXPECT_EQ(size, sharedAllocation->getUnderlyingBufferSize()); + EXPECT_EQ(MemoryPool::SystemCpuInaccessible, sharedAllocation->getMemoryPool()); + + memoryManager.freeGraphicsMemory(sharedAllocation); +} + TEST(OsAgnosticMemoryManager, givenMemoryManagerWhenCreateAllocationFromNtHandleIsCalledThenReturnNullptr) { MockExecutionEnvironment executionEnvironment(*platformDevices); OsAgnosticMemoryManager memoryManager(executionEnvironment); @@ -1069,12 +1073,7 @@ TEST(OsAgnosticMemoryManager, givenPointerAndSizeWhenCreateInternalAllocationIsC EXPECT_EQ(allocationSize, graphicsAllocation->getUnderlyingBufferSize()); memoryManager.freeGraphicsMemory(graphicsAllocation); } -TEST(OsAgnosticMemoryManager, givenDefaultOsAgnosticMemoryManagerWhenItIsQueriedForInternalHeapBaseThen32BitAllocatorBaseIsReturned) { - MockExecutionEnvironment executionEnvironment(*platformDevices); - OsAgnosticMemoryManager memoryManager(executionEnvironment); - auto heapBase = memoryManager.getExternalHeapBaseAddress(); - EXPECT_EQ(heapBase, memoryManager.getInternalHeapBaseAddress()); -} + TEST(OsAgnosticMemoryManager, givenOsAgnosticMemoryManagerWhenAllocateGraphicsMemoryForNonSvmHostPtrIsCalledThenAllocationIsCreated) { MockExecutionEnvironment executionEnvironment(*platformDevices); MockMemoryManager memoryManager(executionEnvironment); @@ -1156,54 +1155,6 @@ INSTANTIATE_TEST_CASE_P(OsAgnosticMemoryManagerWithParams, OsAgnosticMemoryManagerWithParams, ::testing::Values(false, true)); -TEST(OsAgnosticMemoryManager, givenLocalMemoryNotSupportedWhenMemoryManagerIsCreatedThenAllocator32BitHasCorrectBaseAddress) { - MockExecutionEnvironment executionEnvironment(*platformDevices); - MockMemoryManager memoryManager(false, false, false, executionEnvironment); - uint64_t heap32Base = 0x80000000000ul; - - if (is32bit) { - heap32Base = 0; - } - EXPECT_EQ(heap32Base, memoryManager.getExternalHeapBaseAddress()); -} - -TEST(OsAgnosticMemoryManager, givenLocalMemorySupportedAndNotAubUsageWhenMemoryManagerIsCreatedThenAllocator32BitHasCorrectBaseAddress) { - MockExecutionEnvironment executionEnvironment(*platformDevices); - MockMemoryManager memoryManager(false, true, false, executionEnvironment); - memoryManager.allocator32Bit.reset(memoryManager.create32BitAllocator(false)); - uint64_t heap32Base = 0x80000000000ul; - - if (is32bit) { - heap32Base = 0; - } - EXPECT_EQ(heap32Base, memoryManager.getExternalHeapBaseAddress()); -} - -TEST(OsAgnosticMemoryManager, givenLocalMemoryNotSupportedAndAubUsageWhenMemoryManagerIsCreatedThenAllocator32BitHasCorrectBaseAddress) { - MockExecutionEnvironment executionEnvironment(*platformDevices); - MockMemoryManager memoryManager(false, false, true, executionEnvironment); - uint64_t heap32Base = 0x80000000000ul; - - if (is32bit) { - heap32Base = 0; - } - EXPECT_EQ(heap32Base, memoryManager.getExternalHeapBaseAddress()); -} - -TEST(OsAgnosticMemoryManager, givenLocalMemorySupportedAndAubUsageWhenMemoryManagerIsCreatedThenAllocator32BitHasCorrectBaseAddress) { - MockExecutionEnvironment executionEnvironment(*platformDevices); - MockMemoryManager memoryManager(false, true, true, executionEnvironment); - memoryManager.allocator32Bit.reset(memoryManager.create32BitAllocator(true)); - uint64_t heap32Base = 0x80000000000ul; - - if (is32bit) { - heap32Base = 0; - } else { - heap32Base = 0x40000000000ul; - } - EXPECT_EQ(heap32Base, memoryManager.getExternalHeapBaseAddress()); -} - TEST(OsAgnosticMemoryManager, givenOsAgnosticMemoryManagerWhenGraphicsAllocationIsDestroyedThenFreeMemoryOnAubManagerShouldBeCalled) { MockExecutionEnvironment executionEnvironment; OsAgnosticMemoryManager memoryManager(executionEnvironment); diff --git a/unit_tests/mocks/mock_gfx_partition.h b/unit_tests/mocks/mock_gfx_partition.h index e62f0bd15d..82459c78ab 100644 --- a/unit_tests/mocks/mock_gfx_partition.h +++ b/unit_tests/mocks/mock_gfx_partition.h @@ -19,5 +19,13 @@ class MockGfxPartition : public GfxPartition { return getHeapSize(heapIndex) > 0; } + void *getReservedCpuAddressRange() { + return reservedCpuAddressRange; + } + + size_t getReservedCpuAddressRangeSize() { + return reservedCpuAddressRangeSize; + } + static std::array(HeapIndex::TOTAL_HEAPS)> allHeapNames; }; diff --git a/unit_tests/mocks/mock_graphics_allocation.h b/unit_tests/mocks/mock_graphics_allocation.h index 6b2bf81858..2ee322f918 100644 --- a/unit_tests/mocks/mock_graphics_allocation.h +++ b/unit_tests/mocks/mock_graphics_allocation.h @@ -7,26 +7,27 @@ #pragma once #include "runtime/memory_manager/graphics_allocation.h" +#include "runtime/memory_manager/os_agnostic_memory_manager.h" namespace NEO { -class MockGraphicsAllocation : public GraphicsAllocation { +class MockGraphicsAllocation : public MemoryAllocation { public: - using GraphicsAllocation::GraphicsAllocation; - using GraphicsAllocation::objectNotResident; - using GraphicsAllocation::objectNotUsed; - using GraphicsAllocation::usageInfos; + using MemoryAllocation::MemoryAllocation; + using MemoryAllocation::objectNotResident; + using MemoryAllocation::objectNotUsed; + using MemoryAllocation::usageInfos; MockGraphicsAllocation() : MockGraphicsAllocation(true) {} MockGraphicsAllocation(bool multiOsContextCapable) - : GraphicsAllocation(AllocationType::UNKNOWN, nullptr, 0u, 0, MemoryPool::MemoryNull, multiOsContextCapable) {} + : MemoryAllocation(AllocationType::UNKNOWN, nullptr, 0u, 0, MemoryPool::MemoryNull, multiOsContextCapable) {} MockGraphicsAllocation(void *buffer, size_t sizeIn) - : GraphicsAllocation(AllocationType::UNKNOWN, buffer, castToUint64(buffer), 0llu, sizeIn, MemoryPool::MemoryNull, false) {} + : MemoryAllocation(AllocationType::UNKNOWN, buffer, castToUint64(buffer), 0llu, sizeIn, MemoryPool::MemoryNull, false) {} MockGraphicsAllocation(void *buffer, uint64_t gpuAddr, size_t sizeIn) - : GraphicsAllocation(AllocationType::UNKNOWN, buffer, gpuAddr, 0llu, sizeIn, MemoryPool::MemoryNull, false) {} + : MemoryAllocation(AllocationType::UNKNOWN, buffer, gpuAddr, 0llu, sizeIn, MemoryPool::MemoryNull, false) {} void resetInspectionIds() { for (auto &usageInfo : usageInfos) { diff --git a/unit_tests/os_interface/CMakeLists.txt b/unit_tests/os_interface/CMakeLists.txt index b3744e3faf..eebc865dec 100644 --- a/unit_tests/os_interface/CMakeLists.txt +++ b/unit_tests/os_interface/CMakeLists.txt @@ -16,6 +16,7 @@ set(IGDRCL_SRCS_tests_os_interface_base ${CMAKE_CURRENT_SOURCE_DIR}/mock_performance_counters.h ${CMAKE_CURRENT_SOURCE_DIR}/os_interface_tests.cpp ${CMAKE_CURRENT_SOURCE_DIR}/os_library_tests.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/os_memory_tests.cpp ${CMAKE_CURRENT_SOURCE_DIR}/performance_counters_gen_tests.cpp ${CMAKE_CURRENT_SOURCE_DIR}/performance_counters_tests.cpp ) diff --git a/unit_tests/os_interface/linux/allocator_helper.cpp b/unit_tests/os_interface/linux/allocator_helper.cpp index f8e12912af..e5839e3b22 100644 --- a/unit_tests/os_interface/linux/allocator_helper.cpp +++ b/unit_tests/os_interface/linux/allocator_helper.cpp @@ -7,8 +7,17 @@ #include "runtime/os_interface/linux/allocator_helper.h" +#include "core/helpers/basic_math.h" + namespace NEO { + size_t getSizeToMap() { return static_cast(1 * 1024 * 1024u); } + +size_t getSizeToReserve() { + // 4 x sizeof(Heap32) + 2 x sizeof(Standard/Standard64k) + return (4 * 4 + 2 * 4) * GB; +} + } // namespace NEO diff --git a/unit_tests/os_interface/linux/allocator_helper_tests.cpp b/unit_tests/os_interface/linux/allocator_helper_tests.cpp index 3106b34991..0d0fa0f8b9 100644 --- a/unit_tests/os_interface/linux/allocator_helper_tests.cpp +++ b/unit_tests/os_interface/linux/allocator_helper_tests.cpp @@ -5,6 +5,7 @@ * */ +#include "core/helpers/basic_math.h" #include "runtime/os_interface/linux/allocator_helper.h" #include "gtest/gtest.h" @@ -12,3 +13,7 @@ TEST(AllocatorHelper, givenExpectedSizeToMapWhenGetSizetoMapCalledThenExpectedValueReturned) { EXPECT_EQ(1 * 1024 * 1024u, NEO::getSizeToMap()); } + +TEST(AllocatorHelper, givenExpectedSizeToReserveWhenGetSizeToReserveCalledThenExpectedValueReturned) { + EXPECT_EQ((4 * 4 + 2 * 4) * GB, NEO::getSizeToReserve()); +} diff --git a/unit_tests/os_interface/os_memory_tests.cpp b/unit_tests/os_interface/os_memory_tests.cpp new file mode 100644 index 0000000000..667ffce49a --- /dev/null +++ b/unit_tests/os_interface/os_memory_tests.cpp @@ -0,0 +1,19 @@ +/* + * Copyright (C) 2019 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "runtime/os_interface/os_memory.h" + +#include "gtest/gtest.h" + +using namespace NEO; + +TEST(OSMemory, reserveCpuAddressRange) { + size_t reservedCpuAddressRangeSize = 1024; + auto reservedCpuAddressRange = OSMemory::reserveCpuAddressRange(reservedCpuAddressRangeSize); + EXPECT_NE(reservedCpuAddressRange, nullptr); + OSMemory::releaseCpuAddressRange(reservedCpuAddressRange, reservedCpuAddressRangeSize); +} diff --git a/unit_tests/program/program_tests.cpp b/unit_tests/program/program_tests.cpp index ec83b74c44..4448f98fe9 100644 --- a/unit_tests/program/program_tests.cpp +++ b/unit_tests/program/program_tests.cpp @@ -11,6 +11,7 @@ #include "elf/reader.h" #include "runtime/command_stream/command_stream_receiver_hw.h" #include "runtime/compiler_interface/compiler_options.h" +#include "runtime/gmm_helper/gmm_helper.h" #include "runtime/helpers/aligned_memory.h" #include "runtime/helpers/hardware_commands_helper.h" #include "runtime/helpers/hash.h" @@ -645,11 +646,7 @@ TEST_P(ProgramFromBinaryTest, givenProgramWhenItIsBeingBuildThenItContainsGraphi auto kernelIsa = graphicsAllocation->getUnderlyingBuffer(); EXPECT_NE(kernelInfo->heapInfo.pKernelHeap, kernelIsa); EXPECT_EQ(0, memcmp(kernelIsa, kernelInfo->heapInfo.pKernelHeap, kernelInfo->heapInfo.pKernelHeader->KernelHeapSize)); - if (sizeof(void *) == sizeof(uint32_t)) { - EXPECT_EQ(0u, graphicsAllocation->getGpuBaseAddress()); - } else { - EXPECT_NE(0u, graphicsAllocation->getGpuBaseAddress()); - } + EXPECT_EQ(GmmHelper::decanonize(graphicsAllocation->getGpuBaseAddress()), pProgram->getDevice(0).getMemoryManager()->getInternalHeapBaseAddress()); } TEST_P(ProgramFromBinaryTest, givenProgramWhenCleanKernelInfoIsCalledThenKernelAllocationIsFreed) {