2023-11-30 11:12:53 -08:00
|
|
|
// Copyright © 2023 Apple Inc.
|
|
|
|
|
|
2023-11-29 10:30:41 -08:00
|
|
|
#include <cstdlib>
|
|
|
|
|
#include <sstream>
|
|
|
|
|
|
|
|
|
|
#include "mlx/allocator.h"
|
|
|
|
|
|
|
|
|
|
namespace mlx::core::allocator {
|
|
|
|
|
|
|
|
|
|
Buffer malloc(size_t size) {
|
2025-03-20 16:48:43 -07:00
|
|
|
auto buffer = allocator().malloc(size);
|
2023-11-29 10:30:41 -08:00
|
|
|
if (size && !buffer.ptr()) {
|
|
|
|
|
std::ostringstream msg;
|
|
|
|
|
msg << "[malloc] Unable to allocate " << size << " bytes.";
|
|
|
|
|
throw std::runtime_error(msg.str());
|
|
|
|
|
}
|
|
|
|
|
return buffer;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void free(Buffer buffer) {
|
2024-11-18 19:17:01 -08:00
|
|
|
allocator().free(buffer);
|
2023-11-29 10:30:41 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace mlx::core::allocator
|