Repository: tensorflow
Issue: Compilation error on macos with GPU delegate
Labels: stat:awaiting tensorflower,type:build/install,comp:gpu,subtype:macOS,TF 2.15

### Issue type

Build/Install

### Have you reproduced the bug with TensorFlow Nightly?

Yes

### Source

source

### TensorFlow version

2.15.0

### Custom code

No

### OS platform and distribution

Macos 14.3.1

### Mobile device

_No response_

### Python version

_No response_

### Bazel version

_No response_

### GCC/compiler version

Apple clang 15.0.0

### CUDA/cuDNN version

_No response_

### GPU model and memory

_No response_

### Current behavior?

I'm trying to build tensorflow-lite with the GPU delegates with CMake. It works well with Linux and Android (gcc), but for Macos (apple clang compiler) , I have a compilation error:
`tensorflow-lite/tensorflow/lite/delegates/gpu/api.cc:72:10: error: no matching function for call to 'visit'
  return std::visit(ObjectTypeGetter{}, object);`

It complains about using std::visit on a absl::variant.

My guess is that std::visit with gcc is more permissive than the standard about std::visit and allow to use it with not only std::variant but also with other variant-like. On the other side, Clang is not that permissive.

I tried with the source from the 2.15.0 and also with the sources of the latest commit.

### Standalone code to reproduce the issue

```shell
cd tensorflow/lite && cmake -B build -DTFLITE_ENABLE_GPU=ON && cmake --build build
```


### Relevant log output

```shell
/Users/lbertho/devel/.sx/build/tensorflow-lite/tensorflow/lite/delegates/gpu/api.cc:72:10: error: no matching function for call to 'visit'
  return std::visit(ObjectTypeGetter{}, object);
         ^~~~~~~~~~
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.2.sdk/usr/include/c++/v1/variant:1753:26: note: candidate template ignored: substitution failure [with _Visitor = tflite::gpu::(anonymous namespace)::ObjectTypeGetter, _Vs = <const absl::variant<std::monostate, tflite::gpu::OpenGlBuffer, tflite::gpu::OpenGlTexture, tflite::gpu::CpuMemory, tflite::gpu::OpenClBuffer, tflite::gpu::OpenClTexture, tflite::gpu::VulkanBuffer, tflite::gpu::VulkanTexture> &>]: no matching function for call to '__as_variant'
constexpr decltype(auto) visit(_Visitor&& __visitor, _Vs&&... __vs) {
                         ^
/Users/lbertho/devel/.sx/build/tensorflow-lite/tensorflow/lite/delegates/gpu/api.cc:79:10: error: no matching function for call to 'visit'
         std::visit(ObjectValidityChecker{def.object_def.data_type}, object);
         ^~~~~~~~~~
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.2.sdk/usr/include/c++/v1/variant:1753:26: note: candidate template ignored: substitution failure [with _Visitor = tflite::gpu::(anonymous namespace)::ObjectValidityChecker, _Vs = <const absl::variant<std::monostate, tflite::gpu::OpenGlBuffer, tflite::gpu::OpenGlTexture, tflite::gpu::CpuMemory, tflite::gpu::OpenClBuffer, tflite::gpu::OpenClTexture, tflite::gpu::VulkanBuffer, tflite::gpu::VulkanTexture> &>]: no matching function for call to '__as_variant'
constexpr decltype(auto) visit(_Visitor&& __visitor, _Vs&&... __vs) {
                         ^
/Users/lbertho/devel/.sx/build/tensorflow-lite/tensorflow/lite/delegates/gpu/api.cc:85:14: error: no matching function for call to 'holds_alternative'
      return std::holds_alternative<CpuMemory>(obj);
             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.2.sdk/usr/include/c++/v1/variant:1502:16: note: candidate template ignored: could not match 'std::variant' against 'absl::variant'
constexpr bool holds_alternative(const variant<_Types...>& __v) noexcept {
               ^
/Users/lbertho/devel/.sx/build/tensorflow-lite/tensorflow/lite/delegates/gpu/api.cc:87:14: error: no matching function for call to 'holds_alternative'
      return std::holds_alternative<OpenGlBuffer>(obj);
             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.2.sdk/usr/include/c++/v1/variant:1502:16: note: candidate template ignored: could not match 'std::variant' against 'absl::variant'
constexpr bool holds_alternative(const variant<_Types...>& __v) noexcept {
               ^
/Users/lbertho/devel/.sx/build/tensorflow-lite/tensorflow/lite/delegates/gpu/api.cc:89:14: error: no matching function for call to 'holds_alternative'
      return std::holds_alternative<OpenGlTexture>(obj);
             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.2.sdk/usr/include/c++/v1/variant:1502:16: note: candidate template ignored: could not match 'std::variant' against 'absl::variant'
constexpr bool holds_alternative(const variant<_Types...>& __v) noexcept {
               ^
/Users/lbertho/devel/.sx/build/tensorflow-lite/tensorflow/lite/delegates/gpu/api.cc:91:14: error: no matching function for call to 'holds_alternative'
      return std::holds_alternative<OpenClBuffer>(obj);
             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.2.sdk/usr/include/c++/v1/variant:1502:16: note: candidate template ignored: could not match 'std::variant' against 'absl::variant'
constexpr bool holds_alternative(const variant<_Types...>& __v) noexcept {
               ^
/Users/lbertho/devel/.sx/build/tensorflow-lite/tensorflow/lite/delegates/gpu/api.cc:93:14: error: no matching function for call to 'holds_alternative'
      return std::holds_alternative<OpenClTexture>(obj);
             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.2.sdk/usr/include/c++/v1/variant:1502:16: note: candidate template ignored: could not match 'std::variant' against 'absl::variant'
constexpr bool holds_alternative(const variant<_Types...>& __v) noexcept {
               ^
/Users/lbertho/devel/.sx/build/tensorflow-lite/tensorflow/lite/delegates/gpu/api.cc:95:14: error: no matching function for call to 'holds_alternative'
      return std::holds_alternative<VulkanBuffer>(obj);
             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.2.sdk/usr/include/c++/v1/variant:1502:16: note: candidate template ignored: could not match 'std::variant' against 'absl::variant'
constexpr bool holds_alternative(const variant<_Types...>& __v) noexcept {
               ^
/Users/lbertho/devel/.sx/build/tensorflow-lite/tensorflow/lite/delegates/gpu/api.cc:97:14: error: no matching function for call to 'holds_alternative'
      return std::holds_alternative<VulkanTexture>(obj);
             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.2.sdk/usr/include/c++/v1/variant:1502:16: note: candidate template ignored: could not match 'std::variant' against 'absl::variant'
constexpr bool holds_alternative(const variant<_Types...>& __v) noexcept {
```