Skip to content

[mlir][py] NFC: remove exception-based isa from linalg module #92556

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

Merged
merged 1 commit into from
May 24, 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
5 changes: 2 additions & 3 deletions mlir/python/mlir/dialects/linalg/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
# TODO: guard against surprises and fail create Runtime Custom Ops with
# the same name as existing Core Named Ops.
from .opdsl.ops.core_named_ops import *
from .opdsl.lang.emitter import isa

from ...ir import *
from .._ods_common import get_op_result_or_value as _get_op_result_or_value
Expand All @@ -71,7 +70,7 @@ def transpose(
if len(outs) > 1:
raise ValueError(f"{outs=} must have length 1.")
init = _get_op_result_or_value(outs[0])
result_types = [init.type] if isa(RankedTensorType, init.type) else []
result_types = [init.type] if isinstance(init.type, RankedTensorType) else []

op = TransposeOp(
result=result_types,
Expand All @@ -93,7 +92,7 @@ def broadcast(
if len(outs) > 1:
raise ValueError(f"{outs=} must have length 1.")
init = _get_op_result_or_value(outs[0])
result_types = [init.type] if isa(RankedTensorType, init.type) else []
result_types = [init.type] if isinstance(init.type, RankedTensorType) else []

op = BroadcastOp(
result=result_types,
Expand Down
10 changes: 1 addition & 9 deletions mlir/python/mlir/dialects/linalg/opdsl/lang/emitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,6 @@
ValueList = Union[Sequence[Value], OpResultList]


def isa(cls: Type, ty: Type):
try:
cls(ty)
return True
except ValueError:
return False


def prepare_common_structured_op(
op_config: LinalgStructuredOpConfig,
*ins: Value,
Expand Down Expand Up @@ -127,7 +119,7 @@ def prepare_common_structured_op(
op_config, in_arg_defs, ins, out_arg_defs, outs
)

result_types = [t for t in out_types if isa(RankedTensorType, t)]
result_types = [t for t in out_types if isinstance(t, RankedTensorType)]

# Initialize the type dictionary with the predefined types.
type_mapping = dict() # type: Dict[str, Type]
Expand Down
Loading