mlx/mlx/allocator.cpp

25 lines
487 B
C++
Raw Normal View History

2023-12-01 03:12:53 +08:00
// Copyright © 2023 Apple Inc.
2023-11-30 02:30:41 +08:00
#include <cstdlib>
#include <sstream>
#include "mlx/allocator.h"
namespace mlx::core::allocator {
Buffer malloc(size_t size) {
2025-03-21 07:48:43 +08:00
auto buffer = allocator().malloc(size);
2023-11-30 02: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) {
allocator().free(buffer);
2023-11-30 02:30:41 +08:00
}
} // namespace mlx::core::allocator