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

Move getTvsWithDifferentSharding to cpp #3858

Merged
merged 1 commit into from
Feb 9, 2025
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
35 changes: 35 additions & 0 deletions csrc/multidevice/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -637,4 +637,39 @@ void reorderDIDToFront(TensorView* tv) {
tv->reorder(order_map);
}

std::unordered_set<TensorView*> getTvsWithDifferentSharding(
TensorView* ref,
const std::vector<TensorView*>& tvs) {
std::unordered_set<TensorView*> ret;
const auto& reference_dom = ref->getLoopDomain();
FusionGuard fg(ref->fusion());
auto ca_map = ComputeAtMap(FusionGuard::getCurFusion());
std::unordered_map<IterDomain*, IterDomain*> concrete_to_reference_map;
for (auto id : reference_dom) {
auto ca_id =
ca_map.getConcreteMappedID(id, IdMappingMode::PERMISSIVE_RESIZE);
concrete_to_reference_map[ca_id] = id;
}

for (TensorView* tv : tvs) {
if (ref->getDeviceMesh().vector() != tv->getDeviceMesh().vector()) {
ret.insert(tv);
continue;
}
for (auto id : tv->getLoopDomain()) {
auto ca_id =
ca_map.getConcreteMappedID(id, IdMappingMode::PERMISSIVE_RESIZE);
if (concrete_to_reference_map.count(ca_id) > 0) {
auto ref_id = concrete_to_reference_map.at(ca_id);
if ((ref_id->isDeviceDim() || id->isDeviceDim()) &&
ref_id->getParallelType() != id->getParallelType()) {
ret.insert(tv);
break;
}
}
}
}
return ret;
}

} // namespace nvfuser
34 changes: 1 addition & 33 deletions csrc/multidevice/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,41 +42,9 @@ int64_t numDeviceDims(const TensorView*);

// Returns the subset of tvs which elements have the different multi-device
// sharding as ref
template <typename TvIterator>
std::unordered_set<TensorView*> getTvsWithDifferentSharding(
TensorView* ref,
TvIterator tvs) {
std::unordered_set<TensorView*> ret;
const auto& reference_dom = ref->getLoopDomain();
FusionGuard fg(ref->fusion());
auto ca_map = ComputeAtMap(FusionGuard::getCurFusion());
std::unordered_map<IterDomain*, IterDomain*> concrete_to_reference_map;
for (auto id : reference_dom) {
auto ca_id =
ca_map.getConcreteMappedID(id, IdMappingMode::PERMISSIVE_RESIZE);
concrete_to_reference_map[ca_id] = id;
}

for (TensorView* tv : tvs) {
if (ref->getDeviceMesh().vector() != tv->getDeviceMesh().vector()) {
ret.insert(tv);
continue;
}
for (auto id : tv->getLoopDomain()) {
auto ca_id =
ca_map.getConcreteMappedID(id, IdMappingMode::PERMISSIVE_RESIZE);
if (concrete_to_reference_map.count(ca_id) > 0) {
auto ref_id = concrete_to_reference_map.at(ca_id);
if ((ref_id->isDeviceDim() || id->isDeviceDim()) &&
ref_id->getParallelType() != id->getParallelType()) {
ret.insert(tv);
break;
}
}
}
}
return ret;
}
const std::vector<TensorView*>& tvs);

// Returns whether an Expr embeds multi-device resharding
bool isResharding(const Expr* expr);
Expand Down