code: def benchmark_transpose():
      ctx = cl.create_some_context()
  
      for dev in ctx.devices:
          assert dev.local_mem_size > 0
  
      queue = cl.CommandQueue(
          ctx, properties=cl.command_queue_properties.PROFILING_ENABLE
      )
  
      sizes = [
          int(((2**i) // 32) * 32)
          for i in numpy.arange(10, 13, 0.125)
      ]
      # for i in numpy.arange(10, 10.5, 0.125)]
  
      mem_bandwidths = {}
  
      methods = [SillyTranspose, NaiveTranspose, TransposeWithLocal]
      for cls in methods:
          name = cls.__name__.replace("Transpose", "")
  
          mem_bandwidths[cls] = meth_mem_bws = []
  
          for size in sizes:
              source = numpy.random.rand(size, size).astype(
                  numpy.float32
              )
  
              mf = cl.mem_flags
              a_buf = cl.Buffer(
                  ctx, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=source
              )
              a_t_buf = cl.Buffer(
                  ctx, mf.WRITE_ONLY, size=source.nbytes
              )
              method = cls(ctx)
  
              for _i in range(4):
                  method(queue, a_t_buf, a_buf, source.shape)
  
              count = 12
              events = []
              for _i in range(count):
                  events.append(
                      method(queue, a_t_buf, a_buf, source.shape)
                  )
  
              events[-1].wait()
              time = sum(
                  evt.profile.end - evt.profile.start for evt in events
              )
  
              mem_bw = 2 * source.nbytes * count / (time * 1e-9)
              print("benchmarking", name, size, mem_bw / 1e9, "GB/s")
              meth_mem_bws.append(mem_bw)
  
              a_buf.release()
              a_t_buf.release()
  
      try:
          from matplotlib.pyplot import (
              clf,
              plot,
              xlabel,
              ylabel,
              savefig,
              legend,
              grid,
          )
      except ModuleNotFoundError:
          pass
      else:
          for i in range(len(methods)):
              clf()
              for j in range(i + 1):
                  method = methods[j]
                  name = method.__name__.replace("Transpose", "")
                  plot(
                      sizes,
                      numpy.array(mem_bandwidths[method]) / 1e9,
                      "o-",
                      label=name,
                  )
  
              xlabel("Matrix width/height $N$")
              ylabel("Memory Bandwidth [GB/s]")
              legend(loc="best")
              grid()
  
              savefig("transpose-benchmark-%d.pdf" % i)
  
file_path: pyopencl/examples/transpose.py
imports: import pyopencl
  import numpy
  import numpy.linalg
label_desc: Use image node_id 3 for calling a global function with example usage: benchmark_transpose() without return types