From 9c04d7c00ef6b031e6ba66fee3c8cf4b7aef8876 Mon Sep 17 00:00:00 2001 From: "A. Unique TensorFlower" Date: Thu, 8 Aug 2019 19:15:47 -0700 Subject: [PATCH] TFLite GPU Delegate: Extract GpuInfo structure into separate translation module. PiperOrigin-RevId: 262480689 --- tensorflow/lite/delegates/gpu/BUILD | 1 + tensorflow/lite/delegates/gpu/common/BUILD | 9 +++ .../delegates/gpu/{gl => common}/gpu_info.cc | 54 +------------ .../delegates/gpu/{gl => common}/gpu_info.h | 14 +--- tensorflow/lite/delegates/gpu/gl/BUILD | 38 ++++----- tensorflow/lite/delegates/gpu/gl/api.cc | 2 +- .../lite/delegates/gpu/gl/command_queue.cc | 1 + .../lite/delegates/gpu/gl/command_queue.h | 2 +- tensorflow/lite/delegates/gpu/gl/compiler.cc | 1 + tensorflow/lite/delegates/gpu/gl/compiler.h | 2 +- .../lite/delegates/gpu/gl/compiler/BUILD | 2 +- .../gpu/gl/compiler/shader_codegen.cc | 1 + .../gpu/gl/compiler/shader_codegen.h | 2 +- .../lite/delegates/gpu/gl/compiler_options.h | 1 - .../lite/delegates/gpu/gl/egl_environment.cc | 1 + .../lite/delegates/gpu/gl/egl_environment.h | 2 +- .../lite/delegates/gpu/gl/kernels/BUILD | 2 +- .../delegates/gpu/gl/kernels/test_util.cc | 2 +- .../lite/delegates/gpu/gl/node_shader.h | 2 +- .../lite/delegates/gpu/gl/request_gpu_info.cc | 81 +++++++++++++++++++ .../lite/delegates/gpu/gl/request_gpu_info.h | 37 +++++++++ tensorflow/lite/delegates/gpu/gl/runtime.cc | 1 + tensorflow/lite/delegates/gpu/gl/runtime.h | 2 +- .../lite/delegates/gpu/gl/workgroups/BUILD | 10 +-- .../gl/workgroups/best_effort_calculator.cc | 1 + .../gl/workgroups/best_effort_calculator.h | 2 +- .../delegates/gpu/gl/workgroups/calculator.cc | 2 +- .../delegates/gpu/gl/workgroups/calculator.h | 2 +- .../gl/workgroups/calculator_from_metadata.cc | 8 +- .../gl/workgroups/calculator_from_metadata.h | 2 +- .../gpu/gl/workgroups/default_calculator.cc | 1 + .../gpu/gl/workgroups/default_calculator.h | 2 +- .../gl/workgroups/ideal_workgroup_picker.cc | 2 +- .../gl/workgroups/ideal_workgroup_picker.h | 2 +- tensorflow/lite/delegates/gpu/gl_delegate.cc | 1 + 35 files changed, 185 insertions(+), 110 deletions(-) rename tensorflow/lite/delegates/gpu/{gl => common}/gpu_info.cc (63%) rename tensorflow/lite/delegates/gpu/{gl => common}/gpu_info.h (84%) create mode 100644 tensorflow/lite/delegates/gpu/gl/request_gpu_info.cc create mode 100644 tensorflow/lite/delegates/gpu/gl/request_gpu_info.h diff --git a/tensorflow/lite/delegates/gpu/BUILD b/tensorflow/lite/delegates/gpu/BUILD index e85fc5bd688..431fcab2b46 100644 --- a/tensorflow/lite/delegates/gpu/BUILD +++ b/tensorflow/lite/delegates/gpu/BUILD @@ -52,6 +52,7 @@ cc_library( "//tensorflow/lite/delegates/gpu/gl:command_queue", "//tensorflow/lite/delegates/gpu/gl:compiler", "//tensorflow/lite/delegates/gpu/gl:egl_environment", + "//tensorflow/lite/delegates/gpu/gl:request_gpu_info", "//tensorflow/lite/delegates/gpu/gl:gl_call", "//tensorflow/lite/delegates/gpu/gl/converters:bhwc_to_phwc4", "//tensorflow/lite/delegates/gpu/gl/converters:phwc4_to_bhwc", diff --git a/tensorflow/lite/delegates/gpu/common/BUILD b/tensorflow/lite/delegates/gpu/common/BUILD index cd31e45e0c5..9cb80e8a4ad 100644 --- a/tensorflow/lite/delegates/gpu/common/BUILD +++ b/tensorflow/lite/delegates/gpu/common/BUILD @@ -24,6 +24,15 @@ cc_library( hdrs = ["access_type.h"], ) +cc_library( + name = "gpu_info", + srcs = ["gpu_info.cc"], + hdrs = ["gpu_info.h"], + deps = [ + "@com_google_absl//absl/strings", + ], +) + cc_library( name = "data_type", srcs = ["data_type.cc"], diff --git a/tensorflow/lite/delegates/gpu/gl/gpu_info.cc b/tensorflow/lite/delegates/gpu/common/gpu_info.cc similarity index 63% rename from tensorflow/lite/delegates/gpu/gl/gpu_info.cc rename to tensorflow/lite/delegates/gpu/common/gpu_info.cc index d40910c3357..14fb48a2d2d 100644 --- a/tensorflow/lite/delegates/gpu/gl/gpu_info.cc +++ b/tensorflow/lite/delegates/gpu/common/gpu_info.cc @@ -13,19 +13,16 @@ See the License for the specific language governing permissions and limitations under the License. ==============================================================================*/ -#include "tensorflow/lite/delegates/gpu/gl/gpu_info.h" +#include "tensorflow/lite/delegates/gpu/common/gpu_info.h" #include #include #include #include "absl/strings/ascii.h" -#include "tensorflow/lite/delegates/gpu/gl/gl_errors.h" -#include "tensorflow/lite/delegates/gpu/gl/portable_gl31.h" namespace tflite { namespace gpu { -namespace gl { namespace { GpuType GetGpuType(const std::string& renderer) { @@ -102,54 +99,5 @@ void GetGpuModelAndType(const std::string& renderer, GpuModel* gpu_model, *gpu_type == GpuType::ADRENO ? GetGpuModel(lowered) : GpuModel::UNKNOWN; } -Status RequestGpuInfo(GpuInfo* gpu_info) { - GpuInfo info; - - const GLubyte* renderer_name = glGetString(GL_RENDERER); - if (renderer_name) { - info.renderer_name = reinterpret_cast(renderer_name); - GetGpuModelAndType(info.renderer_name, &info.gpu_model, &info.type); - } - - const GLubyte* vendor_name = glGetString(GL_VENDOR); - if (vendor_name) { - info.vendor_name = reinterpret_cast(vendor_name); - } - - const GLubyte* version_name = glGetString(GL_VERSION); - if (version_name) { - info.version = reinterpret_cast(version_name); - } - - glGetIntegerv(GL_MAJOR_VERSION, &info.major_version); - glGetIntegerv(GL_MINOR_VERSION, &info.minor_version); - - GLint extensions_count; - glGetIntegerv(GL_NUM_EXTENSIONS, &extensions_count); - info.extensions.resize(extensions_count); - for (int i = 0; i < extensions_count; ++i) { - info.extensions[i] = std::string( - reinterpret_cast(glGetStringi(GL_EXTENSIONS, i))); - } - glGetIntegerv(GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS, &info.max_ssbo_bindings); - glGetIntegerv(GL_MAX_COMPUTE_IMAGE_UNIFORMS, &info.max_image_bindings); - info.max_work_group_size.resize(3); - glGetIntegeri_v(GL_MAX_COMPUTE_WORK_GROUP_SIZE, 0, - &info.max_work_group_size[0]); - glGetIntegeri_v(GL_MAX_COMPUTE_WORK_GROUP_SIZE, 1, - &info.max_work_group_size[1]); - glGetIntegeri_v(GL_MAX_COMPUTE_WORK_GROUP_SIZE, 2, - &info.max_work_group_size[2]); - glGetIntegerv(GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS, - &info.max_work_group_invocations); - glGetIntegerv(GL_MAX_TEXTURE_SIZE, &info.max_texture_size); - glGetIntegerv(GL_MAX_IMAGE_UNITS, &info.max_image_units); - glGetIntegerv(GL_MAX_ARRAY_TEXTURE_LAYERS, &info.max_array_texture_layers); - RETURN_IF_ERROR(GetOpenGlErrors()); - *gpu_info = info; - return OkStatus(); -} - -} // namespace gl } // namespace gpu } // namespace tflite diff --git a/tensorflow/lite/delegates/gpu/gl/gpu_info.h b/tensorflow/lite/delegates/gpu/common/gpu_info.h similarity index 84% rename from tensorflow/lite/delegates/gpu/gl/gpu_info.h rename to tensorflow/lite/delegates/gpu/common/gpu_info.h index ba7e0a5f3dc..44d10b323df 100644 --- a/tensorflow/lite/delegates/gpu/gl/gpu_info.h +++ b/tensorflow/lite/delegates/gpu/common/gpu_info.h @@ -13,17 +13,14 @@ See the License for the specific language governing permissions and limitations under the License. ==============================================================================*/ -#ifndef TENSORFLOW_LITE_DELEGATES_GPU_GL_GPU_INFO_H_ -#define TENSORFLOW_LITE_DELEGATES_GPU_GL_GPU_INFO_H_ +#ifndef TENSORFLOW_LITE_DELEGATES_GPU_COMMON_GPU_INFO_H_ +#define TENSORFLOW_LITE_DELEGATES_GPU_COMMON_GPU_INFO_H_ #include #include -#include "tensorflow/lite/delegates/gpu/common/status.h" - namespace tflite { namespace gpu { -namespace gl { enum class GpuType { UNKNOWN, MALI, ADRENO, POWERVR, INTEL, NVIDIA }; enum class GpuModel { @@ -89,12 +86,7 @@ struct GpuInfo { void GetGpuModelAndType(const std::string& renderer, GpuModel* gpu_model, GpuType* gpu_type); -// This method performs multiple GL calls, therefore, egl context needs to be -// created upfront. -Status RequestGpuInfo(GpuInfo* gpu_info); - -} // namespace gl } // namespace gpu } // namespace tflite -#endif // TENSORFLOW_LITE_DELEGATES_GPU_GL_GPU_INFO_H_ +#endif // TENSORFLOW_LITE_DELEGATES_GPU_COMMON_GPU_INFO_H_ diff --git a/tensorflow/lite/delegates/gpu/gl/BUILD b/tensorflow/lite/delegates/gpu/gl/BUILD index b3385ea1fa6..7983833cabe 100644 --- a/tensorflow/lite/delegates/gpu/gl/BUILD +++ b/tensorflow/lite/delegates/gpu/gl/BUILD @@ -16,7 +16,7 @@ cc_library( ":compiler", ":compiler_options", ":gl_call", - ":gpu_info", + ":request_gpu_info", ":node_shader", ":object", ":object_manager", @@ -48,8 +48,8 @@ cc_library( ":gl_call", ":gl_program", ":gl_sync", - ":gpu_info", ":portable", + "//tensorflow/lite/delegates/gpu/common:gpu_info", "//tensorflow/lite/delegates/gpu/common:status", "//tensorflow/lite/delegates/gpu/common:types", "@com_google_absl//absl/memory", @@ -80,9 +80,9 @@ cc_library( deps = [ ":compiler_options", ":float16_conversions", - ":gpu_info", ":node_shader", "//tensorflow/lite/delegates/gpu/common:data_type", + "//tensorflow/lite/delegates/gpu/common:gpu_info", "//tensorflow/lite/delegates/gpu/common:model", "//tensorflow/lite/delegates/gpu/common:model_transformer", "//tensorflow/lite/delegates/gpu/common:operations", @@ -103,7 +103,6 @@ cc_library( name = "compiler_options", hdrs = ["compiler_options.h"], deps = [ - ":gpu_info", ":object", ], ) @@ -128,8 +127,8 @@ cc_library( ":egl_context", ":egl_surface", ":gl_call", - ":gpu_info", ":portable", + ":request_gpu_info", "//tensorflow/lite/delegates/gpu/common:status", "@com_google_absl//absl/memory", ], @@ -272,18 +271,6 @@ cc_library( ], ) -cc_library( - name = "gpu_info", - srcs = ["gpu_info.cc"], - hdrs = ["gpu_info.h"], - deps = [ - ":gl_errors", - ":portable", - "//tensorflow/lite/delegates/gpu/common:status", - "@com_google_absl//absl/strings", - ], -) - flatbuffer_cc_library( name = "metadata_cc_fbs", srcs = ["metadata.fbs"], @@ -298,9 +285,9 @@ cc_library( hdrs = ["node_shader.h"], deps = [ ":compiler_options", - ":gpu_info", ":object", ":variable", + "//tensorflow/lite/delegates/gpu/common:gpu_info", "//tensorflow/lite/delegates/gpu/common:model", "//tensorflow/lite/delegates/gpu/common:status", "//tensorflow/lite/delegates/gpu/common:types", @@ -344,6 +331,19 @@ cc_library( ], ) +cc_library( + name = "request_gpu_info", + srcs = ["request_gpu_info.cc"], + hdrs = ["request_gpu_info.h"], + deps = [ + ":gl_errors", + ":portable", + "//tensorflow/lite/delegates/gpu/common:gpu_info", + "//tensorflow/lite/delegates/gpu/common:status", + "@com_google_absl//absl/strings", + ], +) + cc_library( name = "runtime", srcs = ["runtime.cc"], @@ -356,7 +356,6 @@ cc_library( ":gl_program", ":gl_shader", ":gl_texture", - ":gpu_info", ":object", ":object_manager", ":portable", @@ -364,6 +363,7 @@ cc_library( ":stats", ":variable", "//tensorflow/lite/delegates/gpu/common:data_type", + "//tensorflow/lite/delegates/gpu/common:gpu_info", "//tensorflow/lite/delegates/gpu/common:status", "//tensorflow/lite/delegates/gpu/common:types", "//tensorflow/lite/delegates/gpu/gl/runtime:shared_buffer", diff --git a/tensorflow/lite/delegates/gpu/gl/api.cc b/tensorflow/lite/delegates/gpu/gl/api.cc index 2767bc399c6..fc9fcae84a9 100644 --- a/tensorflow/lite/delegates/gpu/gl/api.cc +++ b/tensorflow/lite/delegates/gpu/gl/api.cc @@ -31,9 +31,9 @@ limitations under the License. #include "tensorflow/lite/delegates/gpu/common/util.h" #include "tensorflow/lite/delegates/gpu/gl/compiler.h" #include "tensorflow/lite/delegates/gpu/gl/gl_call.h" -#include "tensorflow/lite/delegates/gpu/gl/gpu_info.h" #include "tensorflow/lite/delegates/gpu/gl/object.h" #include "tensorflow/lite/delegates/gpu/gl/portable_gl31.h" +#include "tensorflow/lite/delegates/gpu/gl/request_gpu_info.h" #include "tensorflow/lite/delegates/gpu/gl/runtime.h" #include "tensorflow/lite/delegates/gpu/gl/variable.h" diff --git a/tensorflow/lite/delegates/gpu/gl/command_queue.cc b/tensorflow/lite/delegates/gpu/gl/command_queue.cc index 8e0e085da28..62f40bf0ce7 100644 --- a/tensorflow/lite/delegates/gpu/gl/command_queue.cc +++ b/tensorflow/lite/delegates/gpu/gl/command_queue.cc @@ -16,6 +16,7 @@ limitations under the License. #include "tensorflow/lite/delegates/gpu/gl/command_queue.h" #include "absl/memory/memory.h" +#include "tensorflow/lite/delegates/gpu/common/gpu_info.h" #include "tensorflow/lite/delegates/gpu/common/status.h" #include "tensorflow/lite/delegates/gpu/common/types.h" #include "tensorflow/lite/delegates/gpu/gl/gl_call.h" diff --git a/tensorflow/lite/delegates/gpu/gl/command_queue.h b/tensorflow/lite/delegates/gpu/gl/command_queue.h index bf313b495a3..a4c21001cf2 100644 --- a/tensorflow/lite/delegates/gpu/gl/command_queue.h +++ b/tensorflow/lite/delegates/gpu/gl/command_queue.h @@ -18,10 +18,10 @@ limitations under the License. #include +#include "tensorflow/lite/delegates/gpu/common/gpu_info.h" #include "tensorflow/lite/delegates/gpu/common/status.h" #include "tensorflow/lite/delegates/gpu/common/types.h" #include "tensorflow/lite/delegates/gpu/gl/gl_program.h" -#include "tensorflow/lite/delegates/gpu/gl/gpu_info.h" namespace tflite { namespace gpu { diff --git a/tensorflow/lite/delegates/gpu/gl/compiler.cc b/tensorflow/lite/delegates/gpu/gl/compiler.cc index 12ee49d3ce7..cef8139fe1e 100644 --- a/tensorflow/lite/delegates/gpu/gl/compiler.cc +++ b/tensorflow/lite/delegates/gpu/gl/compiler.cc @@ -24,6 +24,7 @@ limitations under the License. #include "absl/memory/memory.h" #include "absl/types/any.h" #include "tensorflow/lite/delegates/gpu/common/data_type.h" +#include "tensorflow/lite/delegates/gpu/common/gpu_info.h" #include "tensorflow/lite/delegates/gpu/common/model_transformer.h" #include "tensorflow/lite/delegates/gpu/common/operations.h" #include "tensorflow/lite/delegates/gpu/common/status.h" diff --git a/tensorflow/lite/delegates/gpu/gl/compiler.h b/tensorflow/lite/delegates/gpu/gl/compiler.h index 3b692117024..e8b434869e2 100644 --- a/tensorflow/lite/delegates/gpu/gl/compiler.h +++ b/tensorflow/lite/delegates/gpu/gl/compiler.h @@ -20,11 +20,11 @@ limitations under the License. #include #include +#include "tensorflow/lite/delegates/gpu/common/gpu_info.h" #include "tensorflow/lite/delegates/gpu/common/model.h" #include "tensorflow/lite/delegates/gpu/common/status.h" #include "tensorflow/lite/delegates/gpu/gl/compiler/shader_code.h" #include "tensorflow/lite/delegates/gpu/gl/compiler_options.h" -#include "tensorflow/lite/delegates/gpu/gl/gpu_info.h" #include "tensorflow/lite/delegates/gpu/gl/node_shader.h" namespace tflite { diff --git a/tensorflow/lite/delegates/gpu/gl/compiler/BUILD b/tensorflow/lite/delegates/gpu/gl/compiler/BUILD index fb6c45a7ff1..5a2ba10bb88 100644 --- a/tensorflow/lite/delegates/gpu/gl/compiler/BUILD +++ b/tensorflow/lite/delegates/gpu/gl/compiler/BUILD @@ -81,10 +81,10 @@ cc_library( ":preprocessor", ":shader_code", ":variable_accessor", + "//tensorflow/lite/delegates/gpu/common:gpu_info", "//tensorflow/lite/delegates/gpu/common:model", "//tensorflow/lite/delegates/gpu/common:status", "//tensorflow/lite/delegates/gpu/gl:compiler_options", - "//tensorflow/lite/delegates/gpu/gl:gpu_info", "//tensorflow/lite/delegates/gpu/gl:object", "//tensorflow/lite/delegates/gpu/gl:variable", "@com_google_absl//absl/strings", diff --git a/tensorflow/lite/delegates/gpu/gl/compiler/shader_codegen.cc b/tensorflow/lite/delegates/gpu/gl/compiler/shader_codegen.cc index ac46704fefa..4b61948f6bc 100644 --- a/tensorflow/lite/delegates/gpu/gl/compiler/shader_codegen.cc +++ b/tensorflow/lite/delegates/gpu/gl/compiler/shader_codegen.cc @@ -18,6 +18,7 @@ limitations under the License. #include #include "absl/strings/str_cat.h" +#include "tensorflow/lite/delegates/gpu/common/gpu_info.h" #include "tensorflow/lite/delegates/gpu/common/status.h" #include "tensorflow/lite/delegates/gpu/gl/compiler/preprocessor.h" #include "tensorflow/lite/delegates/gpu/gl/compiler/variable_accessor.h" diff --git a/tensorflow/lite/delegates/gpu/gl/compiler/shader_codegen.h b/tensorflow/lite/delegates/gpu/gl/compiler/shader_codegen.h index 0798a054af4..c4f09a3b6b9 100644 --- a/tensorflow/lite/delegates/gpu/gl/compiler/shader_codegen.h +++ b/tensorflow/lite/delegates/gpu/gl/compiler/shader_codegen.h @@ -19,13 +19,13 @@ limitations under the License. #include #include +#include "tensorflow/lite/delegates/gpu/common/gpu_info.h" #include "tensorflow/lite/delegates/gpu/common/model.h" #include "tensorflow/lite/delegates/gpu/common/status.h" #include "tensorflow/lite/delegates/gpu/gl/compiler/compiled_node.h" #include "tensorflow/lite/delegates/gpu/gl/compiler/object_accessor.h" #include "tensorflow/lite/delegates/gpu/gl/compiler/shader_code.h" #include "tensorflow/lite/delegates/gpu/gl/compiler_options.h" -#include "tensorflow/lite/delegates/gpu/gl/gpu_info.h" #include "tensorflow/lite/delegates/gpu/gl/object.h" namespace tflite { diff --git a/tensorflow/lite/delegates/gpu/gl/compiler_options.h b/tensorflow/lite/delegates/gpu/gl/compiler_options.h index a4545f52379..6dbe7cbeb8e 100644 --- a/tensorflow/lite/delegates/gpu/gl/compiler_options.h +++ b/tensorflow/lite/delegates/gpu/gl/compiler_options.h @@ -16,7 +16,6 @@ limitations under the License. #ifndef TENSORFLOW_LITE_DELEGATES_GPU_GL_COMPILER_OPTIONS_H_ #define TENSORFLOW_LITE_DELEGATES_GPU_GL_COMPILER_OPTIONS_H_ -#include "tensorflow/lite/delegates/gpu/gl/gpu_info.h" #include "tensorflow/lite/delegates/gpu/gl/object.h" namespace tflite { diff --git a/tensorflow/lite/delegates/gpu/gl/egl_environment.cc b/tensorflow/lite/delegates/gpu/gl/egl_environment.cc index 7179696b2a2..baf6002e6c1 100644 --- a/tensorflow/lite/delegates/gpu/gl/egl_environment.cc +++ b/tensorflow/lite/delegates/gpu/gl/egl_environment.cc @@ -18,6 +18,7 @@ limitations under the License. #include "absl/memory/memory.h" #include "tensorflow/lite/delegates/gpu/common/status.h" #include "tensorflow/lite/delegates/gpu/gl/gl_call.h" +#include "tensorflow/lite/delegates/gpu/gl/request_gpu_info.h" namespace tflite { namespace gpu { diff --git a/tensorflow/lite/delegates/gpu/gl/egl_environment.h b/tensorflow/lite/delegates/gpu/gl/egl_environment.h index e23cc9c0480..fa7ca047b6e 100644 --- a/tensorflow/lite/delegates/gpu/gl/egl_environment.h +++ b/tensorflow/lite/delegates/gpu/gl/egl_environment.h @@ -21,9 +21,9 @@ limitations under the License. #include "tensorflow/lite/delegates/gpu/common/status.h" #include "tensorflow/lite/delegates/gpu/gl/egl_context.h" #include "tensorflow/lite/delegates/gpu/gl/egl_surface.h" -#include "tensorflow/lite/delegates/gpu/gl/gpu_info.h" #include "tensorflow/lite/delegates/gpu/gl/portable_egl.h" #include "tensorflow/lite/delegates/gpu/gl/portable_gl31.h" +#include "tensorflow/lite/delegates/gpu/gl/request_gpu_info.h" namespace tflite { namespace gpu { diff --git a/tensorflow/lite/delegates/gpu/gl/kernels/BUILD b/tensorflow/lite/delegates/gpu/gl/kernels/BUILD index 5ea37227aae..63b068312ec 100644 --- a/tensorflow/lite/delegates/gpu/gl/kernels/BUILD +++ b/tensorflow/lite/delegates/gpu/gl/kernels/BUILD @@ -582,9 +582,9 @@ cc_library( "//tensorflow/lite/delegates/gpu/gl:compiler_options", "//tensorflow/lite/delegates/gpu/gl:egl_environment", "//tensorflow/lite/delegates/gpu/gl:gl_buffer", - "//tensorflow/lite/delegates/gpu/gl:gpu_info", "//tensorflow/lite/delegates/gpu/gl:node_shader", "//tensorflow/lite/delegates/gpu/gl:object_manager", + "//tensorflow/lite/delegates/gpu/gl:request_gpu_info", "//tensorflow/lite/delegates/gpu/gl:runtime_options", "//tensorflow/lite/delegates/gpu/gl/workgroups:default_calculator", "@com_google_googletest//:gtest", diff --git a/tensorflow/lite/delegates/gpu/gl/kernels/test_util.cc b/tensorflow/lite/delegates/gpu/gl/kernels/test_util.cc index e55eaf444a9..de6e324017d 100644 --- a/tensorflow/lite/delegates/gpu/gl/kernels/test_util.cc +++ b/tensorflow/lite/delegates/gpu/gl/kernels/test_util.cc @@ -28,8 +28,8 @@ limitations under the License. #include "tensorflow/lite/delegates/gpu/gl/api.h" #include "tensorflow/lite/delegates/gpu/gl/egl_environment.h" #include "tensorflow/lite/delegates/gpu/gl/gl_buffer.h" -#include "tensorflow/lite/delegates/gpu/gl/gpu_info.h" #include "tensorflow/lite/delegates/gpu/gl/object_manager.h" +#include "tensorflow/lite/delegates/gpu/gl/request_gpu_info.h" #include "tensorflow/lite/delegates/gpu/gl/workgroups/default_calculator.h" namespace tflite { diff --git a/tensorflow/lite/delegates/gpu/gl/node_shader.h b/tensorflow/lite/delegates/gpu/gl/node_shader.h index 0225a7cee73..38364656b7a 100644 --- a/tensorflow/lite/delegates/gpu/gl/node_shader.h +++ b/tensorflow/lite/delegates/gpu/gl/node_shader.h @@ -21,11 +21,11 @@ limitations under the License. #include #include +#include "tensorflow/lite/delegates/gpu/common/gpu_info.h" #include "tensorflow/lite/delegates/gpu/common/model.h" #include "tensorflow/lite/delegates/gpu/common/status.h" #include "tensorflow/lite/delegates/gpu/common/types.h" #include "tensorflow/lite/delegates/gpu/gl/compiler_options.h" -#include "tensorflow/lite/delegates/gpu/gl/gpu_info.h" #include "tensorflow/lite/delegates/gpu/gl/object.h" #include "tensorflow/lite/delegates/gpu/gl/variable.h" diff --git a/tensorflow/lite/delegates/gpu/gl/request_gpu_info.cc b/tensorflow/lite/delegates/gpu/gl/request_gpu_info.cc new file mode 100644 index 00000000000..7134fc010d0 --- /dev/null +++ b/tensorflow/lite/delegates/gpu/gl/request_gpu_info.cc @@ -0,0 +1,81 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/lite/delegates/gpu/gl/request_gpu_info.h" + +#include +#include +#include + +#include "absl/strings/ascii.h" +#include "tensorflow/lite/delegates/gpu/common/gpu_info.h" +#include "tensorflow/lite/delegates/gpu/gl/gl_errors.h" +#include "tensorflow/lite/delegates/gpu/gl/portable_gl31.h" + +namespace tflite { +namespace gpu { +namespace gl { + +Status RequestGpuInfo(GpuInfo* gpu_info) { + GpuInfo info; + + const GLubyte* renderer_name = glGetString(GL_RENDERER); + if (renderer_name) { + info.renderer_name = reinterpret_cast(renderer_name); + GetGpuModelAndType(info.renderer_name, &info.gpu_model, &info.type); + } + + const GLubyte* vendor_name = glGetString(GL_VENDOR); + if (vendor_name) { + info.vendor_name = reinterpret_cast(vendor_name); + } + + const GLubyte* version_name = glGetString(GL_VERSION); + if (version_name) { + info.version = reinterpret_cast(version_name); + } + + glGetIntegerv(GL_MAJOR_VERSION, &info.major_version); + glGetIntegerv(GL_MINOR_VERSION, &info.minor_version); + + GLint extensions_count; + glGetIntegerv(GL_NUM_EXTENSIONS, &extensions_count); + info.extensions.resize(extensions_count); + for (int i = 0; i < extensions_count; ++i) { + info.extensions[i] = std::string( + reinterpret_cast(glGetStringi(GL_EXTENSIONS, i))); + } + glGetIntegerv(GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS, &info.max_ssbo_bindings); + glGetIntegerv(GL_MAX_COMPUTE_IMAGE_UNIFORMS, &info.max_image_bindings); + info.max_work_group_size.resize(3); + glGetIntegeri_v(GL_MAX_COMPUTE_WORK_GROUP_SIZE, 0, + &info.max_work_group_size[0]); + glGetIntegeri_v(GL_MAX_COMPUTE_WORK_GROUP_SIZE, 1, + &info.max_work_group_size[1]); + glGetIntegeri_v(GL_MAX_COMPUTE_WORK_GROUP_SIZE, 2, + &info.max_work_group_size[2]); + glGetIntegerv(GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS, + &info.max_work_group_invocations); + glGetIntegerv(GL_MAX_TEXTURE_SIZE, &info.max_texture_size); + glGetIntegerv(GL_MAX_IMAGE_UNITS, &info.max_image_units); + glGetIntegerv(GL_MAX_ARRAY_TEXTURE_LAYERS, &info.max_array_texture_layers); + RETURN_IF_ERROR(GetOpenGlErrors()); + *gpu_info = info; + return OkStatus(); +} + +} // namespace gl +} // namespace gpu +} // namespace tflite diff --git a/tensorflow/lite/delegates/gpu/gl/request_gpu_info.h b/tensorflow/lite/delegates/gpu/gl/request_gpu_info.h new file mode 100644 index 00000000000..4eba7a55c2a --- /dev/null +++ b/tensorflow/lite/delegates/gpu/gl/request_gpu_info.h @@ -0,0 +1,37 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#ifndef TENSORFLOW_LITE_DELEGATES_GPU_GL_REQUEST_GPU_INFO_H_ +#define TENSORFLOW_LITE_DELEGATES_GPU_GL_REQUEST_GPU_INFO_H_ + +#include +#include + +#include "tensorflow/lite/delegates/gpu/common/gpu_info.h" +#include "tensorflow/lite/delegates/gpu/common/status.h" + +namespace tflite { +namespace gpu { +namespace gl { + +// This method performs multiple GL calls, therefore, egl context needs to be +// created upfront. +Status RequestGpuInfo(GpuInfo* gpu_info); + +} // namespace gl +} // namespace gpu +} // namespace tflite + +#endif // TENSORFLOW_LITE_DELEGATES_GPU_GL_REQUEST_GPU_INFO_H_ diff --git a/tensorflow/lite/delegates/gpu/gl/runtime.cc b/tensorflow/lite/delegates/gpu/gl/runtime.cc index 7249ac40ce2..37bf66ee86c 100644 --- a/tensorflow/lite/delegates/gpu/gl/runtime.cc +++ b/tensorflow/lite/delegates/gpu/gl/runtime.cc @@ -22,6 +22,7 @@ limitations under the License. #include "absl/strings/str_cat.h" #include "tensorflow/lite/delegates/gpu/common/data_type.h" +#include "tensorflow/lite/delegates/gpu/common/gpu_info.h" #include "tensorflow/lite/delegates/gpu/common/status.h" #include "tensorflow/lite/delegates/gpu/common/types.h" #include "tensorflow/lite/delegates/gpu/gl/gl_call.h" diff --git a/tensorflow/lite/delegates/gpu/gl/runtime.h b/tensorflow/lite/delegates/gpu/gl/runtime.h index 23fff931c2a..46e0732cd32 100644 --- a/tensorflow/lite/delegates/gpu/gl/runtime.h +++ b/tensorflow/lite/delegates/gpu/gl/runtime.h @@ -18,13 +18,13 @@ limitations under the License. #include +#include "tensorflow/lite/delegates/gpu/common/gpu_info.h" #include "tensorflow/lite/delegates/gpu/common/status.h" #include "tensorflow/lite/delegates/gpu/common/types.h" #include "tensorflow/lite/delegates/gpu/gl/command_queue.h" #include "tensorflow/lite/delegates/gpu/gl/gl_buffer.h" #include "tensorflow/lite/delegates/gpu/gl/gl_program.h" #include "tensorflow/lite/delegates/gpu/gl/gl_shader.h" -#include "tensorflow/lite/delegates/gpu/gl/gpu_info.h" #include "tensorflow/lite/delegates/gpu/gl/object.h" #include "tensorflow/lite/delegates/gpu/gl/object_manager.h" #include "tensorflow/lite/delegates/gpu/gl/runtime/shared_buffer.h" diff --git a/tensorflow/lite/delegates/gpu/gl/workgroups/BUILD b/tensorflow/lite/delegates/gpu/gl/workgroups/BUILD index 28a172b35de..52fdb7435f9 100644 --- a/tensorflow/lite/delegates/gpu/gl/workgroups/BUILD +++ b/tensorflow/lite/delegates/gpu/gl/workgroups/BUILD @@ -8,8 +8,8 @@ cc_library( srcs = ["calculator.cc"], hdrs = ["calculator.h"], deps = [ + "//tensorflow/lite/delegates/gpu/common:gpu_info", "//tensorflow/lite/delegates/gpu/common:types", - "//tensorflow/lite/delegates/gpu/gl:gpu_info", "//tensorflow/lite/delegates/gpu/gl/compiler:shader_code", ], ) @@ -20,8 +20,8 @@ cc_library( hdrs = ["default_calculator.h"], deps = [ ":calculator", + "//tensorflow/lite/delegates/gpu/common:gpu_info", "//tensorflow/lite/delegates/gpu/common:types", - "//tensorflow/lite/delegates/gpu/gl:gpu_info", ], ) @@ -35,7 +35,7 @@ cc_library( ":default_calculator", "//tensorflow/lite/delegates/gpu/gl:common_cc_fbs", "//tensorflow/lite/delegates/gpu/gl:workgroups_cc_fbs", - "//tensorflow/lite/delegates/gpu/gl:gpu_info", + "//tensorflow/lite/delegates/gpu/common:gpu_info", "//tensorflow/lite/delegates/gpu/gl:metadata_cc_fbs", ":calculator", "@com_google_absl//absl/memory", @@ -52,7 +52,7 @@ cc_library( deps = [ ":calculator", ":default_calculator", - "//tensorflow/lite/delegates/gpu/gl:gpu_info", + "//tensorflow/lite/delegates/gpu/common:gpu_info", ] + select({ "//tensorflow/lite/delegates/gpu:tflite_gpu_binary_release": [], "//conditions:default": [ @@ -67,9 +67,9 @@ cc_library( hdrs = ["ideal_workgroup_picker.h"], deps = [ ":calculator", + "//tensorflow/lite/delegates/gpu/common:gpu_info", "//tensorflow/lite/delegates/gpu/common:operations", "//tensorflow/lite/delegates/gpu/common:shape", "//tensorflow/lite/delegates/gpu/common:types", - "//tensorflow/lite/delegates/gpu/gl:gpu_info", ], ) diff --git a/tensorflow/lite/delegates/gpu/gl/workgroups/best_effort_calculator.cc b/tensorflow/lite/delegates/gpu/gl/workgroups/best_effort_calculator.cc index f0a1c4fbd40..528d75d656d 100644 --- a/tensorflow/lite/delegates/gpu/gl/workgroups/best_effort_calculator.cc +++ b/tensorflow/lite/delegates/gpu/gl/workgroups/best_effort_calculator.cc @@ -15,6 +15,7 @@ limitations under the License. #include "tensorflow/lite/delegates/gpu/gl/workgroups/best_effort_calculator.h" +#include "tensorflow/lite/delegates/gpu/common/gpu_info.h" #include "tensorflow/lite/delegates/gpu/gl/workgroups/calculator.h" #include "tensorflow/lite/delegates/gpu/gl/workgroups/default_calculator.h" diff --git a/tensorflow/lite/delegates/gpu/gl/workgroups/best_effort_calculator.h b/tensorflow/lite/delegates/gpu/gl/workgroups/best_effort_calculator.h index 56d192d55cc..e277e45fc27 100644 --- a/tensorflow/lite/delegates/gpu/gl/workgroups/best_effort_calculator.h +++ b/tensorflow/lite/delegates/gpu/gl/workgroups/best_effort_calculator.h @@ -16,7 +16,7 @@ limitations under the License. #ifndef TENSORFLOW_LITE_DELEGATES_GPU_GL_WORKGROUPS_BEST_EFFORT_CALCULATOR_H_ #define TENSORFLOW_LITE_DELEGATES_GPU_GL_WORKGROUPS_BEST_EFFORT_CALCULATOR_H_ -#include "tensorflow/lite/delegates/gpu/gl/gpu_info.h" +#include "tensorflow/lite/delegates/gpu/common/gpu_info.h" #include "tensorflow/lite/delegates/gpu/gl/workgroups/calculator.h" namespace tflite { diff --git a/tensorflow/lite/delegates/gpu/gl/workgroups/calculator.cc b/tensorflow/lite/delegates/gpu/gl/workgroups/calculator.cc index 82ddf006555..e21538b22a5 100644 --- a/tensorflow/lite/delegates/gpu/gl/workgroups/calculator.cc +++ b/tensorflow/lite/delegates/gpu/gl/workgroups/calculator.cc @@ -15,9 +15,9 @@ limitations under the License. #include "tensorflow/lite/delegates/gpu/gl/workgroups/calculator.h" +#include "tensorflow/lite/delegates/gpu/common/gpu_info.h" #include "tensorflow/lite/delegates/gpu/common/types.h" #include "tensorflow/lite/delegates/gpu/gl/compiler/shader_code.h" -#include "tensorflow/lite/delegates/gpu/gl/gpu_info.h" namespace tflite { namespace gpu { diff --git a/tensorflow/lite/delegates/gpu/gl/workgroups/calculator.h b/tensorflow/lite/delegates/gpu/gl/workgroups/calculator.h index c59a9433ffd..132247426f8 100644 --- a/tensorflow/lite/delegates/gpu/gl/workgroups/calculator.h +++ b/tensorflow/lite/delegates/gpu/gl/workgroups/calculator.h @@ -18,9 +18,9 @@ limitations under the License. #include +#include "tensorflow/lite/delegates/gpu/common/gpu_info.h" #include "tensorflow/lite/delegates/gpu/common/types.h" #include "tensorflow/lite/delegates/gpu/gl/compiler/shader_code.h" -#include "tensorflow/lite/delegates/gpu/gl/gpu_info.h" namespace tflite { namespace gpu { diff --git a/tensorflow/lite/delegates/gpu/gl/workgroups/calculator_from_metadata.cc b/tensorflow/lite/delegates/gpu/gl/workgroups/calculator_from_metadata.cc index 673eedc3273..b258f2c4424 100644 --- a/tensorflow/lite/delegates/gpu/gl/workgroups/calculator_from_metadata.cc +++ b/tensorflow/lite/delegates/gpu/gl/workgroups/calculator_from_metadata.cc @@ -20,15 +20,15 @@ limitations under the License. #include #include +#include "absl/memory/memory.h" +#include "flatbuffers/flatbuffers.h" // TF:flatbuffers +#include "tensorflow/lite/delegates/gpu/common/gpu_info.h" +#include "tensorflow/lite/delegates/gpu/common/types.h" #include "tensorflow/lite/delegates/gpu/gl/metadata_generated.h" #include "tensorflow/lite/delegates/gpu/gl/workgroups/calculator.h" #include "tensorflow/lite/delegates/gpu/gl/workgroups/default_calculator.h" #include "tensorflow/lite/delegates/gpu/gl/workgroups_generated.h" -#include "absl/memory/memory.h" -#include "flatbuffers/flatbuffers.h" // TF:flatbuffers -#include "tensorflow/lite/delegates/gpu/common/types.h" - #endif // TFLITE_GPU_BINARY_RELEASE namespace tflite { diff --git a/tensorflow/lite/delegates/gpu/gl/workgroups/calculator_from_metadata.h b/tensorflow/lite/delegates/gpu/gl/workgroups/calculator_from_metadata.h index cca859f8795..4c034b1604f 100644 --- a/tensorflow/lite/delegates/gpu/gl/workgroups/calculator_from_metadata.h +++ b/tensorflow/lite/delegates/gpu/gl/workgroups/calculator_from_metadata.h @@ -16,7 +16,7 @@ limitations under the License. #ifndef TENSORFLOW_LITE_DELEGATES_GPU_GL_WORKGROUPS_CALCULATOR_FROM_METADATA_H_ #define TENSORFLOW_LITE_DELEGATES_GPU_GL_WORKGROUPS_CALCULATOR_FROM_METADATA_H_ -#include "tensorflow/lite/delegates/gpu/gl/gpu_info.h" +#include "tensorflow/lite/delegates/gpu/common/gpu_info.h" #include "tensorflow/lite/delegates/gpu/gl/workgroups/calculator.h" namespace tflite { diff --git a/tensorflow/lite/delegates/gpu/gl/workgroups/default_calculator.cc b/tensorflow/lite/delegates/gpu/gl/workgroups/default_calculator.cc index ebfba146d93..7b6358e3a95 100644 --- a/tensorflow/lite/delegates/gpu/gl/workgroups/default_calculator.cc +++ b/tensorflow/lite/delegates/gpu/gl/workgroups/default_calculator.cc @@ -15,6 +15,7 @@ limitations under the License. #include "tensorflow/lite/delegates/gpu/gl/workgroups/default_calculator.h" +#include "tensorflow/lite/delegates/gpu/common/gpu_info.h" #include "tensorflow/lite/delegates/gpu/common/types.h" #include "tensorflow/lite/delegates/gpu/gl/workgroups/calculator.h" diff --git a/tensorflow/lite/delegates/gpu/gl/workgroups/default_calculator.h b/tensorflow/lite/delegates/gpu/gl/workgroups/default_calculator.h index c8840abf4e5..6053c9e62e2 100644 --- a/tensorflow/lite/delegates/gpu/gl/workgroups/default_calculator.h +++ b/tensorflow/lite/delegates/gpu/gl/workgroups/default_calculator.h @@ -16,7 +16,7 @@ limitations under the License. #ifndef TENSORFLOW_LITE_DELEGATES_GPU_GL_WORKGROUPS_DEFAULT_CALCULATOR_H_ #define TENSORFLOW_LITE_DELEGATES_GPU_GL_WORKGROUPS_DEFAULT_CALCULATOR_H_ -#include "tensorflow/lite/delegates/gpu/gl/gpu_info.h" +#include "tensorflow/lite/delegates/gpu/common/gpu_info.h" #include "tensorflow/lite/delegates/gpu/gl/workgroups/calculator.h" namespace tflite { diff --git a/tensorflow/lite/delegates/gpu/gl/workgroups/ideal_workgroup_picker.cc b/tensorflow/lite/delegates/gpu/gl/workgroups/ideal_workgroup_picker.cc index 07dffa306a1..65636fe6467 100644 --- a/tensorflow/lite/delegates/gpu/gl/workgroups/ideal_workgroup_picker.cc +++ b/tensorflow/lite/delegates/gpu/gl/workgroups/ideal_workgroup_picker.cc @@ -18,10 +18,10 @@ limitations under the License. #include #include +#include "tensorflow/lite/delegates/gpu/common/gpu_info.h" #include "tensorflow/lite/delegates/gpu/common/operations.h" #include "tensorflow/lite/delegates/gpu/common/shape.h" #include "tensorflow/lite/delegates/gpu/common/types.h" -#include "tensorflow/lite/delegates/gpu/gl/gpu_info.h" #include "tensorflow/lite/delegates/gpu/gl/workgroups/calculator.h" namespace tflite { diff --git a/tensorflow/lite/delegates/gpu/gl/workgroups/ideal_workgroup_picker.h b/tensorflow/lite/delegates/gpu/gl/workgroups/ideal_workgroup_picker.h index 34461bdab50..34f628cb7cf 100644 --- a/tensorflow/lite/delegates/gpu/gl/workgroups/ideal_workgroup_picker.h +++ b/tensorflow/lite/delegates/gpu/gl/workgroups/ideal_workgroup_picker.h @@ -16,10 +16,10 @@ limitations under the License. #ifndef TENSORFLOW_LITE_DELEGATES_GPU_GL_WORKGROUPS_IDEAL_WORKGROUP_PICKER_H_ #define TENSORFLOW_LITE_DELEGATES_GPU_GL_WORKGROUPS_IDEAL_WORKGROUP_PICKER_H_ +#include "tensorflow/lite/delegates/gpu/common/gpu_info.h" #include "tensorflow/lite/delegates/gpu/common/operations.h" #include "tensorflow/lite/delegates/gpu/common/shape.h" #include "tensorflow/lite/delegates/gpu/common/types.h" -#include "tensorflow/lite/delegates/gpu/gl/gpu_info.h" namespace tflite { namespace gpu { diff --git a/tensorflow/lite/delegates/gpu/gl_delegate.cc b/tensorflow/lite/delegates/gpu/gl_delegate.cc index f624fb99204..2576ed46376 100644 --- a/tensorflow/lite/delegates/gpu/gl_delegate.cc +++ b/tensorflow/lite/delegates/gpu/gl_delegate.cc @@ -43,6 +43,7 @@ limitations under the License. #include "tensorflow/lite/delegates/gpu/gl/egl_environment.h" #include "tensorflow/lite/delegates/gpu/gl/gl_call.h" #include "tensorflow/lite/delegates/gpu/gl/kernels/registry.h" +#include "tensorflow/lite/delegates/gpu/gl/request_gpu_info.h" #include "tensorflow/lite/delegates/gpu/gl/workgroups/best_effort_calculator.h" #include "tensorflow/lite/minimal_logging.h" -- GitLab