17 #ifndef UPSAMPLE_NEAREST_OP_H_ 18 #define UPSAMPLE_NEAREST_OP_H_ 20 #include "caffe2/core/context.h" 21 #include "caffe2/core/logging.h" 22 #include "caffe2/core/operator.h" 23 #include "caffe2/utils/math.h" 27 template <
typename T,
class Context>
32 scale_(this->
template GetSingleArgument<int>(
"scale", 2)) {
35 USE_OPERATOR_CONTEXT_FUNCTIONS;
37 bool RunOnDevice()
override {
40 auto out_shape = X.sizes().vec();
41 out_shape[X.dim() - 1] *= scale_;
42 out_shape[X.dim() - 2] *= scale_;
43 auto* Y = Output(0, out_shape, at::dtype<T>());
53 d1 = Y->dim32(0) * Y->dim32(1);
58 const T *input_data = X.template data<T>();
59 T *output_data = Y->template mutable_data<T>();
60 int scaled_d2 = d2 / scale_;
61 int scaled_d3 = d3 / scale_;
64 #if (_OPENMP >= 201307) 65 #pragma omp parallel for simd 67 #pragma omp parallel for 70 for (
int i = 0; i < d1; ++i) {
71 for (
int j = 0; j < d2; ++j) {
72 for (
int u = 0; u < d3; ++u) {
73 int ii = (i * d2 + j) * d3 + u;
74 int scaled_u = u / scale_;
75 int scaled_j = j / scale_;
76 int ipidx = ((i * scaled_d2) + scaled_j) * scaled_d3 + scaled_u;
77 output_data[ii] = input_data[ipidx];
89 template <
typename T,
class Context>
94 scale_(this->
template GetSingleArgument<int>(
"scale", 2)) {
97 USE_OPERATOR_CONTEXT_FUNCTIONS;
99 bool RunOnDevice()
override {
101 CAFFE_NOT_IMPLEMENTED;
110 #endif // UPSAMPLE_NEAREST_OP_H_
Workspace is a class that holds all the related objects created during runtime: (1) all blobs...
const Tensor & Input(int idx, DeviceType type=Context::GetDeviceType())
Retrieve a non-owning reference to the input at position 'idx' for this operator. ...
A global dictionary that holds information about what Caffe2 modules have been loaded in the current ...