diff --git a/tensorflow/lite/delegates/gpu/BUILD b/tensorflow/lite/delegates/gpu/BUILD index e85fc5bd6889fe9a498a98955af1c8f981c8e8be..431fcab2b467d494d5a3b35fd521378a9fa350b4 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 cd31e45e0c5eb65681adc18fffb26fc6a2bb93d9..9cb80e8a4addf40bb6fb0c6a3ef341a1de1e574f 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 d40910c33572b5ca5c8e0d988425441dfa01682c..14fb48a2d2dd805be0611bad931762f2d2101822 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 ba7e0a5f3dc904e131881f908a277aed2d467b01..44d10b323df40de3ba64fe0ceeea3ac683d178d0 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 b3385ea1fa6c041ea171d8cbad3af49de05119ad..7983833cabe3e422e32edb4eafeeacd6a5477e0d 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 2767bc399c645220b464453b4ec1d7cfb0cb33d2..fc9fcae84a91852a40addbcf3159825ec9cc2821 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 8e0e085da2867a4311d8dfb7a560f6ea3b960fdc..62f40bf0ce7076083eab5e3d1a4b65327fa262b6 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 bf313b495a35f0e7072f8611d25acf0d65dc4541..a4c21001cf280d6fb3ba92a6d41808eb89a3ef9e 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 12ee49d3ce7f5c23c4e9ecd60de419faee5a5d23..cef8139fe1efe85c171a69737dd2877a1e8c4221 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 3b6921170244325e0362a4bdb55872ea9ea1be91..e8b434869e22f87f21b23929fce33e90e2f2bae1 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 fb6c45a7ff149ea74c43f2a91f1e78accee319ca..5a2ba10bb8818a4894b4d905d48364737539847e 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 ac46704fefab4226cd1d0449c5b137721d8cf7c0..4b61948f6bc469a9f7ebe5f260454701f370097c 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 0798a054af42aaece62d768946486367a82bee1c..c4f09a3b6b94ae9eb332441bec7681abda308d74 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 a4545f5237996cd5c7bd2202895700adda471b0d..6dbe7cbeb8e37ae8e022c78650cf723a34ac5c22 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 7179696b2a2eb6db1ca943608097a08ae25f2459..baf6002e6c1c92fb6ad23a93475a7dca4d316812 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 e23cc9c04805b8e86219e0cdb21736f17a2a9937..fa7ca047b6ebb66b935408a0c6d71916da28975f 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 5ea37227aae5b86300dfac6bd42603483b9d09a2..63b068312ecc597c7a9c22d69d72da779bf6ecba 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 e55eaf444a9bbf81724761d7f308f67c1fb91c8e..de6e324017d76a3fdd2ac6f250386d1a424bb2cb 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 0225a7cee73e514d2f37116064d2f9d0d2bc4213..38364656b7ab0af3f304a027631b2a206afb32a2 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 0000000000000000000000000000000000000000..7134fc010d089231faa315213883aed9f10544e1 --- /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 0000000000000000000000000000000000000000..4eba7a55c2a3715b8bc0294ca46176f2d6e7fb81 --- /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 7249ac40ce2999a99894166f6d63dfbe6aff1514..37bf66ee86c44d2cb9c4586a1e3ca40840fa3440 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 23fff931c2a7763dfe621d1c5083f74c4f7ce8d5..46e0732cd32445744c8e5732dfcab9324abf216d 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 28a172b35de2036dcdf9475447443697a2bdff60..52fdb7435f9268ed78784d27a5b589ddd476663c 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 f0a1c4fbd40d9513eb5f04587ca444c08cbc3232..528d75d656d982ea28dc3a0ecaa0ea5c44506567 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 56d192d55cc698a35c8fe6859190a3a9b30738b8..e277e45fc2760d59545b5a939415feb9d3017869 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 82ddf0065558def9234f52b9ec9d7117ccfa2971..e21538b22a58b63831b2d702c7752afbb7ccfc7b 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 c59a9433ffd594a9903a54c96135600e9046036e..132247426f86dc8594e01865eeee5a8b4a9f4634 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 673eedc3273fe7a6ee8974ff8ea8530019205708..b258f2c44241b147ac5596f5c66b5efb23f39985 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 cca859f8795c39c45ebf7bf743997445f1042426..4c034b1604fa573c75c0bd4c480a102d2d31cb1c 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 ebfba146d93f168e66f1117992b6c735533fd19c..7b6358e3a951ae5a6179042d0352f5316fc7dc15 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 c8840abf4e5451f18c1248aad5641eb58b8e0157..6053c9e62e2a1176e07a30dbe342ef3715027735 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 07dffa306a1e32d4d91f261b42f87e78c71ea6ec..65636fe6467a653982d26ffc41b5a059452ff248 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 34461bdab506df2c8425f513469cac0325eac3a2..34f628cb7cf1b9ec1a456cd3ff50b17948ab9d9c 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 f624fb992046947180be2672bcb0477e0887b3ac..2576ed463767f09033468ecc431e0ae94e9cb440 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"