Skip to content

Commit d6eec88

Browse files
tarun292facebook-github-bot
authored andcommitted
Adding executorch_prim::mod.Scalar (#5721)
Summary: Adding mod.Scalar required by the Seamless ASR model example. Reviewed By: JacobSzwejbka Differential Revision: D63518182
1 parent 3aa6b14 commit d6eec88

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

kernels/prim_ops/register_prim_ops.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,21 @@ static Kernel prim_ops[] = {
286286
out = EValue(a.toInt() % b.toInt());
287287
}),
288288

289+
// executorch_prim::mod.Scalar(Scalar, Scalar) -> Scalar
290+
Kernel(
291+
"executorch_prim::mod.Scalar",
292+
[](KernelRuntimeContext& context, EValue** stack) {
293+
(void)context;
294+
EValue& a = *stack[0];
295+
EValue& b = *stack[1];
296+
EValue& out = *stack[2];
297+
if (a.isInt() && b.isInt()) {
298+
out = EValue(a.toInt() % b.toInt());
299+
} else {
300+
ET_CHECK_MSG(false, "%zu, %zu", (size_t)a.tag, (size_t)b.tag);
301+
}
302+
}),
303+
289304
// executorch_prim::et_copy_index.tensor(tensor, tensor) -> tensor
290305
Kernel("executorch_prim::et_copy_index.tensor", &et_copy_index),
291306
// executorch_prim::et_view.default(Tensor, int[]) -> Tensor

kernels/prim_ops/test/prim_ops_test.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,9 @@ TEST_F(RegisterPrimOpsTest, TestAlgebraOps) {
115115
getOpsFn("executorch_prim::mod.int")(context, stack);
116116
EXPECT_EQ(stack[2]->toInt(), 3);
117117

118+
getOpsFn("executorch_prim::mod.Scalar")(context, stack);
119+
EXPECT_EQ(stack[2]->toInt(), 3);
120+
118121
getOpsFn("executorch_prim::sym_float.Scalar")(context, stack);
119122
EXPECT_FLOAT_EQ(stack[1]->toDouble(), 3.0);
120123
}

0 commit comments

Comments
 (0)