Skip to content
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

Add more mixed type of bfyx to eltwise_blocked_opt #27840

Merged
merged 1 commit into from
Dec 4, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ bool EltwiseKernel_blocked_opt::Validate(const Params& params) const {
}

const auto vec_size = SelectVecSizeFromFormat(ewParams.outputs[0]);
const auto input0 = ewParams.inputs[0];
const auto& input0 = ewParams.inputs[0];
const auto& output = ewParams.outputs[0];
// Check that padding before features doesn't mis-align the blocks
if (input0.Feature().pad.before % vec_size != 0 || output.Feature().pad.before % vec_size != 0)
Expand All @@ -137,11 +137,22 @@ bool EltwiseKernel_blocked_opt::Validate(const Params& params) const {
};

for (size_t i = 1; i < ewParams.inputs.size(); i++) {
if (ewParams.inputs[i].LogicalSize() == input0.LogicalSize() && !(compareTensors(ewParams.inputs[i], input0)))
const auto& input = ewParams.inputs[i];
if (input.LogicalSize() == input0.LogicalSize() && !(compareTensors(input, input0)))
return false;
if (ewParams.inputs[i].Feature().pad.before % vec_size != 0) {
if (input.Feature().pad.before % vec_size != 0) {
return false;
}
if (input.GetLayout() == DataLayout::bfyx) {
bool is_valid = input.LogicalSize() == 1; // Scalar value broadcast
is_valid |= input.LogicalSize() % vec_size == 0 && // Feature value broadcast
input.LogicalSize() == input.Feature().v &&
input.LogicalSize() == output.Feature().v &&
GetInnerBatchBlockSize(input) == 1;
if (!is_valid) {
return false;
}
}
}

return true;
Expand Down Expand Up @@ -422,6 +433,7 @@ static inline int SelectVecSizeFromFormat(const DataTensor& tensor) {
static inline int GetInnerBatchBlockSize(const DataTensor& tensor) {
auto layout = tensor.GetLayout();
switch (layout) {
case DataLayout::bfyx:
case DataLayout::b_fs_yx_fsv4:
case DataLayout::b_fs_yx_fsv16:
case DataLayout::b_fs_zyx_fsv16:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4711,6 +4711,11 @@ struct eltwise_layout_test_params {
#define CASE_ELTWISE_TEST7 eltwise_mode::sum, {4, 5, 4, 1}, {4, 1, 4, 1}, format::bfyx, format::b_fs_yx_fsv16, "generic_eltwise_ref"
#define CASE_ELTWISE_TEST8 eltwise_mode::sum, {4, 2, 4, 4}, {1, 1, 1, 1}, format::bfyx, format::b_fs_yx_fsv16, "generic_eltwise_ref"
#define CASE_ELTWISE_TEST9 eltwise_mode::eq, {4, 2, 4, 4}, {1, 1, 1, 1}, format::b_fs_yx_fsv16, format::bfyx, "generic_eltwise_ref"
#define CASE_ELTWISE_TEST10 eltwise_mode::sum, {4, 8, 1, 1}, {1, 8, 1, 1}, format::b_fs_yx_fsv32, format::bfyx, "eltwise_blocked_opt"
#define CASE_ELTWISE_TEST11 eltwise_mode::sum, {4, 8, 1, 1}, {1, 8, 1, 1}, format::b_fs_yx_fsv16, format::bfyx, "eltwise_blocked_opt"
#define CASE_ELTWISE_TEST12 eltwise_mode::sum, {4, 16, 4, 4}, {1, 16, 1, 1}, format::b_fs_yx_fsv16, format::bfyx, "eltwise_blocked_opt"
#define CASE_ELTWISE_TEST13 eltwise_mode::sum, {4, 7, 4, 4}, {1, 7, 1, 1}, format::b_fs_yx_fsv16, format::bfyx, "generic_eltwise_ref"
#define CASE_ELTWISE_TEST14 eltwise_mode::sum, {1, 8, 1, 1}, {4, 8, 1, 1}, format::bfyx, format::b_fs_yx_fsv32, "generic_eltwise_ref"

class eltwise_layout_test : public BaseEltwiseTest<eltwise_layout_test_params> {
public:
Expand Down Expand Up @@ -4800,6 +4805,11 @@ INSTANTIATE_TEST_SUITE_P(eltwise, eltwise_test_mixed_layout,
eltwise_layout_test_params{CASE_ELTWISE_TEST7},
eltwise_layout_test_params{CASE_ELTWISE_TEST8},
eltwise_layout_test_params{CASE_ELTWISE_TEST9},
eltwise_layout_test_params{CASE_ELTWISE_TEST10},
eltwise_layout_test_params{CASE_ELTWISE_TEST11},
eltwise_layout_test_params{CASE_ELTWISE_TEST12},
eltwise_layout_test_params{CASE_ELTWISE_TEST13},
eltwise_layout_test_params{CASE_ELTWISE_TEST14},
}));

//
Expand Down
Loading