Skip to content

Commit

Permalink
Adding executorch_prim::mod.Scalar (#6133)
Browse files Browse the repository at this point in the history
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
(cherry picked from commit a4ee59a)

Co-authored-by: Tarun Karuturi <tkaruturi@meta.com>
  • Loading branch information
pytorchbot and tarun292 authored Oct 11, 2024
1 parent 539152b commit b077801
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
8 changes: 4 additions & 4 deletions examples/selective_build/test_selective_build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ test_buck2_select_ops_in_list() {
${PYTHON_EXECUTABLE} -m examples.portable.scripts.export --model_name="add_mul"

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

Expand Down Expand Up @@ -117,11 +117,11 @@ test_cmake_select_ops_in_list() {

local example_dir=examples/selective_build
local build_dir=cmake-out/${example_dir}
# set MAX_KERNEL_NUM=21: 19 primops, add, mul
# set MAX_KERNEL_NUM=22: 19 primops, add, mul
rm -rf ${build_dir}
retry cmake -DBUCK2="$BUCK" \
-DCMAKE_BUILD_TYPE=Release \
-DMAX_KERNEL_NUM=21 \
-DMAX_KERNEL_NUM=22 \
-DEXECUTORCH_SELECT_OPS_LIST="aten::convolution.out,\
aten::_native_batch_norm_legit_no_training.out,aten::hardtanh.out,aten::add.out,\
aten::mean.out,aten::view_copy.out,aten::permute_copy.out,aten::addmm.out,\
Expand Down
15 changes: 15 additions & 0 deletions kernels/prim_ops/register_prim_ops.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,21 @@ static Kernel prim_ops[] = {
out = EValue(a.toInt() % b.toInt());
}),

// executorch_prim::mod.Scalar(Scalar, Scalar) -> Scalar
Kernel(
"executorch_prim::mod.Scalar",
[](KernelRuntimeContext& context, EValue** stack) {
(void)context;
EValue& a = *stack[0];
EValue& b = *stack[1];
EValue& out = *stack[2];
if (a.isInt() && b.isInt()) {
out = EValue(a.toInt() % b.toInt());
} else {
ET_CHECK_MSG(false, "%zu, %zu", (size_t)a.tag, (size_t)b.tag);
}
}),

// executorch_prim::et_copy_index.tensor(tensor, tensor) -> tensor
Kernel("executorch_prim::et_copy_index.tensor", &et_copy_index),
// executorch_prim::et_view.default(Tensor, int[]) -> Tensor
Expand Down
3 changes: 3 additions & 0 deletions kernels/prim_ops/test/prim_ops_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ TEST_F(RegisterPrimOpsTest, TestAlgebraOps) {
getOpsFn("executorch_prim::mod.int")(context, stack);
EXPECT_EQ(stack[2]->toInt(), 3);

getOpsFn("executorch_prim::mod.Scalar")(context, stack);
EXPECT_EQ(stack[2]->toInt(), 3);

getOpsFn("executorch_prim::sym_float.Scalar")(context, stack);
EXPECT_FLOAT_EQ(stack[1]->toDouble(), 3.0);
}
Expand Down

0 comments on commit b077801

Please sign in to comment.