fix side-effects and aliasing for custom ops (#18711)
authorMichael Suo <suo@fb.com>
Fri, 5 Apr 2019 17:40:19 +0000 (10:40 -0700)
committerFacebook Github Bot <facebook-github-bot@users.noreply.github.com>
Fri, 5 Apr 2019 17:48:14 +0000 (10:48 -0700)
commitfefa6d305ea3e820afe64cec015d2f6746d9ca88
tree816878c6f72f6372cff70966c319ecc8ee9dbcd7
parentabc758ed40d826ac8af4c9a318e1628194091f34
fix side-effects and aliasing for custom ops (#18711)

Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/18711
ghimport-source-id: c9caedc0660b2b7ba3730cd0e1a2e0e9c3cf422b

Stack from [ghstack](https://github.com/ezyang/ghstack):
* **#18711 [jit] fix side-effects and aliasing for custom ops**

Previously we didn't track aliasing, mutation, or side effects for
custom ops. This PR adds in guards with the most conservative
assumptions possible: the op will
1) have side effects,
2) write to everything
3) produce a wildcard.

In order to tell whether a given operator is a custom op, this PR introduces
the concept of a "reserved" namespace (basically all our builtin namespaces).
Custom ops live in non-reserved namespaces, so a check on the namespace
is sufficient to tell whether a schema/node is "custom" or not.

This is just to get things correct for now. Follow-ups to this:
- Users should be able to specify aliasing/mutability without having to learn
the whole alias annotation schema.
- Relax assumptions a bit. In particular outputs can only alias input tensors,
they don't have to be wildcards.

Fixes #18490

Differential Revision: D14730978

fbshipit-source-id: 540b47a24ccf24145051609bdcc99c97e46e0fe0
aten/src/ATen/core/function_schema.h
test/cpp/jit/test.cpp
test/cpp/jit/test_alias_analysis.h
test/cpp/jit/test_custom_operators.h
test/cpp/jit/test_misc.h
torch/csrc/jit/custom_operator.h
torch/csrc/jit/ir.cpp
torch/csrc/jit/passes/alias_analysis.cpp
torch/csrc/jit/passes/alias_analysis.h