Skip to content

Add a pass to initialize all remaining empty tensors to zero-filled tensors - #8749

Merged
MaheshRavishankar merged 1 commit into
iree-org:mainfrom
MaheshRavishankar:init_empty_tensors
Apr 5, 2022
Merged

MaheshRavishankar merged 1 commit into
iree-org:mainfrom
MaheshRavishankar:init_empty_tensors

Conversation

@MaheshRavishankar

@MaheshRavishankar MaheshRavishankar commented Apr 2, 2022 •

Copy link
Copy Markdown
Collaborator

After dispatch region formation, all remaining linalg.init_tensor
ops are converted to flow.tensor.splat ops as a fallback. Ideally
this should never happen and all linalg.init_tensor get fused with
their uses. But in cases where a front-end generates code where the
init_tensor escapes, this provides a safety net for it. The code is
still correct, but potentially uses more memory and is slower.

Fixes #8717

@MaheshRavishankar MaheshRavishankar changed the title Add a pass to initialize all remaining empty tensors to zero-filled t… Add a pass to initialize all remaining empty tensors to zero-filled tensors Apr 2, 2022
@MaheshRavishankar

Copy link
Copy Markdown
Collaborator Author

}
Value value =
rewriter.create<arith::ConstantOp>(loc, elementType, zero.getValue());
rewriter.replaceOpWithNewOp<TensorSplatOp>(initTensorOp, resultType, value,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

the splat only takes dynamic sizes, not all sizes - maybe that's the failure in the streams.mlir? (it has dynamic shapes)

…ensors.

After dispatch region formation, all remaining `linalg.init_tensor`
ops are converted to `flow.tensor.splat` ops as a fallback. Ideally
this should never happen and all `linalg.init_tensor` get fused with
their uses. But in cases where a front-end generates code where the
`init_tensor` escapes, this provides a safety net for it. The code is
still correct, but potentially uses more memory and is slower.

Fixes iree-org#8717
@MaheshRavishankar
MaheshRavishankar enabled auto-merge (squash) April 5, 2022 17:11
@MaheshRavishankar
MaheshRavishankar merged commit 43a4b76 into iree-org:main Apr 5, 2022
@MaheshRavishankar
MaheshRavishankar deleted the init_empty_tensors branch November 17, 2022 21:18
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.

init_tensor survives until VerifyLoweringToTensorsPass

2 participants