2025-06-09 22:45:08 +09:00
|
|
|
// Copyright © 2025 Apple Inc.
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include "mlx/allocator.h"
|
|
|
|
|
#include "mlx/backend/common/utils.h"
|
|
|
|
|
|
|
|
|
|
namespace mlx::core {
|
|
|
|
|
|
2025-11-05 16:05:23 -08:00
|
|
|
inline void set_unary_output_data(
|
|
|
|
|
const array& in,
|
|
|
|
|
array& out,
|
|
|
|
|
std::function<allocator::Buffer(size_t)> mallocfn = allocator::malloc) {
|
2025-06-09 22:45:08 +09:00
|
|
|
if (in.flags().contiguous) {
|
|
|
|
|
if (is_donatable(in, out)) {
|
|
|
|
|
out.copy_shared_buffer(in);
|
|
|
|
|
} else {
|
|
|
|
|
out.set_data(
|
2025-11-05 16:05:23 -08:00
|
|
|
mallocfn(in.data_size() * out.itemsize()),
|
2025-06-09 22:45:08 +09:00
|
|
|
in.data_size(),
|
|
|
|
|
in.strides(),
|
|
|
|
|
in.flags());
|
|
|
|
|
}
|
|
|
|
|
} else {
|
2025-11-05 16:05:23 -08:00
|
|
|
out.set_data(mallocfn(out.nbytes()));
|
2025-06-09 22:45:08 +09:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace mlx::core
|