Skip to content

Commit a4ee59a

Browse files
tarun292facebook-github-bot
authored andcommitted
Adding executorch_prim::mod.Scalar (#5721)
Summary: Pull Request resolved: #5721 Adding mod.Scalar required by the Seamless ASR model example. Reviewed By: JacobSzwejbka Differential Revision: D63518182 fbshipit-source-id: b76ef5270d75a257216cdb6a218006156a2c48ce
1 parent 433ead0 commit a4ee59a

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-4
lines changed

examples/selective_build/test_selective_build.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ test_buck2_select_ops_in_list() {
4848
${PYTHON_EXECUTABLE} -m examples.portable.scripts.export --model_name="add_mul"
4949

5050
echo "Running selective build test"
51-
# set max_kernel_num=21: 19 primops, add, mul
51+
# set max_kernel_num=22: 19 primops, add, mul
5252
$BUCK run //examples/selective_build:selective_build_test \
53-
--config=executorch.max_kernel_num=21 \
53+
--config=executorch.max_kernel_num=22 \
5454
--config=executorch.select_ops=list \
5555
-- --model_path=./add_mul.pte
5656

@@ -117,11 +117,11 @@ test_cmake_select_ops_in_list() {
117117

118118
local example_dir=examples/selective_build
119119
local build_dir=cmake-out/${example_dir}
120-
# set MAX_KERNEL_NUM=21: 19 primops, add, mul
120+
# set MAX_KERNEL_NUM=22: 19 primops, add, mul
121121
rm -rf ${build_dir}
122122
retry cmake -DBUCK2="$BUCK" \
123123
-DCMAKE_BUILD_TYPE=Release \
124-
-DMAX_KERNEL_NUM=21 \
124+
-DMAX_KERNEL_NUM=22 \
125125
-DEXECUTORCH_SELECT_OPS_LIST="aten::convolution.out,\
126126
aten::_native_batch_norm_legit_no_training.out,aten::hardtanh.out,aten::add.out,\
127127
aten::mean.out,aten::view_copy.out,aten::permute_copy.out,aten::addmm.out,\

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)