Home | History | Annotate | Download | only in xla
      1 /* Copyright 2017 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_COMPILER_XLA_WINDOW_UTIL_H_
     17 #define TENSORFLOW_COMPILER_XLA_WINDOW_UTIL_H_
     18 
     19 #include "tensorflow/compiler/xla/types.h"
     20 #include "tensorflow/compiler/xla/xla_data.pb.h"
     21 #include "tensorflow/core/lib/gtl/array_slice.h"
     22 
     23 namespace xla {
     24 namespace window_util {
     25 
     26 // Creates a window with the given sizes in the dimensions and all strides set
     27 // to 1.
     28 Window MakeWindow(tensorflow::gtl::ArraySlice<int64> sizes);
     29 
     30 // Creates a padding config with symmetrical padding in each dimension, of value
     31 // given by sizes; e.g. {0, 1, 2} would create a R3 padding config that had zero
     32 // pixels of padding in dimension 0, one pixel of padding symmetrically, on each
     33 // side of dimension 1, and two pixels of padding symmetrically on dimension 2.
     34 PaddingConfig MakeSymmetricPadding(tensorflow::gtl::ArraySlice<int64> sizes);
     35 
     36 string ToString(const WindowDimension& dim);
     37 string ToString(const Window& window);
     38 
     39 // The below functions return true if the given field is set to have a
     40 // non-trivial effect, e.g. having a stride means that the stride of some
     41 // dimension is not one. Whether the proto field is populated is not a
     42 // consideration.
     43 
     44 bool HasStride(const Window& window);
     45 bool HasPadding(const Window& window);
     46 bool HasSymmetricPadding(const Window& window);
     47 bool HasNegativePadding(const Window& window);
     48 
     49 // As with HasSymmetricPadding(Window) above, returns whether the "padding low"
     50 // is equivalent to the "padding high" for all dimensions, but works on a
     51 // padding configuration.
     52 bool HasSymmetricPadding(const PaddingConfig& padding_config);
     53 
     54 bool HasBaseDilation(const Window& window);
     55 bool HasWindowDilation(const Window& window);
     56 bool HasDilation(const Window& window);
     57 
     58 bool HasWindowReversal(const Window& window);
     59 
     60 // Returns true if the given logical dimension is inactive in the sense that it
     61 // has window bound 1, no striding and no padding.
     62 bool IsInactiveWindowDimension(const Window& window, int64 logical_dim);
     63 
     64 // Returns the new bound after dilation.
     65 //
     66 // If a window with the given bound in some dimension is dilated with the given
     67 // dilation factor in that dimension, then the value returned is the bound for
     68 // the array in that dimension after dilation.
     69 //
     70 // For a 1D array with 3 entries 1, 2, 3, a dilation factor of 2 yields a new
     71 // window with values 1, x, 2, x, 3, where x indicates holes left by the
     72 // dilation. So DilatedBound(3, 2) == 5.
     73 int64 DilatedBound(int64 bound, int64 dilation);
     74 
     75 // Returns the number of valid positions of a window with the given size and
     76 // stride within an array with the given bound. This is the bound of an output
     77 // array with one element per valid position of the window.
     78 //
     79 // For example, for arguments of (bound=5, window_size=2, stride=2), the
     80 // returned value is 2. There are valid positions at offset 0 and offset 2,
     81 // while offset 4 is not valid since the window's last entry would be at 5,
     82 // which is beyond the bound of 5.
     83 int64 StridedBound(int64 bound, int64 window_size, int64 stride);
     84 
     85 }  // namespace window_util
     86 }  // namespace xla
     87 
     88 #endif  // TENSORFLOW_COMPILER_XLA_WINDOW_UTIL_H_
     89