Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New TransformPropagator algorithm #1763

Merged
merged 25 commits into from
Jun 21, 2022
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions torch/csrc/jit/codegen/cuda/ir_interface_nodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <torch/csrc/jit/codegen/cuda/fusion.h>
#include <torch/csrc/jit/codegen/cuda/ir_base_nodes.h>
#include <torch/csrc/jit/codegen/cuda/ir_internal_nodes.h>
#include <torch/csrc/jit/codegen/cuda/mma_type.h>

#include <torch/csrc/jit/ir/ir.h>

Expand Down Expand Up @@ -158,6 +159,7 @@ class TransformPropagator;
class TransformIter;
class TransformReplay;
class OptOutMutator;
class TensorDomain;

namespace ir_utils {
class TVDomainGuard;
Expand Down
1 change: 0 additions & 1 deletion torch/csrc/jit/codegen/cuda/ir_internal_nodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

#include <torch/csrc/jit/codegen/cuda/fusion.h>
#include <torch/csrc/jit/codegen/cuda/ir_base_nodes.h>
#include <torch/csrc/jit/codegen/cuda/ir_interface_nodes.h>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Just curious, was this causing any problem?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

No, it worked fine, though I don't know why. It looks weird to me that two headers include each other.

#include <torch/csrc/jit/codegen/cuda/mma_type.h>
#include <torch/csrc/jit/codegen/cuda/parallel_type_bitmap.h>

Expand Down
71 changes: 71 additions & 0 deletions torch/csrc/jit/codegen/cuda/test/test_gpu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23574,6 +23574,77 @@ TEST_F(NVFuserTest, FusionReproNoncontigBroadcast_CUDA) {
executor_cache.fusion(), cg_outputs, {t0, t1}, {t2}, __LINE__, __FILE__);
}

TEST_F(NVFuserTest, FusionTransformPropagateSibling_CUDA) {
// https://github.com/csarofeen/pytorch/issues/1760
Fusion fusion;
FusionGuard fg(&fusion);

auto tv0 = makeSymbolicTensor(2);
fusion.addInput(tv0);

auto tvs = Welford(tv0, {1});
fusion.addOutput(tvs.var_sum);

tvs.avg->split(1, 1);
tvs.avg->split(1, 2);
tvs.avg->split(1, 3);
tvs.var_sum->split(1, 1);
tvs.var_sum->split(1, 2);
tvs.var_sum->split(1, 3);
tvs.n->split(1, 1);
tvs.n->split(1, 2);
tvs.n->split(1, 3);

auto tvs2 = tvs.rFactor({1, 4});

TransformPropagator::from(tvs2.var_sum);

// check that the resulting tensors in tvs2 are identical
auto checkSiblingConsistency = [](TensorView* replay, TensorView* target) {
auto replay_root = replay->getRootDomain();
auto replay_dom = replay->domain()->domain();
auto target_root = target->getRootDomain();
auto target_dom = target->domain()->domain();
std::unordered_map<IterDomain*, IterDomain*> target2replay_map;
TORCH_CHECK(replay_root.size() == target_root.size());
target2replay_map.reserve(replay_root.size());
std::transform(
target_root.begin(),
target_root.end(),
replay_root.begin(),
std::inserter(target2replay_map, target2replay_map.begin()),
[](auto a, auto b) { return std::make_pair(a, b); });
BestEffortReplay replay_(replay_dom, target_dom, target2replay_map);
auto r = replay_.getReplay();
for (int64_t i = 0; i < replay_dom.size(); i++) {
auto target_id = target_dom[i];
auto replay_it = r.find(target_id);
TORCH_CHECK(replay_it != r.end());
TORCH_CHECK(
replay_it->second == replay_dom[i],
"IterDomain mismatch when checking ",
replay,
" and ",
target,
" at ",
i,
", got ",
replay_it->second,
" and ",
replay_dom[i]);
}
};
std::vector<TensorView*> siblings[] = {
{tvs.avg, tvs.var_sum, tvs.n}, {tvs2.avg, tvs2.var_sum, tvs2.n}};
for (auto tensors : siblings) {
for (auto t1 : tensors) {
for (auto t2 : tensors) {
checkSiblingConsistency(t1, t2);
}
}
}
}

} // namespace jit
} // namespace torch
#endif // #if defined(USE_CUDA)
Loading