Skip to content

Commit

Permalink
[BYOC] Skip processed functions in FuseOpsByPattern and RunCodegen (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
vinx13 authored Feb 14, 2024
1 parent 07ecb34 commit 059f629
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/relax/transform/fuse_ops.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1199,7 +1199,8 @@ class CompositeFunctionAnnotator : public ExprMutator {
auto all_functions = mod->functions;
for (const auto& entry : all_functions) {
if (const auto* func = entry.second.as<FunctionNode>()) {
if (func->GetAttr<String>(attr::kComposite).defined()) {
if (func->GetAttr<String>(attr::kComposite).defined() ||
func->GetAttr<String>(attr::kCodegen).defined()) {
continue;
}
auto new_body = VisitExpr(func->body);
Expand Down Expand Up @@ -1270,6 +1271,13 @@ IRModule FuseOpsByPattern(const tvm::Array<transform::FusionPattern>& patterns,
if (entry.second->IsInstance<tir::PrimFuncNode>()) {
continue;
}
const FunctionNode* function = entry.second.as<FunctionNode>();
if (function->GetAttr<Integer>(attr::kPrimitive).defined() ||
function->GetAttr<String>(attr::kComposite).defined() ||
function->GetAttr<String>(attr::kCodegen).defined()) {
continue;
}

auto map = PatternBasedPartitioner::Run(pattern->name, pattern->pattern,
pattern->annotation_patterns,
pattern->check.value_or(nullptr), entry.second,
Expand Down
9 changes: 9 additions & 0 deletions tests/python/relax/test_transform_fuse_ops_by_pattern.py
Original file line number Diff line number Diff line change
Expand Up @@ -1046,5 +1046,14 @@ def main(
assert "fused_relax_permute_dims_relax_matmul_cublas" in func_names # add is not fused


def test_multple_runs():
check(
Conv2dReLU_composite_annotated,
[("dnnl.conv2d_relu", conv2d_relu_pat)],
Conv2dReLU_composite_annotated,
annotate_codegen=True,
)


if __name__ == "__main__":
pytest.main([__file__])

0 comments on commit 059f629

Please sign in to comment.