• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright 2020 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_TASK_UTIL_H_
17 #define TENSORFLOW_LITE_DELEGATES_GPU_COMMON_TASK_UTIL_H_
18 
19 #include <string>
20 #include <vector>
21 
22 #include "tensorflow/lite/delegates/gpu/common/gpu_info.h"
23 #include "tensorflow/lite/delegates/gpu/common/precision.h"
24 #include "tensorflow/lite/delegates/gpu/common/task/gpu_object_desc.h"
25 #include "tensorflow/lite/delegates/gpu/common/types.h"
26 
27 namespace tflite {
28 namespace gpu {
29 
30 std::string MemoryTypeToCLType(MemoryType type);
31 
32 std::string MemoryTypeToMetalType(MemoryType type);
33 
34 // Calculates correct X coordinate when stride != 1 and batch != 1 for layouts
35 // with B after W (for example HWBC4) and WB stored in one axis of GPU
36 // resources.
37 std::string GetXStrideCorrected(const std::string& src_x,
38                                 const std::string& batch_size,
39                                 const std::string& stride_x,
40                                 const std::string& padding_x);
41 
42 // Calculates correct X coordinate when stride != 1 and batch != 1 for layouts
43 // with B after W (for example HWBC4) and WB stored in one axis of GPU
44 // resources.
45 std::string GetXStrideCorrectedV2(const std::string& src_x,
46                                   const std::string& batch_size,
47                                   const std::string& stride_x,
48                                   const std::string& padding_x);
49 
50 // Returns float4 mask for last plane(batch of 4 channels)
51 // assumes that plane size is 4;
52 // for example we have 7 channels, in our data structures we align it to 8
53 // but 8s-channel will be empty, then last plane (batch of 4 channels) will
54 // have this mask (1, 1, 1, 0).
55 float4 GetMaskForLastPlane(int channels);
56 
57 // task_size as amount of FLT4 processed elements.
58 int GetRecommendedBlockSizeForConv(const GpuInfo& gpu_info,
59                                    CalculationsPrecision precision,
60                                    int task_size);
61 
62 int3 GetWorkGroupsCount(const int3& grid_size, const int3& work_group_size);
63 
64 }  // namespace gpu
65 }  // namespace tflite
66 
67 #endif  // TENSORFLOW_LITE_DELEGATES_GPU_COMMON_TASK_UTIL_H_
68