From 7413f0926ada8ab24d1866ed2227a8dd43dd5644 Mon Sep 17 00:00:00 2001 From: Sebastian Messmer Date: Thu, 28 Feb 2019 14:12:37 -0800 Subject: [PATCH] refactor caffe2 operator constructors - 8/9 (#17089) Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/17089 clangr codemod Reviewed By: ezyang Differential Revision: D14078539 fbshipit-source-id: 9ca196af4af7f26fc82e6cf82b35d478d0597752 --- caffe2/operators/slice_op.h | 10 +++++---- caffe2/operators/softmax_op.h | 12 +++++----- caffe2/operators/softmax_op_cudnn.cc | 10 +++++---- caffe2/operators/softmax_with_loss_op.h | 16 ++++++++----- caffe2/operators/space_batch_op.h | 5 +++-- caffe2/operators/sparse_normalize_op.h | 5 +++-- caffe2/operators/sparse_to_dense_mask_op.h | 15 ++++++++----- caffe2/operators/sparse_to_dense_op.h | 5 +++-- caffe2/operators/spatial_batch_norm_op.h | 10 +++++---- caffe2/operators/spatial_softmax_with_loss_op.h | 10 +++++---- caffe2/operators/square_root_divide_op.h | 5 +++-- caffe2/operators/stats_ops.cc | 30 ++++++++++++++----------- caffe2/operators/stats_put_ops.h | 2 +- caffe2/operators/string_ops.h | 5 +++-- caffe2/operators/stump_func_op.h | 10 +++++---- caffe2/operators/stylizer_ops.cc | 4 +--- caffe2/operators/summarize_op.h | 2 +- caffe2/operators/text_file_reader.cc | 10 +++++---- caffe2/operators/thresholded_relu_op.h | 10 +++++---- caffe2/operators/tile_op.h | 10 +++++---- caffe2/operators/top_k.h | 10 +++++---- caffe2/operators/transpose_op.h | 5 +++-- caffe2/operators/transpose_op_cudnn.cc | 5 +++-- caffe2/operators/tt_linear_op.h | 10 +++++---- caffe2/operators/upsample_op.h | 14 ++++++++---- 25 files changed, 137 insertions(+), 93 deletions(-) diff --git a/caffe2/operators/slice_op.h b/caffe2/operators/slice_op.h index 536df39..4984f7f 100644 --- a/caffe2/operators/slice_op.h +++ b/caffe2/operators/slice_op.h @@ -202,8 +202,9 @@ template class SliceOp : public Operator { public: USE_OPERATOR_CONTEXT_FUNCTIONS; - SliceOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws), + template + explicit SliceOp(Args&&... args) + : Operator(std::forward(args)...), starts_(this->template GetRepeatedArgument("starts")), ends_(this->template GetRepeatedArgument("ends")), statically_inited_(false) {} @@ -263,8 +264,9 @@ template class SliceGradientOp : public Operator { public: USE_OPERATOR_CONTEXT_FUNCTIONS; - SliceGradientOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws), + template + explicit SliceGradientOp(Args&&... args) + : Operator(std::forward(args)...), starts_(this->template GetRepeatedArgument("starts")), ends_(this->template GetRepeatedArgument("ends")), statically_inited_(false) {} diff --git a/caffe2/operators/softmax_op.h b/caffe2/operators/softmax_op.h index 3f12ddc..cd081a1 100644 --- a/caffe2/operators/softmax_op.h +++ b/caffe2/operators/softmax_op.h @@ -11,9 +11,10 @@ namespace caffe2 { template class SoftmaxOp final : public Operator { public: - SoftmaxOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws), - axis_(this->template GetSingleArgument("axis", 1)) {} + template + explicit SoftmaxOp(Args&&... args) + : Operator(std::forward(args)...), + axis_(this->template GetSingleArgument("axis", 1)) {} USE_OPERATOR_CONTEXT_FUNCTIONS; bool RunOnDevice() override; @@ -27,8 +28,9 @@ class SoftmaxOp final : public Operator { template class SoftmaxGradientOp final : public Operator { public: - SoftmaxGradientOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws), + template + explicit SoftmaxGradientOp(Args&&... args) + : Operator(std::forward(args)...), axis_(this->template GetSingleArgument("axis", 1)) {} USE_OPERATOR_CONTEXT_FUNCTIONS; bool RunOnDevice() override; diff --git a/caffe2/operators/softmax_op_cudnn.cc b/caffe2/operators/softmax_op_cudnn.cc index 38f9c40..337a127 100644 --- a/caffe2/operators/softmax_op_cudnn.cc +++ b/caffe2/operators/softmax_op_cudnn.cc @@ -15,8 +15,9 @@ constexpr int TOP_GRADIENT_DESC_ID = 2; class CuDNNSoftmaxOp final : public Operator { public: - explicit CuDNNSoftmaxOp(const OperatorDef& def, Workspace* ws) - : Operator(def, ws), + template + explicit CuDNNSoftmaxOp(Args&&... args) + : Operator(std::forward(args)...), cudnn_wrapper_(&context_), axis_(OperatorBase::GetSingleArgument("axis", 1)) { CUDNN_ENFORCE(cudnnCreateTensorDescriptor(&desc_)); @@ -77,8 +78,9 @@ class CuDNNSoftmaxOp final : public Operator { class CuDNNSoftmaxGradientOp final : public Operator { public: - explicit CuDNNSoftmaxGradientOp(const OperatorDef& def, Workspace* ws) - : Operator(def, ws), + template + explicit CuDNNSoftmaxGradientOp(Args&&... args) + : Operator(std::forward(args)...), cudnn_wrapper_(&context_), axis_(OperatorBase::GetSingleArgument("axis", 1)) { CUDNN_ENFORCE(cudnnCreateTensorDescriptor(&desc_)); diff --git a/caffe2/operators/softmax_with_loss_op.h b/caffe2/operators/softmax_with_loss_op.h index d72e305..ad70c90 100644 --- a/caffe2/operators/softmax_with_loss_op.h +++ b/caffe2/operators/softmax_with_loss_op.h @@ -11,10 +11,12 @@ namespace caffe2 { template class SoftmaxWithLossOp final : public Operator { public: - SoftmaxWithLossOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws), + template + explicit SoftmaxWithLossOp(Args&&... args) + : Operator(std::forward(args)...), scale_(this->template GetSingleArgument("scale", 1.)), - label_prob_mode_(this->template GetSingleArgument("label_prob", 0)), + label_prob_mode_( + this->template GetSingleArgument("label_prob", 0)), order_(StringToStorageOrder( this->template GetSingleArgument("order", "NCHW"))), axis_(this->template GetSingleArgument("axis", 1)) { @@ -44,10 +46,12 @@ class SoftmaxWithLossOp final : public Operator { template class SoftmaxWithLossGradientOp final : public Operator { public: - SoftmaxWithLossGradientOp(const OperatorDef& def, Workspace* ws) - : Operator(def, ws), + template + explicit SoftmaxWithLossGradientOp(Args&&... args) + : Operator(std::forward(args)...), scale_(this->template GetSingleArgument("scale", 1.)), - label_prob_mode_(this->template GetSingleArgument("label_prob", 0)), + label_prob_mode_( + this->template GetSingleArgument("label_prob", 0)), order_(StringToStorageOrder( this->template GetSingleArgument("order", "NCHW"))), only_loss_(this->template GetSingleArgument("only_loss", false)), diff --git a/caffe2/operators/space_batch_op.h b/caffe2/operators/space_batch_op.h index 1297174..4c80711 100644 --- a/caffe2/operators/space_batch_op.h +++ b/caffe2/operators/space_batch_op.h @@ -111,8 +111,9 @@ template class SpaceBatchOpBase : public Operator { public: USE_OPERATOR_CONTEXT_FUNCTIONS; - SpaceBatchOpBase(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws), + template + explicit SpaceBatchOpBase(Args&&... args) + : Operator(std::forward(args)...), pad_(this->template GetSingleArgument("pad", 0)), pad_t_(this->template GetSingleArgument("pad_t", pad_)), pad_l_(this->template GetSingleArgument("pad", pad_)), diff --git a/caffe2/operators/sparse_normalize_op.h b/caffe2/operators/sparse_normalize_op.h index 90a3702..4f23fa9 100644 --- a/caffe2/operators/sparse_normalize_op.h +++ b/caffe2/operators/sparse_normalize_op.h @@ -9,8 +9,9 @@ template class CAFFE2_API SparseNormalizeOp final : public Operator { public: USE_OPERATOR_CONTEXT_FUNCTIONS; - SparseNormalizeOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws), + template + explicit SparseNormalizeOp(Args&&... args) + : Operator(std::forward(args)...), use_max_norm_( this->template GetSingleArgument("use_max_norm", true)), norm_(this->template GetSingleArgument("norm", 1.0)) { diff --git a/caffe2/operators/sparse_to_dense_mask_op.h b/caffe2/operators/sparse_to_dense_mask_op.h index 0716597..c1d6750 100644 --- a/caffe2/operators/sparse_to_dense_mask_op.h +++ b/caffe2/operators/sparse_to_dense_mask_op.h @@ -15,8 +15,9 @@ template class SparseToDenseMaskBase : public Operator { public: USE_OPERATOR_CONTEXT_FUNCTIONS; - SparseToDenseMaskBase(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws) { + template + explicit SparseToDenseMaskBase(Args&&... args) + : Operator(std::forward(args)...) { std::vector mask = this->template GetRepeatedArgument("mask"); featuresCount_ = mask.size(); @@ -62,8 +63,9 @@ template class SparseToDenseMaskOp : public SparseToDenseMaskBase { public: USE_OPERATOR_CONTEXT_FUNCTIONS; - SparseToDenseMaskOp(const OperatorDef& operator_def, Workspace* ws) - : SparseToDenseMaskBase(operator_def, ws) { + template + explicit SparseToDenseMaskOp(Args&&... args) + : SparseToDenseMaskBase(std::forward(args)...) { returnPresenceMask_ = this->template GetSingleArgument( "return_presence_mask", false); maxSkippedSparseIndices_ = @@ -192,8 +194,9 @@ template class SparseToDenseMaskGradientOp : public SparseToDenseMaskBase { public: USE_OPERATOR_CONTEXT_FUNCTIONS; - SparseToDenseMaskGradientOp(const OperatorDef& operator_def, Workspace* ws) - : SparseToDenseMaskBase(operator_def, ws) {} + template + explicit SparseToDenseMaskGradientOp(Args&&... args) + : SparseToDenseMaskBase(std::forward(args)...) {} bool RunOnDevice() override { return DispatchHelper>::call( diff --git a/caffe2/operators/sparse_to_dense_op.h b/caffe2/operators/sparse_to_dense_op.h index 0d269d1..40498a9 100644 --- a/caffe2/operators/sparse_to_dense_op.h +++ b/caffe2/operators/sparse_to_dense_op.h @@ -13,8 +13,9 @@ class SparseToDenseOp final : public Operator { USE_OPERATOR_CONTEXT_FUNCTIONS; USE_DISPATCH_HELPER; - SparseToDenseOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws), + template + explicit SparseToDenseOp(Args&&... args) + : Operator(std::forward(args)...), output_first_dim_( this->template GetSingleArgument("output_first_dim", 0)) {} diff --git a/caffe2/operators/spatial_batch_norm_op.h b/caffe2/operators/spatial_batch_norm_op.h index c67f86e..3347a52 100644 --- a/caffe2/operators/spatial_batch_norm_op.h +++ b/caffe2/operators/spatial_batch_norm_op.h @@ -19,8 +19,9 @@ class SpatialBNOp : public Operator { public: USE_OPERATOR_CONTEXT_FUNCTIONS; - SpatialBNOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws), + template + explicit SpatialBNOp(Args&&... args) + : Operator(std::forward(args)...), OP_SINGLE_ARG(bool, OpSchema::Arg_IsTest, is_test_, false), OP_SINGLE_ARG(double, "epsilon", epsilon_, 1e-5), OP_SINGLE_ARG(float, "momentum", momentum_, 0.9f), @@ -281,8 +282,9 @@ class SpatialBNGradientOp : public Operator { public: USE_OPERATOR_CONTEXT_FUNCTIONS; - SpatialBNGradientOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws), + template + explicit SpatialBNGradientOp(Args&&... args) + : Operator(std::forward(args)...), OP_SINGLE_ARG(double, "epsilon", epsilon_, 1e-5), order_(StringToStorageOrder( this->template GetSingleArgument("order", "NCHW"))), diff --git a/caffe2/operators/spatial_softmax_with_loss_op.h b/caffe2/operators/spatial_softmax_with_loss_op.h index 97d3818..1b14960 100644 --- a/caffe2/operators/spatial_softmax_with_loss_op.h +++ b/caffe2/operators/spatial_softmax_with_loss_op.h @@ -11,8 +11,9 @@ namespace caffe2 { template class SpatialSoftmaxWithLossOp final : public Operator { public: - SpatialSoftmaxWithLossOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws), + template + explicit SpatialSoftmaxWithLossOp(Args&&... args) + : Operator(std::forward(args)...), scale_(this->template GetSingleArgument("scale", 1.)), order_(StringToStorageOrder( this->template GetSingleArgument("order", "NCHW"))) { @@ -39,8 +40,9 @@ class SpatialSoftmaxWithLossOp final : public Operator { template class SpatialSoftmaxWithLossGradientOp final : public Operator { public: - SpatialSoftmaxWithLossGradientOp(const OperatorDef& def, Workspace* ws) - : Operator(def, ws), + template + explicit SpatialSoftmaxWithLossGradientOp(Args&&... args) + : Operator(std::forward(args)...), scale_(this->template GetSingleArgument("scale", 1.)), order_(StringToStorageOrder( this->template GetSingleArgument("order", "NCHW"))), diff --git a/caffe2/operators/square_root_divide_op.h b/caffe2/operators/square_root_divide_op.h index 0493f11..00a7cac 100644 --- a/caffe2/operators/square_root_divide_op.h +++ b/caffe2/operators/square_root_divide_op.h @@ -13,8 +13,9 @@ class SquareRootDivideOp final : public Operator { USE_OPERATOR_CONTEXT_FUNCTIONS; USE_DISPATCH_HELPER; - SquareRootDivideOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws) {} + template + explicit SquareRootDivideOp(Args&&... args) + : Operator(std::forward(args)...) {} bool RunOnDevice() override { return DispatchHelper>::call(this, Input(DATA)); diff --git a/caffe2/operators/stats_ops.cc b/caffe2/operators/stats_ops.cc index 9bdd13f..33f2c5e 100644 --- a/caffe2/operators/stats_ops.cc +++ b/caffe2/operators/stats_ops.cc @@ -8,8 +8,9 @@ namespace caffe2 { class StatRegistryCreateOp : public Operator { public: - StatRegistryCreateOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws) {} + template + explicit StatRegistryCreateOp(Args&&... args) + : Operator(std::forward(args)...) {} bool RunOnDevice() override { *OperatorBase::Output>(0) = @@ -20,8 +21,9 @@ class StatRegistryCreateOp : public Operator { class StatRegistryExportOp : public Operator { public: - StatRegistryExportOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws), + template + explicit StatRegistryExportOp(Args&&... args) + : Operator(std::forward(args)...), reset_(GetSingleArgument("reset", true)) {} bool RunOnDevice() override { @@ -55,8 +57,9 @@ class StatRegistryExportOp : public Operator { class StatRegistryUpdateOp : public Operator { public: - StatRegistryUpdateOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws) {} + template + explicit StatRegistryUpdateOp(Args&&... args) + : Operator(std::forward(args)...) {} bool RunOnDevice() override { const auto& keys = Input(0); @@ -118,7 +121,7 @@ class TimerInstance { }; struct TimerBeginOp : public Operator { - TimerBeginOp(const OperatorDef& operator_def, Workspace* ws) + explicit TimerBeginOp(const OperatorDef& operator_def, Workspace* ws) : Operator(operator_def, ws), given_name_(GetSingleArgument( "counter_name", @@ -137,8 +140,8 @@ struct TimerBeginOp : public Operator { }; struct TimerEndOp : public Operator { - TimerEndOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws) {} + template + explicit TimerEndOp(Args&&... args) : Operator(std::forward(args)...) {} bool RunOnDevice() override { OperatorBase::Input(0)->end(); @@ -147,8 +150,9 @@ struct TimerEndOp : public Operator { }; struct TimerGetAndEndOp : public Operator { - TimerGetAndEndOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws) {} + template + explicit TimerGetAndEndOp(Args&&... args) + : Operator(std::forward(args)...) {} bool RunOnDevice() override { int64_t nanos = OperatorBase::Input(0)->get_ns(); @@ -161,8 +165,8 @@ struct TimerGetAndEndOp : public Operator { }; struct TimerGetOp : public Operator { - TimerGetOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws) {} + template + explicit TimerGetOp(Args&&... args) : Operator(std::forward(args)...) {} bool RunOnDevice() override { int64_t nanos = OperatorBase::Input(0)->get_ns(); diff --git a/caffe2/operators/stats_put_ops.h b/caffe2/operators/stats_put_ops.h index b2e4b87..458cc37 100644 --- a/caffe2/operators/stats_put_ops.h +++ b/caffe2/operators/stats_put_ops.h @@ -8,7 +8,7 @@ namespace caffe2 { template struct TemplatePutOp : public Operator { - TemplatePutOp(const OperatorDef& operator_def, Workspace* ws) + explicit TemplatePutOp(const OperatorDef& operator_def, Workspace* ws) : Operator(operator_def, ws), given_name_(GetSingleArgument( "stat_name", diff --git a/caffe2/operators/string_ops.h b/caffe2/operators/string_ops.h index 33b6dec..59e81ee 100644 --- a/caffe2/operators/string_ops.h +++ b/caffe2/operators/string_ops.h @@ -41,8 +41,9 @@ class StringJoinOp final : public Operator { public: USE_OPERATOR_CONTEXT_FUNCTIONS; - StringJoinOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws), + template + explicit StringJoinOp(Args&&... args) + : Operator(std::forward(args)...), delimiter_( this->template GetSingleArgument("delimiter", ",")), axis_(this->template GetSingleArgument("axis", 0)) { diff --git a/caffe2/operators/stump_func_op.h b/caffe2/operators/stump_func_op.h index 3f4cced..3957dc7 100644 --- a/caffe2/operators/stump_func_op.h +++ b/caffe2/operators/stump_func_op.h @@ -32,8 +32,9 @@ class StumpFuncOp final : public Operator { public: USE_OPERATOR_CONTEXT_FUNCTIONS; - StumpFuncOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws), + template + explicit StumpFuncOp(Args&&... args) + : Operator(std::forward(args)...), threshold_(this->template GetSingleArgument("threshold", 0)), low_value_(this->template GetSingleArgument("low_value", 0)), high_value_(this->template GetSingleArgument("high_value", 0)) {} @@ -53,8 +54,9 @@ class StumpFuncIndexOp final : public Operator { public: USE_OPERATOR_CONTEXT_FUNCTIONS; - StumpFuncIndexOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws), + template + explicit StumpFuncIndexOp(Args&&... args) + : Operator(std::forward(args)...), threshold_(this->template GetSingleArgument("threshold", 0)) {} bool RunOnDevice() override; diff --git a/caffe2/operators/stylizer_ops.cc b/caffe2/operators/stylizer_ops.cc index 9b4e69f..a456a15 100644 --- a/caffe2/operators/stylizer_ops.cc +++ b/caffe2/operators/stylizer_ops.cc @@ -69,9 +69,7 @@ class PackedInt8BGRANHWCToNCHWCStylizerPreprocessOp static constexpr int kNeonNoiseReadSize = kOutputChannels * 16; USE_OPERATOR_FUNCTIONS(CPUContext); - PackedInt8BGRANHWCToNCHWCStylizerPreprocessOp( - const OperatorDef& operator_def, - Workspace* ws) + explicit PackedInt8BGRANHWCToNCHWCStylizerPreprocessOp(const OperatorDef& operator_def, Workspace* ws) : Operator(operator_def, ws), ws_(ws) {} bool RunOnDevice() override { diff --git a/caffe2/operators/summarize_op.h b/caffe2/operators/summarize_op.h index 5161849..630c903 100644 --- a/caffe2/operators/summarize_op.h +++ b/caffe2/operators/summarize_op.h @@ -14,7 +14,7 @@ constexpr char kSummaryzeOpExtension[] = ".summary"; template class SummarizeOp final : public Operator { public: - SummarizeOp(const OperatorDef& def, Workspace* ws) + explicit SummarizeOp(const OperatorDef& def, Workspace* ws) : Operator(def, ws), to_file_(this->template GetSingleArgument("to_file", 0)) { if (to_file_) { diff --git a/caffe2/operators/text_file_reader.cc b/caffe2/operators/text_file_reader.cc index 3888dc2..5a3e80d 100644 --- a/caffe2/operators/text_file_reader.cc +++ b/caffe2/operators/text_file_reader.cc @@ -38,8 +38,9 @@ struct TextFileReaderInstance { class CreateTextFileReaderOp : public Operator { public: - CreateTextFileReaderOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws), + template + explicit CreateTextFileReaderOp(Args&&... args) + : Operator(std::forward(args)...), filename_(GetSingleArgument("filename", "")), numPasses_(GetSingleArgument("num_passes", 1)), fieldTypes_(GetRepeatedArgument("field_types")) { @@ -86,8 +87,9 @@ inline void convert( class TextFileReaderReadOp : public Operator { public: - TextFileReaderReadOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws), + template + explicit TextFileReaderReadOp(Args&&... args) + : Operator(std::forward(args)...), batchSize_(GetSingleArgument("batch_size", 1)) {} bool RunOnDevice() override { diff --git a/caffe2/operators/thresholded_relu_op.h b/caffe2/operators/thresholded_relu_op.h index 28e04e0..870c927 100644 --- a/caffe2/operators/thresholded_relu_op.h +++ b/caffe2/operators/thresholded_relu_op.h @@ -12,8 +12,9 @@ template class ThresholdedReluOp final : public Operator { public: USE_OPERATOR_CONTEXT_FUNCTIONS; - ThresholdedReluOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws) { + template + explicit ThresholdedReluOp(Args&&... args) + : Operator(std::forward(args)...) { alpha_ = this->template GetSingleArgument("alpha", 1.0); } @@ -27,8 +28,9 @@ template class ThresholdedReluGradientOp final : public Operator { public: USE_OPERATOR_CONTEXT_FUNCTIONS; - ThresholdedReluGradientOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws) { + template + explicit ThresholdedReluGradientOp(Args&&... args) + : Operator(std::forward(args)...) { alpha_ = this->template GetSingleArgument("alpha", 1.0); } diff --git a/caffe2/operators/tile_op.h b/caffe2/operators/tile_op.h index 95e44d8..df33bc6 100644 --- a/caffe2/operators/tile_op.h +++ b/caffe2/operators/tile_op.h @@ -14,8 +14,9 @@ template class TileOp : public Operator { public: USE_OPERATOR_CONTEXT_FUNCTIONS; - TileOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws), + template + explicit TileOp(Args&&... args) + : Operator(std::forward(args)...), tiles_(this->template GetSingleArgument("tiles", 1)), axis_(this->template GetSingleArgument("axis", 0)) {} ~TileOp() {} @@ -129,8 +130,9 @@ template class TileGradientOp : public Operator { public: USE_OPERATOR_CONTEXT_FUNCTIONS; - TileGradientOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws), + template + explicit TileGradientOp(Args&&... args) + : Operator(std::forward(args)...), tiles_(this->template GetSingleArgument("tiles", 1)), axis_(this->template GetSingleArgument("axis", 0)) {} ~TileGradientOp() {} diff --git a/caffe2/operators/top_k.h b/caffe2/operators/top_k.h index a59ac70..447d2ca 100644 --- a/caffe2/operators/top_k.h +++ b/caffe2/operators/top_k.h @@ -12,8 +12,9 @@ class TopKOp : public Operator { public: USE_OPERATOR_CONTEXT_FUNCTIONS; - TopKOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws), + template + explicit TopKOp(Args&&... args) + : Operator(std::forward(args)...), OP_SINGLE_ARG(int, "k", k_, -1), OP_SINGLE_ARG(int, "axis", axis_, -1) { CAFFE_ENFORCE(k_ >= 1, "k argument must be >= 1"); @@ -33,8 +34,9 @@ class TopKGradientOp : public Operator { public: USE_OPERATOR_CONTEXT_FUNCTIONS; - TopKGradientOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws), + template + explicit TopKGradientOp(Args&&... args) + : Operator(std::forward(args)...), OP_SINGLE_ARG(int, "axis", axis_, -1) {} ~TopKGradientOp() {} diff --git a/caffe2/operators/transpose_op.h b/caffe2/operators/transpose_op.h index 389e57f..dad157b 100644 --- a/caffe2/operators/transpose_op.h +++ b/caffe2/operators/transpose_op.h @@ -16,8 +16,9 @@ class TransposeOp final : public Operator { USE_OPERATOR_CONTEXT_FUNCTIONS; USE_DISPATCH_HELPER; - TransposeOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws), + template + explicit TransposeOp(Args&&... args) + : Operator(std::forward(args)...), axes_(this->template GetRepeatedArgument("axes")) { // We will check the legality of axes_: it should be from 0 to axes_.size(). std::vector axes_sorted = axes_; diff --git a/caffe2/operators/transpose_op_cudnn.cc b/caffe2/operators/transpose_op_cudnn.cc index 2b0f12e..d92d9ed 100644 --- a/caffe2/operators/transpose_op_cudnn.cc +++ b/caffe2/operators/transpose_op_cudnn.cc @@ -17,8 +17,9 @@ class CuDNNTransposeOp final : public Operator { USE_OPERATOR_FUNCTIONS(CUDAContext); USE_DISPATCH_HELPER; - CuDNNTransposeOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws), + template + explicit CuDNNTransposeOp(Args&&... args) + : Operator(std::forward(args)...), cudnn_wrapper_(&context_), axes_(OperatorBase::GetRepeatedArgument("axes")) { // We will check the legality of axes_: it should be from 0 to axes_.size(). diff --git a/caffe2/operators/tt_linear_op.h b/caffe2/operators/tt_linear_op.h index 3962f3e..3797d59 100644 --- a/caffe2/operators/tt_linear_op.h +++ b/caffe2/operators/tt_linear_op.h @@ -18,8 +18,9 @@ template class TTLinearOp final : public Operator { public: USE_OPERATOR_CONTEXT_FUNCTIONS; - TTLinearOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws), + template + explicit TTLinearOp(Args&&... args) + : Operator(std::forward(args)...), inp_sizes_(this->template GetRepeatedArgument("inp_sizes")), out_sizes_(this->template GetRepeatedArgument("out_sizes")), tt_ranks_(this->template GetRepeatedArgument("tt_ranks")), @@ -176,8 +177,9 @@ template class TTLinearGradientOp : public Operator { public: USE_OPERATOR_CONTEXT_FUNCTIONS; - TTLinearGradientOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws) {} + template + explicit TTLinearGradientOp(Args&&... args) + : Operator(std::forward(args)...) {} ~TTLinearGradientOp() {} bool RunOnDevice() override { diff --git a/caffe2/operators/upsample_op.h b/caffe2/operators/upsample_op.h index b5eceb2..5bc12fa 100644 --- a/caffe2/operators/upsample_op.h +++ b/caffe2/operators/upsample_op.h @@ -24,8 +24,11 @@ namespace caffe2 { template class UpsampleBilinearOp final : public Operator { public: - UpsampleBilinearOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws), width_scale_(1), height_scale_(1) { + template + explicit UpsampleBilinearOp(Args&&... args) + : Operator(std::forward(args)...), + width_scale_(1), + height_scale_(1) { if (HasArgument("width_scale")) { width_scale_ = static_cast( this->template GetSingleArgument("width_scale", 1)); @@ -49,8 +52,11 @@ class UpsampleBilinearOp final : public Operator { template class UpsampleBilinearGradientOp final : public Operator { public: - UpsampleBilinearGradientOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws), width_scale_(1), height_scale_(1) { + template + explicit UpsampleBilinearGradientOp(Args&&... args) + : Operator(std::forward(args)...), + width_scale_(1), + height_scale_(1) { width_scale_ = static_cast( this->template GetSingleArgument("width_scale", 1)); height_scale_ = static_cast( -- 2.7.4