space_to_depth.h 2.0 KB
Newer Older
L
Liangliang He 已提交
1
// Copyright 2018 Xiaomi, Inc.  All rights reserved.
2
//
L
Liangliang He 已提交
3 4 5
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
6
//
L
Liangliang He 已提交
7 8 9 10 11 12 13
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
14 15 16 17 18 19 20 21

#ifndef MACE_OPS_SPACE_TO_DEPTH_H_
#define MACE_OPS_SPACE_TO_DEPTH_H_

#include <memory>
#include <vector>

#include "mace/core/operator.h"
U
Unknown 已提交
22
#include "mace/kernels/depth_to_space.h"
23 24 25 26 27 28

namespace mace {
namespace ops {

template <DeviceType D, typename T>
class SpaceToDepthOp : public Operator<D, T> {
U
Unknown 已提交
29
 public:
30 31
  SpaceToDepthOp(const OperatorDef &op_def, Workspace *ws)
      : Operator<D, T>(op_def, ws),
U
Unknown 已提交
32 33
        functor_(OperatorBase::GetSingleArgument<int>("block_size", 1), false) {
  }
34 35

  bool Run(StatsFuture *future) override {
U
Unknown 已提交
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
    const Tensor *input = this->Input(INPUT);
    Tensor *output = this->Output(OUTPUT);
    MACE_CHECK(input->dim_size() == 4, "input dim should be 4");
    const int block_size =
        OperatorBase::GetSingleArgument<int>("block_size", 1);
    const int input_height = input->dim(1);
    const int input_width = input->dim(2);
    const int input_depth = input->dim(3);
    MACE_CHECK((input_depth % 4) == 0,
               "input channel should be dividable by 4");
    MACE_CHECK(
        (input_width%block_size == 0)&&(input_height%block_size == 0),
        "input width and height should be dividable by block_size",
        input->dim(3));
    functor_(input, output, future);
    return true;
52 53
  }

U
Unknown 已提交
54 55 56 57 58 59
 protected:
  OP_INPUT_TAGS(INPUT);
  OP_OUTPUT_TAGS(OUTPUT);

 private:
  kernels::DepthToSpaceOpFunctor<D, T> functor_;
60 61 62 63 64 65
};

}  // namespace ops
}  // namespace mace

#endif  // MACE_OPS_SPACE_TO_DEPTH_H_