Skip to content

Commit 352032c

Browse files
smessmerfacebook-github-bot
authored andcommitted
Open up AliasAnalysisKind for any ops (#23834)
Summary: Pull Request resolved: #23834 Re-expot of reverted PR #23810 with the bug fixed A previous diff removed the special casing for aten:: and prim:: ops in alias analysis and implements alias analysis purely based on the AliasAnalysisKind. To be sure it doesn't break our existing code base, it added asserts that make sure that our existing aten:: and prim:: ops set the correct AliasAnalysisKind. However, we don't need that restriction for future ops. Since we are now certain all existing cases are set up correctly, we can remove these assertions. ghstack-source-id: 88050427 Differential Revision: D16657239 fbshipit-source-id: 8a7606da8e9bd961bf47e3e1587b622a9c247ec6
1 parent 390bfd5 commit 352032c

File tree

3 files changed

+17
-21
lines changed

3 files changed

+17
-21
lines changed

test/cpp/jit/test_alias_analysis.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1142,13 +1142,13 @@ void testAliasRegistration() {
11421142
}
11431143
{
11441144
auto registry = torch::RegisterOperators().op(
1145-
"aten::rand6(Tensor arg1) -> Tensor",
1145+
"foo::rand6(Tensor arg1) -> Tensor",
11461146
torch::RegisterOperators::options()
11471147
.catchAllKernel([](at::Tensor) -> at::Tensor {
11481148
return at::rand({2, 2});
11491149
})
11501150
.aliasAnalysis(AliasAnalysisKind::FROM_SCHEMA));
1151-
const auto rand_op = Symbol::fromQualString("aten::rand6");
1151+
const auto rand_op = Symbol::fromQualString("foo::rand6");
11521152
auto graph = std::make_shared<Graph>();
11531153
auto a = graph->addInput();
11541154
auto b = graph->insert(rand_op, {a});
@@ -1159,11 +1159,12 @@ void testAliasRegistration() {
11591159
}
11601160
{
11611161
auto registry = torch::RegisterOperators().op(
1162-
"aten::rand7(Tensor(a) arg1) -> Tensor(a)",
1162+
"foo::rand7(Tensor(a) arg1) -> Tensor(a)",
11631163
torch::RegisterOperators::options()
11641164
.catchAllKernel([](at::Tensor t) -> at::Tensor { return t * 2; })
11651165
.aliasAnalysis(AliasAnalysisKind::FROM_SCHEMA));
1166-
const auto rand_op = Symbol::fromQualString("aten::rand7");
1166+
const auto rand_op = Symbol::fromQualString("foo::rand7");
1167+
11671168
auto graph = std::make_shared<Graph>();
11681169
auto a = graph->addInput();
11691170
auto b = graph->insert(rand_op, {a});
@@ -1173,11 +1174,11 @@ void testAliasRegistration() {
11731174
}
11741175
{
11751176
auto registry = torch::RegisterOperators().op(
1176-
"aten::rand8(Tensor(a) arg1) -> Tensor(b)",
1177+
"foo::rand8(Tensor(a) arg1) -> Tensor(b)",
11771178
torch::RegisterOperators::options()
11781179
.catchAllKernel([](at::Tensor t) -> at::Tensor { return t * 2; })
11791180
.aliasAnalysis(AliasAnalysisKind::FROM_SCHEMA));
1180-
const auto rand_op = Symbol::fromQualString("aten::rand8");
1181+
const auto rand_op = Symbol::fromQualString("foo::rand8");
11811182
auto graph = std::make_shared<Graph>();
11821183
auto a = graph->addInput();
11831184
auto b = graph->insert(rand_op, {a});

torch/csrc/jit/ir.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -904,10 +904,12 @@ bool Node::hasSideEffects() const {
904904
" doesn't have one either. We don't know if this op has side effects.");
905905
return false;
906906
}
907+
907908
if (kind_.is_prim() || kind_.is_aten()) {
908-
// TODO This assert is only introduced to check that we don't break the
909-
// current code base. Remove this later to allow other ops to use
910-
// AliasAnalysisKind::FROM_SCHEMA
909+
// TODO There is nothing in the system that relies on aten:: and prim::
910+
// ops using AliasAnalysisKind::FROM_SCHEMA or AliasAnalysisKind::INTERNAL_SPECIAL_CASE,
911+
// but this is the intended behavior for all current ops and a good error check.
912+
// We can consider lifting this constraint later if we have a use case for it.
911913
TORCH_INTERNAL_ASSERT(
912914
op->aliasAnalysisKind() == AliasAnalysisKind::INTERNAL_SPECIAL_CASE ||
913915
op->aliasAnalysisKind() == AliasAnalysisKind::FROM_SCHEMA,
@@ -916,6 +918,7 @@ bool Node::hasSideEffects() const {
916918
" has ",
917919
toString(op->aliasAnalysisKind()));
918920
}
921+
919922
switch (op->aliasAnalysisKind()) {
920923
case AliasAnalysisKind::PURE:
921924
return false;

torch/csrc/jit/passes/alias_analysis.cpp

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -379,9 +379,10 @@ void AliasDb::analyzeImpl(Node* node) {
379379
"Special cases should be handled already if we're here.");
380380

381381
if (node->kind().is_aten() || node->kind().is_prim()) {
382-
// TODO This assert is only introduced to check that we don't break the
383-
// current code base. Remove this later to allow aten:: and prim:: ops to
384-
// use other alias analysis kinds.
382+
// TODO There is nothing in the system that relies on aten:: and prim::
383+
// ops using AliasAnalysisKind::FROM_SCHEMA or AliasAnalysisKind::INTERNAL_SPECIAL_CASE,
384+
// but this is the intended behavior for all current ops and a good error check.
385+
// We can consider lifting this constraint later if we have a use case for it.
385386
TORCH_INTERNAL_ASSERT(
386387
analysis == AliasAnalysisKind::FROM_SCHEMA,
387388
"aten:: and prim:: operators should use AliasAnalysisKind::FROM_SCHEMA but ",
@@ -418,15 +419,6 @@ void AliasDb::analyzeImpl(Node* node) {
418419
"AliasAnalysisKind::CONSERVATIVE/PURE/INTERNAL_SPECIAL_CASE should already have been handled above");
419420
const auto& schema = node->schema();
420421

421-
// TODO This assert is only introduced to check that we don't break the
422-
// current code base. Remove this later to allow other ops to use
423-
// AliasAnalysisKind::FROM_SCHEMA
424-
TORCH_INTERNAL_ASSERT(
425-
node->kind().is_prim() || node->kind().is_aten(),
426-
"The current code base should only have AliasAnalysisKind::FROM_SCHEMA for aten:: and prim:: ops but we found it for ",
427-
node->kind().toDisplayString(),
428-
". We want to open this up though.");
429-
430422
// Bind the schema's "formal" alias annotation to the actual values those
431423
// schema arguments represent
432424
std::unordered_map<Symbol, Value*> formalToActual;

0 commit comments

Comments
 (0)