class_docstr: Benchmark conv2d!
class_docstr_tok: ["Benchmark","conv2d","!"]
code: def benchmark_conv2d(self):
      print("conv2d benchmark:")
  
      data_types = [dtypes.float32, dtypes.float16]
      data_formats = ["NHWC", "NCHW"]
      in_channels = (
          list(range(1, 10))
          + list(range(10, 20, 2))
          + list(range(20, 33, 4))
      )
      out_channels = [4, 16, 32]
      hw_strides = [[2, 2]]
      paddings = ["VALID", "SAME"]
  
      args_lists = [
          data_types,
          data_formats,
          in_channels,
          out_channels,
          hw_strides,
          paddings,
      ]
      for args in itertools.product(*args_lists):
          (
              dtype,
              data_format,
              in_channel,
              out_channel,
              hw_stride,
              padding,
          ) = args
  
          # Keep batch size same as out channels just to reduce the number of
          # different configurations to benchmark.
          batch_size = out_channel
          h, w, fh, fw = 500, 500, 3, 3
          if data_format == "NHWC":
              ishape = [batch_size, h, w, in_channel]
              stride = [1] + hw_stride + [1]
          elif data_format == "NCHW":
              ishape = [batch_size, in_channel, h, w]
              stride = [1, 1] + hw_stride
          else:
              raise ValueError(
                  "Unknown data_format: " + str(data_format)
              )
          fshape = [fh, fw, in_channel, out_channel]
          num_iters = 80
          warmup_iters = 2
          self._run_graph(
              "gpu",
              dtype,
              data_format,
              ishape,
              fshape,
              stride,
              padding,
              num_iters,
              warmup_iters,
          )
  
file_path: tensorflow-upstream/tensorflow/python/ops/conv2d_benchmark.py
imports: import itertools
  import time
  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 dtypes
  from tensorflow.python.framework import ops
  from tensorflow.python.ops import control_flow_ops
  from tensorflow.python.ops import nn_ops
  from tensorflow.python.ops import random_ops
  from tensorflow.python.ops import variable_v1
  from tensorflow.python.ops import variables
  from tensorflow.python.platform import flags
  from tensorflow.python.platform import test
label_desc: Use image node_id 2 for calling the Conv2DBenchmark obj's underlying member method code with example usage: obj.benchmark_conv2d() without return types