vinx13 commented on code in PR #14252:
URL: https://github.com/apache/tvm/pull/14252#discussion_r1131767137
##########
python/tvm/relax/backend/contrib/cutlass.py:
##########
@@ -51,21 +52,59 @@ def _is_supported_dtype(lhs_dtype, rhs_dtype):
)
-def _check_matmul(
- match_result: Mapping[DFPattern, Expr],
- _: Expr,
-) -> bool:
- matmul_call: Call = None
+def _find_call(op_name: str, match_result: Mapping[DFPattern, Expr]) ->
Optional[Expr]:
+ result = None
+
for pattern, expr in match_result.items():
if (
isinstance(expr, Call)
and isinstance(pattern, CallPattern)
and isinstance(expr.op, tvm.ir.Op)
- and expr.op.name == "relax.matmul"
+ and expr.op.name == op_name
):
- matmul_call = expr
+ if result is not None:
+ raise ValueError(f"Found multiple matched call node for
{op_name}")
+ result = expr
+
+ return result
+
+
+def _check_conv2d(
+ match_result: Mapping[DFPattern, Expr],
+ _: Expr,
+):
+ """Check if the given conv2d workload can be offloaded to CUTLASS."""
+
+ conv2d_call = _find_call("relax.nn.conv2d", match_result)
+ if conv2d_call is None:
+ return False
+
+ data_layout = conv2d_call.attrs.data_layout
+ kernel_layout = conv2d_call.attrs.kernel_layout
+ data, weight, *_ = conv2d_call.args
+ if (
+ data_layout != "NHWC"
+ or kernel_layout != "OHWI"
+ or not _is_supported_dtype(data.struct_info.dtype,
weight.struct_info.dtype)
+ ):
+ return False
+
+ # pylint: disable=invalid-name
+ IC = data.struct_info.shape.values[3]
+ OC = weight.struct_info.shape.values[0]
+ # not depthwise conv2d
Review Comment:
the codegen part for depthwise is still missing
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]