mirror of
https://github.com/zebrajr/pytorch.git
synced 2025-12-06 12:20:52 +01:00
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
This commit is contained in:
parent
28b5df1c8f
commit
7413f0926a
|
|
@ -202,8 +202,9 @@ template <class Context>
|
||||||
class SliceOp : public Operator<Context> {
|
class SliceOp : public Operator<Context> {
|
||||||
public:
|
public:
|
||||||
USE_OPERATOR_CONTEXT_FUNCTIONS;
|
USE_OPERATOR_CONTEXT_FUNCTIONS;
|
||||||
SliceOp(const OperatorDef& operator_def, Workspace* ws)
|
template <class... Args>
|
||||||
: Operator<Context>(operator_def, ws),
|
explicit SliceOp(Args&&... args)
|
||||||
|
: Operator<Context>(std::forward<Args>(args)...),
|
||||||
starts_(this->template GetRepeatedArgument<int64_t>("starts")),
|
starts_(this->template GetRepeatedArgument<int64_t>("starts")),
|
||||||
ends_(this->template GetRepeatedArgument<int64_t>("ends")),
|
ends_(this->template GetRepeatedArgument<int64_t>("ends")),
|
||||||
statically_inited_(false) {}
|
statically_inited_(false) {}
|
||||||
|
|
@ -263,8 +264,9 @@ template <class Context>
|
||||||
class SliceGradientOp : public Operator<Context> {
|
class SliceGradientOp : public Operator<Context> {
|
||||||
public:
|
public:
|
||||||
USE_OPERATOR_CONTEXT_FUNCTIONS;
|
USE_OPERATOR_CONTEXT_FUNCTIONS;
|
||||||
SliceGradientOp(const OperatorDef& operator_def, Workspace* ws)
|
template <class... Args>
|
||||||
: Operator<Context>(operator_def, ws),
|
explicit SliceGradientOp(Args&&... args)
|
||||||
|
: Operator<Context>(std::forward<Args>(args)...),
|
||||||
starts_(this->template GetRepeatedArgument<int64_t>("starts")),
|
starts_(this->template GetRepeatedArgument<int64_t>("starts")),
|
||||||
ends_(this->template GetRepeatedArgument<int64_t>("ends")),
|
ends_(this->template GetRepeatedArgument<int64_t>("ends")),
|
||||||
statically_inited_(false) {}
|
statically_inited_(false) {}
|
||||||
|
|
|
||||||
|
|
@ -11,9 +11,10 @@ namespace caffe2 {
|
||||||
template <typename T, class Context>
|
template <typename T, class Context>
|
||||||
class SoftmaxOp final : public Operator<Context> {
|
class SoftmaxOp final : public Operator<Context> {
|
||||||
public:
|
public:
|
||||||
SoftmaxOp(const OperatorDef& operator_def, Workspace* ws)
|
template <class... Args>
|
||||||
: Operator<Context>(operator_def, ws),
|
explicit SoftmaxOp(Args&&... args)
|
||||||
axis_(this->template GetSingleArgument<int>("axis", 1)) {}
|
: Operator<Context>(std::forward<Args>(args)...),
|
||||||
|
axis_(this->template GetSingleArgument<int>("axis", 1)) {}
|
||||||
USE_OPERATOR_CONTEXT_FUNCTIONS;
|
USE_OPERATOR_CONTEXT_FUNCTIONS;
|
||||||
bool RunOnDevice() override;
|
bool RunOnDevice() override;
|
||||||
|
|
||||||
|
|
@ -27,8 +28,9 @@ class SoftmaxOp final : public Operator<Context> {
|
||||||
template <typename T, class Context>
|
template <typename T, class Context>
|
||||||
class SoftmaxGradientOp final : public Operator<Context> {
|
class SoftmaxGradientOp final : public Operator<Context> {
|
||||||
public:
|
public:
|
||||||
SoftmaxGradientOp(const OperatorDef& operator_def, Workspace* ws)
|
template <class... Args>
|
||||||
: Operator<Context>(operator_def, ws),
|
explicit SoftmaxGradientOp(Args&&... args)
|
||||||
|
: Operator<Context>(std::forward<Args>(args)...),
|
||||||
axis_(this->template GetSingleArgument<int>("axis", 1)) {}
|
axis_(this->template GetSingleArgument<int>("axis", 1)) {}
|
||||||
USE_OPERATOR_CONTEXT_FUNCTIONS;
|
USE_OPERATOR_CONTEXT_FUNCTIONS;
|
||||||
bool RunOnDevice() override;
|
bool RunOnDevice() override;
|
||||||
|
|
|
||||||
|
|
@ -15,8 +15,9 @@ constexpr int TOP_GRADIENT_DESC_ID = 2;
|
||||||
|
|
||||||
class CuDNNSoftmaxOp final : public Operator<CUDAContext> {
|
class CuDNNSoftmaxOp final : public Operator<CUDAContext> {
|
||||||
public:
|
public:
|
||||||
explicit CuDNNSoftmaxOp(const OperatorDef& def, Workspace* ws)
|
template <class... Args>
|
||||||
: Operator<CUDAContext>(def, ws),
|
explicit CuDNNSoftmaxOp(Args&&... args)
|
||||||
|
: Operator<CUDAContext>(std::forward<Args>(args)...),
|
||||||
cudnn_wrapper_(&context_),
|
cudnn_wrapper_(&context_),
|
||||||
axis_(OperatorBase::GetSingleArgument<int>("axis", 1)) {
|
axis_(OperatorBase::GetSingleArgument<int>("axis", 1)) {
|
||||||
CUDNN_ENFORCE(cudnnCreateTensorDescriptor(&desc_));
|
CUDNN_ENFORCE(cudnnCreateTensorDescriptor(&desc_));
|
||||||
|
|
@ -77,8 +78,9 @@ class CuDNNSoftmaxOp final : public Operator<CUDAContext> {
|
||||||
|
|
||||||
class CuDNNSoftmaxGradientOp final : public Operator<CUDAContext> {
|
class CuDNNSoftmaxGradientOp final : public Operator<CUDAContext> {
|
||||||
public:
|
public:
|
||||||
explicit CuDNNSoftmaxGradientOp(const OperatorDef& def, Workspace* ws)
|
template <class... Args>
|
||||||
: Operator<CUDAContext>(def, ws),
|
explicit CuDNNSoftmaxGradientOp(Args&&... args)
|
||||||
|
: Operator<CUDAContext>(std::forward<Args>(args)...),
|
||||||
cudnn_wrapper_(&context_),
|
cudnn_wrapper_(&context_),
|
||||||
axis_(OperatorBase::GetSingleArgument<int>("axis", 1)) {
|
axis_(OperatorBase::GetSingleArgument<int>("axis", 1)) {
|
||||||
CUDNN_ENFORCE(cudnnCreateTensorDescriptor(&desc_));
|
CUDNN_ENFORCE(cudnnCreateTensorDescriptor(&desc_));
|
||||||
|
|
|
||||||
|
|
@ -11,10 +11,12 @@ namespace caffe2 {
|
||||||
template <typename T, class Context>
|
template <typename T, class Context>
|
||||||
class SoftmaxWithLossOp final : public Operator<Context> {
|
class SoftmaxWithLossOp final : public Operator<Context> {
|
||||||
public:
|
public:
|
||||||
SoftmaxWithLossOp(const OperatorDef& operator_def, Workspace* ws)
|
template <class... Args>
|
||||||
: Operator<Context>(operator_def, ws),
|
explicit SoftmaxWithLossOp(Args&&... args)
|
||||||
|
: Operator<Context>(std::forward<Args>(args)...),
|
||||||
scale_(this->template GetSingleArgument<float>("scale", 1.)),
|
scale_(this->template GetSingleArgument<float>("scale", 1.)),
|
||||||
label_prob_mode_(this->template GetSingleArgument<int>("label_prob", 0)),
|
label_prob_mode_(
|
||||||
|
this->template GetSingleArgument<int>("label_prob", 0)),
|
||||||
order_(StringToStorageOrder(
|
order_(StringToStorageOrder(
|
||||||
this->template GetSingleArgument<string>("order", "NCHW"))),
|
this->template GetSingleArgument<string>("order", "NCHW"))),
|
||||||
axis_(this->template GetSingleArgument<int>("axis", 1)) {
|
axis_(this->template GetSingleArgument<int>("axis", 1)) {
|
||||||
|
|
@ -44,10 +46,12 @@ class SoftmaxWithLossOp final : public Operator<Context> {
|
||||||
template <typename T, class Context>
|
template <typename T, class Context>
|
||||||
class SoftmaxWithLossGradientOp final : public Operator<Context> {
|
class SoftmaxWithLossGradientOp final : public Operator<Context> {
|
||||||
public:
|
public:
|
||||||
SoftmaxWithLossGradientOp(const OperatorDef& def, Workspace* ws)
|
template <class... Args>
|
||||||
: Operator<Context>(def, ws),
|
explicit SoftmaxWithLossGradientOp(Args&&... args)
|
||||||
|
: Operator<Context>(std::forward<Args>(args)...),
|
||||||
scale_(this->template GetSingleArgument<float>("scale", 1.)),
|
scale_(this->template GetSingleArgument<float>("scale", 1.)),
|
||||||
label_prob_mode_(this->template GetSingleArgument<int>("label_prob", 0)),
|
label_prob_mode_(
|
||||||
|
this->template GetSingleArgument<int>("label_prob", 0)),
|
||||||
order_(StringToStorageOrder(
|
order_(StringToStorageOrder(
|
||||||
this->template GetSingleArgument<string>("order", "NCHW"))),
|
this->template GetSingleArgument<string>("order", "NCHW"))),
|
||||||
only_loss_(this->template GetSingleArgument<bool>("only_loss", false)),
|
only_loss_(this->template GetSingleArgument<bool>("only_loss", false)),
|
||||||
|
|
|
||||||
|
|
@ -111,8 +111,9 @@ template <typename Context>
|
||||||
class SpaceBatchOpBase : public Operator<Context> {
|
class SpaceBatchOpBase : public Operator<Context> {
|
||||||
public:
|
public:
|
||||||
USE_OPERATOR_CONTEXT_FUNCTIONS;
|
USE_OPERATOR_CONTEXT_FUNCTIONS;
|
||||||
SpaceBatchOpBase(const OperatorDef& operator_def, Workspace* ws)
|
template <class... Args>
|
||||||
: Operator<Context>(operator_def, ws),
|
explicit SpaceBatchOpBase(Args&&... args)
|
||||||
|
: Operator<Context>(std::forward<Args>(args)...),
|
||||||
pad_(this->template GetSingleArgument<int>("pad", 0)),
|
pad_(this->template GetSingleArgument<int>("pad", 0)),
|
||||||
pad_t_(this->template GetSingleArgument<int>("pad_t", pad_)),
|
pad_t_(this->template GetSingleArgument<int>("pad_t", pad_)),
|
||||||
pad_l_(this->template GetSingleArgument<int>("pad", pad_)),
|
pad_l_(this->template GetSingleArgument<int>("pad", pad_)),
|
||||||
|
|
|
||||||
|
|
@ -9,8 +9,9 @@ template <typename T, class Context>
|
||||||
class CAFFE2_API SparseNormalizeOp final : public Operator<Context> {
|
class CAFFE2_API SparseNormalizeOp final : public Operator<Context> {
|
||||||
public:
|
public:
|
||||||
USE_OPERATOR_CONTEXT_FUNCTIONS;
|
USE_OPERATOR_CONTEXT_FUNCTIONS;
|
||||||
SparseNormalizeOp(const OperatorDef& operator_def, Workspace* ws)
|
template <class... Args>
|
||||||
: Operator<Context>(operator_def, ws),
|
explicit SparseNormalizeOp(Args&&... args)
|
||||||
|
: Operator<Context>(std::forward<Args>(args)...),
|
||||||
use_max_norm_(
|
use_max_norm_(
|
||||||
this->template GetSingleArgument<bool>("use_max_norm", true)),
|
this->template GetSingleArgument<bool>("use_max_norm", true)),
|
||||||
norm_(this->template GetSingleArgument<float>("norm", 1.0)) {
|
norm_(this->template GetSingleArgument<float>("norm", 1.0)) {
|
||||||
|
|
|
||||||
|
|
@ -15,8 +15,9 @@ template <class Context>
|
||||||
class SparseToDenseMaskBase : public Operator<Context> {
|
class SparseToDenseMaskBase : public Operator<Context> {
|
||||||
public:
|
public:
|
||||||
USE_OPERATOR_CONTEXT_FUNCTIONS;
|
USE_OPERATOR_CONTEXT_FUNCTIONS;
|
||||||
SparseToDenseMaskBase(const OperatorDef& operator_def, Workspace* ws)
|
template <class... Args>
|
||||||
: Operator<Context>(operator_def, ws) {
|
explicit SparseToDenseMaskBase(Args&&... args)
|
||||||
|
: Operator<Context>(std::forward<Args>(args)...) {
|
||||||
std::vector<int64_t> mask =
|
std::vector<int64_t> mask =
|
||||||
this->template GetRepeatedArgument<int64_t>("mask");
|
this->template GetRepeatedArgument<int64_t>("mask");
|
||||||
featuresCount_ = mask.size();
|
featuresCount_ = mask.size();
|
||||||
|
|
@ -62,8 +63,9 @@ template <class Context>
|
||||||
class SparseToDenseMaskOp : public SparseToDenseMaskBase<Context> {
|
class SparseToDenseMaskOp : public SparseToDenseMaskBase<Context> {
|
||||||
public:
|
public:
|
||||||
USE_OPERATOR_CONTEXT_FUNCTIONS;
|
USE_OPERATOR_CONTEXT_FUNCTIONS;
|
||||||
SparseToDenseMaskOp(const OperatorDef& operator_def, Workspace* ws)
|
template <class... Args>
|
||||||
: SparseToDenseMaskBase<Context>(operator_def, ws) {
|
explicit SparseToDenseMaskOp(Args&&... args)
|
||||||
|
: SparseToDenseMaskBase<Context>(std::forward<Args>(args)...) {
|
||||||
returnPresenceMask_ = this->template GetSingleArgument<bool>(
|
returnPresenceMask_ = this->template GetSingleArgument<bool>(
|
||||||
"return_presence_mask", false);
|
"return_presence_mask", false);
|
||||||
maxSkippedSparseIndices_ =
|
maxSkippedSparseIndices_ =
|
||||||
|
|
@ -192,8 +194,9 @@ template <class Context>
|
||||||
class SparseToDenseMaskGradientOp : public SparseToDenseMaskBase<Context> {
|
class SparseToDenseMaskGradientOp : public SparseToDenseMaskBase<Context> {
|
||||||
public:
|
public:
|
||||||
USE_OPERATOR_CONTEXT_FUNCTIONS;
|
USE_OPERATOR_CONTEXT_FUNCTIONS;
|
||||||
SparseToDenseMaskGradientOp(const OperatorDef& operator_def, Workspace* ws)
|
template <class... Args>
|
||||||
: SparseToDenseMaskBase<Context>(operator_def, ws) {}
|
explicit SparseToDenseMaskGradientOp(Args&&... args)
|
||||||
|
: SparseToDenseMaskBase<Context>(std::forward<Args>(args)...) {}
|
||||||
|
|
||||||
bool RunOnDevice() override {
|
bool RunOnDevice() override {
|
||||||
return DispatchHelper<TensorTypes<int32_t, int64_t>>::call(
|
return DispatchHelper<TensorTypes<int32_t, int64_t>>::call(
|
||||||
|
|
|
||||||
|
|
@ -13,8 +13,9 @@ class SparseToDenseOp final : public Operator<Context> {
|
||||||
USE_OPERATOR_CONTEXT_FUNCTIONS;
|
USE_OPERATOR_CONTEXT_FUNCTIONS;
|
||||||
USE_DISPATCH_HELPER;
|
USE_DISPATCH_HELPER;
|
||||||
|
|
||||||
SparseToDenseOp(const OperatorDef& operator_def, Workspace* ws)
|
template <class... Args>
|
||||||
: Operator<Context>(operator_def, ws),
|
explicit SparseToDenseOp(Args&&... args)
|
||||||
|
: Operator<Context>(std::forward<Args>(args)...),
|
||||||
output_first_dim_(
|
output_first_dim_(
|
||||||
this->template GetSingleArgument<int>("output_first_dim", 0)) {}
|
this->template GetSingleArgument<int>("output_first_dim", 0)) {}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -19,8 +19,9 @@ class SpatialBNOp : public Operator<Context> {
|
||||||
public:
|
public:
|
||||||
USE_OPERATOR_CONTEXT_FUNCTIONS;
|
USE_OPERATOR_CONTEXT_FUNCTIONS;
|
||||||
|
|
||||||
SpatialBNOp(const OperatorDef& operator_def, Workspace* ws)
|
template <class... Args>
|
||||||
: Operator<Context>(operator_def, ws),
|
explicit SpatialBNOp(Args&&... args)
|
||||||
|
: Operator<Context>(std::forward<Args>(args)...),
|
||||||
OP_SINGLE_ARG(bool, OpSchema::Arg_IsTest, is_test_, false),
|
OP_SINGLE_ARG(bool, OpSchema::Arg_IsTest, is_test_, false),
|
||||||
OP_SINGLE_ARG(double, "epsilon", epsilon_, 1e-5),
|
OP_SINGLE_ARG(double, "epsilon", epsilon_, 1e-5),
|
||||||
OP_SINGLE_ARG(float, "momentum", momentum_, 0.9f),
|
OP_SINGLE_ARG(float, "momentum", momentum_, 0.9f),
|
||||||
|
|
@ -281,8 +282,9 @@ class SpatialBNGradientOp : public Operator<Context> {
|
||||||
public:
|
public:
|
||||||
USE_OPERATOR_CONTEXT_FUNCTIONS;
|
USE_OPERATOR_CONTEXT_FUNCTIONS;
|
||||||
|
|
||||||
SpatialBNGradientOp(const OperatorDef& operator_def, Workspace* ws)
|
template <class... Args>
|
||||||
: Operator<Context>(operator_def, ws),
|
explicit SpatialBNGradientOp(Args&&... args)
|
||||||
|
: Operator<Context>(std::forward<Args>(args)...),
|
||||||
OP_SINGLE_ARG(double, "epsilon", epsilon_, 1e-5),
|
OP_SINGLE_ARG(double, "epsilon", epsilon_, 1e-5),
|
||||||
order_(StringToStorageOrder(
|
order_(StringToStorageOrder(
|
||||||
this->template GetSingleArgument<string>("order", "NCHW"))),
|
this->template GetSingleArgument<string>("order", "NCHW"))),
|
||||||
|
|
|
||||||
|
|
@ -11,8 +11,9 @@ namespace caffe2 {
|
||||||
template <typename T, class Context>
|
template <typename T, class Context>
|
||||||
class SpatialSoftmaxWithLossOp final : public Operator<Context> {
|
class SpatialSoftmaxWithLossOp final : public Operator<Context> {
|
||||||
public:
|
public:
|
||||||
SpatialSoftmaxWithLossOp(const OperatorDef& operator_def, Workspace* ws)
|
template <class... Args>
|
||||||
: Operator<Context>(operator_def, ws),
|
explicit SpatialSoftmaxWithLossOp(Args&&... args)
|
||||||
|
: Operator<Context>(std::forward<Args>(args)...),
|
||||||
scale_(this->template GetSingleArgument<float>("scale", 1.)),
|
scale_(this->template GetSingleArgument<float>("scale", 1.)),
|
||||||
order_(StringToStorageOrder(
|
order_(StringToStorageOrder(
|
||||||
this->template GetSingleArgument<string>("order", "NCHW"))) {
|
this->template GetSingleArgument<string>("order", "NCHW"))) {
|
||||||
|
|
@ -39,8 +40,9 @@ class SpatialSoftmaxWithLossOp final : public Operator<Context> {
|
||||||
template <typename T, class Context>
|
template <typename T, class Context>
|
||||||
class SpatialSoftmaxWithLossGradientOp final : public Operator<Context> {
|
class SpatialSoftmaxWithLossGradientOp final : public Operator<Context> {
|
||||||
public:
|
public:
|
||||||
SpatialSoftmaxWithLossGradientOp(const OperatorDef& def, Workspace* ws)
|
template <class... Args>
|
||||||
: Operator<Context>(def, ws),
|
explicit SpatialSoftmaxWithLossGradientOp(Args&&... args)
|
||||||
|
: Operator<Context>(std::forward<Args>(args)...),
|
||||||
scale_(this->template GetSingleArgument<float>("scale", 1.)),
|
scale_(this->template GetSingleArgument<float>("scale", 1.)),
|
||||||
order_(StringToStorageOrder(
|
order_(StringToStorageOrder(
|
||||||
this->template GetSingleArgument<string>("order", "NCHW"))),
|
this->template GetSingleArgument<string>("order", "NCHW"))),
|
||||||
|
|
|
||||||
|
|
@ -13,8 +13,9 @@ class SquareRootDivideOp final : public Operator<Context> {
|
||||||
USE_OPERATOR_CONTEXT_FUNCTIONS;
|
USE_OPERATOR_CONTEXT_FUNCTIONS;
|
||||||
USE_DISPATCH_HELPER;
|
USE_DISPATCH_HELPER;
|
||||||
|
|
||||||
SquareRootDivideOp(const OperatorDef& operator_def, Workspace* ws)
|
template <class... Args>
|
||||||
: Operator<Context>(operator_def, ws) {}
|
explicit SquareRootDivideOp(Args&&... args)
|
||||||
|
: Operator<Context>(std::forward<Args>(args)...) {}
|
||||||
|
|
||||||
bool RunOnDevice() override {
|
bool RunOnDevice() override {
|
||||||
return DispatchHelper<TensorTypes<float>>::call(this, Input(DATA));
|
return DispatchHelper<TensorTypes<float>>::call(this, Input(DATA));
|
||||||
|
|
|
||||||
|
|
@ -8,8 +8,9 @@ namespace caffe2 {
|
||||||
|
|
||||||
class StatRegistryCreateOp : public Operator<CPUContext> {
|
class StatRegistryCreateOp : public Operator<CPUContext> {
|
||||||
public:
|
public:
|
||||||
StatRegistryCreateOp(const OperatorDef& operator_def, Workspace* ws)
|
template <class... Args>
|
||||||
: Operator(operator_def, ws) {}
|
explicit StatRegistryCreateOp(Args&&... args)
|
||||||
|
: Operator(std::forward<Args>(args)...) {}
|
||||||
|
|
||||||
bool RunOnDevice() override {
|
bool RunOnDevice() override {
|
||||||
*OperatorBase::Output<std::unique_ptr<StatRegistry>>(0) =
|
*OperatorBase::Output<std::unique_ptr<StatRegistry>>(0) =
|
||||||
|
|
@ -20,8 +21,9 @@ class StatRegistryCreateOp : public Operator<CPUContext> {
|
||||||
|
|
||||||
class StatRegistryExportOp : public Operator<CPUContext> {
|
class StatRegistryExportOp : public Operator<CPUContext> {
|
||||||
public:
|
public:
|
||||||
StatRegistryExportOp(const OperatorDef& operator_def, Workspace* ws)
|
template <class... Args>
|
||||||
: Operator(operator_def, ws),
|
explicit StatRegistryExportOp(Args&&... args)
|
||||||
|
: Operator(std::forward<Args>(args)...),
|
||||||
reset_(GetSingleArgument<bool>("reset", true)) {}
|
reset_(GetSingleArgument<bool>("reset", true)) {}
|
||||||
|
|
||||||
bool RunOnDevice() override {
|
bool RunOnDevice() override {
|
||||||
|
|
@ -55,8 +57,9 @@ class StatRegistryExportOp : public Operator<CPUContext> {
|
||||||
|
|
||||||
class StatRegistryUpdateOp : public Operator<CPUContext> {
|
class StatRegistryUpdateOp : public Operator<CPUContext> {
|
||||||
public:
|
public:
|
||||||
StatRegistryUpdateOp(const OperatorDef& operator_def, Workspace* ws)
|
template <class... Args>
|
||||||
: Operator(operator_def, ws) {}
|
explicit StatRegistryUpdateOp(Args&&... args)
|
||||||
|
: Operator(std::forward<Args>(args)...) {}
|
||||||
|
|
||||||
bool RunOnDevice() override {
|
bool RunOnDevice() override {
|
||||||
const auto& keys = Input(0);
|
const auto& keys = Input(0);
|
||||||
|
|
@ -118,7 +121,7 @@ class TimerInstance {
|
||||||
};
|
};
|
||||||
|
|
||||||
struct TimerBeginOp : public Operator<CPUContext> {
|
struct TimerBeginOp : public Operator<CPUContext> {
|
||||||
TimerBeginOp(const OperatorDef& operator_def, Workspace* ws)
|
explicit TimerBeginOp(const OperatorDef& operator_def, Workspace* ws)
|
||||||
: Operator(operator_def, ws),
|
: Operator(operator_def, ws),
|
||||||
given_name_(GetSingleArgument<std::string>(
|
given_name_(GetSingleArgument<std::string>(
|
||||||
"counter_name",
|
"counter_name",
|
||||||
|
|
@ -137,8 +140,8 @@ struct TimerBeginOp : public Operator<CPUContext> {
|
||||||
};
|
};
|
||||||
|
|
||||||
struct TimerEndOp : public Operator<CPUContext> {
|
struct TimerEndOp : public Operator<CPUContext> {
|
||||||
TimerEndOp(const OperatorDef& operator_def, Workspace* ws)
|
template <class... Args>
|
||||||
: Operator(operator_def, ws) {}
|
explicit TimerEndOp(Args&&... args) : Operator(std::forward<Args>(args)...) {}
|
||||||
|
|
||||||
bool RunOnDevice() override {
|
bool RunOnDevice() override {
|
||||||
OperatorBase::Input<TimerInstance*>(0)->end();
|
OperatorBase::Input<TimerInstance*>(0)->end();
|
||||||
|
|
@ -147,8 +150,9 @@ struct TimerEndOp : public Operator<CPUContext> {
|
||||||
};
|
};
|
||||||
|
|
||||||
struct TimerGetAndEndOp : public Operator<CPUContext> {
|
struct TimerGetAndEndOp : public Operator<CPUContext> {
|
||||||
TimerGetAndEndOp(const OperatorDef& operator_def, Workspace* ws)
|
template <class... Args>
|
||||||
: Operator(operator_def, ws) {}
|
explicit TimerGetAndEndOp(Args&&... args)
|
||||||
|
: Operator(std::forward<Args>(args)...) {}
|
||||||
|
|
||||||
bool RunOnDevice() override {
|
bool RunOnDevice() override {
|
||||||
int64_t nanos = OperatorBase::Input<TimerInstance*>(0)->get_ns();
|
int64_t nanos = OperatorBase::Input<TimerInstance*>(0)->get_ns();
|
||||||
|
|
@ -161,8 +165,8 @@ struct TimerGetAndEndOp : public Operator<CPUContext> {
|
||||||
};
|
};
|
||||||
|
|
||||||
struct TimerGetOp : public Operator<CPUContext> {
|
struct TimerGetOp : public Operator<CPUContext> {
|
||||||
TimerGetOp(const OperatorDef& operator_def, Workspace* ws)
|
template <class... Args>
|
||||||
: Operator(operator_def, ws) {}
|
explicit TimerGetOp(Args&&... args) : Operator(std::forward<Args>(args)...) {}
|
||||||
|
|
||||||
bool RunOnDevice() override {
|
bool RunOnDevice() override {
|
||||||
int64_t nanos = OperatorBase::Input<TimerInstance*>(0)->get_ns();
|
int64_t nanos = OperatorBase::Input<TimerInstance*>(0)->get_ns();
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ namespace caffe2 {
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
struct TemplatePutOp : public Operator<CPUContext> {
|
struct TemplatePutOp : public Operator<CPUContext> {
|
||||||
TemplatePutOp(const OperatorDef& operator_def, Workspace* ws)
|
explicit TemplatePutOp(const OperatorDef& operator_def, Workspace* ws)
|
||||||
: Operator(operator_def, ws),
|
: Operator(operator_def, ws),
|
||||||
given_name_(GetSingleArgument<std::string>(
|
given_name_(GetSingleArgument<std::string>(
|
||||||
"stat_name",
|
"stat_name",
|
||||||
|
|
|
||||||
|
|
@ -41,8 +41,9 @@ class StringJoinOp final : public Operator<Context> {
|
||||||
public:
|
public:
|
||||||
USE_OPERATOR_CONTEXT_FUNCTIONS;
|
USE_OPERATOR_CONTEXT_FUNCTIONS;
|
||||||
|
|
||||||
StringJoinOp(const OperatorDef& operator_def, Workspace* ws)
|
template <class... Args>
|
||||||
: Operator<Context>(operator_def, ws),
|
explicit StringJoinOp(Args&&... args)
|
||||||
|
: Operator<Context>(std::forward<Args>(args)...),
|
||||||
delimiter_(
|
delimiter_(
|
||||||
this->template GetSingleArgument<std::string>("delimiter", ",")),
|
this->template GetSingleArgument<std::string>("delimiter", ",")),
|
||||||
axis_(this->template GetSingleArgument<int>("axis", 0)) {
|
axis_(this->template GetSingleArgument<int>("axis", 0)) {
|
||||||
|
|
|
||||||
|
|
@ -32,8 +32,9 @@ class StumpFuncOp final : public Operator<Context> {
|
||||||
public:
|
public:
|
||||||
USE_OPERATOR_CONTEXT_FUNCTIONS;
|
USE_OPERATOR_CONTEXT_FUNCTIONS;
|
||||||
|
|
||||||
StumpFuncOp(const OperatorDef& operator_def, Workspace* ws)
|
template <class... Args>
|
||||||
: Operator<Context>(operator_def, ws),
|
explicit StumpFuncOp(Args&&... args)
|
||||||
|
: Operator<Context>(std::forward<Args>(args)...),
|
||||||
threshold_(this->template GetSingleArgument<TIN>("threshold", 0)),
|
threshold_(this->template GetSingleArgument<TIN>("threshold", 0)),
|
||||||
low_value_(this->template GetSingleArgument<TOUT>("low_value", 0)),
|
low_value_(this->template GetSingleArgument<TOUT>("low_value", 0)),
|
||||||
high_value_(this->template GetSingleArgument<TOUT>("high_value", 0)) {}
|
high_value_(this->template GetSingleArgument<TOUT>("high_value", 0)) {}
|
||||||
|
|
@ -53,8 +54,9 @@ class StumpFuncIndexOp final : public Operator<Context> {
|
||||||
public:
|
public:
|
||||||
USE_OPERATOR_CONTEXT_FUNCTIONS;
|
USE_OPERATOR_CONTEXT_FUNCTIONS;
|
||||||
|
|
||||||
StumpFuncIndexOp(const OperatorDef& operator_def, Workspace* ws)
|
template <class... Args>
|
||||||
: Operator<Context>(operator_def, ws),
|
explicit StumpFuncIndexOp(Args&&... args)
|
||||||
|
: Operator<Context>(std::forward<Args>(args)...),
|
||||||
threshold_(this->template GetSingleArgument<TIN>("threshold", 0)) {}
|
threshold_(this->template GetSingleArgument<TIN>("threshold", 0)) {}
|
||||||
|
|
||||||
bool RunOnDevice() override;
|
bool RunOnDevice() override;
|
||||||
|
|
|
||||||
|
|
@ -69,9 +69,7 @@ class PackedInt8BGRANHWCToNCHWCStylizerPreprocessOp
|
||||||
static constexpr int kNeonNoiseReadSize = kOutputChannels * 16;
|
static constexpr int kNeonNoiseReadSize = kOutputChannels * 16;
|
||||||
|
|
||||||
USE_OPERATOR_FUNCTIONS(CPUContext);
|
USE_OPERATOR_FUNCTIONS(CPUContext);
|
||||||
PackedInt8BGRANHWCToNCHWCStylizerPreprocessOp(
|
explicit PackedInt8BGRANHWCToNCHWCStylizerPreprocessOp(const OperatorDef& operator_def, Workspace* ws)
|
||||||
const OperatorDef& operator_def,
|
|
||||||
Workspace* ws)
|
|
||||||
: Operator<CPUContext>(operator_def, ws), ws_(ws) {}
|
: Operator<CPUContext>(operator_def, ws), ws_(ws) {}
|
||||||
|
|
||||||
bool RunOnDevice() override {
|
bool RunOnDevice() override {
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ constexpr char kSummaryzeOpExtension[] = ".summary";
|
||||||
template <typename T, class Context>
|
template <typename T, class Context>
|
||||||
class SummarizeOp final : public Operator<Context> {
|
class SummarizeOp final : public Operator<Context> {
|
||||||
public:
|
public:
|
||||||
SummarizeOp(const OperatorDef& def, Workspace* ws)
|
explicit SummarizeOp(const OperatorDef& def, Workspace* ws)
|
||||||
: Operator<Context>(def, ws),
|
: Operator<Context>(def, ws),
|
||||||
to_file_(this->template GetSingleArgument<int>("to_file", 0)) {
|
to_file_(this->template GetSingleArgument<int>("to_file", 0)) {
|
||||||
if (to_file_) {
|
if (to_file_) {
|
||||||
|
|
|
||||||
|
|
@ -38,8 +38,9 @@ struct TextFileReaderInstance {
|
||||||
|
|
||||||
class CreateTextFileReaderOp : public Operator<CPUContext> {
|
class CreateTextFileReaderOp : public Operator<CPUContext> {
|
||||||
public:
|
public:
|
||||||
CreateTextFileReaderOp(const OperatorDef& operator_def, Workspace* ws)
|
template <class... Args>
|
||||||
: Operator<CPUContext>(operator_def, ws),
|
explicit CreateTextFileReaderOp(Args&&... args)
|
||||||
|
: Operator<CPUContext>(std::forward<Args>(args)...),
|
||||||
filename_(GetSingleArgument<string>("filename", "")),
|
filename_(GetSingleArgument<string>("filename", "")),
|
||||||
numPasses_(GetSingleArgument<int>("num_passes", 1)),
|
numPasses_(GetSingleArgument<int>("num_passes", 1)),
|
||||||
fieldTypes_(GetRepeatedArgument<int>("field_types")) {
|
fieldTypes_(GetRepeatedArgument<int>("field_types")) {
|
||||||
|
|
@ -86,8 +87,9 @@ inline void convert(
|
||||||
|
|
||||||
class TextFileReaderReadOp : public Operator<CPUContext> {
|
class TextFileReaderReadOp : public Operator<CPUContext> {
|
||||||
public:
|
public:
|
||||||
TextFileReaderReadOp(const OperatorDef& operator_def, Workspace* ws)
|
template <class... Args>
|
||||||
: Operator<CPUContext>(operator_def, ws),
|
explicit TextFileReaderReadOp(Args&&... args)
|
||||||
|
: Operator<CPUContext>(std::forward<Args>(args)...),
|
||||||
batchSize_(GetSingleArgument<int>("batch_size", 1)) {}
|
batchSize_(GetSingleArgument<int>("batch_size", 1)) {}
|
||||||
|
|
||||||
bool RunOnDevice() override {
|
bool RunOnDevice() override {
|
||||||
|
|
|
||||||
|
|
@ -12,8 +12,9 @@ template <typename T, class Context>
|
||||||
class ThresholdedReluOp final : public Operator<Context> {
|
class ThresholdedReluOp final : public Operator<Context> {
|
||||||
public:
|
public:
|
||||||
USE_OPERATOR_CONTEXT_FUNCTIONS;
|
USE_OPERATOR_CONTEXT_FUNCTIONS;
|
||||||
ThresholdedReluOp(const OperatorDef& operator_def, Workspace* ws)
|
template <class... Args>
|
||||||
: Operator<Context>(operator_def, ws) {
|
explicit ThresholdedReluOp(Args&&... args)
|
||||||
|
: Operator<Context>(std::forward<Args>(args)...) {
|
||||||
alpha_ = this->template GetSingleArgument<T>("alpha", 1.0);
|
alpha_ = this->template GetSingleArgument<T>("alpha", 1.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -27,8 +28,9 @@ template <typename T, class Context>
|
||||||
class ThresholdedReluGradientOp final : public Operator<Context> {
|
class ThresholdedReluGradientOp final : public Operator<Context> {
|
||||||
public:
|
public:
|
||||||
USE_OPERATOR_CONTEXT_FUNCTIONS;
|
USE_OPERATOR_CONTEXT_FUNCTIONS;
|
||||||
ThresholdedReluGradientOp(const OperatorDef& operator_def, Workspace* ws)
|
template <class... Args>
|
||||||
: Operator<Context>(operator_def, ws) {
|
explicit ThresholdedReluGradientOp(Args&&... args)
|
||||||
|
: Operator<Context>(std::forward<Args>(args)...) {
|
||||||
alpha_ = this->template GetSingleArgument<T>("alpha", 1.0);
|
alpha_ = this->template GetSingleArgument<T>("alpha", 1.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -14,8 +14,9 @@ template <class Context>
|
||||||
class TileOp : public Operator<Context> {
|
class TileOp : public Operator<Context> {
|
||||||
public:
|
public:
|
||||||
USE_OPERATOR_CONTEXT_FUNCTIONS;
|
USE_OPERATOR_CONTEXT_FUNCTIONS;
|
||||||
TileOp(const OperatorDef& operator_def, Workspace* ws)
|
template <class... Args>
|
||||||
: Operator<Context>(operator_def, ws),
|
explicit TileOp(Args&&... args)
|
||||||
|
: Operator<Context>(std::forward<Args>(args)...),
|
||||||
tiles_(this->template GetSingleArgument<int32_t>("tiles", 1)),
|
tiles_(this->template GetSingleArgument<int32_t>("tiles", 1)),
|
||||||
axis_(this->template GetSingleArgument<int32_t>("axis", 0)) {}
|
axis_(this->template GetSingleArgument<int32_t>("axis", 0)) {}
|
||||||
~TileOp() {}
|
~TileOp() {}
|
||||||
|
|
@ -129,8 +130,9 @@ template <typename T, class Context>
|
||||||
class TileGradientOp : public Operator<Context> {
|
class TileGradientOp : public Operator<Context> {
|
||||||
public:
|
public:
|
||||||
USE_OPERATOR_CONTEXT_FUNCTIONS;
|
USE_OPERATOR_CONTEXT_FUNCTIONS;
|
||||||
TileGradientOp(const OperatorDef& operator_def, Workspace* ws)
|
template <class... Args>
|
||||||
: Operator<Context>(operator_def, ws),
|
explicit TileGradientOp(Args&&... args)
|
||||||
|
: Operator<Context>(std::forward<Args>(args)...),
|
||||||
tiles_(this->template GetSingleArgument<int32_t>("tiles", 1)),
|
tiles_(this->template GetSingleArgument<int32_t>("tiles", 1)),
|
||||||
axis_(this->template GetSingleArgument<int32_t>("axis", 0)) {}
|
axis_(this->template GetSingleArgument<int32_t>("axis", 0)) {}
|
||||||
~TileGradientOp() {}
|
~TileGradientOp() {}
|
||||||
|
|
|
||||||
|
|
@ -12,8 +12,9 @@ class TopKOp : public Operator<Context> {
|
||||||
public:
|
public:
|
||||||
USE_OPERATOR_CONTEXT_FUNCTIONS;
|
USE_OPERATOR_CONTEXT_FUNCTIONS;
|
||||||
|
|
||||||
TopKOp(const OperatorDef& operator_def, Workspace* ws)
|
template <class... Args>
|
||||||
: Operator<Context>(operator_def, ws),
|
explicit TopKOp(Args&&... args)
|
||||||
|
: Operator<Context>(std::forward<Args>(args)...),
|
||||||
OP_SINGLE_ARG(int, "k", k_, -1),
|
OP_SINGLE_ARG(int, "k", k_, -1),
|
||||||
OP_SINGLE_ARG(int, "axis", axis_, -1) {
|
OP_SINGLE_ARG(int, "axis", axis_, -1) {
|
||||||
CAFFE_ENFORCE(k_ >= 1, "k argument must be >= 1");
|
CAFFE_ENFORCE(k_ >= 1, "k argument must be >= 1");
|
||||||
|
|
@ -33,8 +34,9 @@ class TopKGradientOp : public Operator<Context> {
|
||||||
public:
|
public:
|
||||||
USE_OPERATOR_CONTEXT_FUNCTIONS;
|
USE_OPERATOR_CONTEXT_FUNCTIONS;
|
||||||
|
|
||||||
TopKGradientOp(const OperatorDef& operator_def, Workspace* ws)
|
template <class... Args>
|
||||||
: Operator<Context>(operator_def, ws),
|
explicit TopKGradientOp(Args&&... args)
|
||||||
|
: Operator<Context>(std::forward<Args>(args)...),
|
||||||
OP_SINGLE_ARG(int, "axis", axis_, -1) {}
|
OP_SINGLE_ARG(int, "axis", axis_, -1) {}
|
||||||
|
|
||||||
~TopKGradientOp() {}
|
~TopKGradientOp() {}
|
||||||
|
|
|
||||||
|
|
@ -16,8 +16,9 @@ class TransposeOp final : public Operator<Context> {
|
||||||
USE_OPERATOR_CONTEXT_FUNCTIONS;
|
USE_OPERATOR_CONTEXT_FUNCTIONS;
|
||||||
USE_DISPATCH_HELPER;
|
USE_DISPATCH_HELPER;
|
||||||
|
|
||||||
TransposeOp(const OperatorDef& operator_def, Workspace* ws)
|
template <class... Args>
|
||||||
: Operator<Context>(operator_def, ws),
|
explicit TransposeOp(Args&&... args)
|
||||||
|
: Operator<Context>(std::forward<Args>(args)...),
|
||||||
axes_(this->template GetRepeatedArgument<int>("axes")) {
|
axes_(this->template GetRepeatedArgument<int>("axes")) {
|
||||||
// We will check the legality of axes_: it should be from 0 to axes_.size().
|
// We will check the legality of axes_: it should be from 0 to axes_.size().
|
||||||
std::vector<int> axes_sorted = axes_;
|
std::vector<int> axes_sorted = axes_;
|
||||||
|
|
|
||||||
|
|
@ -17,8 +17,9 @@ class CuDNNTransposeOp final : public Operator<CUDAContext> {
|
||||||
USE_OPERATOR_FUNCTIONS(CUDAContext);
|
USE_OPERATOR_FUNCTIONS(CUDAContext);
|
||||||
USE_DISPATCH_HELPER;
|
USE_DISPATCH_HELPER;
|
||||||
|
|
||||||
CuDNNTransposeOp(const OperatorDef& operator_def, Workspace* ws)
|
template <class... Args>
|
||||||
: Operator<CUDAContext>(operator_def, ws),
|
explicit CuDNNTransposeOp(Args&&... args)
|
||||||
|
: Operator<CUDAContext>(std::forward<Args>(args)...),
|
||||||
cudnn_wrapper_(&context_),
|
cudnn_wrapper_(&context_),
|
||||||
axes_(OperatorBase::GetRepeatedArgument<int>("axes")) {
|
axes_(OperatorBase::GetRepeatedArgument<int>("axes")) {
|
||||||
// We will check the legality of axes_: it should be from 0 to axes_.size().
|
// We will check the legality of axes_: it should be from 0 to axes_.size().
|
||||||
|
|
|
||||||
|
|
@ -18,8 +18,9 @@ template <typename T, class Context, class Engine = DefaultEngine>
|
||||||
class TTLinearOp final : public Operator<Context> {
|
class TTLinearOp final : public Operator<Context> {
|
||||||
public:
|
public:
|
||||||
USE_OPERATOR_CONTEXT_FUNCTIONS;
|
USE_OPERATOR_CONTEXT_FUNCTIONS;
|
||||||
TTLinearOp(const OperatorDef& operator_def, Workspace* ws)
|
template <class... Args>
|
||||||
: Operator<Context>(operator_def, ws),
|
explicit TTLinearOp(Args&&... args)
|
||||||
|
: Operator<Context>(std::forward<Args>(args)...),
|
||||||
inp_sizes_(this->template GetRepeatedArgument<int>("inp_sizes")),
|
inp_sizes_(this->template GetRepeatedArgument<int>("inp_sizes")),
|
||||||
out_sizes_(this->template GetRepeatedArgument<int>("out_sizes")),
|
out_sizes_(this->template GetRepeatedArgument<int>("out_sizes")),
|
||||||
tt_ranks_(this->template GetRepeatedArgument<int>("tt_ranks")),
|
tt_ranks_(this->template GetRepeatedArgument<int>("tt_ranks")),
|
||||||
|
|
@ -176,8 +177,9 @@ template <typename T, class Context, class Engine = DefaultEngine>
|
||||||
class TTLinearGradientOp : public Operator<Context> {
|
class TTLinearGradientOp : public Operator<Context> {
|
||||||
public:
|
public:
|
||||||
USE_OPERATOR_CONTEXT_FUNCTIONS;
|
USE_OPERATOR_CONTEXT_FUNCTIONS;
|
||||||
TTLinearGradientOp(const OperatorDef& operator_def, Workspace* ws)
|
template <class... Args>
|
||||||
: Operator<Context>(operator_def, ws) {}
|
explicit TTLinearGradientOp(Args&&... args)
|
||||||
|
: Operator<Context>(std::forward<Args>(args)...) {}
|
||||||
~TTLinearGradientOp() {}
|
~TTLinearGradientOp() {}
|
||||||
|
|
||||||
bool RunOnDevice() override {
|
bool RunOnDevice() override {
|
||||||
|
|
|
||||||
|
|
@ -24,8 +24,11 @@ namespace caffe2 {
|
||||||
template <typename T, class Context>
|
template <typename T, class Context>
|
||||||
class UpsampleBilinearOp final : public Operator<Context> {
|
class UpsampleBilinearOp final : public Operator<Context> {
|
||||||
public:
|
public:
|
||||||
UpsampleBilinearOp(const OperatorDef& operator_def, Workspace* ws)
|
template <class... Args>
|
||||||
: Operator<Context>(operator_def, ws), width_scale_(1), height_scale_(1) {
|
explicit UpsampleBilinearOp(Args&&... args)
|
||||||
|
: Operator<Context>(std::forward<Args>(args)...),
|
||||||
|
width_scale_(1),
|
||||||
|
height_scale_(1) {
|
||||||
if (HasArgument("width_scale")) {
|
if (HasArgument("width_scale")) {
|
||||||
width_scale_ = static_cast<T>(
|
width_scale_ = static_cast<T>(
|
||||||
this->template GetSingleArgument<float>("width_scale", 1));
|
this->template GetSingleArgument<float>("width_scale", 1));
|
||||||
|
|
@ -49,8 +52,11 @@ class UpsampleBilinearOp final : public Operator<Context> {
|
||||||
template <typename T, class Context>
|
template <typename T, class Context>
|
||||||
class UpsampleBilinearGradientOp final : public Operator<Context> {
|
class UpsampleBilinearGradientOp final : public Operator<Context> {
|
||||||
public:
|
public:
|
||||||
UpsampleBilinearGradientOp(const OperatorDef& operator_def, Workspace* ws)
|
template <class... Args>
|
||||||
: Operator<Context>(operator_def, ws), width_scale_(1), height_scale_(1) {
|
explicit UpsampleBilinearGradientOp(Args&&... args)
|
||||||
|
: Operator<Context>(std::forward<Args>(args)...),
|
||||||
|
width_scale_(1),
|
||||||
|
height_scale_(1) {
|
||||||
width_scale_ = static_cast<T>(
|
width_scale_ = static_cast<T>(
|
||||||
this->template GetSingleArgument<float>("width_scale", 1));
|
this->template GetSingleArgument<float>("width_scale", 1));
|
||||||
height_scale_ = static_cast<T>(
|
height_scale_ = static_cast<T>(
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user