mirror of
https://github.com/saymrwulf/pytorch.git
synced 2026-05-14 20:57:59 +00:00
Summary:
This reverts commit d73c830e23.
We have observed significant perf drop when training ResNext101 with multiple amd GPUs:
Before:
https://ci.pytorch.org/jenkins/job/caffe2-builds/job/py2-clang7-rocmdeb-ubuntu16.04-bench/1636/console
2 GPUs ResNext training got 150\~160 imgs/sec
4 GPUs ResNext training got 270\~280 imgs/sec
After:
https://ci.pytorch.org/jenkins/job/caffe2-builds/job/py2-clang7-rocmdeb-ubuntu16.04-bench/1637/console
Both 2 and 4 GPUs ResNext training drop to 110\~120 imgs/sec
Similar perf drop are seen on ResNet50 training jobs as well.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/18680
Differential Revision: D14702941
Pulled By: bddppq
fbshipit-source-id: 828141805afc23f25c08d4a2eb6d4b99f817c128
85 lines
2.6 KiB
C++
85 lines
2.6 KiB
C++
#ifndef CAFFE2_OPERATORS_REMOVE_DATA_BLOCKS_OP_H_
|
|
#define CAFFE2_OPERATORS_REMOVE_DATA_BLOCKS_OP_H_
|
|
|
|
#include <algorithm>
|
|
#include <vector>
|
|
|
|
#include "caffe2/core/context.h"
|
|
#include "caffe2/core/operator.h"
|
|
|
|
namespace caffe2 {
|
|
|
|
template <class Context>
|
|
class RemoveDataBlocksOp final : public Operator<Context> {
|
|
public:
|
|
USE_OPERATOR_CONTEXT_FUNCTIONS;
|
|
USE_SIMPLE_CTOR_DTOR(RemoveDataBlocksOp);
|
|
USE_DISPATCH_HELPER;
|
|
|
|
bool RunOnDevice() override {
|
|
if (Input(INDICES).sizes()[0] == 0) {
|
|
Output(0)->CopyFrom(Input(0));
|
|
return true;
|
|
} else {
|
|
return DispatchHelper<TensorTypes<int, long>>::call(this, Input(INDICES));
|
|
}
|
|
}
|
|
|
|
template <typename T>
|
|
bool DoRunWithType() {
|
|
const auto& data = Input(DATA);
|
|
const auto& indices = Input(INDICES);
|
|
CAFFE_ENFORCE(data.dim() > 0, "DATA should be at leat 1-D.");
|
|
CAFFE_ENFORCE(indices.dim() == 1, "INDICES should be 1-D.");
|
|
|
|
const auto outer_size = data.sizes()[0];
|
|
const auto block_size = data.size_from_dim(1);
|
|
const auto block_size_bytes = block_size * data.dtype().itemsize();
|
|
auto indices_size = indices.sizes()[0];
|
|
const char* data_ptr = (char*)data.raw_data();
|
|
const auto* ind_ptr = indices.template data<T>();
|
|
|
|
std::vector<T> ind_vec;
|
|
for (int64_t i = 0; i < indices_size; i++) {
|
|
ind_vec.push_back(ind_ptr[i]);
|
|
}
|
|
std::sort(ind_vec.begin(), ind_vec.end());
|
|
CAFFE_ENFORCE(ind_vec[0] >= 0, "The min index should be larger than zero.");
|
|
CAFFE_ENFORCE(
|
|
ind_vec[indices_size - 1] < outer_size,
|
|
"The max index should be smaller than the data outer size.");
|
|
// removes duplicate indices
|
|
ind_vec.erase(std::unique(ind_vec.begin(), ind_vec.end()), ind_vec.end());
|
|
indices_size = ind_vec.size();
|
|
|
|
auto* output = Output(0);
|
|
auto shape = data.sizes().vec();
|
|
shape[0] -= indices_size;
|
|
output->Resize(shape);
|
|
char* out_ptr = (char*)output->raw_mutable_data(data.dtype());
|
|
|
|
ind_vec.insert(ind_vec.begin(), -1);
|
|
int64_t ind_vec_size = ind_vec.size();
|
|
for (auto i = 0; i < ind_vec_size; i++) {
|
|
int64_t interval_start = ind_vec[i] + 1;
|
|
int64_t interval_end =
|
|
(i == ind_vec_size - 1) ? outer_size : ind_vec[i + 1];
|
|
auto num_items = interval_end - interval_start;
|
|
context_.CopyItemsSameDevice(
|
|
data.dtype(),
|
|
num_items * block_size,
|
|
data_ptr + block_size_bytes * interval_start,
|
|
out_ptr);
|
|
out_ptr += block_size_bytes * num_items;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
private:
|
|
INPUT_TAGS(DATA, INDICES);
|
|
};
|
|
|
|
} // namespace caffe2
|
|
|
|
#endif // CAFFE2_OPERATORS_REMOVE_DATA_BLOCKS_OP_H_
|