Skip to content

Commit 2b4db21

Browse files
author
devsh
committed
add a test vase for GPAA
1 parent fd8ebfe commit 2b4db21

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

20_AllocatorTest/main.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,40 @@ class AllocatorTestApp final : public nbl::application_templates::MonoSystemMono
309309
if (!base_t::onAppInitialized(std::move(system)))
310310
return false;
311311

312+
// Special Test (repro by Erfan)
313+
{
314+
using AddressAllocator = nbl::core::GeneralpurposeAddressAllocator<uint64_t>;
315+
using ReservedAllocator = nbl::core::allocator<uint8_t>;
316+
317+
static constexpr uint64_t TotalSize = 14280 * 1024u; // safe choice based on hardware reports
318+
static constexpr uint64_t MaxMemoryAlignment = 4096u; // safe choice based on hardware reports
319+
static constexpr uint64_t MinAllocSize = 128 * 1024u; // 128KB, the larger this is the better
320+
321+
auto m_reservedAllocSize = AddressAllocator::reserved_size(MaxMemoryAlignment, TotalSize, MinAllocSize);
322+
auto m_reservedAllocator = std::unique_ptr<ReservedAllocator>(new ReservedAllocator());
323+
auto m_reservedAlloc = m_reservedAllocator->allocate(m_reservedAllocSize, _NBL_SIMD_ALIGNMENT);
324+
auto m_addressAllocator = std::unique_ptr<AddressAllocator>(new AddressAllocator(
325+
m_reservedAlloc, 0u, 0u, MaxMemoryAlignment, TotalSize, MinAllocSize
326+
));
327+
328+
// 1. Allocate with `14622720` successful, Free Size = 0
329+
auto offset1 = m_addressAllocator->alloc_addr(TotalSize, 1024u); assert(offset1 != AddressAllocator::invalid_address);
330+
// 2. Allocate with `9240576` fails (as expected), Free Size = 0
331+
auto offset2 = m_addressAllocator->alloc_addr(9240576, 1024u); assert(offset2 == AddressAllocator::invalid_address);
332+
// 3. Free Initial Allocation (size=14622720, offset=0) ==> Allocator Free Size=14622720
333+
m_addressAllocator->free_addr(offset1, TotalSize);
334+
335+
// 4. Allocate with `9240576` successful (as expected), Free Size = 5382144
336+
auto offset3 = m_addressAllocator->alloc_addr(9240576, 1024u); assert(offset3 != AddressAllocator::invalid_address);
337+
// 5. Allocate with `14622720` fails (as expected), Free Size = 5382144
338+
auto offset4 = m_addressAllocator->alloc_addr(TotalSize, 1024u); assert(offset4 == AddressAllocator::invalid_address);
339+
// 6. Free Second Allocation (size=9240576, offset=0) ==> Allocator Free Size=14622720
340+
m_addressAllocator->free_addr(offset3, 9240576);
341+
342+
// 7. Allocate with `14622720` fails (UNEXPECTED), Free Size = 0
343+
auto offset5 = m_addressAllocator->alloc_addr(TotalSize, 1024u); assert(offset5 != AddressAllocator::invalid_address);
344+
}
345+
312346
// Allocator test
313347
{
314348
{

0 commit comments

Comments
 (0)