mirror of
https://github.com/ml-explore/mlx.git
synced 2025-06-26 10:41:14 +08:00
Do not release buffers on exit (#1142)
This commit is contained in:
parent
987785d8d7
commit
2f83d6e4b7
@ -242,8 +242,17 @@ void MetalAllocator::free(Buffer buffer) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
MetalAllocator& allocator() {
|
MetalAllocator& allocator() {
|
||||||
static MetalAllocator allocator_;
|
// By creating the |allocator_| on heap, the destructor of MetalAllocator will
|
||||||
return allocator_;
|
// not be called on exit and all the buffers will be leaked. This is necessary
|
||||||
|
// because releasing buffers can take more than 30sec when the program holds a
|
||||||
|
// lot of RAM (for example inferencing a LLM), and it would feel frozen to
|
||||||
|
// users when exiting.
|
||||||
|
// TODO(zcbenz): Consider using the `base::NoDestructor` class from Chromium
|
||||||
|
// when applying this pattern to more places, or when introducing sanitizers
|
||||||
|
// to MLX.
|
||||||
|
// https://source.chromium.org/chromium/chromium/src/+/main:base/no_destructor.h
|
||||||
|
static MetalAllocator* allocator_ = new MetalAllocator;
|
||||||
|
return *allocator_;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t set_cache_limit(size_t limit) {
|
size_t set_cache_limit(size_t limit) {
|
||||||
|
Loading…
Reference in New Issue
Block a user