Skip to content

Commit

Permalink
Auto parallel/fast collector (#7958)
Browse files Browse the repository at this point in the history
* Try to speed up sbp collector.
However, throughput drop

* Shrink the parallel candidates for the proxy node

* Print out some information and then refine

* Store the sbp set for each consumer

* Update binary set intersection

* Remove impossible parallel candidates from sbp proxy

* Refine binary set

* Add a Clear() in binary set

* Filter out those proxy candidates containing two
sbps from the same unique group

* refine

* Check spells

* Clip useless edges
  • Loading branch information
Yipeng1994 authored and wyg1997 committed May 5, 2022
1 parent fdc6d0e commit 5497cd0
Show file tree
Hide file tree
Showing 4 changed files with 199 additions and 107 deletions.
23 changes: 18 additions & 5 deletions oneflow/core/auto_parallel/binary_set.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,11 @@ void BinarySet::Initialize(int32_t size_of_set) {
BinarySetValues.resize(k, 0);
}

// Clear all the elements in the set
void BinarySet::Clear() { BinarySetValues.assign(BinarySetValues.size(), 0); }

// Check if i-th element in this subset
int32_t BinarySet::CheckExistency(int32_t i) {
int32_t BinarySet::CheckExistency(int32_t i) const {
int32_t k = i / bit_of_BinarySetEntryType;
int32_t j = i % bit_of_BinarySetEntryType;
return BinarySetValues[k] >> j & 1;
Expand All @@ -68,14 +71,24 @@ void BinarySet::UnionTo(BinarySet& bs, BinarySet& u) {
u.BinarySetValues[k] = BinarySetValues[k] | bs.BinarySetValues[k];
}
}
// If this binary set intersects another one
bool BinarySet::IfIntersect(const BinarySet& bs) const {
int32_t min_bs_size = std::min(BinarySetValues.size(), bs.BinarySetValues.size());
for (int32_t k = 0; k < min_bs_size; k++) {
if (BinarySetValues[k] & bs.BinarySetValues[k]) { return true; }
}
return false;
}
// Get the intersection with another subset and store it into i
void BinarySet::IntersectionTo(BinarySet& bs, BinarySet& i) {
void BinarySet::IntersectionTo(const BinarySet& bs, BinarySet& i) const {
int32_t min_bs_size = std::min(BinarySetValues.size(), bs.BinarySetValues.size());
if (min_bs_size > i.BinarySetValues.size()) { i.BinarySetValues.resize(min_bs_size, 0); }
for (int32_t k = 0; k < BinarySetValues.size(); k++) {
i.BinarySetValues[k] = BinarySetValues[k] & bs.BinarySetValues[k];
}
}
// Count number of elements in this subset
int32_t BinarySet::Total() {
int32_t BinarySet::Total() const {
int32_t t = 0;
for (int32_t k = 0; k < BinarySetValues.size(); k++) {
BinarySetEntryType bsv = BinarySetValues[k];
Expand All @@ -91,15 +104,15 @@ int32_t BinarySet::Total() {
}

// Output all the elements in the subset
void BinarySet::OutPut(std::vector<int32_t>& out) {
void BinarySet::OutPut(std::vector<int32_t>& out) const {
out.clear();
for (int32_t i = 0; i < SizeOfSet; i++) {
if (CheckExistency(i)) { out.emplace_back(i); }
}
}

// Output all the elements in the subset
void BinarySet::QuickOutPut(std::vector<int32_t>& out) {
void BinarySet::QuickOutPut(std::vector<int32_t>& out) const {
out.clear();
for (int32_t i = 0; i < BinarySetValues.size(); i++) {
BinarySetEntryType x = BinarySetValues[i];
Expand Down
14 changes: 9 additions & 5 deletions oneflow/core/auto_parallel/binary_set.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,22 +46,26 @@ class BinarySet {

// Initialization
void Initialize(int32_t size_of_set);
// Clear all the elements in the set
void Clear();
// Check if i-th element in this subset
int32_t CheckExistency(int32_t i);
int32_t CheckExistency(int32_t i) const;
// Add i-th element into this subset
void AddEntry(int32_t i);
// Take i-th element out from this subset
void DeleteEntry(int32_t i);
// Get the union with another subset and store it into u
void UnionTo(BinarySet& bs, BinarySet& u);
// If this binary set intersects another one
bool IfIntersect(const BinarySet& bs) const;
// Get the intersection with another subset and store it into i
void IntersectionTo(BinarySet& bs, BinarySet& i);
void IntersectionTo(const BinarySet& bs, BinarySet& i) const;
// Count number of elements in this subset
int32_t Total();
int32_t Total() const;
// Output all the elements in the subset
void OutPut(std::vector<int32_t>& out);
void OutPut(std::vector<int32_t>& out) const;
// Output all the elements in the subset
void QuickOutPut(std::vector<int32_t>& out);
void QuickOutPut(std::vector<int32_t>& out) const;
// Add elements of input into this subset
void AddEntrys(std::vector<int32_t>& in);
// If two binary sets are equal to each other
Expand Down
Loading

0 comments on commit 5497cd0

Please sign in to comment.