code: def speed_multilayer_conv():
      # calculate the speed up of different combination of unroll
      # put the parameter to the same you will try.
      # validate = False  # we don't validate the result to have it much faster!
      repeat = 3
      verbose = 1
      unroll_batch = [
          1,
          2,
          3,
          4,
          5,
          6,
          10,
      ]  # 15, 30, 60 always much slower
      unroll_kern = [
          1,
          2,
          3,
          4,
          5,
          6,
          10,
      ]  # 15, 30, 60 always much slower
      # unroll_batch = [1,4,5]
      # unroll_kern = [1,4,5]
      # unroll_batch = [1,4]
      # unroll_kern = [1,4]
      # unroll_patch = [True, False]
      bsize = 60  # batch size
      imshp_start = (
          1,
          48,
          48,
      )  # un square shape to test more corner case.
      kshps = ([11, 12],)  # un square shape to test more corner case.
      nkerns = [60]  # per output pixel
      ssizes = [
          (1, 1),
      ]  # (1,1)]#(2,2) bugged
      convmodes = ["valid", "full"]
      # do_convolve2 = False
      a = T.dmatrix()
      kerns = [a for i in nkerns]
  
      assert len(kshps) == len(nkerns) == len(kerns)
      timing = N.zeros(
          (
              len(unroll_batch),
              len(unroll_kern),
              3,
              len(convmodes) * len(ssizes),
          )
      )
      t_b_k = []
      # calculate the timing with unrolling
  
      print("time unroll batch kern")
      best = []
      worst = []
      t_ = []
      for unroll_b, n_b in zip(unroll_batch, xrange(len(unroll_batch))):
          for unroll_k, n_k in zip(
              unroll_kern, xrange(len(unroll_kern))
          ):
              t_b_k.append(str(unroll_b) + "/" + str(unroll_k))
              if not t_:
                  tctot, tpytot, ntot = [], [], []
                  for conv_mode, n_mode in zip(
                      convmodes, xrange(len(convmodes))
                  ):
                      for ss, n_ss in zip(ssizes, xrange(len(ssizes))):
                          # tctot_, tpytot_, ntot_ = exec_multilayer_conv_nnet_old(conv_mode, ss, bsize, imshp_start, kshps, nkerns, unroll_batch=unroll_b, unroll_kern=unroll_k, validate=validate, verbose=verbose,do_print=False)
                          (
                              tctot_,
                              tpytot_,
                              ntot_,
                          ) = exec_multilayer_conv_nnet(
                              conv_mode,
                              ss,
                              bsize,
                              imshp_start,
                              kshps,
                              nkerns,
                              unroll_batch=unroll_b,
                              unroll_kern=unroll_k,
                              verbose=verbose,
                              do_print=False,
                              repeat=repeat,
                          )
                          tctot += [tctot_]
                          tpytot += [tpytot_]
                          ntot += [ntot_]
                  if unroll_b == 4 and unroll_k == 4:
                      # print "unroll 4/4",tctot
                      best = tctot
                  if unroll_b == 1 and unroll_k == 1:
                      # print "unroll 1/1",tctot
                      worst = tctot
                  timing[n_b, n_k] = [
                      tctot,
                      tpytot,
                      ntot,
                  ]  # [sum(tctot), sum(tpytot), sum(ntot)]
      if not t_:
          t = timing[:, :, 0, :]  # We select only the c timing.
      else:
          t = t_
      t = N.asarray(t)
      # calculate the old timing
      print("time old version")
      tctot, tpytot, ntot = [], [], []
      tctot_ = []
      if not tctot_:
          for conv_mode, n_mode in zip(
              convmodes, xrange(len(convmodes))
          ):
              for ss, n_ss in zip(ssizes, xrange(len(ssizes))):
                  # tctot_, tpytot_, ntot_ = exec_multilayer_conv_nnet_old(conv_mode, ss, bsize, imshp_start, kshps, nkerns, unroll_batch=0, unroll_kern=0, validate=validate, verbose=verbose,do_print=False)
                  tctot_, tpytot_, ntot_ = exec_multilayer_conv_nnet(
                      conv_mode,
                      ss,
                      bsize,
                      imshp_start,
                      kshps,
                      nkerns,
                      unroll_batch=0,
                      unroll_kern=0,
                      verbose=verbose,
                      do_print=False,
                      repeat=repeat,
                  )
                  tctot += [tctot_]
                  tpytot += [tpytot_]
                  ntot += [ntot_]
      else:
          tctot = N.asarray(tctot_)
      print("old code timing %.3fs" % sum(tctot), tctot)
      best = N.asarray(best)
      worst = N.asarray(worst)
      print("timing for unrolled version")
      print("unroll_batch/unroll_kern valid_mode full_mode")
      for n_b in xrange(len(unroll_batch)):
          for n_k in xrange(len(unroll_kern)):
              print(
                  (unroll_batch[n_b], unroll_kern[n_k])
                  + tuple(t[n_b, n_k]),
                  ",",
              )
      # t_detail = t
      t = t.sum(axis=2)
      print(
          "max %.3fs" % t.max(),
          "max param(batch unloop size/kernel unloop size)",
          t_b_k[t.argmax()],
      )
      print(
          "min %.3fs" % t.min(),
          "min param(batch unloop size/kernel unloop size)",
          t_b_k[t.argmin()],
      )
      print(
          "speedup vs (1/1)%.3fx, vs old %.3fx"
          % (t.max() / t.min(), sum(tctot) / t.min())
      )
      print(worst / best, tctot / best)
  
      # calculate the timing of unroll_patch
      print("time unroll_patch")
      tctot_patch = []
      tctot_patch_size = []
      for conv_mode, n_mode in zip(convmodes, xrange(len(convmodes))):
          for ss, n_ss in zip(ssizes, xrange(len(ssizes))):
              # tctot_, tpytot_, ntot_ = exec_multilayer_conv_nnet_old(conv_mode, ss, bsize, imshp_start, kshps, nkerns, unroll_batch=0, unroll_kern=0, validate=validate,unroll_patch=True,verbose=verbose,do_print=False)
              tctot_, tpytot_, ntot_ = exec_multilayer_conv_nnet(
                  conv_mode,
                  ss,
                  bsize,
                  imshp_start,
                  kshps,
                  nkerns,
                  unroll_batch=0,
                  unroll_kern=0,
                  unroll_patch=True,
                  verbose=verbose,
                  do_print=False,
                  repeat=repeat,
              )
              tctot_patch += [tctot_]
              # tctot_, tpytot_, ntot_ = exec_multilayer_conv_nnet_old(conv_mode, ss, bsize, imshp_start, kshps, nkerns, unroll_batch=0, unroll_kern=0, validate=validate,unroll_patch=True,verbose=verbose,do_print=False,unroll_patch_size=True)
              tctot_, tpytot_, ntot_ = exec_multilayer_conv_nnet(
                  conv_mode,
                  ss,
                  bsize,
                  imshp_start,
                  kshps,
                  nkerns,
                  unroll_batch=0,
                  unroll_kern=0,
                  unroll_patch=True,
                  verbose=verbose,
                  do_print=False,
                  unroll_patch_size=True,
                  repeat=repeat,
              )
              tctot_patch_size += [tctot_]
  
      t_patch = sum(tctot_patch)
      print("unroll_patch without shape time", tctot_patch)
      print(
          "speedup vs (1/1)%.3fx, vs old %.3fx"
          % (t.max() / t_patch, sum(tctot) / t_patch)
      )
      print(best / tctot_patch, worst / tctot_patch)
      t_patch_size = sum(tctot_patch_size)
      print("unroll_patch with shape time", tctot_patch_size)
      print(
          "speedup vs (1/1)%.3fx, vs old %.3fx"
          % (t.max() / t_patch_size, sum(tctot) / t_patch_size)
      )
      print(best / tctot_patch_size, worst / tctot_patch_size)
      return
  
file_path: Theano/theano/tensor/nnet/tests/speed_test_conv.py
imports: from __future__ import absolute_import, print_function, division
  import time
  import numpy
  from six.moves import xrange
  from theano import function, Mode
  import theano.tensor
  from theano.tensor.nnet.conv import ConvOp
label_desc: Use image node_id 4 for calling a global function with example usage: speed_multilayer_conv() without return types