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
11 changes: 4 additions & 7 deletions kernels/portable/cpu/util/dtype_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,14 @@ bool check_tensor_dtype(
case SupportedTensorDtypes::INTB:
return executorch::runtime::tensor_is_integral_type(t, true);
case SupportedTensorDtypes::BOOL_OR_BYTE:
return (
executorch::runtime::tensor_is_type(t, ScalarType::Bool) ||
executorch::runtime::tensor_is_type(t, ScalarType::Byte));
return (executorch::runtime::tensor_is_type(
t, ScalarType::Bool, ScalarType::Byte));
case SupportedTensorDtypes::SAME_AS_COMPUTE:
return executorch::runtime::tensor_is_type(t, compute_type);
case SupportedTensorDtypes::SAME_AS_COMMON: {
if (compute_type == ScalarType::Float) {
return (
executorch::runtime::tensor_is_type(t, ScalarType::Float) ||
executorch::runtime::tensor_is_type(t, ScalarType::Half) ||
executorch::runtime::tensor_is_type(t, ScalarType::BFloat16));
return (executorch::runtime::tensor_is_type(
t, ScalarType::Float, ScalarType::Half, ScalarType::BFloat16));
} else {
return executorch::runtime::tensor_is_type(t, compute_type);
}
Expand Down
31 changes: 31 additions & 0 deletions runtime/core/exec_aten/util/tensor_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,37 @@ inline bool tensor_is_type(
return true;
}

inline bool tensor_is_type(
executorch::aten::Tensor t,
executorch::aten::ScalarType dtype,
executorch::aten::ScalarType dtype2) {
ET_LOG_MSG_AND_RETURN_IF_FALSE(
t.scalar_type() == dtype || t.scalar_type() == dtype2,
"Expected to find %s or %s type, but tensor has type %s",
torch::executor::toString(dtype),
torch::executor::toString(dtype2),
torch::executor::toString(t.scalar_type()));

return true;
}

inline bool tensor_is_type(
executorch::aten::Tensor t,
executorch::aten::ScalarType dtype,
executorch::aten::ScalarType dtype2,
executorch::aten::ScalarType dtype3) {
ET_LOG_MSG_AND_RETURN_IF_FALSE(
t.scalar_type() == dtype || t.scalar_type() == dtype2 ||
t.scalar_type() == dtype3,
"Expected to find %s, %s, or %s type, but tensor has type %s",
torch::executor::toString(dtype),
torch::executor::toString(dtype2),
torch::executor::toString(dtype3),
torch::executor::toString(t.scalar_type()));

return true;
}

inline bool tensor_is_integral_type(
executorch::aten::Tensor t,
bool includeBool = false) {
Expand Down
Loading