mirror of
https://github.com/pytorch/pytorch.git
synced 2025-11-11 22:34:53 +08:00
Summary: The mkldnn-bridge is upgraded in this PR to support DNNLOWP operators. Meanwhile, APIs have been updated in caffe2 to use latest version. Pull Request resolved: https://github.com/pytorch/pytorch/pull/16308 Differential Revision: D14697018 Pulled By: yinghai fbshipit-source-id: ca952589098accb08295fd5aa92924c61e74d69c
78 lines
2.0 KiB
C++
78 lines
2.0 KiB
C++
#ifndef CAFFE2_IDEEP_OPERATORS_CONV_POOL_BASE_OP_H_
|
|
#define CAFFE2_IDEEP_OPERATORS_CONV_POOL_BASE_OP_H_
|
|
|
|
#include <vector>
|
|
|
|
#include "caffe2/ideep/ideep_utils.h"
|
|
#include "caffe2/operators/conv_pool_op_base.h"
|
|
|
|
namespace caffe2 {
|
|
|
|
class IDEEPConvPoolOpBase : public ConvPoolOpBase<IDEEPContext> {
|
|
public:
|
|
IDEEPConvPoolOpBase(const OperatorDef& operator_def, Workspace* ws)
|
|
: ConvPoolOpBase<IDEEPContext>(operator_def, ws) {}
|
|
virtual ~IDEEPConvPoolOpBase() {}
|
|
|
|
inline const ideep::tensor& Input(int index) {
|
|
return OperatorBase::template Input<ideep::tensor>(index);
|
|
}
|
|
inline ideep::tensor* Output(int index) {
|
|
return OperatorBase::template Output<ideep::tensor>(index);
|
|
}
|
|
|
|
ideep::tensor::dims pad_tl() const {
|
|
return {pad_t(), pad_l()};
|
|
}
|
|
|
|
ideep::tensor::dims pad_br() const {
|
|
return {pad_b(), pad_r()};
|
|
}
|
|
|
|
ideep::tensor::dims CalcOutputDims(
|
|
const ideep::tensor& input,
|
|
int output_channel) {
|
|
CAFFE_ENFORCE_GT(input.get_size(), 0);
|
|
ideep::tensor::dims output_dims;
|
|
const auto input_dims = input.get_dims();
|
|
std::vector<std::int64_t> input_Tdims(
|
|
input_dims.cbegin(), input_dims.cend());
|
|
InferOutputSize(
|
|
input_Tdims,
|
|
output_channel,
|
|
StorageOrder::NCHW, //order_,
|
|
global_pooling_,
|
|
legacy_pad_,
|
|
dilation_,
|
|
stride_,
|
|
&kernel_,
|
|
&pads_,
|
|
&output_dims);
|
|
return output_dims;
|
|
}
|
|
|
|
bool RunOnDevice() override {
|
|
if (!global_pooling_) {
|
|
for (int dim = 0; dim < kernel_.size(); ++dim) {
|
|
CAFFE_ENFORCE_GT(kernel_[dim], 0);
|
|
}
|
|
}
|
|
|
|
try {
|
|
return RunOnDeviceWithOrderNCHW();
|
|
} catch (ideep::error& e) {
|
|
LOG(ERROR) << "IDEEP error:" << e.message;
|
|
throw;
|
|
}
|
|
}
|
|
};
|
|
|
|
#define USE_IDEEP_CONV_POOL_BASE_FUNCTIONS() \
|
|
USE_OPERATOR_BASE_FUNCTIONS; \
|
|
/* using override */ using IDEEPConvPoolOpBase::Input; \
|
|
/* using override */ using IDEEPConvPoolOpBase::Output;
|
|
|
|
} // namespace caffe2
|
|
|
|
#endif // CAFFE2_IDEEP_OPERATORS_CONV_POOL_BASE_OP_H_
|