class_docstr: Sort an array (or one axis of one) using a sorting network.
  
  Will only work if the axis of the array to be sorted has a length
  that is a power of 2.
  
  .. versionadded:: 2015.2
  
  .. seealso:: :class:`pyopencl.algorithm.RadixSort`
  
  .. automethod:: __call__
class_docstr_tok: ["Sort","an","array","(","or","one","axis","of","one",")","using","a","sorting","network",".","Will","only","work","if","the","axis","of","the","array","to","be","sorted","has","a","length","that","is","a","power","of","2",".","..","versionadded",":",":","2015.2","..","seealso",":",":",":","class",":","`","pyopencl.algorithm.RadixSort","`","..","automethod",":",":","__call__"]
code: def sort_b_prepare_wl(
      self, argsort, key_dtype, idx_dtype, shape, axis
  ):
      key_ctype = dtype_to_ctype(key_dtype)
  
      if idx_dtype is None:
          idx_ctype = "uint"  # Dummy
  
      else:
          idx_ctype = dtype_to_ctype(idx_dtype)
  
      run_queue = []
      ds = int(shape[axis])
      size = reduce(mul, shape)
      ndim = len(shape)
  
      ns = reduce(mul, shape[(axis + 1) :]) if axis < ndim - 1 else 1
  
      ds = int(shape[axis])
      allowb4 = True
      allowb8 = True
      allowb16 = True
  
      dev = self.context.devices[0]
  
      # {{{ find workgroup size
  
      wg = min(ds, dev.max_work_group_size)
  
      available_lmem = dev.local_mem_size
      while True:
          lmem_size = _tmpl.LOCAL_MEM_FACTOR * wg * key_dtype.itemsize
          if argsort:
              lmem_size += (
                  _tmpl.LOCAL_MEM_FACTOR * wg * idx_dtype.itemsize
              )
  
          if lmem_size + 512 > available_lmem:
              wg //= 2
  
              if not wg:
                  raise RuntimeError(
                      "too little local memory available on '%s'" % dev
                  )
  
          else:
              break
  
      # }}}
  
      length = wg >> 1
      prg = self.get_program(
          "BLO", argsort, (1, 1, key_ctype, idx_ctype, ds, ns)
      )
      run_queue.append((prg.run, size, (wg,), True))
  
      while length < ds:
          inc = length
          while inc > 0:
              ninc = 0
              direction = length << 1
              if allowb16 and inc >= 8 and ninc == 0:
                  letter = "B16"
                  ninc = 4
              elif allowb8 and inc >= 4 and ninc == 0:
                  letter = "B8"
                  ninc = 3
              elif allowb4 and inc >= 2 and ninc == 0:
                  letter = "B4"
                  ninc = 2
              elif inc >= 0:
                  letter = "B2"
                  ninc = 1
  
              nthreads = size >> ninc
  
              prg = self.get_program(
                  letter,
                  argsort,
                  (inc, direction, key_ctype, idx_ctype, ds, ns),
              )
              run_queue.append(
                  (
                      prg.run,
                      nthreads,
                      None,
                      False,
                  )
              )
              inc >>= ninc
  
          length <<= 1
  
      return run_queue
  
file_path: pyopencl/pyopencl/bitonic_sort.py
imports: import pyopencl
  from pyopencl.tools import dtype_to_ctype
  from operator import mul
  from functools import reduce
  from pytools import memoize_method
  from mako.template import Template
  import pyopencl.bitonic_sort_templates
label_desc: Use image node_id 4 for calling the BitonicSort obj's underlying member method code with example usage: obj.sort_b_prepare_wl(argsort, key_dtype, idx_dtype, shape, axis) and returns: run_queue