Skip to content

Commit 54c4b5a

Browse files
smessmerfacebook-github-bot
authored andcommitted
refactor caffe2 operator constructors - 1/9 (pytorch#17082)
Summary: Pull Request resolved: pytorch#17082 clangr codemod Reviewed By: ezyang Differential Revision: D14078498 fbshipit-source-id: f7f65d6d81c7942293f53fdaa61f756d8b7360c1
1 parent 910519e commit 54c4b5a

12 files changed

+51
-34
lines changed

Diff for: caffe2/operators/accumulate_op.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ namespace caffe2 {
1010
template <typename T, class Context>
1111
class AccumulateOp final : public Operator<Context> {
1212
public:
13-
AccumulateOp(const OperatorDef& operator_def, Workspace* ws)
14-
: Operator<Context>(operator_def, ws),
13+
template <class... Args>
14+
explicit AccumulateOp(Args&&... args)
15+
: Operator<Context>(std::forward<Args>(args)...),
1516
gamma_(static_cast<T>(
1617
this->template GetSingleArgument<float>("gamma", 1.0))) {}
1718
USE_OPERATOR_CONTEXT_FUNCTIONS;

Diff for: caffe2/operators/accuracy_op.h

+4-3
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@ template <typename T, class Context>
1010
class AccuracyOp final : public Operator<Context> {
1111
public:
1212
USE_OPERATOR_CONTEXT_FUNCTIONS;
13-
AccuracyOp(const OperatorDef& operator_def, Workspace* ws)
14-
: Operator<Context>(operator_def, ws),
13+
template <class... Args>
14+
explicit AccuracyOp(Args&&... args)
15+
: Operator<Context>(std::forward<Args>(args)...),
1516
top_k_(this->template GetSingleArgument<int>("top_k", 1)) {}
16-
17+
1718
bool RunOnDevice() override;
1819

1920
protected:

Diff for: caffe2/operators/activation_ops_cudnn.h

+10-6
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@ class CuDNNActivationOpBase : public Operator<CUDAContext> {
1313
public:
1414
USE_OPERATOR_FUNCTIONS(CUDAContext);
1515

16-
CuDNNActivationOpBase(const OperatorDef& operator_def, Workspace* ws)
17-
: Operator<CUDAContext>(operator_def, ws), cudnn_wrapper_(&context_) {
16+
template <class... Args>
17+
explicit CuDNNActivationOpBase(Args&&... args)
18+
: Operator<CUDAContext>(std::forward<Args>(args)...),
19+
cudnn_wrapper_(&context_) {
1820
CUDNN_ENFORCE(cudnnCreateTensorDescriptor(&data_desc_));
1921
CUDNN_ENFORCE(cudnnCreateActivationDescriptor(&act_desc_));
2022
}
@@ -55,8 +57,9 @@ class CuDNNActivationOp final : public CuDNNActivationOpBase {
5557
public:
5658
USE_OPERATOR_FUNCTIONS(CUDAContext);
5759

58-
CuDNNActivationOp(const OperatorDef& operator_def, Workspace* ws)
59-
: CuDNNActivationOpBase(operator_def, ws) {
60+
template <class... Args>
61+
explicit CuDNNActivationOp(Args&&... args)
62+
: CuDNNActivationOpBase(std::forward<Args>(args)...) {
6063
CUDNN_ENFORCE(cudnnSetActivationDescriptor(
6164
act_desc_, kCuDNNActivationMode, CUDNN_PROPAGATE_NAN, 0.0));
6265
}
@@ -93,8 +96,9 @@ class CuDNNActivationGradientOp final : public CuDNNActivationOpBase {
9396
public:
9497
USE_OPERATOR_FUNCTIONS(CUDAContext);
9598

96-
CuDNNActivationGradientOp(const OperatorDef& operator_def, Workspace* ws)
97-
: CuDNNActivationOpBase(operator_def, ws) {
99+
template <class... Args>
100+
explicit CuDNNActivationGradientOp(Args&&... args)
101+
: CuDNNActivationOpBase(std::forward<Args>(args)...) {
98102
CUDNN_ENFORCE(cudnnSetActivationDescriptor(
99103
act_desc_, kCuDNNActivationMode, CUDNN_PROPAGATE_NAN, 0.0));
100104
}

Diff for: caffe2/operators/adjust_batch_op.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ template <class Context>
99
class AdjustBatchOp final : public Operator<Context> {
1010
public:
1111
USE_OPERATOR_CONTEXT_FUNCTIONS;
12-
AdjustBatchOp(const OperatorDef& operator_def, Workspace* ws)
13-
: Operator<Context>(operator_def, ws),
12+
template <class... Args>
13+
explicit AdjustBatchOp(Args&&... args)
14+
: Operator<Context>(std::forward<Args>(args)...),
1415
max_batch_size_(
1516
this->template GetSingleArgument<int64_t>("max_batch_size", -1)) {}
1617

Diff for: caffe2/operators/affine_channel_op.h

+6-4
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ class AffineChannelOp final : public Operator<Context> {
1515
public:
1616
USE_OPERATOR_CONTEXT_FUNCTIONS;
1717

18-
AffineChannelOp(const OperatorDef& operator_def, Workspace* ws)
19-
: Operator<Context>(operator_def, ws),
18+
template <class... Args>
19+
explicit AffineChannelOp(Args&&... args)
20+
: Operator<Context>(std::forward<Args>(args)...),
2021
order_(StringToStorageOrder(
2122
this->template GetSingleArgument<std::string>("order", "NCHW"))),
2223
OP_SINGLE_ARG(bool, "is_learnable", is_learnable_, false) {
@@ -94,8 +95,9 @@ class AffineChannelGradientOp final : public Operator<Context> {
9495
public:
9596
USE_OPERATOR_CONTEXT_FUNCTIONS;
9697

97-
AffineChannelGradientOp(const OperatorDef& def, Workspace* ws)
98-
: Operator<Context>(def, ws),
98+
template <class... Args>
99+
explicit AffineChannelGradientOp(Args&&... args)
100+
: Operator<Context>(std::forward<Args>(args)...),
99101
order_(StringToStorageOrder(
100102
this->template GetSingleArgument<std::string>("order", "NCHW"))),
101103
OP_SINGLE_ARG(bool, "is_learnable", is_learnable_, false) {

Diff for: caffe2/operators/apmeter_op.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ class APMeterOp final : public Operator<Context> {
1111
public:
1212
USE_OPERATOR_CONTEXT_FUNCTIONS;
1313

14-
APMeterOp(const OperatorDef& operator_def, Workspace* ws)
15-
: Operator<Context>(operator_def, ws),
14+
template <class... Args>
15+
explicit APMeterOp(Args&&... args)
16+
: Operator<Context>(std::forward<Args>(args)...),
1617
buffer_size_(
1718
this->template GetSingleArgument<int32_t>("buffer_size", 1000)),
1819
buffer_used_(0) {}

Diff for: caffe2/operators/arg_ops.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@ class ArgOp final : public Operator<Context> {
1616
public:
1717
USE_OPERATOR_CONTEXT_FUNCTIONS;
1818

19-
ArgOp(const OperatorDef& operator_def, Workspace* ws)
20-
: Operator<Context>(operator_def, ws),
19+
template <class... Args>
20+
explicit ArgOp(Args&&... args)
21+
: Operator<Context>(std::forward<Args>(args)...),
2122
OP_SINGLE_ARG(int, "axis", axis_, -1),
2223
OP_SINGLE_ARG(bool, "keepdims", keep_dims_, true) {}
2324

Diff for: caffe2/operators/assert_op.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ namespace caffe2 {
99
template <class Context>
1010
class AssertOp final : public Operator<Context> {
1111
public:
12-
AssertOp(const OperatorDef& operator_def, Workspace* ws)
13-
: Operator<Context>(operator_def, ws),
12+
template <class... Args>
13+
explicit AssertOp(Args&&... args)
14+
: Operator<Context>(std::forward<Args>(args)...),
1415
error_msg_(
1516
this->template GetSingleArgument<std::string>("error_msg", "")) {}
1617

Diff for: caffe2/operators/atomic_ops.cc

+6-4
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@ namespace {
1414

1515
class CreateMutexOp final : public Operator<CPUContext> {
1616
public:
17-
CreateMutexOp(const OperatorDef& operator_def, Workspace* ws)
18-
: Operator<CPUContext>(operator_def, ws) {}
17+
template <class... Args>
18+
explicit CreateMutexOp(Args&&... args)
19+
: Operator<CPUContext>(std::forward<Args>(args)...) {}
1920

2021
bool RunOnDevice() override {
2122
*OperatorBase::Output<std::unique_ptr<std::mutex>>(0) =
@@ -26,8 +27,9 @@ class CreateMutexOp final : public Operator<CPUContext> {
2627

2728
class AtomicFetchAddOp final : public Operator<CPUContext> {
2829
public:
29-
AtomicFetchAddOp(const OperatorDef& operator_def, Workspace* ws)
30-
: Operator<CPUContext>(operator_def, ws) {}
30+
template <class... Args>
31+
explicit AtomicFetchAddOp(Args&&... args)
32+
: Operator<CPUContext>(std::forward<Args>(args)...) {}
3133

3234
bool RunOnDevice() override {
3335
auto& mutex = OperatorBase::Input<std::unique_ptr<std::mutex>>(0);

Diff for: caffe2/operators/batch_box_cox_op.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@ template <class Context>
1212
class BatchBoxCoxOp final : public Operator<Context> {
1313
public:
1414
USE_OPERATOR_CONTEXT_FUNCTIONS;
15-
BatchBoxCoxOp(const OperatorDef& operator_def, Workspace* ws)
16-
: Operator<Context>(operator_def, ws),
15+
template <class... Args>
16+
explicit BatchBoxCoxOp(Args&&... args)
17+
: Operator<Context>(std::forward<Args>(args)...),
1718
min_block_size_(
1819
this->template GetSingleArgument<int>("min_block_size", 256)) {}
1920

Diff for: caffe2/operators/batch_bucketize_op.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@ class BatchBucketizeOp final : public Operator<Context> {
1414
public:
1515
USE_OPERATOR_CONTEXT_FUNCTIONS;
1616

17-
BatchBucketizeOp(const OperatorDef& operator_def, Workspace* ws)
18-
: Operator<Context>(operator_def, ws) {}
17+
template <class... Args>
18+
explicit BatchBucketizeOp(Args&&... args)
19+
: Operator<Context>(std::forward<Args>(args)...) {}
1920

2021
bool RunOnDevice() override;
2122

Diff for: caffe2/operators/batch_gather_ops.h

+4-3
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,10 @@ class BatchGatherGradientOp final : public Operator<Context> {
3636

3737
// Constructor to recieve axis in case it was passed for GatherOp gradient,
3838
// use default of 1 for batch gather otherwise.
39-
BatchGatherGradientOp(const OperatorDef& operator_def, Workspace* ws)
40-
: Operator<Context>(operator_def, ws),
41-
OP_SINGLE_ARG(int, "axis", axis_, 1) { }
39+
template <class... Args>
40+
explicit BatchGatherGradientOp(Args&&... args)
41+
: Operator<Context>(std::forward<Args>(args)...),
42+
OP_SINGLE_ARG(int, "axis", axis_, 1) {}
4243
virtual ~BatchGatherGradientOp() noexcept {}
4344

4445
bool RunOnDevice() override {

0 commit comments

Comments
 (0)