Skip to content
Open
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
29 changes: 17 additions & 12 deletions src/caffe/parallel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,11 @@ void DevicePair::compute(const vector<int> devices, vector<DevicePair>* pairs) {
#ifndef CPU_ONLY
vector<int> remaining(devices);

// Group GPUs by board - some boards can have more than 2 ASICs
for (int d = 0; d < remaining.size(); ++d) {
// Depth for reduction tree
int remaining_depth = static_cast<int>(ceil(log2(remaining.size())));

// Group GPUs by board
for (int d = 0; d < remaining_depth; ++d) {
for (int i = 0; i < remaining.size(); ++i) {
for (int j = i + 1; j < remaining.size(); ++j) {
cudaDeviceProp a, b;
Expand All @@ -144,8 +147,9 @@ void DevicePair::compute(const vector<int> devices, vector<DevicePair>* pairs) {
}
DLOG(INFO) << "GPUs paired by boards, remaining: " << s.str();

// Group by P2P accessibility - P2P group can be larger than 4 boards
for (int d = 0; d < remaining.size(); ++d) {
// Group by P2P accessibility
remaining_depth = ceil(log2(remaining.size()));
for (int d = 0; d < remaining_depth; ++d) {
for (int i = 0; i < remaining.size(); ++i) {
for (int j = i + 1; j < remaining.size(); ++j) {
int access;
Expand All @@ -169,18 +173,19 @@ void DevicePair::compute(const vector<int> devices, vector<DevicePair>* pairs) {
DLOG(INFO) << "GPUs paired by P2P access, remaining: " << s.str();

// Group remaining
for (int d = 0; d < remaining.size(); ++d) { // try to pair everyone
for (int i = 0; i < remaining.size(); ++i) {
for (int j = i + 1; j < remaining.size(); ++j) {
pairs->push_back(DevicePair(remaining[i], remaining[j]));
remaining_depth = ceil(log2(remaining.size()));
for (int d = 0; d < remaining_depth; ++d) {
for (int i = 0; i < remaining.size(); ++i) {
pairs->push_back(DevicePair(remaining[i], remaining[i+1]));
DLOG(INFO) << "Remaining pair: " << remaining[i]
<< ":" << remaining[j];
remaining.erase(remaining.begin() + j);
break;
}
<< ":" << remaining[i+1];
remaining.erase(remaining.begin() + i+1);
}
}

// Should only be the parent node remaining
CHECK_EQ(remaining.size(), 1);

pairs->insert(pairs->begin(), DevicePair(-1, remaining[0]));

CHECK(pairs->size() == devices.size());
Expand Down