pytorch/caffe2/operators/async_net_barrier_op.cc
Nikita Shulga a9b0a921d5 Disable avoid-non-const-global-variables lint check (#62008)
Summary:
As GoogleTest `TEST` macro is non-compliant with it as well as `DEFINE_DISPATCH`

All changes but the ones to `.clang-tidy` are generated using following script:
```
for i in `find . -type f -iname "*.c*" -or -iname "*.h"|xargs grep cppcoreguidelines-avoid-non-const-global-variables|cut -f1 -d:|sort|uniq`;  do sed -i "/\/\/ NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)/d" $i; done
```

Pull Request resolved: https://github.com/pytorch/pytorch/pull/62008

Reviewed By: driazati, r-barnes

Differential Revision: D29838584

Pulled By: malfet

fbshipit-source-id: 1b2f8602c945bd4ce50a9bfdd204755556e31d13
2021-07-22 18:04:40 -07:00

51 lines
1.5 KiB
C++

#include "caffe2/operators/async_net_barrier_op.h"
namespace caffe2 {
namespace {
std::pair<std::vector<DeviceOption>, std::vector<DeviceOption>>
asyncBarrierOpDevInfer(const OperatorDef& def) {
auto op_device =
def.has_device_option() ? def.device_option() : DeviceOption();
ArgumentHelper helper(def);
auto cross_device = helper.GetSingleArgument<int>("cross_device", 0);
std::vector<DeviceOption> opt;
for (int i = 0; i < def.input().size(); ++i) {
if (cross_device == 1) {
DeviceOption dev;
dev.set_device_type(op_device.device_type());
dev.set_device_id(i);
opt.push_back(dev);
} else {
opt.push_back(op_device);
}
}
return std::make_pair(opt, opt);
}
}
OPERATOR_SCHEMA(AsyncNetBarrier)
.NumInputs(1, INT_MAX)
.NumOutputs(1, INT_MAX)
.IdenticalTypeAndShape()
.InputsCanCrossDevices()
.AllowOneToOneInplace()
.DeviceInferenceFunction(asyncBarrierOpDevInfer)
.SetDoc(R"DOC(
This is a pretty much no-op operator, since it's only purposes is make sure that
async_scheduling will schedule certian operations earlier than others.
Exaple where this operator can work well - mixture of data-parallel and model-
parallel training, where one wants to force that all copies are started before
data-parallel part starts.
)DOC")
.Arg(
"cross_device",
"Specifies either inputs should be across different devices in dev inference options");
SHOULD_NOT_DO_GRADIENT(AsyncNetBarrier);
REGISTER_CPU_OPERATOR(AsyncNetBarrier, AsyncNetBarrierOp<CPUContext>);
} // namespace caffe2