Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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: 1 addition & 1 deletion csrc/device_lower/validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -699,7 +699,7 @@ class VectorizeValidator : public OptInDispatch {
size_t last_alloc_dim_pos = 0;
for (size_t i = tv->getMaybeAllocationDomain().size(); i > 0; i--) {
auto r_id = tv->getMaybeAllocationDomain()[i - 1];
if (r_id->isReduction() || r_id->isBroadcast()) {
if (r_id->isReduction() || r_id->isBroadcast() || r_id->isDeviceDim()) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

DIDx is not reordered to the front in allocation domain and may appear in the innermost position. For e..g. test_matmul.test_linear_reduce_scatter (the copy kernel is pointwise scheduled and codegen-ed).

continue;
}
if ((tv->getMemoryType() == MemoryType::Shared ||
Expand Down
9 changes: 5 additions & 4 deletions csrc/multidevice/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ IterDomain* getShardedIterDomain(
NVF_THROW("Unexpected parallel type: ", parallel_type);
}();

for (auto&& [index, id] : enumerate(domain)) {
for (IterDomain* id : domain | TensorDomain::kNoReductions) {
if (id->getParallelType() == parallel_type) {
return id;
}
Expand Down Expand Up @@ -266,9 +266,10 @@ std::vector<int64_t> unshardedSizes(
}

const int64_t sharded_axis = getProducingLogicalAxis(tv, sharded_id);
if (sharded_axis == -1) {
continue;
}
NVF_ERROR(
sharded_axis != -1,
"Producing logical axis not found for ",
sharded_id);

auto multiplier = [&]() -> int64_t {
if (parallel_type == ParallelType::Stream) {
Expand Down
35 changes: 2 additions & 33 deletions csrc/preseg_passes/finalize_multidevice_domains.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,39 +91,8 @@ void setLoopAndAllocationDomain(TensorView* tv, bool is_resharding) {
new_allocation_domain.push_back(id);
new_contiguity.push_back(contiguity);
}

std::optional<std::vector<int64_t>> permutation =
ir_utils::computePermutation(new_allocation_domain, tv->getLoopDomain());
NVF_ERROR(
permutation.has_value(),
"Failed to find a valid permutation for reordering ",
tv->getLoopDomain(),
" as ",
new_allocation_domain);
tv->reorder(permutation.value());

if (is_resharding) {
// Resharding expressions have specific requirements on position of
// gathered/scattered dimensions in the allocation domain that is ensured
// by ReorderShardedAxisPass. So we do not move the DIDx to the front in
// this case. For example, in reduce-scatter, the scattered axis is the
// outer-most dimension in communication input and output.
tv->setAllocationDomain(tv->getLoopDomain(), new_contiguity);
return;
}

// Most schedulers require DIDx to be at the front of the loop domain.
auto old2new = reorderParallelizedToFront(tv);
auto new2old = ir_utils::normalizeOld2New(old2new, tv->nDims());
std::vector<std::optional<bool>> reordered_contiguity;
std::transform(
new2old.begin(),
new2old.end(),
std::back_inserter(reordered_contiguity),
[&new_contiguity](int64_t i) -> std::optional<bool> {
return new_contiguity[i];
});
tv->setAllocationDomain(tv->getLoopDomain(), reordered_contiguity);
tv->setAllocationDomain(new_allocation_domain, new_contiguity);
reorderParallelizedToFront(tv);
}

} // namespace
Expand Down