Unverified Commit 199f9141 authored by yassha's avatar yassha Committed by GitHub
Browse files

fix(cpu): add null check for aligned_alloc in ScratchPadManager (#37369)


Signed-off-by: default avataryassha <50112520+yassha@users.noreply.github.com>
parent ca21483b
...@@ -173,10 +173,13 @@ ScratchPadManager::ScratchPadManager() : size_(0), ptr_(nullptr) { ...@@ -173,10 +173,13 @@ ScratchPadManager::ScratchPadManager() : size_(0), ptr_(nullptr) {
void ScratchPadManager::realloc(size_t new_size) { void ScratchPadManager::realloc(size_t new_size) {
new_size = round(new_size); new_size = round(new_size);
if (new_size > size_) { if (new_size > size_) {
void* new_ptr = std::aligned_alloc(64, new_size);
TORCH_CHECK(new_ptr != nullptr,
"ScratchPadManager: aligned_alloc failed for size ", new_size);
if (ptr_ != nullptr) { if (ptr_ != nullptr) {
std::free(ptr_); std::free(ptr_);
} }
ptr_ = std::aligned_alloc(64, new_size); ptr_ = new_ptr;
size_ = new_size; size_ = new_size;
} }
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment