Added opencl driver info to gpu_info.
Discarding DepthWise3x3 for specific driver.

PiperOrigin-RevId: 382682255
Change-Id: I07428e2d5bf55492ca614c0652e47c3f6cc20ed6
diff --git a/tensorflow/lite/delegates/gpu/cl/cl_device.cc b/tensorflow/lite/delegates/gpu/cl/cl_device.cc
index 10dd873..99b9b36 100644
--- a/tensorflow/lite/delegates/gpu/cl/cl_device.cc
+++ b/tensorflow/lite/delegates/gpu/cl/cl_device.cc
@@ -17,6 +17,7 @@
 
 #include <algorithm>
 #include <string>
+#include <utility>
 #include <vector>
 
 #include "absl/strings/numbers.h"
@@ -129,16 +130,21 @@
   return gpu_version >= min_version && gpu_version < max_version;
 }
 
-GpuInfo GpuInfoFromDeviceID(cl_device_id id) {
+GpuInfo GpuInfoFromDeviceID(cl_device_id id, cl_platform_id platform_id) {
   GpuInfo info;
-  const auto device_name = GetDeviceInfo<std::string>(id, CL_DEVICE_NAME);
-  const auto vendor_name = GetDeviceInfo<std::string>(id, CL_DEVICE_VENDOR);
-  const auto opencl_c_version =
+  info.opencl_info.platform_version =
+      GetPlatformInfo(platform_id, CL_PLATFORM_VERSION);
+  info.opencl_info.device_name = GetDeviceInfo<std::string>(id, CL_DEVICE_NAME);
+  info.opencl_info.vendor_name =
+      GetDeviceInfo<std::string>(id, CL_DEVICE_VENDOR);
+  info.opencl_info.opencl_c_version =
       GetDeviceInfo<std::string>(id, CL_DEVICE_OPENCL_C_VERSION);
-  const std::string gpu_description =
-      absl::StrCat(device_name, " ", vendor_name, " ", opencl_c_version);
+  const std::string gpu_description = absl::StrCat(
+      info.opencl_info.device_name, " ", info.opencl_info.vendor_name, " ",
+      info.opencl_info.opencl_c_version);
   GetGpuInfoFromDeviceDescription(gpu_description, GpuApi::kOpenCl, &info);
-  info.opencl_info.cl_version = ParseCLVersion(opencl_c_version);
+  info.opencl_info.cl_version =
+      ParseCLVersion(info.opencl_info.opencl_c_version);
   info.opencl_info.extensions =
       absl::StrSplit(GetDeviceInfo<std::string>(id, CL_DEVICE_EXTENSIONS), ' ');
   info.opencl_info.supports_fp16 = false;
@@ -261,7 +267,9 @@
 }  // namespace
 
 CLDevice::CLDevice(cl_device_id id, cl_platform_id platform_id)
-    : info_(GpuInfoFromDeviceID(id)), id_(id), platform_id_(platform_id) {
+    : info_(GpuInfoFromDeviceID(id, platform_id)),
+      id_(id),
+      platform_id_(platform_id) {
   if (info_.IsAdreno() &&
       info_.adreno_info.adreno_gpu == AdrenoGpu::kAdreno630) {
     acceleration::AndroidInfo android_info;
diff --git a/tensorflow/lite/delegates/gpu/common/gpu_info.h b/tensorflow/lite/delegates/gpu/common/gpu_info.h
index e2adf1a..6d07d9c 100644
--- a/tensorflow/lite/delegates/gpu/common/gpu_info.h
+++ b/tensorflow/lite/delegates/gpu/common/gpu_info.h
@@ -264,6 +264,11 @@
 std::string OpenClVersionToString(OpenClVersion version);
 
 struct OpenClInfo {
+  std::string device_name;
+  std::string vendor_name;
+  std::string opencl_c_version;
+  std::string platform_version;
+
   OpenClVersion cl_version;
 
   std::vector<std::string> extensions;
diff --git a/tensorflow/lite/delegates/gpu/common/selectors/default/dw_convolution_selector.cc b/tensorflow/lite/delegates/gpu/common/selectors/default/dw_convolution_selector.cc
index e434e89..f4956e7 100644
--- a/tensorflow/lite/delegates/gpu/common/selectors/default/dw_convolution_selector.cc
+++ b/tensorflow/lite/delegates/gpu/common/selectors/default/dw_convolution_selector.cc
@@ -26,7 +26,7 @@
 std::unique_ptr<GPUOperation> SelectDWConvolutionAdreno(
     const DepthwiseConvolution2DAttributes& attr, const GpuInfo& gpu_info,
     const OperationDef& op_def) {
-  if (IsDepthwiseConv3x3Supported(attr)) {
+  if (IsDepthwiseConv3x3Supported(gpu_info, attr)) {
     return absl::make_unique<DepthwiseConv3x3>(
         CreateDepthwiseConv3x3(gpu_info, op_def, attr));
   } else {
@@ -38,7 +38,7 @@
 std::unique_ptr<GPUOperation> SelectDWConvolutionPowerVR(
     const DepthwiseConvolution2DAttributes& attr, const GpuInfo& gpu_info,
     const OperationDef& op_def) {
-  if (IsDepthwiseConv3x3Supported(attr)) {
+  if (IsDepthwiseConv3x3Supported(gpu_info, attr)) {
     return absl::make_unique<DepthwiseConv3x3>(
         CreateDepthwiseConv3x3(gpu_info, op_def, attr));
   } else {
@@ -54,7 +54,7 @@
   bool buffer_type = storage_type == TensorStorageType::BUFFER ||
                      storage_type == TensorStorageType::IMAGE_BUFFER;
   const MaliInfo mali_info = gpu_info.mali_info;
-  if (IsDepthwiseConv3x3Supported(attr) && !mali_info.IsMidgard() &&
+  if (IsDepthwiseConv3x3Supported(gpu_info, attr) && !mali_info.IsMidgard() &&
       !buffer_type && op_def.precision != CalculationsPrecision::F32) {
     return absl::make_unique<DepthwiseConv3x3>(
         CreateDepthwiseConv3x3(gpu_info, op_def, attr));
@@ -67,7 +67,7 @@
 std::unique_ptr<GPUOperation> SelectDWConvolutionApple(
     const DepthwiseConvolution2DAttributes& attr, const GpuInfo& gpu_info,
     const OperationDef& op_def) {
-  if (IsDepthwiseConv3x3Supported(attr)) {
+  if (IsDepthwiseConv3x3Supported(gpu_info, attr)) {
     return absl::make_unique<DepthwiseConv3x3>(
         CreateDepthwiseConv3x3(gpu_info, op_def, attr));
   } else if (IsDepthWiseConv3x3StrideH2Supported(attr)) {
diff --git a/tensorflow/lite/delegates/gpu/common/tasks/BUILD b/tensorflow/lite/delegates/gpu/common/tasks/BUILD
index 95a69e0..391c561 100644
--- a/tensorflow/lite/delegates/gpu/common/tasks/BUILD
+++ b/tensorflow/lite/delegates/gpu/common/tasks/BUILD
@@ -444,6 +444,7 @@
         "//tensorflow/lite/delegates/gpu/common/task:tensor_desc",
         "//tensorflow/lite/delegates/gpu/common/task:texture2d_desc",
         "//tensorflow/lite/delegates/gpu/common/task:work_group_picking",
+        "@com_google_absl//absl/strings",
     ],
 )
 
diff --git a/tensorflow/lite/delegates/gpu/common/tasks/depthwise_conv_3x3.cc b/tensorflow/lite/delegates/gpu/common/tasks/depthwise_conv_3x3.cc
index 8358aca..2ff9605 100644
--- a/tensorflow/lite/delegates/gpu/common/tasks/depthwise_conv_3x3.cc
+++ b/tensorflow/lite/delegates/gpu/common/tasks/depthwise_conv_3x3.cc
@@ -18,6 +18,7 @@
 #include <string>
 #include <utility>
 
+#include "absl/strings/match.h"
 #include "tensorflow/lite/delegates/gpu/common/status.h"
 #include "tensorflow/lite/delegates/gpu/common/task/work_group_picking.h"
 
@@ -299,7 +300,16 @@
   }
 }
 
-bool IsDepthwiseConv3x3Supported(const DepthwiseConvolution2DAttributes& attr) {
+bool IsDepthwiseConv3x3Supported(const GpuInfo& gpu_info,
+                                 const DepthwiseConvolution2DAttributes& attr) {
+  if (gpu_info.IsApiOpenCl() && gpu_info.IsAdreno()) {
+    const std::string kBadDriver =
+        "OpenCL 2.0 QUALCOMM build: commit #7daed58 changeid #I7ece6fe30d "
+        "Date: 10/19/16";
+    if (absl::StrContains(gpu_info.opencl_info.platform_version, kBadDriver)) {
+      return false;
+    }
+  }
   return attr.weights.shape.o == 1 && attr.dilations.w == 1 &&
          attr.dilations.h == 1 && attr.weights.shape.w == 3 &&
          attr.weights.shape.h == 3 && attr.strides.w == 1 &&
diff --git a/tensorflow/lite/delegates/gpu/common/tasks/depthwise_conv_3x3.h b/tensorflow/lite/delegates/gpu/common/tasks/depthwise_conv_3x3.h
index 59d1858..2793b1a 100644
--- a/tensorflow/lite/delegates/gpu/common/tasks/depthwise_conv_3x3.h
+++ b/tensorflow/lite/delegates/gpu/common/tasks/depthwise_conv_3x3.h
@@ -146,7 +146,8 @@
   }
 }
 
-bool IsDepthwiseConv3x3Supported(const DepthwiseConvolution2DAttributes& attr);
+bool IsDepthwiseConv3x3Supported(const GpuInfo& gpu_info,
+                                 const DepthwiseConvolution2DAttributes& attr);
 
 DepthwiseConv3x3 CreateDepthwiseConv3x3(
     const GpuInfo& gpu_info, const OperationDef& definition,