Skip to content

Empty tensor to alloc tensor

empty_tensor_to_alloc_tensor

EmptyTensorLoweringPattern

Bases: RewritePattern

Source code in xdsl/transforms/empty_tensor_to_alloc_tensor.py
12
13
14
15
16
17
18
19
20
21
class EmptyTensorLoweringPattern(RewritePattern):
    @op_type_rewrite_pattern
    def match_and_rewrite(self, op: tensor.EmptyOp, rewriter: PatternRewriter, /):
        rewriter.replace_op(
            op,
            bufferization.AllocTensorOp(
                op.tensor.type,
                op.dynamic_sizes,
            ),
        )

match_and_rewrite(op: tensor.EmptyOp, rewriter: PatternRewriter)

Source code in xdsl/transforms/empty_tensor_to_alloc_tensor.py
13
14
15
16
17
18
19
20
21
@op_type_rewrite_pattern
def match_and_rewrite(self, op: tensor.EmptyOp, rewriter: PatternRewriter, /):
    rewriter.replace_op(
        op,
        bufferization.AllocTensorOp(
            op.tensor.type,
            op.dynamic_sizes,
        ),
    )

EmptyTensorToAllocTensorPass dataclass

Bases: ModulePass

tensor.empty ops return a tensor of unspecified contents whose only purpose is to carry the tensor shape. This pass converts such ops to bufferization.alloc_tensor ops, which bufferize to buffer allocations.

Source code in xdsl/transforms/empty_tensor_to_alloc_tensor.py
24
25
26
27
28
29
30
31
32
33
34
35
36
37
class EmptyTensorToAllocTensorPass(ModulePass):
    """
    tensor.empty ops return a tensor of unspecified contents whose only purpose
    is to carry the tensor shape. This pass converts such ops to
    bufferization.alloc_tensor ops, which bufferize to buffer allocations.
    """

    name = "empty-tensor-to-alloc-tensor"

    def apply(self, ctx: Context, op: builtin.ModuleOp) -> None:
        PatternRewriteWalker(
            EmptyTensorLoweringPattern(),
            apply_recursively=False,
        ).rewrite_module(op)

name = 'empty-tensor-to-alloc-tensor' class-attribute instance-attribute

apply(ctx: Context, op: builtin.ModuleOp) -> None

Source code in xdsl/transforms/empty_tensor_to_alloc_tensor.py
33
34
35
36
37
def apply(self, ctx: Context, op: builtin.ModuleOp) -> None:
    PatternRewriteWalker(
        EmptyTensorLoweringPattern(),
        apply_recursively=False,
    ).rewrite_module(op)