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_CLIENT_PADDING_H_ 17 #define TENSORFLOW_COMPILER_XLA_CLIENT_PADDING_H_ 18 19 #include <utility> 20 #include <vector> 21 22 #include "absl/types/span.h" 23 #include "tensorflow/compiler/xla/statusor.h" 24 #include "tensorflow/compiler/xla/types.h" 25 26 namespace xla { 27 28 // Describes the padding applied for a windowed operation like 29 // convolution, where a window is placed inside a base area. 30 enum class Padding { 31 // Make the output have the same dimensions as the base area. For 32 // example, for a 3x3 base area and a 2x2 window, the output will be 33 // 3x3, so that requires padding the 3x3 base area to 4x4. 34 kSame, 35 36 // Use no padding. For example, for a 4x4 base area and a 2x2 37 // window, the output will be 3x3. 38 kValid, 39 }; 40 41 // Validates that the slices are acceptable for determining padding -- this can 42 // be used to check the preconditions of MakePadding below to produce an error 43 // message that can be returned to the user. 44 Status ValidatePaddingValues(absl::Span<const int64> input_dimensions, 45 absl::Span<const int64> window_dimensions, 46 absl::Span<const int64> window_strides); 47 48 // Returns the padding needed for the base area, given the base area dimensions, 49 // window dimensions, strides, and the type of padding. 50 // 51 // If v is the returned vector, then for each dimension number i, 52 // v[i].first is the padding to the left (i.e. in the direction of 53 // lower indices) and v[i].second is the padding to the right (i.e. in 54 // the direction of higher indices). 55 // 56 // Precondition: The number of dimensions (i.e., rank) in input_dimensions, 57 // window_dimensions, and strides must match, which is equal to the number 58 // of elements in the result vector. 59 std::vector<std::pair<int64, int64>> MakePadding( 60 absl::Span<const int64> input_dimensions, 61 absl::Span<const int64> window_dimensions, 62 absl::Span<const int64> window_strides, Padding padding); 63 64 } // namespace xla 65 66 #endif // TENSORFLOW_COMPILER_XLA_CLIENT_PADDING_H_ 67