1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
|
#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);
std::vector<int> 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.begin(), output_dims.end()};
}
bool RunOnDevice() override {
if (!global_pooling_) {
for (const auto dim : c10::irange(kernel_.size())) {
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_
|