Skip to content

Conversation

@HobbitQia
Copy link
Collaborator

For issue 196

@HobbitQia HobbitQia requested a review from tancheng December 30, 2025 03:02
@tancheng
Copy link
Contributor

Thanks @HobbitQia, can you paste the two DFGs in png here?

@tancheng tancheng requested a review from syifan December 30, 2025 03:09
@HobbitQia
Copy link
Collaborator Author

HobbitQia commented Dec 30, 2025

Thanks @HobbitQia, can you paste the two DFGs in png here?

Sure! Here I provided two DFGs before our transformations:

fir_kernel:
image

relu_kernel:
image

And I admit that here are some unnecessary nodes outside the core loop and I can try to remove them for cleanup.

@tancheng
Copy link
Contributor

Thanks @HobbitQia, I meant two DFGs for FIR. original and last level. Also, can you please include the FIR's mlir.llvm IR as well? I don't get the const -> br on the right side of your DFG. They may be viewed as "unnecessary nodes" by you, I am just wondering what are them.

@HobbitQia
Copy link
Collaborator Author

Thanks @HobbitQia, I meant two DFGs for FIR. original and last level. Also, can you please include the FIR's mlir.llvm IR as well? I don't get the const -> br on the right side of your DFG. They may be viewed as "unnecessary nodes" by you, I am just wondering what are them.

For FIR, the DFG before transformation:
image

the DFG after transformation:
image

And the IR before transformation:

%0 = llvm.mlir.constant(0 : i64) : i64
    %1 = llvm.mlir.constant(0 : i32) : i32
    %2 = llvm.mlir.constant(1 : i64) : i64
    %3 = llvm.mlir.constant(32 : i64) : i64
    llvm.br ^bb1(%0, %1 : i64, i32)
  ^bb1(%4: i64, %5: i32):  // 2 preds: ^bb0, ^bb1
    %6 = llvm.getelementptr inbounds %arg0[%4] : (!llvm.ptr, i64) -> !llvm.ptr, i32
    %7 = llvm.load %6 {alignment = 4 : i64, tbaa = [#tbaa_tag]} : !llvm.ptr -> i32
    %8 = llvm.getelementptr inbounds %arg2[%4] : (!llvm.ptr, i64) -> !llvm.ptr, i32
    %9 = llvm.load %8 {alignment = 4 : i64, tbaa = [#tbaa_tag]} : !llvm.ptr -> i32
    %10 = llvm.mul %9, %7 overflow<nsw> : i32
    %11 = llvm.add %10, %5 overflow<nsw> : i32
    %12 = llvm.add %4, %2 overflow<nsw, nuw> : i64
    %13 = llvm.icmp "eq" %12, %3 : i64
    llvm.cond_br %13, ^bb2, ^bb1(%12, %11 : i64, i32) {loop_annotation = #loop_annotation}
  ^bb2:  // pred: ^bb1
    llvm.return %11 : i32

I think some nodes that are constant or arguments of functions, which make the DFG look redundant. I am not sure whether I can remove them from DFG or not...

@tancheng
Copy link
Contributor

Oh, they are necessary. The issue is the dot or MLIR dot parser cannot represent br -> BB label correctly.

@tancheng tancheng linked an issue Dec 30, 2025 that may be closed by this pull request
@tancheng
Copy link
Contributor

Hi @syifan, two json files are generated for illustration of DFGs.

@tancheng tancheng merged commit 5e719bc into coredac:main Dec 30, 2025
1 check passed
@syifan
Copy link
Collaborator

syifan commented Dec 30, 2025

Got it. So what does the "transformation" do here?

@tancheng
Copy link
Contributor

Got it. So what does the "transformation" do here?

"transformation" transforms original ctrl flow IRs to dataflow IRs. For example, br is replaced with phi.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[P1] Generate DFG.png by default for kernels

3 participants