1/* Copyright 2015 The TensorFlow Authors. All Rights Reserved.
2
3Licensed under the Apache License, Version 2.0 (the "License");
4you may not use this file except in compliance with the License.
5You may obtain a copy of the License at
6
7 http://www.apache.org/licenses/LICENSE-2.0
8
9Unless required by applicable law or agreed to in writing, software
10distributed under the License is distributed on an "AS IS" BASIS,
11WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12See the License for the specific language governing permissions and
13limitations under the License.
14==============================================================================*/
15
16#ifndef TENSORFLOW_CORE_KERNELS_DEPTHTOSPACE_OP_H_
17#define TENSORFLOW_CORE_KERNELS_DEPTHTOSPACE_OP_H_
18
19#include "third_party/eigen3/unsupported/Eigen/CXX11/Tensor"
20#include "tensorflow/core/framework/tensor_types.h"
21#include "tensorflow/core/util/tensor_format.h"
22
23namespace tensorflow {
24namespace functor {
25
26// Functor used by DepthToSpaceOp to do the computations.
27// Implements a family of Depth to Space transforms for a 4D 'input' tensor
28// to a 4D 'output' tensor, both tensors use type 'T' and layout 'data_format'.
29// These transforms multiply the vertical and horizontal image sizes by
30// 'block_size', and divide the depth dimension by (block_size * block_size)
31// which must divide evenly.
32// Each pixel in the input image is converted to a square block of pixels in
33// the output image. The Y, X coordinates within each block comes from the
34// high component of the input depth (channel) index.
35// e.g. for data_format = NHWC:
36// Each element in the input tensor can be specified via 6 coordinates,
37// ordered by decreasing memory layout significance as:
38// n,iY,iX,bY,bX,oC (where n=batch index, iX, iY means X or Y coordinates
39// within the input image, bX, bY means coordinates
40// within the output block, oC means output channel).
41// The output would be a transpose to the following layout:
42// n,iY,bY,iX,bX,oC
43template <typename Device, typename T, TensorFormat data_format>
44struct DepthToSpaceOpFunctor {
45 void operator()(const Device& d, typename TTypes<T, 4>::ConstTensor input,
46 int block_size, typename TTypes<T, 4>::Tensor output);
47
48 // This 5-D version is to support NCHW_VECT_C.
49 void operator()(const Device& d, typename TTypes<T, 5>::ConstTensor input,
50 int block_size, typename TTypes<T, 5>::Tensor output);
51};
52
53} // namespace functor
54} // namespace tensorflow
55
56#endif // TENSORFLOW_CORE_KERNELS_DEPTHTOSPACE_OP_H_
57