Skip to content

Commit 39ee3b1

Browse files
committed
Update base for Update on "[Executorch] Use temp allocator for allocating scratch memory"
This allows us to leverage temp memory allocator and if that allocator is caching allocator it reduces the allocaiton overhead. Differential Revision: [D85532076](https://our.internmc.facebook.com/intern/diff/D85532076/) [ghstack-poisoned]
2 parents 0f9d6f4 + a09a4b7 commit 39ee3b1

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

extension/memory_allocator/cpu_caching_malloc_allocator.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ namespace executorch::extension {
66

77
namespace {
88
size_t get_alignment_adjusted_size(size_t size, size_t alignment) {
9-
alignment = std::max(alignment, kCachingAllocatorDefaultAlignment);
109
if (size % alignment != 0) {
1110
// Adjust size to the next multiple of alignment
1211
// This is needed for aligned_alloc to work
@@ -30,6 +29,7 @@ void* CPUCachingAllocator::allocate(size_t size, size_t alignment) {
3029
ET_LOG(Error, "Alignment %zu is not a power of 2", alignment);
3130
return nullptr;
3231
}
32+
alignment = std::max(alignment, kCachingAllocatorDefaultAlignment);
3333
size = get_alignment_adjusted_size(size, alignment);
3434

3535
std::lock_guard<std::mutex> guard(mutex_);
@@ -39,14 +39,14 @@ void* CPUCachingAllocator::allocate(size_t size, size_t alignment) {
3939
// 2. Allocate new memory
4040
// 2 can lead to current_size > max_size_
4141
if (it == available_map_.end() || it->second.empty()) {
42-
void* ptr = std::aligned_alloc(alignment, size);
42+
void* ptr = std::malloc(size);
4343
if (ptr == nullptr) {
4444
ET_LOG(Error, "Failed to allocate memory");
4545
return nullptr;
4646
}
4747
current_size_ += size;
4848
allocation_map_[ptr] = size;
49-
return ptr;
49+
return alignPointer(ptr, alignment);
5050
}
5151
void* ptr = it->second.back();
5252
it->second.pop_back();

0 commit comments

Comments
 (0)