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