Skip to content

Cleanup operator class #113

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
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
52 changes: 26 additions & 26 deletions kernels/prim_ops/register_prim_ops.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include <executorch/runtime/kernel/kernel_includes.h>
#include <executorch/runtime/kernel/operator_registry.h>

using OpArrayRef = ::torch::executor::ArrayRef<::torch::executor::Operator>;
using KernelArrayRef = ::torch::executor::ArrayRef<::torch::executor::Kernel>;
using torch::executor::function::et_copy_index;

namespace torch {
Expand All @@ -20,9 +20,9 @@ namespace function {

namespace {

static Operator prim_ops[] = {
static Kernel prim_ops[] = {
// aten::sym_size.int(Tensor self, int dim) -> SymInt
Operator(
Kernel(
"aten::sym_size.int",
[](RuntimeContext& context, EValue** stack) {
(void)context;
Expand All @@ -35,7 +35,7 @@ static Operator prim_ops[] = {
out = EValue(size);
}),
// aten::sym_numel(Tensor self) -> SymInt
Operator(
Kernel(
"aten::sym_numel",
[](RuntimeContext& context, EValue** stack) {
(void)context;
Expand All @@ -46,7 +46,7 @@ static Operator prim_ops[] = {
out = EValue(numel);
}),
// executorch_prim::add.Scalar(Scalar, Scalar) -> Scalar
Operator(
Kernel(
"executorch_prim::add.Scalar",
[](RuntimeContext& context, EValue** stack) {
(void)context;
Expand All @@ -64,7 +64,7 @@ static Operator prim_ops[] = {
}),

// executorch_prim::sub.Scalar(Scalar, Scalar) -> Scalar
Operator(
Kernel(
"executorch_prim::sub.Scalar",
[](RuntimeContext& context, EValue** stack) {
(void)context;
Expand All @@ -82,7 +82,7 @@ static Operator prim_ops[] = {
}),

// executorch_prim::mul.Scalar(Scalar, Scalar) -> Scalar
Operator(
Kernel(
"executorch_prim::mul.Scalar",
[](RuntimeContext& context, EValue** stack) {
(void)context;
Expand All @@ -100,7 +100,7 @@ static Operator prim_ops[] = {
}),

// executorch_prim::floordiv.Scalar(Scalar, Scalar) -> Scalar
Operator(
Kernel(
"executorch_prim::floordiv.Scalar",
[](RuntimeContext& context, EValue** stack) {
(void)context;
Expand All @@ -118,7 +118,7 @@ static Operator prim_ops[] = {
}),

// executorch_prim::eq.Scalar(Scalar, Scalar) -> bool
Operator(
Kernel(
"executorch_prim::eq.Scalar",
[](RuntimeContext& context, EValue** stack) {
(void)context;
Expand All @@ -138,7 +138,7 @@ static Operator prim_ops[] = {
}),

// executorch_prim::gt.Scalar(Scalar, Scalar) -> bool
Operator(
Kernel(
"executorch_prim::gt.Scalar",
[](RuntimeContext& context, EValue** stack) {
(void)context;
Expand All @@ -158,7 +158,7 @@ static Operator prim_ops[] = {
}),

// executorch_prim::lt.Scalar(Scalar, Scalar) -> bool
Operator(
Kernel(
"executorch_prim::lt.Scalar",
[](RuntimeContext& context, EValue** stack) {
(void)context;
Expand All @@ -178,7 +178,7 @@ static Operator prim_ops[] = {
}),

// executorch_prim::ge.Scalar(Scalar, Scalar) -> bool
Operator(
Kernel(
"executorch_prim::ge.Scalar",
[](RuntimeContext& context, EValue** stack) {
(void)context;
Expand All @@ -198,7 +198,7 @@ static Operator prim_ops[] = {
}),

// executorch_prim::le.Scalar(Scalar, Scalar) -> bool
Operator(
Kernel(
"executorch_prim::le.Scalar",
[](RuntimeContext& context, EValue** stack) {
(void)context;
Expand All @@ -220,7 +220,7 @@ static Operator prim_ops[] = {
// TODO(T159977211): wait a little bit so older models with these ops are
// regenerated and then delete them
// executorch_prim::add.int(int, int) -> int
Operator(
Kernel(
"executorch_prim::add.int",
[](RuntimeContext& context, EValue** stack) {
(void)context;
Expand All @@ -231,7 +231,7 @@ static Operator prim_ops[] = {
}),

// executorch_prim::sub.int(int, int) -> int
Operator(
Kernel(
"executorch_prim::sub.int",
[](RuntimeContext& context, EValue** stack) {
(void)context;
Expand All @@ -242,7 +242,7 @@ static Operator prim_ops[] = {
}),

// executorch_prim::mul.int(int, int) -> int
Operator(
Kernel(
"executorch_prim::mul.int",
[](RuntimeContext& context, EValue** stack) {
(void)context;
Expand All @@ -253,7 +253,7 @@ static Operator prim_ops[] = {
}),

// executorch_prim::floordiv.int(int, int) -> int
Operator(
Kernel(
"executorch_prim::floordiv.int",
[](RuntimeContext& context, EValue** stack) {
(void)context;
Expand All @@ -264,7 +264,7 @@ static Operator prim_ops[] = {
}),

// executorch_prim::eq.int(int, int) -> bool
Operator(
Kernel(
"executorch_prim::eq.int",
[](RuntimeContext& context, EValue** stack) {
(void)context;
Expand All @@ -275,7 +275,7 @@ static Operator prim_ops[] = {
}),

// executorch_prim::gt.int(int, int) -> bool
Operator(
Kernel(
"executorch_prim::gt.int",
[](RuntimeContext& context, EValue** stack) {
(void)context;
Expand All @@ -286,7 +286,7 @@ static Operator prim_ops[] = {
}),

// executorch_prim::lt.int(int, int) -> bool
Operator(
Kernel(
"executorch_prim::lt.int",
[](RuntimeContext& context, EValue** stack) {
(void)context;
Expand All @@ -297,7 +297,7 @@ static Operator prim_ops[] = {
}),

// executorch_prim::ge.int(int, int) -> bool
Operator(
Kernel(
"executorch_prim::ge.int",
[](RuntimeContext& context, EValue** stack) {
(void)context;
Expand All @@ -308,7 +308,7 @@ static Operator prim_ops[] = {
}),

// executorch_prim::le.int(int, int) -> bool
Operator(
Kernel(
"executorch_prim::le.int",
[](RuntimeContext& context, EValue** stack) {
(void)context;
Expand All @@ -319,17 +319,17 @@ static Operator prim_ops[] = {
}),

// executorch_prim::et_copy_index.tensor(tensor, tensor) -> tensor
Operator("executorch_prim::et_copy_index.tensor", &et_copy_index),
Kernel("executorch_prim::et_copy_index.tensor", &et_copy_index),

};

static OpArrayRef op_array_ref(
static KernelArrayRef kernel_array_ref(
prim_ops,
prim_ops + sizeof(prim_ops) / sizeof(Operator));
prim_ops + sizeof(prim_ops) / sizeof(Kernel));

// Return value not used. Keep the static variable assignment to register
// operators in static initialization time.
static auto success_with_op_reg = register_operators(op_array_ref);
static auto success_with_kernel_reg = register_kernels(kernel_array_ref);

} // namespace
} // namespace function
Expand Down
10 changes: 5 additions & 5 deletions runtime/executor/test/executor_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,25 +153,25 @@ TEST_F(ExecutorTest, EValueToScalar) {
void test_op(KernelRuntimeContext& /*unused*/, EValue** /*unused*/) {}

TEST_F(ExecutorTest, OpRegistration) {
auto s1 = register_operators({Operator("test", test_op)});
auto s2 = register_operators({Operator("test_2", test_op)});
auto s1 = register_kernels({Kernel("test", test_op)});
auto s2 = register_kernels({Kernel("test_2", test_op)});
ASSERT_EQ(Error::Ok, s1);
ASSERT_EQ(Error::Ok, s2);
ET_EXPECT_DEATH(
{ auto s3 = register_operators({Operator("test", test_op)}); }, "");
{ auto s3 = register_kernels({Kernel("test", test_op)}); }, "");

ASSERT_TRUE(hasOpsFn("test"));
ASSERT_TRUE(hasOpsFn("test_2"));
}

TEST_F(ExecutorTest, OpRegistrationWithContext) {
auto op = Operator(
auto op = Kernel(
"test_op_with_context",
[](KernelRuntimeContext& context, EValue** values) {
(void)context;
*(values[0]) = Scalar(100);
});
auto s1 = register_operators({op});
auto s1 = register_kernels({op});
ASSERT_EQ(Error::Ok, s1);
ASSERT_TRUE(hasOpsFn("test_op_with_context"));

Expand Down
Loading