Skip to content
Closed
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
18 changes: 17 additions & 1 deletion python/tvm/relay/op/strategy/arm_cpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
# pylint: disable=invalid-name,unused-argument,wildcard-import,unused-wildcard-import
import re

from tvm import relay, topi
from tvm import relay, topi, tir

from ....auto_scheduler import is_auto_scheduler_enabled
from ....meta_schedule import is_meta_schedule_enabled
Expand Down Expand Up @@ -558,6 +558,22 @@ def schedule_dense_arm_cpu(attrs, inputs, out_type, target):
name="dense_dsp.arm_cpu",
)
else:
# For dynamic matrix-vector multiply we use a hand written kernel.
if (
isinstance(inputs[0].shape[0], (int, tir.IntImm))
and inputs[0].shape[0] == 1
and (
topi.utils.is_dynamic_shape(inputs[0].shape)
or topi.utils.is_dynamic_shape(inputs[1].shape)
)
):
strategy.add_implementation(
wrap_compute_dense(topi.x86.dense_dynamic),
wrap_topi_schedule(topi.x86.schedule_dense_dynamic),
name="dense_dynamic.x86",
plevel=20,
)
return strategy
logger.warning("dense is not optimized for arm cpu.")
strategy.add_implementation(
wrap_compute_dense(
Expand Down
9 changes: 4 additions & 5 deletions python/tvm/relay/op/strategy/x86.py
Original file line number Diff line number Diff line change
Expand Up @@ -507,10 +507,6 @@ def matmul_strategy_cpu(attrs, inputs, out_type, target):
return strategy


def is_dynamic_shape(shape):
return any([isinstance(x, (tir.Any, tir.SizeVar)) for x in shape])


@dense_strategy.register("cpu")
def dense_strategy_cpu(attrs, inputs, out_type, target):
"""dense x86 strategy"""
Expand All @@ -520,7 +516,10 @@ def dense_strategy_cpu(attrs, inputs, out_type, target):
if (
isinstance(inputs[0].shape[0], (int, tir.IntImm))
and inputs[0].shape[0] == 1
and (is_dynamic_shape(inputs[0].shape) or is_dynamic_shape(inputs[1].shape))
and (
topi.utils.is_dynamic_shape(inputs[0].shape)
or topi.utils.is_dynamic_shape(inputs[1].shape)
)
):
strategy.add_implementation(
wrap_compute_dense(topi.x86.dense_dynamic),
Expand Down
5 changes: 5 additions & 0 deletions python/tvm/topi/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -534,3 +534,8 @@ def is_target(names):
names = [names] if isinstance(names, str) else names
target = tvm.target.Target.current(allow_none=False)
return any(name in target.keys for name in names)


def is_dynamic_shape(shape):
"""Checks if any part of a shape is dynamic"""
return any([isinstance(x, (tir.Any, tir.SizeVar)) for x in shape])