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
31 changes: 17 additions & 14 deletions kernels/portable/cpu/util/elementwise_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#pragma once

#include <c10/util/irange.h>
#include <executorch/kernels/portable/cpu/selective_build.h>
#include <executorch/kernels/portable/cpu/util/broadcast_indexes_range.h>
#include <executorch/kernels/portable/cpu/util/broadcast_util.h>
#include <executorch/kernels/portable/cpu/util/dtype_util.h>
Expand Down Expand Up @@ -345,20 +346,22 @@ inline void apply_elementwise_fn(
}

constexpr auto compute_type = CppTypeToScalarType<CTYPE_COMPUTE>::value;
const bool all_inputs_compute_dtype =
((inputs.first->scalar_type() == compute_type) && ...);

constexpr ScalarType out_specialized_scalar_type =
specialized_output_scalar_type<CTYPE_COMPUTE>(out_dtypes);
if (all_inputs_compute_dtype &&
out.scalar_type() == out_specialized_scalar_type) {
using CTYPE_OUT =
typename ScalarTypeToCppType<out_specialized_scalar_type>::type;
dtype_specialized_elementwise_fn_impl<
CTYPE_COMPUTE,
CTYPE_OUT,
support_noncontiguous_tensors>(compute_fun, ctx, out, inputs...);
return;
if constexpr (should_include_kernel_dtype(op_name, compute_type)) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I got this wrong. Talked to @lucylq and she confirmed that dtype selective build is about input and output tensor types, not the compute type. My plan is to fix this on main (see PR #12183 ) and to just revert this PR from the release branch for safety.

const bool all_inputs_compute_dtype =
((inputs.first->scalar_type() == compute_type) && ...);

constexpr ScalarType out_specialized_scalar_type =
specialized_output_scalar_type<CTYPE_COMPUTE>(out_dtypes);
if (all_inputs_compute_dtype &&
out.scalar_type() == out_specialized_scalar_type) {
using CTYPE_OUT =
typename ScalarTypeToCppType<out_specialized_scalar_type>::type;
dtype_specialized_elementwise_fn_impl<
CTYPE_COMPUTE,
CTYPE_OUT,
support_noncontiguous_tensors>(compute_fun, ctx, out, inputs...);
return;
}
}

apply_elementwise_fn_generic_impl<
Expand Down
2 changes: 1 addition & 1 deletion kernels/portable/cpu/util/targets.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,10 @@ def define_common_targets():
":vectorized_math",
"//executorch/runtime/core/portable_type/c10/c10:aten_headers_for_executorch",
"//executorch/runtime/kernel:kernel_runtime_context",
"//executorch/kernels/portable/cpu:scalar_utils",
"//executorch/extension/threadpool:threadpool",
],
deps = [
"//executorch/kernels/portable/cpu:scalar_utils",
"//executorch/runtime/kernel:kernel_includes",
],
visibility = ["//executorch/kernels/portable/cpu/...", "//executorch/kernels/optimized/cpu/...", "@EXECUTORCH_CLIENTS"],
Expand Down
Loading