Ejemplo n.º 1
0
 def _compile_out_x(self):
     # 2D: int out_x_0 = i / (out_1) % out_0;
     #     int out_x_1 = i % out_1;
     def aux(out_x, outs):
         head = outs[0]
         tail = outs[1:]
         if tail:
             return 'int {} = i / ({}) % {};'.format(
                 out_x, conv_nd_kernel.mulexp(tail), head)
         else:
             return 'int {} = i % {};'.format(out_x, head)
     out_xs = conv_nd_kernel.vars('out_x', self.ndim)
     out_xs_decls = conv_nd_kernel.map_(
         aux, out_xs, conv_nd_kernel.succ_sublists(self.outs))
     return out_xs_decls, out_xs
Ejemplo n.º 2
0
 def _compile_x(self):
     # 2D: int x_0 = i / (d_1) % d_0 + p_0;
     #     int x_1 = i % d_1 + p_1;
     def aux(x, ds, p):
         head = ds[0]
         tail = ds[1:]
         if tail:
             return 'int {} = i / ({}) % {} + {};'.format(
                 x, conv_nd_kernel.mulexp(tail), head, p)
         else:
             return 'int {} = i % {} + {};'.format(x, head, p)
     xs = conv_nd_kernel.vars('x', self.ndim)
     xs_decls = conv_nd_kernel.map_(
         aux, xs, conv_nd_kernel.succ_sublists(self.ds), self.ps)
     return xs_decls, xs
Ejemplo n.º 3
0
 def _compile_out_x(self):
     # 2D: int out_x_0 = i / (out_1) % out_0;
     #     int out_x_1 = i % out_1;
     def aux(out_x, outs):
         head = outs[0]
         tail = outs[1:]
         if tail:
             return 'int {} = i / ({}) % {};'.format(
                 out_x, conv_nd_kernel.mulexp(tail), head)
         else:
             return 'int {} = i % {};'.format(out_x, head)
     out_xs = conv_nd_kernel.vars('out_x', self.ndim)
     out_xs_decls = conv_nd_kernel.map_(
         aux, out_xs, conv_nd_kernel.succ_sublists(self.outs))
     return out_xs_decls, out_xs
Ejemplo n.º 4
0
 def _compile_x(self):
     # 2D: int x_0 = i / (d_1) % d_0 + p_0;
     #     int x_1 = i % d_1 + p_1;
     def aux(x, ds, p):
         head = ds[0]
         tail = ds[1:]
         if tail:
             return 'int {} = i / ({}) % {} + {};'.format(
                 x, conv_nd_kernel.mulexp(tail), head, p)
         else:
             return 'int {} = i % {} + {};'.format(x, head, p)
     xs = conv_nd_kernel.vars('x', self.ndim)
     xs_decls = conv_nd_kernel.map_(
         aux, xs, conv_nd_kernel.succ_sublists(self.ds), self.ps)
     return xs_decls, xs
    def _compile_max_x(self):
        def aux(max_val, out_val, stride_val, pad_val, ksize_vals):
            head = ksize_vals[0]
            tail = ksize_vals[1:]
            if tail:
                command = 'int {} = max(0, {} * {} - {} + index / ({}) % {});'
                return command.format(max_val, out_val, stride_val, pad_val,
                                      conv_nd_kernel.mulexp(tail), head)
            else:
                return 'int {} = max(0, {} * {} - {} + index % {});'.format(
                    max_val, out_val, stride_val, pad_val, head)

        max_vals = conv_nd_kernel.vars('max', self.ndim)
        out_vals = conv_nd_kernel.vars('out_x', self.ndim)
        stride_vals = conv_nd_kernel.vars('s', self.ndim)
        pad_vals = conv_nd_kernel.vars('p', self.ndim)
        ksize_vals = conv_nd_kernel.vars('k', self.ndim)

        offset_ks_decls = conv_nd_kernel.map_(
            aux, max_vals, out_vals, stride_vals, pad_vals,
            conv_nd_kernel.succ_sublists(ksize_vals))
        return offset_ks_decls
Ejemplo n.º 6
0
    def _compile_max_x(self):
        def aux(max_val, out_val, stride_val, pad_val, ksize_vals):
            head = ksize_vals[0]
            tail = ksize_vals[1:]
            if tail:
                command = 'int {} = max(0, {} * {} - {} + index / ({}) % {});'
                return command.format(
                    max_val, out_val, stride_val, pad_val,
                    conv_nd_kernel.mulexp(tail), head)
            else:
                return 'int {} = max(0, {} * {} - {} + index % {});'.format(
                    max_val, out_val, stride_val, pad_val, head)

        max_vals = conv_nd_kernel.vars('max', self.ndim)
        out_vals = conv_nd_kernel.vars('out_x', self.ndim)
        stride_vals = conv_nd_kernel.vars('s', self.ndim)
        pad_vals = conv_nd_kernel.vars('p', self.ndim)
        ksize_vals = conv_nd_kernel.vars('k', self.ndim)

        offset_ks_decls = conv_nd_kernel.map_(
            aux, max_vals, out_vals, stride_vals, pad_vals,
            conv_nd_kernel.succ_sublists(ksize_vals))
        return offset_ks_decls