class_docstr: Images2Neibs for the GPU.
class_docstr_tok: ["Images2Neibs","for","the","GPU","."]
code: def gpu_kernels(self, node, nodename):
      dtype_ten4 = node.inputs[0].dtype
      dtype_z = node.outputs[0].dtype
      flags = Kernel.get_flags(dtype_ten4, dtype_z)
      type_ten4 = gpuarray.dtype_to_ctype(dtype_ten4)
      type_z = gpuarray.dtype_to_ctype(dtype_z)
      # `BORDER_MODE`'s c_support_code() contains C constants definitions that are useful here.
      mode_constants = self.BORDER_MODE.c_support_code()
      kernels = []
      kname = "k_multi_warp_less"
      k_var = "k_multi_warp_less_" + nodename
      code = """#include "cluda.h"
  
          // a version that uses less registers but doesn't work in all cases.
          %(mode_constants)s
          KERNEL void %(kname)s(
              const ga_int mode,
              const ga_int nb_batch,
              const ga_int nb_stack,
              const ga_int height,
              const ga_int width,
              const ga_int c,
              const ga_int d,
              const ga_int step_x,
              const ga_int step_y,
              const ga_int grid_c,
              const ga_int grid_d,
              const ga_size stride0, const ga_size stride1,
              const ga_size stride2, const ga_size stride3,
              GLOBAL_MEM const %(type_ten4)s * global_ten4, const ga_size offset_ten4,
              const ga_size out_s0, const ga_size out_s1,
              GLOBAL_MEM %(type_z)s * global_out, const ga_size offset_out
          )
          {
              const ga_int wrap_centered_half_idx_shift_x = c/2;
              const ga_int wrap_centered_half_idx_shift_y = d/2;
              global_ten4 = (GLOBAL_MEM const %(type_ten4)s *)(((GLOBAL_MEM char *)global_ten4)+offset_ten4);
              global_out = (GLOBAL_MEM %(type_z)s *)(((GLOBAL_MEM char *)global_out)+offset_out);
  
              for(ga_int tblock = GID_0*LDIM_2+LID_2;
                  tblock<nb_batch*nb_stack*grid_c*grid_d;
                  tblock+=GDIM_0*LDIM_2){
                  const ga_int b = tblock%%grid_d;
                  ga_int left = tblock/grid_d;
                  const ga_int a = left%%grid_c;
                  left = left/grid_c;
                  const ga_int s = left%%nb_stack;
                  left = left/nb_stack;
                  const ga_int n = left;
  
                  if(n>nb_batch)continue;
                  if(s>nb_stack)continue;
                  if(a>grid_c)continue;
                  if(b>grid_d)continue;
                              ga_int z_row = b + grid_d*(a + grid_c*
                                                      (s + nb_stack*n));
                              ga_int i = LID_1;     // loop over c
                              {
                                  ga_int ten4_2 = i + a * step_x;
                                  if(mode == MODE_WRAP_CENTERED) {
                                      ten4_2 -= wrap_centered_half_idx_shift_x;
                                      if ( ten4_2 < 0 )
                                          ten4_2 += height;
                                      else if (ten4_2 >= height)
                                          ten4_2 -= height;
                                  } else if (mode == MODE_HALF) {
                                      ten4_2 -= wrap_centered_half_idx_shift_x;
                                  } else if (mode == MODE_FULL) {
                                      ten4_2 -= c - 1;
                                  }
                                  ga_int j = LID_0;  // loop over d
                                  {
                                      ga_int ten4_3 = j + b * step_y;
                                      if(mode == MODE_WRAP_CENTERED){
                                          ten4_3 -= wrap_centered_half_idx_shift_y;
                                          if ( ten4_3 < 0 )
                                              ten4_3 += width;
                                          else if (ten4_3 >= width)
                                              ten4_3 -= width;
                                      } else if (mode == MODE_HALF) {
                                          ten4_3 -= wrap_centered_half_idx_shift_y;
                                      } else if (mode == MODE_FULL) {
                                          ten4_3 -= d - 1;
                                      }
  
                                      ga_int z_col = j + d * i;
                                      ga_int z_idx = z_col * out_s1 +
                                                  z_row * out_s0;
                                      if(ten4_2 < 0 || ten4_2 >= height || ten4_3 < 0 || ten4_3 >= width){
                                          global_out[z_idx] = 0;
                                      } else {
                                          ga_int ten4_idx = stride3*ten4_3 +
                                                         stride2*ten4_2 +
                                                         stride1*s + stride0*n;
                                          global_out[z_idx] = global_ten4[ten4_idx];
                                      }
                                  }
                              }
              }
          }""" % dict(
          kname=kname,
          type_ten4=type_ten4,
          type_z=type_z,
          mode_constants=mode_constants,
      )
      params = [
          "intc",
          "intc",
          "intc",
          "intc",
          "intc",
          "intc",
          "intc",
          "intc",
          "intc",
          "intc",
          "intc",
          "uintp",
          "uintp",
          "uintp",
          "uintp",
          gpuarray.GpuArray,
          "uintp",
          "uintp",
          "uintp",
          gpuarray.GpuArray,
          "uintp",
      ]
      kernels.append(
          Kernel(
              code=code,
              name=kname,
              params=params,
              flags=flags,
              objvar=k_var,
          )
      )
  
      kname = "k_multi_warp"
      k_var = "k_multi_warp_" + nodename
      code = """#include "cluda.h"
  
          %(mode_constants)s
          KERNEL void %(kname)s(
              const ga_int mode,
              const ga_int nb_batch,
              const ga_int nb_stack,
              const ga_int height,
              const ga_int width,
              const ga_int c,
              const ga_int d,
              const ga_int step_x,
              const ga_int step_y,
              const ga_int grid_c,
              const ga_int grid_d,
              const ga_size stride0, const ga_size stride1,
              const ga_size stride2, const ga_size stride3,
              GLOBAL_MEM const %(type_ten4)s * global_ten4, const ga_size offset_ten4,
              const ga_size out_s0, const ga_size out_s1,
              GLOBAL_MEM %(type_z)s * global_out, const ga_size offset_out
          )
          {
              const ga_int wrap_centered_half_idx_shift_x = c/2;
              const ga_int wrap_centered_half_idx_shift_y = d/2;
              global_ten4 = (GLOBAL_MEM const %(type_ten4)s *)(((GLOBAL_MEM char *)global_ten4)+offset_ten4);
              global_out = (GLOBAL_MEM %(type_z)s *)(((GLOBAL_MEM char *)global_out)+offset_out);
  
              for(ga_int tblock = GID_0*LDIM_2+LID_2;
                  tblock<nb_batch*nb_stack*grid_c*grid_d;
                  tblock+=GDIM_0*LDIM_2){
                  const ga_int b = tblock%%grid_d;
                  ga_int left = tblock/grid_d;
                  const ga_int a = left%%grid_c;
                  left = left/grid_c;
                  const ga_int s = left%%nb_stack;
                  left = left/nb_stack;
                  const ga_int n = left;
  
                  if(n>nb_batch)continue;
                  if(s>nb_stack)continue;
                  if(a>grid_c)continue;
                  if(b>grid_d)continue;
                              ga_int z_row = b + grid_d*(a + grid_c*
                                                      (s + nb_stack*n));
                              // loop over c
                              for (ga_int i = LID_1; i < c; i+=LDIM_1)
                              {
                                  ga_int ten4_2 = i + a * step_x;
                                  if(mode == MODE_WRAP_CENTERED) {
                                      ten4_2 -= wrap_centered_half_idx_shift_x;
                                      if ( ten4_2 < 0 )
                                          ten4_2 += height;
                                      else if (ten4_2 >= height)
                                          ten4_2 -= height;
                                  } else if (mode == MODE_HALF) {
                                      ten4_2 -= wrap_centered_half_idx_shift_x;
                                  } else if (mode == MODE_FULL) {
                                      ten4_2 -= c - 1;
                                  }
                                  // loop over d
                                  for (ga_int j = LID_0; j < d; j+=LDIM_0)
                                  {
                                      ga_int ten4_3 = j + b * step_y;
                                      if(mode == MODE_WRAP_CENTERED) {
                                          ten4_3 -= wrap_centered_half_idx_shift_y;
                                          if ( ten4_3 < 0 )
                                              ten4_3 += width;
                                          else if (ten4_3 >= width)
                                              ten4_3 -= width;
                                      } else if (mode == MODE_HALF) {
                                          ten4_3 -= wrap_centered_half_idx_shift_y;
                                      } else if (mode == MODE_FULL) {
                                          ten4_3 -= d - 1;
                                      }
  
                                      ga_int z_col = j + d * i;
                                      ga_int z_idx = z_col * out_s1 +
                                                  z_row * out_s0;
                                      if(ten4_2 < 0 || ten4_2 >= height || ten4_3 < 0 || ten4_3 >= width){
                                          global_out[z_idx] = 0;
                                      } else {
                                          ga_int ten4_idx = stride3*ten4_3 +
                                                         stride2*ten4_2 +
                                                         stride1*s + stride0*n;
                                          global_out[z_idx] = global_ten4[ten4_idx];
                                      }
                                  }
                              }
              }
          }
          """ % dict(
          kname=kname,
          type_ten4=type_ten4,
          type_z=type_z,
          mode_constants=mode_constants,
      )
      params = [
          "intc",
          "intc",
          "intc",
          "intc",
          "intc",
          "intc",
          "intc",
          "intc",
          "intc",
          "intc",
          "intc",
          "uintp",
          "uintp",
          "uintp",
          "uintp",
          gpuarray.GpuArray,
          "uintp",
          "uintp",
          "uintp",
          gpuarray.GpuArray,
          "uintp",
      ]
      kernels.append(
          Kernel(
              code=code,
              name=kname,
              params=params,
              flags=flags,
              objvar=k_var,
          )
      )
      return kernels
  
file_path: Theano/theano/gpuarray/neighbours.py
imports: from __future__ import absolute_import, print_function, division
  from theano import Op, Apply
  from theano.gof import ParamsType
  from theano.tensor.nnet.neighbours import Images2Neibs
  import theano.tensor
  from .basic_ops import as_gpuarray_variable, GpuKernelBase, Kernel, infer_context_name
  from .type import GpuArrayType, gpu_context_type
label_desc: Use image node_id 5 for calling the GpuImages2Neibs obj's underlying member method code with example usage: obj.gpu_kernels(node, nodename) and returns: kernels