mirror of
https://github.com/ml-explore/mlx.git
synced 2025-07-25 20:11:19 +08:00
change initial memory limits and add memory size to device info (#1064)
This commit is contained in:
parent
02a9fc7bfa
commit
b00ac960b4
@ -140,10 +140,15 @@ void BufferCache::remove_from_list(BufferCache::BufferHolder* to_remove) {
|
|||||||
|
|
||||||
MetalAllocator::MetalAllocator()
|
MetalAllocator::MetalAllocator()
|
||||||
: device_(device(mlx::core::Device::gpu).mtl_device()),
|
: device_(device(mlx::core::Device::gpu).mtl_device()),
|
||||||
buffer_cache_(device_),
|
buffer_cache_(device_) {
|
||||||
block_limit_(1.5 * device_->recommendedMaxWorkingSetSize()),
|
auto memsize = std::get<size_t>(device_info()["memory_size"]);
|
||||||
gc_limit_(0.95 * device_->recommendedMaxWorkingSetSize()),
|
block_limit_ =
|
||||||
max_pool_size_(block_limit_) {}
|
std::min(1.5 * device_->recommendedMaxWorkingSetSize(), 0.95 * memsize);
|
||||||
|
gc_limit_ = std::min(
|
||||||
|
static_cast<size_t>(0.95 * device_->recommendedMaxWorkingSetSize()),
|
||||||
|
block_limit_);
|
||||||
|
max_pool_size_ = block_limit_;
|
||||||
|
}
|
||||||
|
|
||||||
size_t MetalAllocator::set_cache_limit(size_t limit) {
|
size_t MetalAllocator::set_cache_limit(size_t limit) {
|
||||||
std::swap(limit, max_pool_size_);
|
std::swap(limit, max_pool_size_);
|
||||||
|
@ -5,6 +5,8 @@
|
|||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
|
#include <sys/sysctl.h>
|
||||||
|
|
||||||
#define NS_PRIVATE_IMPLEMENTATION
|
#define NS_PRIVATE_IMPLEMENTATION
|
||||||
#define CA_PRIVATE_IMPLEMENTATION
|
#define CA_PRIVATE_IMPLEMENTATION
|
||||||
#define MTL_PRIVATE_IMPLEMENTATION
|
#define MTL_PRIVATE_IMPLEMENTATION
|
||||||
@ -560,11 +562,19 @@ std::unordered_map<std::string, std::variant<std::string, size_t>>
|
|||||||
device_info() {
|
device_info() {
|
||||||
auto raw_device = device(default_device()).mtl_device();
|
auto raw_device = device(default_device()).mtl_device();
|
||||||
auto arch = std::string(raw_device->architecture()->name()->utf8String());
|
auto arch = std::string(raw_device->architecture()->name()->utf8String());
|
||||||
|
|
||||||
|
int mib[] = {CTL_HW, HW_MEMSIZE};
|
||||||
|
size_t memsize = 0;
|
||||||
|
size_t length = sizeof(memsize);
|
||||||
|
|
||||||
|
sysctl(mib, 2, &memsize, &length, NULL, 0);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
{"architecture", arch},
|
{"architecture", arch},
|
||||||
{"max_buffer_length", raw_device->maxBufferLength()},
|
{"max_buffer_length", raw_device->maxBufferLength()},
|
||||||
{"max_recommended_working_set_size",
|
{"max_recommended_working_set_size",
|
||||||
raw_device->recommendedMaxWorkingSetSize()}};
|
raw_device->recommendedMaxWorkingSetSize()},
|
||||||
|
{"memory_size", memsize}};
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace mlx::core::metal
|
} // namespace mlx::core::metal
|
||||||
|
@ -129,6 +129,7 @@ void init_metal(nb::module_& m) {
|
|||||||
* ``architecture``
|
* ``architecture``
|
||||||
* ``max_buffer_size``
|
* ``max_buffer_size``
|
||||||
* ``max_recommended_working_set_size``
|
* ``max_recommended_working_set_size``
|
||||||
|
* ``memory_size``
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
dict: A dictionary with string keys and string or integer values.
|
dict: A dictionary with string keys and string or integer values.
|
||||||
|
Loading…
Reference in New Issue
Block a user