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_COMMAND_QUEUE_H_ 17 #define TENSORFLOW_LITE_DELEGATES_GPU_GL_COMMAND_QUEUE_H_ 18 19 #include <memory> 20 21 #include "tensorflow/lite/delegates/gpu/common/gpu_info.h" 22 #include "tensorflow/lite/delegates/gpu/common/status.h" 23 #include "tensorflow/lite/delegates/gpu/common/types.h" 24 #include "tensorflow/lite/delegates/gpu/gl/gl_program.h" 25 26 namespace tflite { 27 namespace gpu { 28 namespace gl { 29 30 // GL programs can be executed directly via dispatch call or using a queue 31 // abstraction similar to one in OpenCL and Vulkan. 32 // CommandQueue executes given programs in order as they come. 33 class CommandQueue { 34 public: 35 virtual ~CommandQueue() = default; 36 37 // Dispatches a program. It may or may not call glFlush. 38 virtual absl::Status Dispatch(const GlProgram& program, 39 const uint3& workgroups) = 0; 40 41 // Called at the end of dispatching of all programs. 42 virtual absl::Status Flush() = 0; 43 44 // Waits until all programs dispatched prior this call are completed. 45 virtual absl::Status WaitForCompletion() = 0; 46 }; 47 48 // By default memory barrier is inserted after every dispatch. 49 std::unique_ptr<CommandQueue> NewCommandQueue(const GpuInfo& gpu_info); 50 51 } // namespace gl 52 } // namespace gpu 53 } // namespace tflite 54 55 #endif // TENSORFLOW_LITE_DELEGATES_GPU_GL_COMMAND_QUEUE_H_ 56