[Bugfix][Relax] Raise exception for OOM allocation #16905
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
If the Relax VM attempts to allocate more memory than is available on the GPU, it should raise an exception. Prior to this commit, an out-of-memory exception instead triggered a segfault within
"vm.builtin.alloc_storage".When an allocation succeeds, the sequence of events is:
StorageObjinstance is constructed.alloc->Alloc, which returns the allocated buffer.StorageObj::buffer.StorageObj::allocator.However, when the GPU has insufficient memory, the sequence instead is:
StorageObjinstance is constructed.alloc->Alloc, which raises an out-of-memory exception.StorageObjdestructor is called.StorageObjdestructor callsallocator->Free(buffer). Since neitherallocatornorbufferhave been defined, this causes a segfault.This commit implements two independent fixes for this bug.
First, the
"vm.builtin.alloc_storage"function is reordered to callalloc->Alloc(...)before constructing theStorageObjinstance. If an exception is raised during the allocation, there is noStorageObjinstance whose destructor must be called.Second, the
StorageObj::allocatorfield is initialized tonullptrby default, and the destructor only callsallocator->Freeif theallocatoris non-null. This prevents a similar error from occurring at any other callsites that directly construct aStorageObj.