Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions src/gpgmm/common/DedicatedMemoryAllocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,7 @@ namespace gpgmm {
mStats.UsedBlockCount++;
mStats.UsedBlockUsage += allocation->GetSize();

allocation->SetOffset(0);
allocation->SetAllocator(this);
allocation->SetBlock(new MemoryBlock{0, allocation->GetSize()});

return allocation;
}
Expand All @@ -60,11 +58,9 @@ namespace gpgmm {

std::lock_guard<std::mutex> lock(mMutex);

MemoryBlock* block = allocation->GetBlock();
mStats.UsedBlockCount--;
mStats.UsedBlockUsage -= block->Size;
mStats.UsedBlockUsage -= allocation->GetSize();

SafeDelete(block);
GetNextInChain()->DeallocateMemory(std::move(allocation));
}

Expand Down
9 changes: 5 additions & 4 deletions src/gpgmm/common/DedicatedMemoryAllocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@

namespace gpgmm {

// DedicatedMemoryAllocator allocates from device memory with exactly one block.
// DedicatedMemoryAllocator is useful in situations where whole memory objects could be reused
// without the need for sub-allocation. DedicatedMemoryAllocator also allows
// memory to be tracked.
// DedicatedMemoryAllocator always allocates the entire region of memory.
// This is useful in situations where entire memory allocations could be reused
// without the need for sub-allocation.
class DedicatedMemoryAllocator final : public MemoryAllocatorBase {
public:
// Constructs a dedicated allocation.
// The underlying |memoryAllocator| cannot be a sub-allocator.
DedicatedMemoryAllocator(ScopedRef<MemoryAllocatorBase> memoryAllocator,
uint64_t memoryAlignment);

Expand Down
2 changes: 2 additions & 0 deletions src/gpgmm/common/MemoryAllocation.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ namespace gpgmm {
uint64_t mRequestSize;
#endif

// Assigns a contiguously allocated sub-region.
// When the entire allocation region gets assigned, |mBlock| will be nullptr.
MemoryBlock* mBlock;
};
} // namespace gpgmm
Expand Down