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_COMPILER_H_ 17 #define TENSORFLOW_LITE_DELEGATES_GPU_GL_COMPILER_H_ 18 19 #include <functional> 20 #include <memory> 21 #include <unordered_set> 22 23 #include "tensorflow/lite/delegates/gpu/common/gpu_info.h" 24 #include "tensorflow/lite/delegates/gpu/common/model.h" 25 #include "tensorflow/lite/delegates/gpu/common/status.h" 26 #include "tensorflow/lite/delegates/gpu/gl/compiler/shader_code.h" 27 #include "tensorflow/lite/delegates/gpu/gl/compiler_options.h" 28 #include "tensorflow/lite/delegates/gpu/gl/node_shader.h" 29 30 namespace tflite { 31 namespace gpu { 32 namespace gl { 33 34 using ShaderCodeCallback = std::function<absl::Status(ShaderCode code)>; 35 36 class Compiler { 37 public: 38 virtual ~Compiler() = default; 39 40 // Goes over a graph and generates OpenGL shaders for the given graph. 41 // Callback is called for every generated shader. Callback may execute shaders 42 // as they come or store them elsewhere to execute later. 43 virtual absl::Status Compile( 44 const GraphFloat32& graph, 45 const std::unordered_set<int>& tflite_graph_io, // NOLINT 46 const ShaderCodeCallback& callback) = 0; 47 }; 48 49 std::unique_ptr<Compiler> NewCompiler( 50 const NodeShader* node_shader, const GpuInfo* gpu_info, 51 const CompilationOptions& options); 52 53 } // namespace gl 54 } // namespace gpu 55 } // namespace tflite 56 57 #endif // TENSORFLOW_LITE_DELEGATES_GPU_GL_COMPILER_H_ 58