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

Auto parallel/fast collector #7958

Merged
merged 13 commits into from
Apr 27, 2022
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