Use GfxPartition for GPU address range allocations

[4/n] - Remove allocator32Bit

Related-To: NEO-2877

Change-Id: I0772a7fe1fda19daa12699c546587bd3cdd84f2c
Signed-off-by: Venevtsev, Igor <igor.venevtsev@intel.com>
This commit is contained in:
Venevtsev, Igor
2019-07-04 12:40:58 +02:00
committed by sys_ocldev
parent 09e87879db
commit 4403796f58
33 changed files with 13 additions and 451 deletions

View File

@@ -11,7 +11,6 @@
#include "runtime/helpers/hw_info.h"
#include "runtime/helpers/options.h"
#include "runtime/memory_manager/os_agnostic_memory_manager.h"
#include "runtime/os_interface/32bit_memory.h"
#include "runtime/os_interface/debug_settings_manager.h"
#include "runtime/os_interface/os_interface.h"
#include "runtime/source_level_debugger/source_level_debugger.h"
@@ -176,7 +175,7 @@ TEST(Device_GetCaps, validate) {
EXPECT_EQ(16384u, caps.image2DMaxWidth);
EXPECT_EQ(16384u, caps.image2DMaxHeight);
EXPECT_EQ(2048u, caps.imageMaxArraySize);
if (device->getHardwareInfo().capabilityTable.clVersionSupport == 12 && is32BitOsAllocatorAvailable) {
if (device->getHardwareInfo().capabilityTable.clVersionSupport == 12 && is64bit) {
EXPECT_TRUE(caps.force32BitAddressess);
} else {
//EXPECT_FALSE(caps.force32BitAddressess);

View File

@@ -9,7 +9,6 @@
#include "runtime/helpers/hw_info.h"
#include "runtime/helpers/options.h"
#include "runtime/memory_manager/os_agnostic_memory_manager.h"
#include "runtime/os_interface/32bit_memory.h"
#include "runtime/os_interface/debug_settings_manager.h"
#include "test.h"
#include "unit_tests/fixtures/device_fixture.h"

View File

@@ -29,7 +29,7 @@ BXTTEST_F(BxtDeviceCaps, BxtClVersionSupport) {
EXPECT_STREQ("OpenCL C 1.2 ", caps.clCVersion);
auto memoryManager = pDevice->getMemoryManager();
if (is32BitOsAllocatorAvailable) {
if (is64bit) {
EXPECT_TRUE(memoryManager->peekForce32BitAllocations());
EXPECT_TRUE(caps.force32BitAddressess);
} else {

View File

@@ -30,7 +30,7 @@ GLKTEST_F(Gen9DeviceCaps, GlkClVersionSupport) {
GLKTEST_F(Gen9DeviceCaps, GlkIs32BitOsAllocatorAvailable) {
const auto &caps = pDevice->getDeviceInfo();
auto memoryManager = pDevice->getMemoryManager();
if (is32BitOsAllocatorAvailable) {
if (is64bit) {
EXPECT_TRUE(memoryManager->peekForce32BitAllocations());
EXPECT_TRUE(caps.force32BitAddressess);
} else {

View File

@@ -357,12 +357,8 @@ TEST_F(DrmTests, failOnInvalidDeviceName) {
EXPECT_EQ(drm, nullptr);
}
TEST(AllocatorHelper, givenExpectedSizeToMapWhenGetSizetoMapCalledThenExpectedValueReturned) {
EXPECT_EQ((alignUp(4 * GB - 8096, 4096)), NEO::getSizeToMap());
}
TEST(AllocatorHelper, givenExpectedSizeToReserveWhenGetSizeToReserveCalledThenExpectedValueReturned) {
EXPECT_EQ(maxNBitValue<47> / 4, NEO::getSizeToReserve());
EXPECT_EQ((maxNBitValue<47> + 1) / 4, NEO::getSizeToReserve());
}
TEST(DrmMemoryManagerCreate, whenCallCreateMemoryManagerThenDrmMemoryManagerIsCreated) {

View File

@@ -6,7 +6,6 @@
set(IGDRCL_SRCS_tests_mocks
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
${CMAKE_CURRENT_SOURCE_DIR}/mock_32bitAllocator.h
${CMAKE_CURRENT_SOURCE_DIR}/mock_allocation_properties.h
${CMAKE_CURRENT_SOURCE_DIR}/mock_async_event_handler.cpp
${CMAKE_CURRENT_SOURCE_DIR}/mock_async_event_handler.h

View File

@@ -48,7 +48,6 @@ class TestedDrmMemoryManager : public MemoryManagerCreate<DrmMemoryManager> {
using DrmMemoryManager::allocateGraphicsMemoryWithAlignment;
using DrmMemoryManager::allocateGraphicsMemoryWithHostPtr;
using DrmMemoryManager::AllocationData;
using DrmMemoryManager::allocator32Bit;
using DrmMemoryManager::allocUserptr;
using DrmMemoryManager::createGraphicsAllocation;
using DrmMemoryManager::gfxPartition;

View File

@@ -1,81 +0,0 @@
/*
* Copyright (C) 2017-2019 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#pragma once
#include "runtime/helpers/aligned_memory.h"
#include "runtime/os_interface/32bit_memory.h"
#include "runtime/os_interface/linux/drm_32bit_memory.cpp"
#include <limits>
namespace NEO {
constexpr uintptr_t startOf32MmapRegion = 0x40000000;
static bool failMmap = false;
static size_t maxMmapLength = std::numeric_limits<size_t>::max();
static uintptr_t offsetIn32BitRange = 0;
static uint32_t mmapCallCount = 0u;
static uint32_t unmapCallCount = 0u;
static uint32_t mmapFailCount = 0u;
void *MockMmap(void *addr, size_t length, int prot, int flags,
int fd, off_t offset) noexcept {
mmapCallCount++;
UNRECOVERABLE_IF(addr);
if (failMmap || length > maxMmapLength) {
return MAP_FAILED;
}
if (mmapFailCount > 0) {
mmapFailCount--;
return MAP_FAILED;
}
uintptr_t ptrToReturn = startOf32MmapRegion + offsetIn32BitRange;
offsetIn32BitRange += alignUp(length, MemoryConstants::pageSize);
return reinterpret_cast<void *>(ptrToReturn);
}
int MockMunmap(void *addr, size_t length) noexcept {
unmapCallCount++;
return 0;
}
class MockAllocator32Bit : public Allocator32bit {
public:
class OsInternalsPublic : public Allocator32bit::OsInternals {
};
MockAllocator32Bit(Allocator32bit::OsInternals *osInternalsIn) : Allocator32bit(osInternalsIn) {
}
MockAllocator32Bit() {
this->osInternals->mmapFunction = MockMmap;
this->osInternals->munmapFunction = MockMunmap;
resetState();
}
~MockAllocator32Bit() {
resetState();
}
static void resetState() {
failMmap = false;
maxMmapLength = std::numeric_limits<size_t>::max();
offsetIn32BitRange = 0u;
mmapCallCount = 0u;
unmapCallCount = 0u;
mmapFailCount = 0u;
}
static OsInternalsPublic *createOsInternals() {
return new OsInternalsPublic;
}
OsInternals *getOsInternals() const { return this->osInternals.get(); }
};
} // namespace NEO

View File

@@ -33,7 +33,6 @@ class MockMemoryManager : public MemoryManagerCreate<OsAgnosticMemoryManager> {
using MemoryManager::allocateGraphicsMemoryInPreferredPool;
using MemoryManager::allocateGraphicsMemoryWithProperties;
using MemoryManager::AllocationData;
using MemoryManager::allocator32Bit;
using MemoryManager::createGraphicsAllocation;
using MemoryManager::createStorageInfoFromProperties;
using MemoryManager::getAllocationData;
@@ -193,10 +192,6 @@ class FailMemoryManager : public MockMemoryManager {
return 0;
};
uint64_t getMaxApplicationAddress() override {
return MemoryConstants::max32BitAppAddress;
};
GraphicsAllocation *createGraphicsAllocation(OsHandleStorage &handleStorage, const AllocationData &allocationData) override {
return nullptr;
};

View File

@@ -1,45 +0,0 @@
/*
* Copyright (C) 2017-2019 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "runtime/helpers/aligned_memory.h"
#include "runtime/os_interface/32bit_memory.h"
#include "gtest/gtest.h"
using namespace NEO;
TEST(Memory32Bit, Given32bitAllocatorWhenAskedForAllocationThen32BitPointerIsReturned) {
size_t size = 100u;
Allocator32bit allocator32bit;
auto ptr = allocator32bit.allocate(size);
uintptr_t address64bit = (uintptr_t)ptr - allocator32bit.getBase();
if (is32BitOsAllocatorAvailable) {
EXPECT_LT(address64bit, max32BitAddress);
}
EXPECT_LT(0u, address64bit);
auto ret = allocator32bit.free(ptr, size);
EXPECT_EQ(0, ret);
}
TEST(Memory32Bit, Given32bitAllocatorWhenAskedForAllocationThenPageAlignedPointerIsReturnedWithSizeAlignedToPage) {
size_t size = 100u;
Allocator32bit allocator32bit;
auto ptr = allocator32bit.allocate(size);
EXPECT_EQ(ptr, alignDown(ptr, MemoryConstants::pageSize));
auto ret = allocator32bit.free(ptr, size);
EXPECT_EQ(0, ret);
}
TEST(Memory32Bit, Given32bitAllocatorWithBaseAndSizeWhenAskedForBaseThenCorrectBaseIsReturned) {
uint64_t size = 100u;
uint64_t base = 0x23000;
Allocator32bit allocator32bit(base, size);
EXPECT_EQ(base, allocator32bit.getBase());
}

View File

@@ -6,7 +6,6 @@
set(IGDRCL_SRCS_tests_os_interface_base
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
${CMAKE_CURRENT_SOURCE_DIR}/32bit_memory_tests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/debug_settings_manager_fixture.h
${CMAKE_CURRENT_SOURCE_DIR}/debug_settings_manager_tests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/device_factory_tests.cpp

View File

@@ -11,10 +11,6 @@
namespace NEO {
size_t getSizeToMap() {
return static_cast<size_t>(1 * 1024 * 1024u);
}
size_t getSizeToReserve() {
// 4 x sizeof(Heap32) + 2 x sizeof(Standard/Standard64k)
return (4 * 4 + 2 * 4) * GB;

View File

@@ -10,10 +10,6 @@
#include "gtest/gtest.h"
TEST(AllocatorHelper, givenExpectedSizeToMapWhenGetSizetoMapCalledThenExpectedValueReturned) {
EXPECT_EQ(1 * 1024 * 1024u, NEO::getSizeToMap());
}
TEST(AllocatorHelper, givenExpectedSizeToReserveWhenGetSizeToReserveCalledThenExpectedValueReturned) {
EXPECT_EQ((4 * 4 + 2 * 4) * GB, NEO::getSizeToReserve());
}

View File

@@ -19,7 +19,6 @@
#include "runtime/mem_obj/image.h"
#include "runtime/memory_manager/host_ptr_manager.h"
#include "runtime/memory_manager/memory_constants.h"
#include "runtime/os_interface/32bit_memory.h"
#include "runtime/os_interface/linux/allocator_helper.h"
#include "runtime/os_interface/linux/drm_allocation.h"
#include "runtime/os_interface/linux/drm_buffer_object.h"
@@ -32,7 +31,6 @@
#include "unit_tests/helpers/debug_manager_state_restore.h"
#include "unit_tests/helpers/memory_management.h"
#include "unit_tests/mocks/linux/mock_drm_command_stream_receiver.h"
#include "unit_tests/mocks/mock_32bitAllocator.h"
#include "unit_tests/mocks/mock_context.h"
#include "unit_tests/mocks/mock_gmm.h"
@@ -1140,7 +1138,7 @@ TEST_F(DrmMemoryManagerTest, Given32BitDeviceWithMemoryManagerWhenInternalHeapIs
memoryManager->setForce32BitAllocations(true);
std::unique_ptr<Device> pDevice(MockDevice::createWithNewExecutionEnvironment<MockDevice>(nullptr));
size_t size = getSizeToMap();
size_t size = MemoryConstants::pageSize64k;
auto alloc = memoryManager->gfxPartition.heapAllocate(internalHeapIndex, size);
EXPECT_NE(0llu, alloc);
@@ -2393,41 +2391,6 @@ TEST_F(DrmMemoryManagerWithExplicitExpectationsTest, givenDefaultDrmMemoryManage
EXPECT_EQ(nullptr, memoryManager->getAlignedMallocRestrictions());
}
TEST(Allocator32BitUsingHeapAllocator, given32BitAllocatorWhenMMapFailsThenNullptrIsReturned) {
MockAllocator32Bit::resetState();
failMmap = true;
MockAllocator32Bit::OsInternalsPublic *osInternals = MockAllocator32Bit::createOsInternals();
osInternals->mmapFunction = MockMmap;
osInternals->munmapFunction = MockMunmap;
MockAllocator32Bit mock32BitAllocator{osInternals};
size_t size = 100u;
auto ptr = mock32BitAllocator.allocate(size);
EXPECT_EQ(0llu, ptr);
EXPECT_EQ(2u, mmapCallCount);
}
TEST(Allocator32BitUsingHeapAllocator, given32BitAllocatorWhenFirstMMapFailsThenSecondIsCalledWithSmallerSize) {
MockAllocator32Bit::resetState();
maxMmapLength = getSizeToMap() - 1;
MockAllocator32Bit::OsInternalsPublic *osInternals = MockAllocator32Bit::createOsInternals();
osInternals->mmapFunction = MockMmap;
osInternals->munmapFunction = MockMunmap;
MockAllocator32Bit mock32BitAllocator{osInternals};
size_t size = 100u;
auto ptr = mock32BitAllocator.allocate(size);
EXPECT_NE(0llu, ptr);
EXPECT_EQ(2u, mmapCallCount);
EXPECT_NE(nullptr, osInternals->heapBasePtr);
EXPECT_NE(0u, osInternals->heapSize);
}
TEST(Allocator32BitUsingHeapAllocator, given32bitAllocatorWhenFreeIsCalledWithMapFailedThenZeroIsReturned) {
MockAllocator32Bit::OsInternalsPublic *osInternals = MockAllocator32Bit::createOsInternals();
MockAllocator32Bit mock32BitAllocator{osInternals};
EXPECT_EQ(0, mock32BitAllocator.free(castToUint64(MAP_FAILED), 4096u));
}
#include <chrono>
#include <iostream>

View File

@@ -8,7 +8,6 @@
#include "runtime/helpers/string.h"
#include "runtime/memory_manager/allocations_list.h"
#include "runtime/memory_manager/graphics_allocation.h"
#include "runtime/os_interface/32bit_memory.h"
#include "runtime/platform/platform.h"
#include "runtime/program/program.h"
#include "test.h"