class_docstr: Tests the Grappler remapper optimizer.
docstr: Test MatMul+BiasAdd+Gelu fusion.
code: def test_matmul_biasadd_activation_fusion(self, mode):
      """Test MatMul+BiasAdd+Gelu fusion."""
      self.maybe_skip_test(mode)
  
      def gelu_approximate(x):
          return nn.gelu(x, approximate=True)
  
      def gelu_exact(x):
          return nn.gelu(x, approximate=False)
  
      device = "/device:GPU:0" if mode == "cuda" else "/device:CPU:0"
      config = []
      use_fp16 = True
      if (
          test_util.IsMklEnabled()
          and not _pywrap_utils.IsDataTypeSupportedByOneDNNOnThisCPU(
              dtypes.float16
          )
      ):
          use_fp16 = False
      if mode == "mkl":
          config.append((dtypes.float32, gelu_exact, b"GeluExact"))
          config.append(
              (dtypes.float32, gelu_approximate, b"GeluApproximate")
          )
          if _pywrap_utils.IsDataTypeSupportedByOneDNNOnThisCPU(
              dtypes.bfloat16
          ):
              config.append(
                  (
                      dtypes.bfloat16,
                      gelu_approximate,
                      b"GeluApproximate",
                  )
              )
              config.append((dtypes.bfloat16, gelu_exact, b"GeluExact"))
      elif mode == "cuda":
          config.append(
              (dtypes.float32, gelu_approximate, b"GeluApproximate")
          )
          if use_fp16:
              config.append(
                  (dtypes.float16, gelu_approximate, b"GeluApproximate")
              )
          # Gelu exact fusion is supported by cuDNN frontend APIs and performant
          # with fp16 and on Ampere GPUs and later.
          if test_util.is_gpu_available(
              cuda_only=True, min_cuda_compute_capability=(8, 0)
          ):
              config.append((dtypes.float16, gelu_exact, b"GeluExact"))
              config.append((dtypes.float16, math_ops.tanh, b"Tanh"))
              config.append(
                  (dtypes.float16, math_ops.sigmoid, b"Sigmoid")
              )
  
      m, n, k = (2, 4, 6)  # Matrix dimensions
      fused_op = [
          "_MklNativeFusedMatMul",
          "_MklFusedMatMul",
          "_FusedMatMul",
      ]
  
      for precision, act_fn, act_name in config:
          for transpose in (False, True):
              # Create MatMul + BiasAdd + Activation graph
              ops.reset_default_graph()
              with ops.device(device):
                  x = _input([k, m] if transpose else [m, k])
                  w = _weight([n, k] if transpose else [k, n])
                  b = _bias([n])
                  x = math_ops.cast(x, precision)
                  w = math_ops.cast(w, precision)
                  b = math_ops.cast(b, precision)
                  y = math_ops.matmul(
                      x, w, transpose_a=transpose, transpose_b=transpose
                  )
                  z = nn.bias_add(y, b)
                  out = act_fn(z)
  
              if (
                  transpose
                  and (device == "/device:CPU:0")
                  and act_name in (b"GeluApproximate", b"GeluExact")
              ):
                  if precision == dtypes.bfloat16:
                      # No fusion should happen on CPU.
                      self._VerifyNoFusion(out)
                      continue
                  else:
                      # Gelu should not get fused, only BiasAdd.
                      epilog_ops = [b"BiasAdd"]
              else:
                  epilog_ops = [b"BiasAdd", act_name]
              graph = self._VerifyValues(
                  out, precision != dtypes.float32, fused_op, epilog_ops
              )
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import os
  from absl.testing import parameterized
  from tensorflow.core.protobuf import config_pb2
  from tensorflow.core.protobuf import rewriter_config_pb2
  from tensorflow.python.client import session
  from tensorflow.python.framework import constant_op
  from tensorflow.python.framework import dtypes
  from tensorflow.python.framework import meta_graph
  from tensorflow.python.framework import ops
  from tensorflow.python.framework import test_util
  from tensorflow.python.grappler import tf_optimizer
  from tensorflow.python.ops import array_ops
  from tensorflow.python.ops import init_ops
  from tensorflow.python.ops import math_ops
  from tensorflow.python.ops import nn
  from tensorflow.python.ops import nn_ops
  from tensorflow.python.ops import random_ops
  from tensorflow.python.ops import variables
  from tensorflow.python.platform import sysconfig
  from tensorflow.python.platform import test
  from tensorflow.python.util import _pywrap_utils
label_desc: Use image node_id 5 for calling the RemapperTest obj's underlying member method code with example usage: obj.test_matmul_biasadd_activation_fusion(mode) and returns: nn, nn