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: 1 addition & 1 deletion codegen/gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ def __call__(
f"""
Kernel(
"{f.namespace}::{f.func.name}",{newline + '"' + (k + '",') if k != "default" else ""}
[]({contextArg.defn()}, EValue** stack) {{
[]({contextArg.defn()}, Span<EValue*> stack) {{
{code_connector.join(code_list)}
{exception_boundary_begin}
Expand Down
8 changes: 4 additions & 4 deletions codegen/test/test_executorch_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ def test_codegen_unboxed_specialized(self) -> None:
Kernel(
"custom_1::op_1",
"v1/7;0,1,2,3|7;0,1,2,3|7;0,1,2,3",
[](torch::executor::KernelRuntimeContext & context, EValue** stack) {
[](torch::executor::KernelRuntimeContext & context, Span<EValue*> stack) {
"""
+ """
Expand Down Expand Up @@ -605,7 +605,7 @@ def test_codegen_unboxed_default(self) -> None:
"""
Kernel(
"custom_1::op_1",
[](torch::executor::KernelRuntimeContext & context, EValue** stack) {
[](torch::executor::KernelRuntimeContext & context, Span<EValue*> stack) {
"""
+ """
Expand All @@ -632,7 +632,7 @@ def test_codegen_unboxed_default(self) -> None:
"""
Kernel(
"custom_1::op_1",
[](torch::executor::KernelRuntimeContext & context, EValue** stack) {
[](torch::executor::KernelRuntimeContext & context, Span<EValue*> stack) {
"""
+ """
Expand Down Expand Up @@ -675,7 +675,7 @@ def test_codegen_unboxed_default_kernel_key_selected(self) -> None:
"""
Kernel(
"custom_1::op_1",
[](torch::executor::KernelRuntimeContext & context, EValue** stack) {
[](torch::executor::KernelRuntimeContext & context, Span<EValue*> stack) {
"""
+ """
Expand Down
6 changes: 3 additions & 3 deletions extension/kernel_util/make_boxed_from_unboxed_functor.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ struct evalue_to_arg<executorch::aten::ArrayRef<std::optional<T>>> final {

template <class Functor, size_t... evalue_arg_indices, typename... ArgTypes>
void call_functor_with_args_from_stack(
::executorch::runtime::KernelRuntimeContext& ctx,
executorch::runtime::EValue** stack,
executorch::runtime::KernelRuntimeContext& ctx,
executorch::runtime::Span<executorch::runtime::EValue*> stack,
std::index_sequence<evalue_arg_indices...>,
typelist<ArgTypes...>*) {
(*Functor::func_ptr())(
Expand Down Expand Up @@ -151,7 +151,7 @@ struct WrapUnboxedIntoFunctor {

static void call(
::executorch::runtime::KernelRuntimeContext& ctx,
executorch::runtime::EValue** stack) {
executorch::runtime::Span<executorch::runtime::EValue*> stack) {
constexpr size_t num_inputs =
kernel_util_internal::size<ContextRemovedArgsType>::value;
return kernel_util_internal::call_functor_with_args_from_stack<FuncType>(
Expand Down
2 changes: 1 addition & 1 deletion kernels/prim_ops/et_copy_index.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ constexpr size_t kTensorDimensionLimit = 16;
//
// The output of each iteration (copy_from) is copied into the copy_to tensor at
// the specified index. This operator is supported in both ATen and lean modes.
void et_copy_index(KernelRuntimeContext& context, EValue** stack) {
void et_copy_index(KernelRuntimeContext& context, Span<EValue*> stack) {
(void)context;
SizesType expected_output_size[kTensorDimensionLimit];

Expand Down
3 changes: 2 additions & 1 deletion kernels/prim_ops/et_copy_index.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@
#pragma once

#include <executorch/runtime/core/evalue.h>
#include <executorch/runtime/core/span.h>
#include <executorch/runtime/kernel/kernel_runtime_context.h>

namespace torch {
namespace executor {
namespace function {

void et_copy_index(KernelRuntimeContext& context, EValue** stack);
void et_copy_index(KernelRuntimeContext& context, Span<EValue*> stack);

} // namespace function
} // namespace executor
Expand Down
2 changes: 1 addition & 1 deletion kernels/prim_ops/et_view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ bool get_view_target_size(
}
} // namespace

void et_view(KernelRuntimeContext& context, EValue** stack) {
void et_view(KernelRuntimeContext& context, Span<EValue*> stack) {
(void)context;

auto self = (*stack[0]).toTensor();
Expand Down
3 changes: 2 additions & 1 deletion kernels/prim_ops/et_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@
#pragma once

#include <executorch/runtime/core/evalue.h>
#include <executorch/runtime/core/span.h>
#include <executorch/runtime/kernel/kernel_runtime_context.h>

namespace torch {
namespace executor {
namespace function {

void et_view(KernelRuntimeContext& context, EValue** stack);
void et_view(KernelRuntimeContext& context, Span<EValue*> stack);

} // namespace function
} // namespace executor
Expand Down
50 changes: 25 additions & 25 deletions kernels/prim_ops/register_prim_ops.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ static Kernel prim_ops[] = {
// aten::sym_size.int(Tensor self, int dim) -> SymInt
Kernel(
"aten::sym_size.int",
[](KernelRuntimeContext& context, EValue** stack) {
[](KernelRuntimeContext& context, Span<EValue*> stack) {
(void)context;
EValue& self = *stack[0];
EValue& dim = *stack[1];
Expand All @@ -93,7 +93,7 @@ static Kernel prim_ops[] = {
// aten::_local_scalar_dense(Tensor self) -> Scalar
Kernel(
"aten::_local_scalar_dense",
[](KernelRuntimeContext& context, EValue** stack) {
[](KernelRuntimeContext& context, Span<EValue*> stack) {
(void)context;
EValue& self = *stack[0];
EValue& out = *stack[1];
Expand All @@ -112,7 +112,7 @@ static Kernel prim_ops[] = {
// aten::sym_numel(Tensor self) -> SymInt
Kernel(
"aten::sym_numel",
[](KernelRuntimeContext& context, EValue** stack) {
[](KernelRuntimeContext& context, Span<EValue*> stack) {
(void)context;
EValue& self = *stack[0];
EValue& out = *stack[1];
Expand All @@ -124,7 +124,7 @@ static Kernel prim_ops[] = {
// executorch_prim::sym_max.Scalar(SymInt a, SymInt b) -> SymInt
Kernel(
"executorch_prim::sym_max.Scalar",
[](KernelRuntimeContext& context, EValue** stack) {
[](KernelRuntimeContext& context, Span<EValue*> stack) {
(void)context;
EValue& a = *stack[0];
EValue& b = *stack[1];
Expand All @@ -145,7 +145,7 @@ static Kernel prim_ops[] = {
// executorch_prim::sym_min.Scalar(SymInt a, SymInt b) -> SymInt
Kernel(
"executorch_prim::sym_min.Scalar",
[](KernelRuntimeContext& context, EValue** stack) {
[](KernelRuntimeContext& context, Span<EValue*> stack) {
(void)context;
EValue& a = *stack[0];
EValue& b = *stack[1];
Expand All @@ -166,22 +166,22 @@ static Kernel prim_ops[] = {
// executorch_prim::add.Scalar(Scalar, Scalar) -> Scalar
Kernel(
"executorch_prim::add.Scalar",
[](KernelRuntimeContext& context, EValue** stack) {
[](KernelRuntimeContext& context, Span<EValue*> stack) {
(void)context;
ALGEBRA_ET_PRIM_OP(+, stack, context);
}),

// executorch_prim::sub.Scalar(Scalar, Scalar) -> Scalar
Kernel(
"executorch_prim::sub.Scalar",
[](KernelRuntimeContext& context, EValue** stack) {
[](KernelRuntimeContext& context, Span<EValue*> stack) {
ALGEBRA_ET_PRIM_OP(-, stack, context);
}),

// executorch_prim::mul.Scalar(Scalar, Scalar) -> Scalar
Kernel(
"executorch_prim::mul.Scalar",
[](KernelRuntimeContext& context, EValue** stack) {
[](KernelRuntimeContext& context, Span<EValue*> stack) {
ALGEBRA_ET_PRIM_OP(*, stack, context);
}),

Expand All @@ -196,7 +196,7 @@ static Kernel prim_ops[] = {
*/
Kernel(
"executorch_prim::floordiv.Scalar",
[](KernelRuntimeContext& context, EValue** stack) {
[](KernelRuntimeContext& context, Span<EValue*> stack) {
(void)context;
EValue& a = *stack[0];
EValue& b = *stack[1];
Expand Down Expand Up @@ -231,7 +231,7 @@ static Kernel prim_ops[] = {
// executorch_prim::floordiv.Scalar(Scalar, Scalar) -> Scalar
Kernel(
"executorch_prim::truediv.Scalar",
[](KernelRuntimeContext& context, EValue** stack) {
[](KernelRuntimeContext& context, Span<EValue*> stack) {
// can't use macro because of custom casting behavior
(void)context;
EValue& a = *stack[0];
Expand Down Expand Up @@ -262,7 +262,7 @@ static Kernel prim_ops[] = {
// executorch_prim::sym_float.Scalar(Scalar) -> Scalar
Kernel(
"executorch_prim::sym_float.Scalar",
[](KernelRuntimeContext& context, EValue** stack) {
[](KernelRuntimeContext& context, Span<EValue*> stack) {
// can't use macro because of custom casting behavior
// TODO: Now that we are reliably generating conversion operators,
// we can remove the mixed type handling for other operators
Expand All @@ -283,41 +283,41 @@ static Kernel prim_ops[] = {
// executorch_prim::eq.Scalar(Scalar, Scalar) -> bool
Kernel(
"executorch_prim::eq.Scalar",
[](KernelRuntimeContext& context, EValue** stack) {
[](KernelRuntimeContext& context, Span<EValue*> stack) {
BOOLEAN_ET_PRIM_OP(==, stack, context);
}),

// executorch_prim::gt.Scalar(Scalar, Scalar) -> bool
Kernel(
"executorch_prim::gt.Scalar",
[](KernelRuntimeContext& context, EValue** stack) {
[](KernelRuntimeContext& context, Span<EValue*> stack) {
BOOLEAN_ET_PRIM_OP(>, stack, context);
}),

// executorch_prim::lt.Scalar(Scalar, Scalar) -> bool
Kernel(
"executorch_prim::lt.Scalar",
[](KernelRuntimeContext& context, EValue** stack) {
[](KernelRuntimeContext& context, Span<EValue*> stack) {
BOOLEAN_ET_PRIM_OP(<, stack, context);
}),

// executorch_prim::ge.Scalar(Scalar, Scalar) -> bool
Kernel(
"executorch_prim::ge.Scalar",
[](KernelRuntimeContext& context, EValue** stack) {
[](KernelRuntimeContext& context, Span<EValue*> stack) {
BOOLEAN_ET_PRIM_OP(>=, stack, context);
}),

// executorch_prim::le.Scalar(Scalar, Scalar) -> bool
Kernel(
"executorch_prim::le.Scalar",
[](KernelRuntimeContext& context, EValue** stack) {
[](KernelRuntimeContext& context, Span<EValue*> stack) {
BOOLEAN_ET_PRIM_OP(<=, stack, context);
}),
// executorch_prim::neg.Scalar(Scalar) -> Scalar
Kernel(
"executorch_prim::neg.Scalar",
[](KernelRuntimeContext& context, EValue** stack) {
[](KernelRuntimeContext& context, Span<EValue*> stack) {
(void)context;
EValue& a = *stack[0];
EValue& out = *stack[1];
Expand All @@ -334,7 +334,7 @@ static Kernel prim_ops[] = {
// executorch_prim::floordiv.int(int, int) -> int
Kernel(
"executorch_prim::floordiv.int",
[](KernelRuntimeContext& context, EValue** stack) {
[](KernelRuntimeContext& context, Span<EValue*> stack) {
(void)context;
EValue& a = *stack[0];
EValue& b = *stack[1];
Expand All @@ -345,7 +345,7 @@ static Kernel prim_ops[] = {
// executorch_prim::mod.int(int, int) -> int
Kernel(
"executorch_prim::mod.int",
[](KernelRuntimeContext& context, EValue** stack) {
[](KernelRuntimeContext& context, Span<EValue*> stack) {
(void)context;
EValue& a = *stack[0];
EValue& b = *stack[1];
Expand All @@ -356,7 +356,7 @@ static Kernel prim_ops[] = {
// executorch_prim::mod.Scalar(Scalar, Scalar) -> Scalar
Kernel(
"executorch_prim::mod.Scalar",
[](KernelRuntimeContext& context, EValue** stack) {
[](KernelRuntimeContext& context, Span<EValue*> stack) {
(void)context;
EValue& a = *stack[0];
EValue& b = *stack[1];
Expand All @@ -378,7 +378,7 @@ static Kernel prim_ops[] = {
// ceil.Scalar(Scalar a) -> Scalar
Kernel(
"executorch_prim::ceil.Scalar",
[](KernelRuntimeContext& context, EValue** stack) {
[](KernelRuntimeContext& context, Span<EValue*> stack) {
(void)context;
EValue& a = *stack[0];
EValue& out = *stack[1];
Expand All @@ -398,7 +398,7 @@ static Kernel prim_ops[] = {
// round.Scalar(Scalar a) -> Scalar
Kernel(
"executorch_prim::round.Scalar",
[](KernelRuntimeContext& context, EValue** stack) {
[](KernelRuntimeContext& context, Span<EValue*> stack) {
(void)context;
EValue& a = *stack[0];
EValue& out = *stack[1];
Expand Down Expand Up @@ -435,7 +435,7 @@ static Kernel prim_ops[] = {
// trunc.Scalar(Scalar a) -> Scalar
Kernel(
"executorch_prim::trunc.Scalar",
[](KernelRuntimeContext& context, EValue** stack) {
[](KernelRuntimeContext& context, Span<EValue*> stack) {
(void)context;
EValue& a = *stack[0];
EValue& out = *stack[1];
Expand All @@ -450,13 +450,13 @@ static Kernel prim_ops[] = {
// executorch_prim::et_copy_index.tensor(tensor, tensor) -> tensor
Kernel(
"executorch_prim::et_copy_index.tensor",
[](KernelRuntimeContext& context, EValue** stack) {
[](KernelRuntimeContext& context, Span<EValue*> stack) {
et_copy_index(context, stack);
}),
// executorch_prim::et_view.default(Tensor, int[]) -> Tensor
Kernel(
"executorch_prim::et_view.default",
[](KernelRuntimeContext& context, EValue** stack) {
[](KernelRuntimeContext& context, Span<EValue*> stack) {
et_view(context, stack);
}),

Expand Down
2 changes: 2 additions & 0 deletions kernels/prim_ops/targets.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ def define_common_targets():
exported_headers = ["et_copy_index.h"],
deps = [
"//executorch/runtime/kernel:kernel_includes" + aten_suffix,
"//executorch/runtime/core:core",
],
exported_deps = [
"//executorch/runtime/core:evalue" + aten_suffix,
Expand All @@ -31,6 +32,7 @@ def define_common_targets():
exported_headers = ["et_view.h"],
deps = [
"//executorch/runtime/kernel:kernel_includes" + aten_suffix,
"//executorch/runtime/core:core",
],
exported_deps = [
"//executorch/runtime/core:evalue" + aten_suffix,
Expand Down
2 changes: 1 addition & 1 deletion runtime/executor/method.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1319,7 +1319,7 @@ Error Method::execute_instruction() {
// TODO(T147221312): Also expose tensor resizer via the context.
KernelRuntimeContext context(event_tracer_, temp_allocator_);
auto args = chain.argument_lists_[step_state_.instr_idx];
chain.kernels_[step_state_.instr_idx](context, args.data());
chain.kernels_[step_state_.instr_idx](context, args);
// We reset the temp_allocator after the switch statement
err = context.failure_state();
if (err != Error::Ok) {
Expand Down
2 changes: 1 addition & 1 deletion runtime/executor/method.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class Program;
class BackendDelegate;
struct Chain;
class KernelRuntimeContext;
using OpFunction = void (*)(KernelRuntimeContext&, EValue**);
using OpFunction = void (*)(KernelRuntimeContext&, Span<EValue*>);
/// A list of pointers into the master values table that together compose the
/// argument list for a single instruction
using InstructionArgs = Span<EValue*>;
Expand Down
5 changes: 3 additions & 2 deletions runtime/executor/test/executor_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ using executorch::ET_RUNTIME_NAMESPACE::registry_has_op_function;
using executorch::runtime::Error;
using executorch::runtime::EValue;
using executorch::runtime::Result;
using executorch::runtime::Span;
using executorch::runtime::testing::TensorFactory;

namespace pytree = ::executorch::extension::pytree;
Expand Down Expand Up @@ -165,7 +166,7 @@ TEST_F(ExecutorTest, EValueToScalar) {
ASSERT_EQ(s.to<int64_t>(), 2);
}

void test_op(KernelRuntimeContext& /*unused*/, EValue** /*unused*/) {}
void test_op(KernelRuntimeContext& /*unused*/, Span<EValue*> /*unused*/) {}

TEST_F(ExecutorTest, OpRegistration) {
auto s1 = register_kernel(Kernel("test", test_op));
Expand All @@ -182,7 +183,7 @@ TEST_F(ExecutorTest, OpRegistration) {
TEST_F(ExecutorTest, OpRegistrationWithContext) {
auto op = Kernel(
"test_op_with_context",
[](KernelRuntimeContext& context, EValue** values) {
[](KernelRuntimeContext& context, Span<EValue*> values) {
(void)context;
*(values[0]) = Scalar(100);
});
Expand Down
Loading
Loading