Skip to content

Add SupportedTensorDtypes::BOOL #9584

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

Open
wants to merge 2 commits into
base: gh/swolchok/396/head
Choose a base branch
from
Open
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: 2 additions & 0 deletions kernels/portable/cpu/util/dtype_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ bool check_tensor_dtype(
return executorch::runtime::tensor_is_floating_type(t);
case SupportedTensorDtypes::INTB:
return executorch::runtime::tensor_is_integral_type(t, true);
case SupportedTensorDtypes::BOOL:
return executorch::runtime::tensor_is_type(t, ScalarType::Bool);
case SupportedTensorDtypes::BOOL_OR_BYTE:
return (executorch::runtime::tensor_is_type(
t, ScalarType::Bool, ScalarType::Byte));
Expand Down
44 changes: 34 additions & 10 deletions kernels/portable/cpu/util/dtype_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,16 @@ load_to_compute_fn<CTYPE_COMPUTE> get_load_to_compute_fn_intb(const Tensor& t) {
return result;
}

template <typename CTYPE_COMPUTE, const char* op_name>
load_to_compute_fn<CTYPE_COMPUTE> get_load_to_compute_fn_bool(const Tensor& t) {
ET_CHECK_MSG(
t.scalar_type() == ScalarType::Bool,
"Unhandled dtype %s for %s",
::executorch::runtime::toString(t.scalar_type()),
op_name);
return internal::load_and_convert<CTYPE_COMPUTE, bool>;
}

template <typename CTYPE_COMPUTE, const char* op_name>
load_to_compute_fn<CTYPE_COMPUTE> get_load_to_compute_fn_bool_or_byte(
const Tensor& t) {
Expand Down Expand Up @@ -165,6 +175,17 @@ store_compute_to_tensor_fn<CTYPE_COMPUTE> get_store_compute_to_tensor_fn_intb(
return result;
}

template <typename CTYPE_COMPUTE, const char* op_name>
store_compute_to_tensor_fn<CTYPE_COMPUTE> get_store_compute_to_tensor_fn_bool(
const Tensor& t) {
ET_CHECK_MSG(
t.scalar_type() == ScalarType::Bool,
"Unhandled dtype %s for %s",
::executorch::runtime::toString(t.scalar_type()),
op_name);
return internal::convert_and_store<bool, CTYPE_COMPUTE>;
}

template <typename CTYPE_COMPUTE, const char* op_name>
store_compute_to_tensor_fn<CTYPE_COMPUTE>
get_store_compute_to_tensor_fn_bool_or_byte(const Tensor& t) {
Expand Down Expand Up @@ -219,6 +240,7 @@ enum class SupportedTensorDtypes {
REALHBF16,
FLOATHBF16,
INTB,
BOOL,
BOOL_OR_BYTE,
// DEPRECATED: not likely to be correct; use SAME_AS_COMMON.
SAME_AS_COMPUTE,
Expand All @@ -240,6 +262,8 @@ load_to_compute_fn<CTYPE_COMPUTE> get_load_to_compute_fn_impl(
return get_load_to_compute_fn_realhbf16<CTYPE_COMPUTE, op_name>(t);
case SupportedTensorDtypes::INTB:
return get_load_to_compute_fn_intb<CTYPE_COMPUTE, op_name>(t);
case SupportedTensorDtypes::BOOL:
return get_load_to_compute_fn_bool<CTYPE_COMPUTE, op_name>(t);
case SupportedTensorDtypes::BOOL_OR_BYTE:
return get_load_to_compute_fn_bool_or_byte<CTYPE_COMPUTE, op_name>(t);
case SupportedTensorDtypes::SAME_AS_COMPUTE:
Expand All @@ -261,20 +285,18 @@ store_compute_to_tensor_fn<CTYPE_COMPUTE> get_store_compute_to_tensor_fn(
SupportedTensorDtypes dtypes) {
switch (dtypes) {
case SupportedTensorDtypes::REALHBBF16:
return get_store_compute_to_tensor_fn_realhbbf16<CTYPE_COMPUTE, op_name>(
t);
return get_store_compute_to_tensor_fn_realhbbf16<CTYPE_COMPUTE, op_name>(t);
case SupportedTensorDtypes::REALHBF16:
return get_store_compute_to_tensor_fn_realhbf16<CTYPE_COMPUTE, op_name>(
t);
return get_store_compute_to_tensor_fn_realhbf16<CTYPE_COMPUTE, op_name>(t);
case SupportedTensorDtypes::FLOATHBF16:
return get_store_compute_to_tensor_fn_floathbf16<CTYPE_COMPUTE, op_name>(
t);
return get_store_compute_to_tensor_fn_floathbf16<CTYPE_COMPUTE, op_name>(t);
case SupportedTensorDtypes::INTB:
return get_store_compute_to_tensor_fn_intb<CTYPE_COMPUTE, op_name>(t);
case SupportedTensorDtypes::BOOL:
return get_store_compute_to_tensor_fn_bool<CTYPE_COMPUTE, op_name>(t);
case SupportedTensorDtypes::BOOL_OR_BYTE:
return get_store_compute_to_tensor_fn_bool_or_byte<
CTYPE_COMPUTE,
op_name>(t);
return get_store_compute_to_tensor_fn_bool_or_byte<CTYPE_COMPUTE, op_name>(
t);
case SupportedTensorDtypes::SAME_AS_COMPUTE:
return get_store_compute_to_tensor_fn_same_as_compute<
CTYPE_COMPUTE,
Expand Down Expand Up @@ -318,12 +340,14 @@ bool check_tensor_dtype(
const ScalarType compute_type);

/// Return the one output type we are willing to emit specialized code
/// to handle, given a compute type of CTYPE_COMMON and supported
/// to handle, given a compute type of CTYPE_COMPUTE and supported
/// output types of out_dtypes.
template <typename CTYPE_COMPUTE>
inline constexpr ScalarType specialized_output_scalar_type(
SupportedTensorDtypes out_dtypes) {
switch (out_dtypes) {
case SupportedTensorDtypes::BOOL:
return ScalarType::Bool;
case SupportedTensorDtypes::BOOL_OR_BYTE:
return ScalarType::Bool;
case SupportedTensorDtypes::REALHBBF16:
Expand Down
Loading