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

[Relay][Strategy] Use x86 pool schedules for arm_cpu #15506

Merged
merged 2 commits into from
Aug 9, 2023
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
3 changes: 1 addition & 2 deletions python/tvm/relay/op/strategy/arm_cpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,7 @@ def schedule_pool_arm_cpu(attrs, outs, target):
and layout in ("NWC", "NHWC")
):
return topi.arm_cpu.schedule_pool(outs, layout)
logger.warning("pool is not optimized for arm cpu.")
return topi.generic.schedule_pool(outs, layout)
return topi.x86.schedule_pool(outs, layout)
ashutosh-arm marked this conversation as resolved.
Show resolved Hide resolved


def _get_padding_width(padding):
Expand Down
31 changes: 31 additions & 0 deletions tests/python/relay/strategy/test_select_implementation.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@

import pytest
import numpy as np
from unittest.mock import MagicMock

import tvm
from tvm import relay
from tvm import te
from tvm.relay.testing import run_infer_type
import tvm.testing
from tvm import topi


@pytest.mark.parametrize(
Expand Down Expand Up @@ -187,5 +189,34 @@ def test_dense(target, expected_valid_impl, expected_impl):
assert selected_impl.name == expected_impl


@pytest.mark.parametrize(
"target,schedule_func",
[
("llvm -device=arm_cpu", topi.x86),
("c -device=arm_cpu -mcpu=cortex-m55", topi.arm_cpu),
],
)
def test_pool2d(target, schedule_func, monkeypatch):
target = tvm.target.Target(target)

data_shape = (1, 2, 2, 4)
dtype = "float32"

out = relay.nn.avg_pool2d(relay.var("data", shape=data_shape, dtype=dtype))
placeholders = [te.placeholder(data_shape, dtype)]

mock_schedule = MagicMock()
monkeypatch.setattr(schedule_func, "schedule_pool", mock_schedule)

# Since pool does not use OpStrategy to determine the relevant schedule,
# we cannot simply check the schedule name that was selected with
# `select_implementation`. With this implementation of schedule selection,
# "pool.arm_cpu" will always be the schedule name, regardless of what schedule
# was selected. Instead, this test checks that the relevant schedule function
# is called when selecting the pooling from schedule from arm_cpu.
relay.op.strategy.arm_cpu.schedule_pool_arm_cpu(out.attrs, placeholders, target)
mock_schedule.assert_called()


if __name__ == "__main__":
tvm.testing.main()