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
9 changes: 8 additions & 1 deletion kernels/prim_ops/et_copy_index.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,14 @@ 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, Span<EValue*> stack) {
(void)context;
ET_KERNEL_CHECK_MSG(
context,
stack.size() == 3,
InvalidProgram,
/* void */,
"Expected %zu args, got %zu",
(size_t)3,
stack.size());
SizesType expected_output_size[kTensorDimensionLimit];

auto copy_to = (*stack[0]).toTensor();
Expand Down
9 changes: 8 additions & 1 deletion kernels/prim_ops/et_view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,14 @@ bool get_view_target_size(
} // namespace

void et_view(KernelRuntimeContext& context, Span<EValue*> stack) {
(void)context;
ET_KERNEL_CHECK_MSG(
context,
stack.size() == 3,
InvalidProgram,
/* void */,
"Expected %zu args, got %zu",
(size_t)3,
stack.size());

auto self = (*stack[0]).toTensor();
auto size = (*stack[1]).toIntList();
Expand Down
150 changes: 133 additions & 17 deletions kernels/prim_ops/register_prim_ops.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ namespace {
}

#define __NUMBER_ET_PRIM_OP_IMPL(operator, stack, context) \
(void)context; \
EValue& a = *stack[0]; \
EValue& b = *stack[1]; \
EValue& out = *stack[2]; \
Expand All @@ -50,11 +49,23 @@ namespace {
out = EValue(a.toDouble() operator b.toInt()); \
}

#define __ET_PRIM_OP_NUM_ARGS_CHECK_IMPL(stack, context) \
ET_KERNEL_CHECK_MSG( \
context, \
stack.size() == 3, \
InvalidProgram, \
/* void */, \
"Expected %zu args, got %zu", \
(size_t)3, \
stack.size());

#define ALGEBRA_ET_PRIM_OP(operator, stack, context) \
__ET_PRIM_OP_NUM_ARGS_CHECK_IMPL(stack, context) \
__NUMBER_ET_PRIM_OP_IMPL(operator, stack, context) \
__ET_PRIM_OP_ERROR_IMPL(a, b, context)

#define BOOLEAN_ET_PRIM_OP(operator, stack, context) \
__ET_PRIM_OP_NUM_ARGS_CHECK_IMPL(stack, context) \
__NUMBER_ET_PRIM_OP_IMPL(operator, stack, context) \
else if (a.isBool() && b.isBool()) { \
out = EValue(a.toBool() operator b.toBool()); \
Expand All @@ -80,7 +91,14 @@ static Kernel prim_ops[] = {
Kernel(
"aten::sym_size.int",
[](KernelRuntimeContext& context, Span<EValue*> stack) {
(void)context;
ET_KERNEL_CHECK_MSG(
context,
stack.size() == 3,
InvalidProgram,
/* void */,
"Expected %zu args, got %zu",
(size_t)3,
stack.size());
EValue& self = *stack[0];
EValue& dim = *stack[1];
EValue& out = *stack[2];
Expand All @@ -94,7 +112,14 @@ static Kernel prim_ops[] = {
Kernel(
"aten::_local_scalar_dense",
[](KernelRuntimeContext& context, Span<EValue*> stack) {
(void)context;
ET_KERNEL_CHECK_MSG(
context,
stack.size() == 2,
InvalidProgram,
/* void */,
"Expected %zu args, got %zu",
(size_t)2,
stack.size());
EValue& self = *stack[0];
EValue& out = *stack[1];
executorch::aten::Tensor self_tensor =
Expand All @@ -113,7 +138,14 @@ static Kernel prim_ops[] = {
Kernel(
"aten::sym_numel",
[](KernelRuntimeContext& context, Span<EValue*> stack) {
(void)context;
ET_KERNEL_CHECK_MSG(
context,
stack.size() == 2,
InvalidProgram,
/* void */,
"Expected %zu args, got %zu",
(size_t)2,
stack.size());
EValue& self = *stack[0];
EValue& out = *stack[1];
executorch::aten::Tensor self_tensor =
Expand All @@ -125,7 +157,15 @@ static Kernel prim_ops[] = {
Kernel(
"executorch_prim::sym_max.Scalar",
[](KernelRuntimeContext& context, Span<EValue*> stack) {
(void)context;
ET_KERNEL_CHECK_MSG(
context,
stack.size() == 3,
InvalidProgram,
/* void */,
"Expected %zu args, got %zu",
(size_t)3,
stack.size());

EValue& a = *stack[0];
EValue& b = *stack[1];
EValue& out = *stack[2];
Expand All @@ -146,7 +186,14 @@ static Kernel prim_ops[] = {
Kernel(
"executorch_prim::sym_min.Scalar",
[](KernelRuntimeContext& context, Span<EValue*> stack) {
(void)context;
ET_KERNEL_CHECK_MSG(
context,
stack.size() == 3,
InvalidProgram,
/* void */,
"Expected %zu args, got %zu",
(size_t)3,
stack.size());
EValue& a = *stack[0];
EValue& b = *stack[1];
EValue& out = *stack[2];
Expand All @@ -167,7 +214,6 @@ static Kernel prim_ops[] = {
Kernel(
"executorch_prim::add.Scalar",
[](KernelRuntimeContext& context, Span<EValue*> stack) {
(void)context;
ALGEBRA_ET_PRIM_OP(+, stack, context);
}),

Expand Down Expand Up @@ -197,7 +243,14 @@ static Kernel prim_ops[] = {
Kernel(
"executorch_prim::floordiv.Scalar",
[](KernelRuntimeContext& context, Span<EValue*> stack) {
(void)context;
ET_KERNEL_CHECK_MSG(
context,
stack.size() == 3,
InvalidProgram,
/* void */,
"Expected %zu args, got %zu",
(size_t)3,
stack.size());
EValue& a = *stack[0];
EValue& b = *stack[1];
EValue& out = *stack[2];
Expand Down Expand Up @@ -233,7 +286,14 @@ static Kernel prim_ops[] = {
"executorch_prim::truediv.Scalar",
[](KernelRuntimeContext& context, Span<EValue*> stack) {
// can't use macro because of custom casting behavior
(void)context;
ET_KERNEL_CHECK_MSG(
context,
stack.size() == 3,
InvalidProgram,
/* void */,
"Expected %zu args, got %zu",
(size_t)3,
stack.size());
EValue& a = *stack[0];
EValue& b = *stack[1];
EValue& out = *stack[2];
Expand Down Expand Up @@ -266,7 +326,14 @@ static Kernel prim_ops[] = {
// 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
(void)context;
ET_KERNEL_CHECK_MSG(
context,
stack.size() == 2,
InvalidProgram,
/* void */,
"Expected %zu args, got %zu",
(size_t)2,
stack.size());
EValue& a = *stack[0];
EValue& out = *stack[1];
if (a.isInt()) {
Expand Down Expand Up @@ -318,7 +385,14 @@ static Kernel prim_ops[] = {
Kernel(
"executorch_prim::neg.Scalar",
[](KernelRuntimeContext& context, Span<EValue*> stack) {
(void)context;
ET_KERNEL_CHECK_MSG(
context,
stack.size() == 2,
InvalidProgram,
/* void */,
"Expected %zu args, got %zu",
(size_t)2,
stack.size());
EValue& a = *stack[0];
EValue& out = *stack[1];
if (a.isInt()) {
Expand All @@ -335,7 +409,14 @@ static Kernel prim_ops[] = {
Kernel(
"executorch_prim::floordiv.int",
[](KernelRuntimeContext& context, Span<EValue*> stack) {
(void)context;
ET_KERNEL_CHECK_MSG(
context,
stack.size() == 3,
InvalidProgram,
/* void */,
"Expected %zu args, got %zu",
(size_t)3,
stack.size());
EValue& a = *stack[0];
EValue& b = *stack[1];
EValue& out = *stack[2];
Expand All @@ -346,7 +427,14 @@ static Kernel prim_ops[] = {
Kernel(
"executorch_prim::mod.int",
[](KernelRuntimeContext& context, Span<EValue*> stack) {
(void)context;
ET_KERNEL_CHECK_MSG(
context,
stack.size() == 3,
InvalidProgram,
/* void */,
"Expected %zu args, got %zu",
(size_t)3,
stack.size());
EValue& a = *stack[0];
EValue& b = *stack[1];
EValue& out = *stack[2];
Expand All @@ -357,7 +445,14 @@ static Kernel prim_ops[] = {
Kernel(
"executorch_prim::mod.Scalar",
[](KernelRuntimeContext& context, Span<EValue*> stack) {
(void)context;
ET_KERNEL_CHECK_MSG(
context,
stack.size() == 3,
InvalidProgram,
/* void */,
"Expected %zu args, got %zu",
(size_t)3,
stack.size());
EValue& a = *stack[0];
EValue& b = *stack[1];
EValue& out = *stack[2];
Expand All @@ -379,7 +474,14 @@ static Kernel prim_ops[] = {
Kernel(
"executorch_prim::ceil.Scalar",
[](KernelRuntimeContext& context, Span<EValue*> stack) {
(void)context;
ET_KERNEL_CHECK_MSG(
context,
stack.size() == 2,
InvalidProgram,
/* void */,
"Expected %zu args, got %zu",
(size_t)2,
stack.size());
EValue& a = *stack[0];
EValue& out = *stack[1];
if (a.isDouble()) {
Expand All @@ -399,7 +501,14 @@ static Kernel prim_ops[] = {
Kernel(
"executorch_prim::round.Scalar",
[](KernelRuntimeContext& context, Span<EValue*> stack) {
(void)context;
ET_KERNEL_CHECK_MSG(
context,
stack.size() == 2,
InvalidProgram,
/* void */,
"Expected %zu args, got %zu",
(size_t)2,
stack.size());
EValue& a = *stack[0];
EValue& out = *stack[1];
if (a.isDouble()) {
Expand Down Expand Up @@ -436,7 +545,14 @@ static Kernel prim_ops[] = {
Kernel(
"executorch_prim::trunc.Scalar",
[](KernelRuntimeContext& context, Span<EValue*> stack) {
(void)context;
ET_KERNEL_CHECK_MSG(
context,
stack.size() == 2,
InvalidProgram,
/* void */,
"Expected %zu args, got %zu",
(size_t)2,
stack.size());
EValue& a = *stack[0];
EValue& out = *stack[1];
if (a.isDouble()) {
Expand Down
Loading
Loading