Skip to content

Commit fca7b4e

Browse files
Remove Drm32Bit allocator.
- not used anymore. Change-Id: Ibb7da1758feb67224ac0b172c72f45c2f1c229d9
1 parent fbcc782 commit fca7b4e

File tree

5 files changed

+33
-347
lines changed

5 files changed

+33
-347
lines changed

runtime/os_interface/debug_variables_base.inl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ DECLARE_DEBUG_VARIABLE(bool, ForceCsrFlushing, false, "Forces flushing of comman
7474
DECLARE_DEBUG_VARIABLE(bool, ForceCsrReprogramming, false, "Forces reprogramming of command stream receiver")
7575
DECLARE_DEBUG_VARIABLE(bool, DisableStatelessToStatefulOptimization, false, "Disables stateless to stateful optimization for buffers")
7676
DECLARE_DEBUG_VARIABLE(bool, DisableConcurrentBlockExecution, false, "disables concurrent block kernel execution")
77-
DECLARE_DEBUG_VARIABLE(bool, UseNewHeapAllocator, true, "Custom 4GB heap allocator is used")
7877
DECLARE_DEBUG_VARIABLE(bool, UseNoRingFlushesKmdMode, true, "Windows only, passes flag to KMD that informs KMD to not emit any ring buffer flushes.")
7978
DECLARE_DEBUG_VARIABLE(bool, DisableZeroCopyForUseHostPtr, false, "When active all buffer allocations created with CL_MEM_USE_HOST_PTR flag will not share memory with CPU.")
8079
DECLARE_DEBUG_VARIABLE(bool, DisableZeroCopyForBuffers, false, "When active all buffer allocations will not share memory with CPU.")

runtime/os_interface/linux/drm_32bit_memory.cpp

Lines changed: 20 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -15,64 +15,13 @@
1515
#include <memory>
1616
#include <sys/mman.h>
1717
using namespace OCLRT;
18-
constexpr uintptr_t maxMmap32BitAddress = 0x80000000;
19-
constexpr uintptr_t lowerRangeStart = 0x10000000;
2018

2119
class Allocator32bit::OsInternals {
2220
public:
23-
uintptr_t upperRangeAddress = maxMmap32BitAddress;
24-
uintptr_t lowerRangeAddress = lowerRangeStart;
2521
decltype(&mmap) mmapFunction = mmap;
2622
decltype(&munmap) munmapFunction = munmap;
2723
void *heapBasePtr = nullptr;
2824
size_t heapSize = 0;
29-
30-
class Drm32BitAllocator {
31-
protected:
32-
Allocator32bit::OsInternals &outer;
33-
34-
public:
35-
Drm32BitAllocator(Allocator32bit::OsInternals &outer) : outer(outer) {
36-
}
37-
38-
void *allocate(size_t size) {
39-
auto ptr = outer.mmapFunction(nullptr, size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_32BIT, -1, 0);
40-
41-
// In case we failed, retry with address provided as a hint
42-
if (ptr == MAP_FAILED) {
43-
ptr = outer.mmapFunction((void *)outer.upperRangeAddress, size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
44-
if (((uintptr_t)ptr + alignUp(size, 4096)) >= max32BitAddress || ptr == MAP_FAILED) {
45-
outer.munmapFunction(ptr, size);
46-
47-
// Try to use lower range
48-
ptr = outer.mmapFunction((void *)outer.lowerRangeAddress, size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
49-
if ((uintptr_t)ptr >= max32BitAddress) {
50-
outer.munmapFunction(ptr, size);
51-
return nullptr;
52-
}
53-
54-
outer.lowerRangeAddress = (uintptr_t)ptr + alignUp(size, 4096);
55-
return ptr;
56-
}
57-
58-
outer.upperRangeAddress = (uintptr_t)ptr + alignUp(size, 4096);
59-
}
60-
return ptr;
61-
}
62-
63-
int free(void *ptr, uint64_t size) {
64-
auto alignedSize = alignUp(size, 4096);
65-
auto offsetedPtr = (uintptr_t)ptrOffset(ptr, alignedSize);
66-
67-
if (offsetedPtr == outer.upperRangeAddress) {
68-
outer.upperRangeAddress -= alignedSize;
69-
} else if (offsetedPtr == outer.lowerRangeAddress) {
70-
outer.lowerRangeAddress -= alignedSize;
71-
}
72-
return outer.munmapFunction(ptr, size);
73-
}
74-
};
75-
Drm32BitAllocator *drmAllocator = nullptr;
7625
};
7726

7827
bool OCLRT::is32BitOsAllocatorAvailable = true;
@@ -85,65 +34,48 @@ OCLRT::Allocator32bit::Allocator32bit() : Allocator32bit(new OsInternals) {
8534
}
8635

8736
OCLRT::Allocator32bit::Allocator32bit(Allocator32bit::OsInternals *osInternalsIn) : osInternals(osInternalsIn) {
37+
size_t sizeToMap = getSizeToMap();
38+
void *ptr = this->osInternals->mmapFunction(nullptr, sizeToMap, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_NORESERVE, -1, 0);
8839

89-
if (DebugManager.flags.UseNewHeapAllocator.get()) {
90-
size_t sizeToMap = getSizeToMap();
91-
void *ptr = this->osInternals->mmapFunction(nullptr, sizeToMap, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_NORESERVE, -1, 0);
40+
if (ptr == MAP_FAILED) {
41+
sizeToMap -= sizeToMap / 4;
42+
ptr = this->osInternals->mmapFunction(nullptr, sizeToMap, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_NORESERVE, -1, 0);
9243

93-
if (ptr == MAP_FAILED) {
94-
sizeToMap -= sizeToMap / 4;
95-
ptr = this->osInternals->mmapFunction(nullptr, sizeToMap, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_NORESERVE, -1, 0);
44+
DebugManager.log(DebugManager.flags.PrintDebugMessages.get(), __FUNCTION__, " Allocator RETRY ptr == ", ptr);
9645

97-
DebugManager.log(DebugManager.flags.PrintDebugMessages.get(), __FUNCTION__, " Allocator RETRY ptr == ", ptr);
98-
99-
if (ptr == MAP_FAILED) {
100-
ptr = nullptr;
101-
sizeToMap = 0;
102-
}
46+
if (ptr == MAP_FAILED) {
47+
ptr = nullptr;
48+
sizeToMap = 0;
10349
}
50+
}
10451

105-
DebugManager.log(DebugManager.flags.PrintDebugMessages.get(), __FUNCTION__, "Allocator ptr == ", ptr);
52+
DebugManager.log(DebugManager.flags.PrintDebugMessages.get(), __FUNCTION__, "Allocator ptr == ", ptr);
10653

107-
osInternals->heapBasePtr = ptr;
108-
osInternals->heapSize = sizeToMap;
109-
base = reinterpret_cast<uint64_t>(ptr);
110-
size = sizeToMap;
54+
osInternals->heapBasePtr = ptr;
55+
osInternals->heapSize = sizeToMap;
56+
base = reinterpret_cast<uint64_t>(ptr);
57+
size = sizeToMap;
11158

112-
heapAllocator = std::unique_ptr<HeapAllocator>(new HeapAllocator(base, sizeToMap));
113-
} else {
114-
this->osInternals->drmAllocator = new Allocator32bit::OsInternals::Drm32BitAllocator(*this->osInternals);
115-
}
59+
heapAllocator = std::unique_ptr<HeapAllocator>(new HeapAllocator(base, sizeToMap));
11660
}
11761

11862
OCLRT::Allocator32bit::~Allocator32bit() {
11963
if (this->osInternals.get() != nullptr) {
12064
if (this->osInternals->heapBasePtr != nullptr)
12165
this->osInternals->munmapFunction(this->osInternals->heapBasePtr, this->osInternals->heapSize);
122-
123-
if (this->osInternals->drmAllocator != nullptr)
124-
delete this->osInternals->drmAllocator;
12566
}
12667
}
12768

12869
uint64_t OCLRT::Allocator32bit::allocate(size_t &size) {
129-
uint64_t ptr = 0llu;
130-
if (DebugManager.flags.UseNewHeapAllocator.get()) {
131-
ptr = this->heapAllocator->allocate(size);
132-
} else {
133-
ptr = reinterpret_cast<uint64_t>(this->osInternals->drmAllocator->allocate(size));
134-
}
135-
return ptr;
70+
return this->heapAllocator->allocate(size);
13671
}
13772

13873
int Allocator32bit::free(uint64_t ptr, size_t size) {
139-
if (ptr == reinterpret_cast<uint64_t>(MAP_FAILED) || ptr == 0llu)
74+
if (ptr == reinterpret_cast<uint64_t>(MAP_FAILED))
14075
return 0;
14176

142-
if (DebugManager.flags.UseNewHeapAllocator.get()) {
143-
this->heapAllocator->free(ptr, size);
144-
} else {
145-
return this->osInternals->drmAllocator->free(reinterpret_cast<void *>(ptr), size);
146-
}
77+
this->heapAllocator->free(ptr, size);
78+
14779
return 0;
14880
}
14981

unit_tests/mocks/mock_32bitAllocator.h

Lines changed: 5 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,8 @@ namespace OCLRT {
1515

1616
constexpr uintptr_t startOf32MmapRegion = 0x40000000;
1717
static bool failMmap = false;
18-
static bool fail32BitMmap = false;
19-
static bool failUpperRange = false;
20-
static bool failLowerRanger = false;
2118
static size_t maxMmapLength = std::numeric_limits<size_t>::max();
2219

23-
static uintptr_t startUpperHeap = maxMmap32BitAddress;
24-
static uintptr_t lowerRangeHeapStart = lowerRangeStart;
25-
2620
static uintptr_t offsetIn32BitRange = 0;
2721
static uint32_t mmapCallCount = 0u;
2822
static uint32_t unmapCallCount = 0u;
@@ -31,10 +25,8 @@ static uint32_t mmapFailCount = 0u;
3125
void *MockMmap(void *addr, size_t length, int prot, int flags,
3226
int fd, off_t offset) noexcept {
3327

34-
bool return32bitRange = true;
35-
bool returnUpperRange = false;
36-
bool returnLowerRange = false;
3728
mmapCallCount++;
29+
UNRECOVERABLE_IF(addr);
3830

3931
if (failMmap || length > maxMmapLength) {
4032
return MAP_FAILED;
@@ -45,42 +37,10 @@ void *MockMmap(void *addr, size_t length, int prot, int flags,
4537
return MAP_FAILED;
4638
}
4739

48-
if (addr) {
49-
return32bitRange = false;
50-
if ((uintptr_t)addr >= maxMmap32BitAddress) {
51-
if (failUpperRange) {
52-
return MAP_FAILED;
53-
}
54-
returnUpperRange = true;
55-
}
56-
if ((uintptr_t)addr >= lowerRangeStart) {
57-
if (failLowerRanger) {
58-
return MAP_FAILED;
59-
}
60-
returnLowerRange = true;
61-
}
62-
}
63-
64-
if (flags & MAP_32BIT) {
65-
if (fail32BitMmap) {
66-
return MAP_FAILED;
67-
}
68-
return32bitRange = true;
69-
}
70-
71-
uintptr_t ptrToReturn = (uintptr_t)addr;
72-
if (return32bitRange) {
73-
ptrToReturn = startOf32MmapRegion + offsetIn32BitRange;
74-
offsetIn32BitRange += alignUp(length, MemoryConstants::pageSize);
75-
} else if (returnUpperRange) {
76-
ptrToReturn = (uintptr_t)addr;
77-
} else if (returnLowerRange) {
78-
ptrToReturn = (uintptr_t)addr;
79-
} else {
80-
ptrToReturn = (uintptr_t)MAP_FAILED;
81-
}
40+
uintptr_t ptrToReturn = startOf32MmapRegion + offsetIn32BitRange;
41+
offsetIn32BitRange += alignUp(length, MemoryConstants::pageSize);
8242

83-
return (void *)ptrToReturn;
43+
return reinterpret_cast<void *>(ptrToReturn);
8444
}
8545
int MockMunmap(void *addr, size_t length) noexcept {
8646
unmapCallCount++;
@@ -104,13 +64,8 @@ class MockAllocator32Bit : public Allocator32bit {
10464
resetState();
10565
}
10666
static void resetState() {
107-
fail32BitMmap = false;
108-
failUpperRange = false;
109-
failLowerRanger = false;
11067
failMmap = false;
11168
maxMmapLength = std::numeric_limits<size_t>::max();
112-
startUpperHeap = maxMmap32BitAddress;
113-
lowerRangeHeapStart = lowerRangeStart;
11469
offsetIn32BitRange = 0u;
11570
mmapCallCount = 0u;
11671
unmapCallCount = 0u;
@@ -123,4 +78,4 @@ class MockAllocator32Bit : public Allocator32bit {
12378

12479
OsInternals *getOsInternals() const { return this->osInternals.get(); }
12580
};
126-
} // namespace OCLRT
81+
} // namespace OCLRT

0 commit comments

Comments
 (0)