• 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_GL_WORKGROUPS_CALCULATOR_H_
17 #define TENSORFLOW_LITE_DELEGATES_GPU_GL_WORKGROUPS_CALCULATOR_H_
18 
19 #include <memory>
20 
21 #include "tensorflow/lite/delegates/gpu/common/gpu_info.h"
22 #include "tensorflow/lite/delegates/gpu/common/types.h"
23 #include "tensorflow/lite/delegates/gpu/gl/compiler/shader_code.h"
24 
25 namespace tflite {
26 namespace gpu {
27 namespace gl {
28 
29 constexpr uint3 kEmptyWorkgroupSize(0, 0, 0);
30 
31 // Calculates workgroup size for the given shader code in a model graph.
32 //
33 // Potentially there are multiple implementations possible:
34 //   - per-operation type hard-coded constants
35 //   - statistic-based calculator that uses aggregated stats for all operations
36 class WorkgroupsCalculator {
37  public:
38   explicit WorkgroupsCalculator(const GpuInfo& gpu_info);
39 
40   virtual ~WorkgroupsCalculator() = default;
41 
42   // Uses shader code recommended work group size if available and doesn't
43   // exceed max work group invocations num, otherwise work group size from
44   // passed calculator.
45   uint3 Calculate(const ShaderCode& shader_code) const;
46 
47  protected:
48   virtual uint3 CalculateInternal(const ShaderCode& shader_code) const = 0;
49 
50  private:
51   GpuInfo gpu_info_;
52 };
53 
54 }  // namespace gl
55 }  // namespace gpu
56 }  // namespace tflite
57 
58 #endif  // TENSORFLOW_LITE_DELEGATES_GPU_GL_WORKGROUPS_CALCULATOR_H_
59