Skip to content

Commit 64c891f

Browse files
committed
Use specific address for Allocator32Bit in AUB CSR
Change-Id: If3fd466fcfea21c1967b10def57acf67ccfdc5e6
1 parent efdbde2 commit 64c891f

File tree

6 files changed

+71
-10
lines changed

6 files changed

+71
-10
lines changed

Jenkinsfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!groovy
22
neoDependenciesRev='800243-1090'
33
strategy='EQUAL'
4-
allowedCD=272
4+
allowedCD=274
55
allowedF=4

runtime/command_stream/aub_command_stream_receiver_hw.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class AUBCommandStreamReceiverHw : public CommandStreamReceiverSimulatedHw<GfxFa
6969
void freeEngineInfoTable();
7070

7171
MemoryManager *createMemoryManager(bool enable64kbPages, bool enableLocalMemory) override {
72-
this->memoryManager = new OsAgnosticMemoryManager(enable64kbPages, enableLocalMemory);
72+
this->memoryManager = new OsAgnosticMemoryManager(enable64kbPages, enableLocalMemory, true);
7373
this->flatBatchBufferHelper->setMemoryManager(this->memoryManager);
7474
return this->memoryManager;
7575
}

runtime/memory_manager/os_agnostic_memory_manager.cpp

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,11 @@ GraphicsAllocation *OsAgnosticMemoryManager::allocate32BitGraphicsMemory(size_t
8989

9090
auto allocationSize = alignUp(size, MemoryConstants::pageSize);
9191
void *ptrAlloc = nullptr;
92+
auto gpuAddress = allocator32Bit->allocate(allocationSize);
9293

93-
if (size < 0xfffff000)
94+
if (size < 0xfffff000) {
9495
ptrAlloc = alignedMallocWrapper(allocationSize, MemoryConstants::allocationAlignment);
95-
auto gpuAddress = allocator32Bit->allocate(allocationSize);
96+
}
9697

9798
MemoryAllocation *memoryAllocation = nullptr;
9899
if (ptrAlloc != nullptr) {
@@ -227,4 +228,18 @@ GraphicsAllocation *OsAgnosticMemoryManager::allocateGraphicsMemoryForImage(Imag
227228

228229
return alloc;
229230
}
231+
232+
Allocator32bit *OsAgnosticMemoryManager::create32BitAllocator(bool aubUsage) {
233+
uint64_t allocatorSize = MemoryConstants::gigaByte - 2 * 4096;
234+
uint64_t heap32Base = 0x80000000000ul;
235+
236+
if (is64bit && this->localMemorySupported && aubUsage) {
237+
heap32Base = 0x40000000000ul;
238+
}
239+
240+
if (is32bit) {
241+
heap32Base = 0x0;
242+
}
243+
return new Allocator32bit(heap32Base, allocatorSize);
244+
}
230245
} // namespace OCLRT

runtime/memory_manager/os_agnostic_memory_manager.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,12 @@ class OsAgnosticMemoryManager : public MemoryManager {
3838
using MemoryManager::createGraphicsAllocationFromSharedHandle;
3939

4040
OsAgnosticMemoryManager() : OsAgnosticMemoryManager(false, false){};
41-
OsAgnosticMemoryManager(bool enable64kbPages, bool enableLocalMemory) : MemoryManager(enable64kbPages, enableLocalMemory) {
42-
uint64_t heap32Base = 0x80000000000ul;
43-
if (sizeof(uintptr_t) == 4) {
44-
heap32Base = 0x0;
45-
}
46-
allocator32Bit = std::unique_ptr<Allocator32bit>(new Allocator32bit(heap32Base, GB - 2 * 4096));
41+
OsAgnosticMemoryManager(bool enable64kbPages, bool enableLocalMemory) : OsAgnosticMemoryManager(enable64kbPages, enableLocalMemory, false){};
42+
43+
OsAgnosticMemoryManager(bool enable64kbPages, bool enableLocalMemory, bool aubUsage) : MemoryManager(enable64kbPages, enableLocalMemory) {
44+
allocator32Bit = std::unique_ptr<Allocator32bit>(create32BitAllocator(aubUsage));
4745
};
46+
4847
~OsAgnosticMemoryManager() override;
4948
GraphicsAllocation *allocateGraphicsMemory(size_t size, size_t alignment, bool forcePin, bool uncacheable) override;
5049
GraphicsAllocation *allocateGraphicsMemory64kb(size_t size, size_t alignment, bool forcePin, bool preferRenderCompressed) override;
@@ -72,6 +71,8 @@ class OsAgnosticMemoryManager : public MemoryManager {
7271

7372
void turnOnFakingBigAllocations();
7473

74+
Allocator32bit *create32BitAllocator(bool enableLocalMemory);
75+
7576
private:
7677
unsigned long long counter = 0;
7778
bool fakeBigAllocations = false;

unit_tests/memory_manager/memory_manager_tests.cpp

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "runtime/event/event.h"
99
#include "runtime/helpers/dispatch_info.h"
1010
#include "runtime/helpers/timestamp_packet.h"
11+
#include "runtime/memory_manager/memory_constants.h"
1112
#include "runtime/mem_obj/image.h"
1213
#include "runtime/os_interface/os_context.h"
1314
#include "runtime/os_interface/os_interface.h"
@@ -1288,6 +1289,48 @@ TEST(OsAgnosticMemoryManager, givenFullGpuAddressSpaceWhenAllocateGraphicsMemory
12881289
memoryManager.freeGraphicsMemory(allocation);
12891290
}
12901291

1292+
TEST(OsAgnosticMemoryManager, givenLocalMemoryNotSupportedWhenMemoryManagerIsCreatedThenAllocator32BitHasCorrectBaseAddress) {
1293+
MockMemoryManager memoryManager(false, false, false);
1294+
uint64_t heap32Base = 0x80000000000ul;
1295+
1296+
if (is32bit) {
1297+
heap32Base = 0;
1298+
}
1299+
EXPECT_EQ(heap32Base, memoryManager.allocator32Bit->getBase());
1300+
}
1301+
1302+
TEST(OsAgnosticMemoryManager, givenLocalMemorySupportedAndNotAubUsageWhenMemoryManagerIsCreatedThenAllocator32BitHasCorrectBaseAddress) {
1303+
MockMemoryManager memoryManager(false, true, false);
1304+
uint64_t heap32Base = 0x80000000000ul;
1305+
1306+
if (is32bit) {
1307+
heap32Base = 0;
1308+
}
1309+
EXPECT_EQ(heap32Base, memoryManager.allocator32Bit->getBase());
1310+
}
1311+
1312+
TEST(OsAgnosticMemoryManager, givenLocalMemoryNotSupportedAndAubUsageWhenMemoryManagerIsCreatedThenAllocator32BitHasCorrectBaseAddress) {
1313+
MockMemoryManager memoryManager(false, false, true);
1314+
uint64_t heap32Base = 0x80000000000ul;
1315+
1316+
if (is32bit) {
1317+
heap32Base = 0;
1318+
}
1319+
EXPECT_EQ(heap32Base, memoryManager.allocator32Bit->getBase());
1320+
}
1321+
1322+
TEST(OsAgnosticMemoryManager, givenLocalMemorySupportedAndAubUsageWhenMemoryManagerIsCreatedThenAllocator32BitHasCorrectBaseAddress) {
1323+
MockMemoryManager memoryManager(false, true, true);
1324+
uint64_t heap32Base = 0x80000000000ul;
1325+
1326+
if (is32bit) {
1327+
heap32Base = 0;
1328+
} else {
1329+
heap32Base = 0x40000000000ul;
1330+
}
1331+
EXPECT_EQ(heap32Base, memoryManager.allocator32Bit->getBase());
1332+
}
1333+
12911334
TEST_F(MemoryAllocatorTest, GivenSizeWhenGmmIsCreatedThenSuccess) {
12921335
Gmm *gmm = new Gmm(nullptr, 65536, false);
12931336
EXPECT_NE(nullptr, gmm);

unit_tests/mocks/mock_memory_manager.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ class MockMemoryManager : public OsAgnosticMemoryManager {
2121

2222
MockMemoryManager() : OsAgnosticMemoryManager(false, false){};
2323
MockMemoryManager(bool enable64pages) : OsAgnosticMemoryManager(enable64pages, false) {}
24+
MockMemoryManager(bool enable64kbPages, bool enableLocalMemory, bool aubUsage) : OsAgnosticMemoryManager(enable64kbPages, enableLocalMemory, aubUsage) {}
25+
2426
GraphicsAllocation *allocateGraphicsMemory64kb(size_t size, size_t alignment, bool forcePin, bool preferRenderCompressed) override;
2527
void setDeferredDeleter(DeferredDeleter *deleter);
2628
void overrideAsyncDeleterFlag(bool newValue);

0 commit comments

Comments
 (0)