Skip to content

Commit

Permalink
[Inductor] Kill has_aliasing (pytorch#112875)
Browse files Browse the repository at this point in the history
Pull Request resolved: pytorch#112875
Approved by: https://github.com/Chillee
  • Loading branch information
oulgen authored and Skylion007 committed Nov 14, 2023
1 parent d416a00 commit 2f47b8f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 20 deletions.
29 changes: 13 additions & 16 deletions torch/_inductor/ir.py
Original file line number Diff line number Diff line change
Expand Up @@ -3855,9 +3855,6 @@ def create(cls, *, kernel_idx, grid, kernel_args):
if isinstance(arg, TensorBox):
MutationOutput(arg.layout, arg, packed)

def has_aliasing(self):
return True

def get_alias_names(self):
return [i.get_name() for i in self.inputs]

Expand All @@ -3879,9 +3876,6 @@ def is_no_op(self):
def has_side_effects(self):
return True

def has_aliasing(self):
return True

def get_alias_names(self):
return [self.inputs[0].get_name()]

Expand Down Expand Up @@ -4315,11 +4309,15 @@ def has_side_effects(self):
return False
return get_schema_info(self.op_overload).is_mutable()

def has_aliasing(self):
def get_alias_names(self):
# TODO - some fallbacks are still OpOverloadPackets
if not isinstance(self.op_overload, torch._ops.OpOverload):
return False
return torch._inductor.utils.is_view(self.op_overload)
return []
if torch._inductor.utils.is_view(self.op_overload):
# TODO - use op._schema.arguments alias_info to figure out
# precise list
return [inp.get_name() for inp in self.inputs]
return []

# ProxyExecutor Design Note
# We export the ExternFallbackNodes (for custom ops) into a serialized file
Expand Down Expand Up @@ -4494,9 +4492,6 @@ class ComplexView(ExternKernelAlloc):
def should_allocate(self):
return False

def has_aliasing(self):
return True

def get_alias_names(self):
# Signal to codegen that our output buffer isn't safe to reuse
return [self.inputs[0].get_name()]
Expand Down Expand Up @@ -4595,11 +4590,13 @@ def get_unbacked_symbol_uses(self):
def should_allocate(self):
return False

def has_aliasing(self):
return any(
isinstance(inp, (FallbackKernel, ComplexView)) and inp.has_aliasing()
def get_alias_names(self):
return [
inp.get_name()
for inp in self.inputs
)
if isinstance(inp, (FallbackKernel, ComplexView))
and len(inp.get_alias_names()) > 0
]


def _prepare_convolution_fusion_create(
Expand Down
6 changes: 2 additions & 4 deletions torch/_inductor/scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,10 +332,8 @@ def decide_inplace_update(self):
),
)
and not (
isinstance(
input_node.node, (ir.FallbackKernel, ir.MultiOutput)
)
and input_node.node.has_aliasing()
isinstance(input_node.node, ir.FallbackKernel)
and len(input_node.node.get_alias_names()) > 0
)
and buffer_reuse_key(input_node.node)
== buffer_reuse_key(self.node)
Expand Down

0 comments on commit 2f47b8f

Please sign in to comment.