Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions backends/mlx/ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@
TransposeNode,
TrilNode,
TriuNode,
TruncNode,
UpdateAndAttendNode,
VarNode,
VidOrTid,
Expand Down Expand Up @@ -384,6 +385,7 @@ def normalize_reduction_dim(
# Rounding
(torch.ops.aten.floor.default, FloorNode, "aten.floor"),
(torch.ops.aten.ceil.default, CeilNode, "aten.ceil"),
(torch.ops.aten.trunc.default, TruncNode, "aten.trunc"),
# Powers / roots
(torch.ops.aten.square.default, SquareNode, "aten.square"),
(torch.ops.aten.exp.default, ExpNode, "aten.exp"),
Expand Down
8 changes: 8 additions & 0 deletions backends/mlx/runtime/MLXInterpreter.h
Original file line number Diff line number Diff line change
Expand Up @@ -1545,6 +1545,11 @@ inline void exec_ceil(const CeilNode& n, ExecutionState& st, StreamOrDevice s) {
st.set_tensor(n.out, ceil(st.const_tensor_ref(n.x), s));
}

inline void
exec_trunc(const TruncNode& n, ExecutionState& st, StreamOrDevice s) {
st.set_tensor(n.out, trunc(st.const_tensor_ref(n.x), s));
}

inline void
exec_square(const SquareNode& n, ExecutionState& st, StreamOrDevice s) {
st.set_tensor(n.out, square(st.const_tensor_ref(n.x), s));
Expand Down Expand Up @@ -2236,6 +2241,9 @@ class Interpreter {
case OpCode::CEIL:
ops::exec_ceil(std::get<CeilNode>(instr.node), st, s);
break;
case OpCode::TRUNC:
ops::exec_trunc(std::get<TruncNode>(instr.node), st, s);
break;
case OpCode::SQUARE:
ops::exec_square(std::get<SquareNode>(instr.node), st, s);
break;
Expand Down
8 changes: 7 additions & 1 deletion backends/mlx/serialization/schema.fbs
Original file line number Diff line number Diff line change
Expand Up @@ -845,6 +845,11 @@ table NegNode {
out: Tid (required);
}

table TruncNode {
x: Tid (required);
out: Tid (required);
}

// =============================================================================
// Math ops - Binary element-wise
// =============================================================================
Expand Down Expand Up @@ -1191,7 +1196,8 @@ union OpNode {
BitwiseXorNode,
IfNode,
RandomBitsNode,
UpdateAndAttendNode
UpdateAndAttendNode,
TruncNode,
// BC: Add new op nodes here (append only)
}

Expand Down
1 change: 1 addition & 0 deletions backends/mlx/test/test_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -4819,6 +4819,7 @@ def create_model(self) -> nn.Module:
_UNARY_OP_TESTS = [
{"op_name": "floor", "op_fn": torch.floor, "shapes": _SHAPES_3, "input_fn": _input_fn(scale=10)},
{"op_name": "ceil", "op_fn": torch.ceil, "shapes": _SHAPES_3, "input_fn": _input_fn(scale=10)},
{"op_name": "trunc", "op_fn": torch.trunc, "shapes": _SHAPES_3, "input_fn": _input_fn(scale=10)},
{"op_name": "square", "op_fn": torch.square, "shapes": _SHAPES_3},
{"op_name": "exp", "op_fn": torch.exp, "shapes": _SHAPES_3},
{"op_name": "sin", "op_fn": torch.sin, "shapes": _SHAPES_3, "input_fn": _input_fn(scale=3.14159)},
Expand Down
Loading