• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright 2019 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_LITE_DELEGATES_GPU_COMMON_UTIL_H_
17 #define TENSORFLOW_LITE_DELEGATES_GPU_COMMON_UTIL_H_
18 
19 #include "tensorflow/lite/delegates/gpu/common/types.h"
20 
21 namespace tflite {
22 namespace gpu {
23 
24 // @param n must be non negative
25 // @param divisor must be greater than zero
26 template <typename T, typename N>
DivideRoundUp(T n,N divisor)27 T DivideRoundUp(T n, N divisor) {
28   const T div = static_cast<T>(divisor);
29   const T q = n / div;
30   return n % div == 0 ? q : q + 1;
31 }
32 
33 template <>
DivideRoundUp(uint3 n,uint3 divisor)34 inline uint3 DivideRoundUp(uint3 n, uint3 divisor) {
35   return uint3(DivideRoundUp(n.x, divisor.x), DivideRoundUp(n.y, divisor.y),
36                DivideRoundUp(n.z, divisor.z));
37 }
38 
39 // @param number or its components must be greater than zero
40 // @param n must be greater than zero
41 template <typename T, typename N>
AlignByN(T number,N n)42 T AlignByN(T number, N n) {
43   return DivideRoundUp(number, n) * n;
44 }
45 
46 }  // namespace gpu
47 }  // namespace tflite
48 
49 #endif  // TENSORFLOW_LITE_DELEGATES_GPU_COMMON_UTIL_H_
50