Skip to content

Conversation

@Yun-Fly
Copy link
Contributor

@Yun-Fly Yun-Fly commented Aug 27, 2024

Automatically yield fused producer if it has multiple uses. E,g,

func.func @yield_fused_producer(%arg0: tensor<16x32x32xf32>) -> (tensor<16x32x32xf32>, tensor<16x32xf32>) {
    %cst_0 = arith.constant dense<2.000000e+00> : tensor<16x32x32xf32>
    %dest0 = tensor.empty() : tensor<16x32x32xf32>
    %0 = linalg.powf ins(%arg0, %cst_0 : tensor<16x32x32xf32>, tensor<16x32x32xf32>) outs(%dest0 : tensor<16x32x32xf32>) -> tensor<16x32x32xf32>
    %dest1 = tensor.empty() : tensor<16x32xf32>
    %1 = linalg.reduce { arith.addf } ins(%0 : tensor<16x32x32xf32>) outs(%dest1 : tensor<16x32xf32>) dimensions = [2]
    return %0, %1 : tensor<16x32x32xf32>, tensor<16x32xf32>
  }

When fusing powf into tiled consumer reduce, %0 should also be yield because it has two users. Otherwise, there would exist repeat powf computation.

@Yun-Fly Yun-Fly force-pushed the yunfei/yield_fused_producer branch from 7ab0442 to 3cfdafc Compare August 27, 2024 07:53
@Yun-Fly
Copy link
Contributor Author

Yun-Fly commented Aug 28, 2024

This patch is also helpful to debug intermediate result when correctness check failed.

@Yun-Fly Yun-Fly requested review from Menooker and ZhennanQin August 28, 2024 03:01
@Yun-Fly Yun-Fly force-pushed the yunfei/yield_fused_producer branch from 3cfdafc to 0f75ff9 Compare August 28, 2024 03:48
void notifyOperationErased(Operation *op) override {
// Call old listener hook.
if (auto *oldListener =
dyn_cast_if_present<RewriterBase::Listener>(oldListenerHook))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we need this cast?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

notifyOperationErased is just the member function of RewriterBase::Listener, which is the sub-class of OpBuilder::Listener.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Offline discussed.

@ZhennanQin ZhennanQin merged commit b593976 into main Aug 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Eliminate redundant computation when fusing producer with multiple uses

5 participants