• 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 #include "tensorflow/lite/delegates/gpu/gl/request_gpu_info.h"
17 
18 #include <algorithm>
19 #include <cctype>
20 #include <string>
21 
22 #include "absl/strings/ascii.h"
23 #include "tensorflow/lite/delegates/gpu/common/gpu_info.h"
24 #include "tensorflow/lite/delegates/gpu/gl/gl_errors.h"
25 #include "tensorflow/lite/delegates/gpu/gl/portable_gl31.h"
26 
27 namespace tflite {
28 namespace gpu {
29 namespace gl {
30 
RequestOpenGlInfo(OpenGlInfo * gl_info)31 absl::Status RequestOpenGlInfo(OpenGlInfo* gl_info) {
32   const GLubyte* renderer_name = glGetString(GL_RENDERER);
33   if (renderer_name) {
34     gl_info->renderer_name = reinterpret_cast<const char*>(renderer_name);
35   }
36 
37   const GLubyte* vendor_name = glGetString(GL_VENDOR);
38   if (vendor_name) {
39     gl_info->vendor_name = reinterpret_cast<const char*>(vendor_name);
40   }
41 
42   const GLubyte* version_name = glGetString(GL_VERSION);
43   if (version_name) {
44     gl_info->version = reinterpret_cast<const char*>(version_name);
45   }
46 
47   glGetIntegerv(GL_MAJOR_VERSION, &gl_info->major_version);
48   glGetIntegerv(GL_MINOR_VERSION, &gl_info->minor_version);
49 
50   return absl::OkStatus();
51 }
52 
RequestGpuInfo(GpuInfo * gpu_info)53 absl::Status RequestGpuInfo(GpuInfo* gpu_info) {
54   GpuInfo info;
55   RETURN_IF_ERROR(RequestOpenGlInfo(&info.opengl_info));
56 
57   GetGpuInfoFromDeviceDescription(info.opengl_info.renderer_name,
58                                   GpuApi::kOpenGl, &info);
59 
60   GLint extensions_count;
61   glGetIntegerv(GL_NUM_EXTENSIONS, &extensions_count);
62   info.opengl_info.extensions.resize(extensions_count);
63   for (int i = 0; i < extensions_count; ++i) {
64     info.opengl_info.extensions[i] = std::string(
65         reinterpret_cast<const char*>(glGetStringi(GL_EXTENSIONS, i)));
66   }
67   glGetIntegerv(GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS,
68                 &info.opengl_info.max_ssbo_bindings);
69   glGetIntegerv(GL_MAX_COMPUTE_IMAGE_UNIFORMS,
70                 &info.opengl_info.max_image_bindings);
71   glGetIntegeri_v(GL_MAX_COMPUTE_WORK_GROUP_SIZE, 0,
72                   &info.opengl_info.max_compute_work_group_size_x);
73   glGetIntegeri_v(GL_MAX_COMPUTE_WORK_GROUP_SIZE, 1,
74                   &info.opengl_info.max_compute_work_group_size_y);
75   glGetIntegeri_v(GL_MAX_COMPUTE_WORK_GROUP_SIZE, 2,
76                   &info.opengl_info.max_compute_work_group_size_z);
77   glGetIntegerv(GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS,
78                 &info.opengl_info.max_work_group_invocations);
79   glGetIntegerv(GL_MAX_TEXTURE_SIZE, &info.opengl_info.max_texture_size);
80   glGetIntegerv(GL_MAX_IMAGE_UNITS, &info.opengl_info.max_image_units);
81   glGetIntegerv(GL_MAX_ARRAY_TEXTURE_LAYERS,
82                 &info.opengl_info.max_array_texture_layers);
83   RETURN_IF_ERROR(GetOpenGlErrors());
84   *gpu_info = info;
85   return absl::OkStatus();
86 }
87 
88 }  // namespace gl
89 }  // namespace gpu
90 }  // namespace tflite
91