Ejemplo n.º 1
0
 def run(self, src, **kws):
     n = 64
     a = np.pi * np.arange(2 * n, dtype=cltypes.float) / n
     b = np.e * np.arange(3 * n, dtype=cltypes.float) / n
     c = np.zeros(4 * n, dtype=cltypes.float)
     run_kernel(self.ctx, src, (n, ), *[Mem(x) for x in [c, a, b]])
     return (c, a, b)
Ejemplo n.º 2
0
 def run(self, src, **kws):
     m = 64
     n = 4 * m
     a = np.arange(n, dtype=cltypes.int)
     b = np.zeros_like(a)
     run_kernel(self.ctx, src, (m, ), *[Mem(x) for x in [a, b]])
     return (a, b)
Ejemplo n.º 3
0
 def run(self, src, **kws):
     n = 64
     c = np.arange(3 * n, dtype=cltypes.float)
     b = np.arange(n, dtype=cltypes.int)
     a = np.zeros_like(b)
     run_kernel(self.ctx, src, (n, ), *[Mem(x) for x in [a, b, c]])
     return (a, b, c)
Ejemplo n.º 4
0
    def run(self, src, **kws):
        a = self.a.copy()
        b = np.zeros_like(a)

        run_kernel(self.ctx, src, (self.n,), *[Mem(x) for x in [a, b]])

        return [a, b]
Ejemplo n.º 5
0
    def run(self, src, **kws):
        buf = [x for x in self.ibuf]
        for i in range(27):
            buf.append(np.zeros(self.N * self.n, dtype=self.UT))

        run_kernel(self.ctx, src, (self.n, ), *[Mem(x) for x in buf])

        return buf
Ejemplo n.º 6
0
 def run(self, src, **kws):
     n = 64
     a = np.arange(n, dtype=cltypes.int) - n//2
     b = np.arange(n, dtype=cltypes.int)
     c = np.zeros(n, dtype=cltypes.float)
     d = np.zeros(n, dtype=cltypes.int)
     run_kernel(self.ctx, src, (n,), *[Mem(x) for x in [a, b, c, d]])
     return (a, b, c, d)
Ejemplo n.º 7
0
 def run(self, src, **kws):
     n = 64
     a = np.pi * np.arange(n, dtype=cltypes.float) / n
     b = np.e * np.arange(n, dtype=cltypes.float) / n
     c = np.sqrt(2) * np.arange(n, dtype=cltypes.float) / n
     d = np.zeros(3 * n, dtype=cltypes.float)
     run_kernel(self.ctx, src, (n, ), *[Mem(x) for x in [a, b, c, d]])
     return (a, b, c, d)
Ejemplo n.º 8
0
    def run(self, src, **kws):
        a = self.a
        b = self.b
        c = np.zeros_like(self.c)
        o = np.zeros_like(self.o)

        run_kernel(self.ctx, src, (self.n, ), *[Mem(x) for x in [a, b, c, o]])

        return [a, b, c, o]
Ejemplo n.º 9
0
 def run(self, src, **kws):
     n = 64
     a = np.arange(n, dtype=cl.cltypes.int)
     b = np.arange(n, dtype=cl.cltypes.float)
     c = np.zeros_like(a)
     d = np.zeros_like(b)
     run_kernel(self.ctx, src, (n, ), *[Mem(x) for x in (a, b, c, d)])
     assert np.allclose(a, c)
     assert np.allclose(b, d)
     return (a, b, c, d)
Ejemplo n.º 10
0
 def run(self, src, **kws):
     n = 64
     buf = [
         np.arange(n, dtype=cltypes.char),
         np.arange(n, dtype=cltypes.short),
         np.arange(n, dtype=cltypes.int),
         np.arange(n, dtype=cltypes.long),
         np.zeros(n*15, dtype=cltypes.uchar),
     ]
     run_kernel(self.ctx, src, (n,), *[Mem(x) for x in buf])
     return buf
Ejemplo n.º 11
0
 def run(self, src, **kws):
     n = 64
     buf = [
         np.arange(4*n, dtype=cltypes.int),
         np.arange(4*n, dtype=cltypes.int) - 4*n,
         (np.arange(4*n, dtype=cltypes.int) % 2) - 1,
         np.zeros(4*n, dtype=cltypes.int),
         np.zeros(4*n, dtype=cltypes.int),
     ]
     run_kernel(self.ctx, src, (n,), *[Mem(x) for x in buf])
     return buf
Ejemplo n.º 12
0
    def run(self, src, **kws):
        n = 256
        a = (np.arange(n, dtype=cltypes.uint) % 13)
        b = (np.arange(n, dtype=cltypes.uint) % 17)
        c = (np.arange(n, dtype=cltypes.uint) % 5)
        buf = [a, b, c]

        for i in range(23):
            buf.append(np.zeros(n, dtype=cltypes.int))

        for i in range(18):
            buf.append((np.arange(n, dtype=cltypes.int) % 7))

        run_kernel(self.ctx, src, (n, ), *[Mem(x) for x in buf])
        return buf
Ejemplo n.º 13
0
    def run(self, src, **kws):
        n = 256
        a = np.pi * ((np.arange(n, dtype=cltypes.float) % 13) - 13 / 2)
        b = np.pi * ((np.arange(n, dtype=cltypes.float) % 17) - 17 / 2)
        c = (np.arange(n, dtype=cltypes.int) % 5) - 5 // 2
        buf = [a, b, c]

        for i in range(13):
            buf.append(np.zeros(n, dtype=cltypes.float))

        for i in range(4):
            buf.append(np.e *
                       ((np.arange(n, dtype=cltypes.float) % 7) - 7 / 2))

        run_kernel(self.ctx, src, (n, ), *[Mem(x) for x in buf])
        return buf
Ejemplo n.º 14
0
    def run(self, src, **kws):
        m = 64
        n = 4 * m
        a = (np.arange(n, dtype=cltypes.uint) % 51)
        b = (np.arange(n, dtype=cltypes.uint) % 67)
        c = (np.arange(n, dtype=cltypes.uint) % 19)
        buf = [a, b, c]

        for i in range(23):
            buf.append(np.zeros(n, dtype=cltypes.uint))

        for i in range(18):
            buf.append((np.arange(n, dtype=cltypes.uint) % 29))

        run_kernel(self.ctx, src, (m, ), *[Mem(x) for x in buf])
        return buf
Ejemplo n.º 15
0
    def run(self, src, **kws):
        n = 64
        a = np.arange(n, dtype=cltypes.uchar) % 2
        b = (np.arange(n, dtype=cltypes.uchar) + 1) % 2
        c = (np.arange(n, dtype=cltypes.uchar) // 2) % 2
        buf = [a, b, c]

        for i in range(23):
            buf.append(np.zeros(n, dtype=cltypes.uchar))

        for i in range(18):
            buf.append(np.clip(np.arange(n, dtype=cltypes.uchar) % 3, 0, 1))

        run_kernel(self.ctx, src, (n, ), *[Mem(x) for x in buf])

        #buf = [b & 1 for b in buf]
        return buf
Ejemplo n.º 16
0
 def run(self, src, **kws):
     n = 64
     #b = np.arange(4*n, dtype=cltypes.float)/(2*n**0.5)
     ibuf = [
         np.arange(4 * n, dtype=cltypes.uint) - (4 * n) // 2,
         np.arange(4 * n, dtype=cltypes.int) - (4 * n) // 2,
         np.arange(4 * n, dtype=cltypes.int) - (4 * n) // 2,
         np.arange(4 * n, dtype=cltypes.float) - (4 * n) // 2,
     ]
     obuf = [
         np.zeros(4 * n, dtype=cltypes.int),
         np.zeros(4 * n, dtype=cltypes.uint),
         np.zeros(4 * n, dtype=cltypes.float),
         np.zeros(4 * n, dtype=cltypes.int),
     ]
     run_kernel(self.ctx, src, (n, ), *[Mem(x) for x in ibuf + obuf])
     return ibuf + obuf
Ejemplo n.º 17
0
    def run(self, src, **kws):
        m = 64
        n = 4 * m
        a = np.pi * ((np.arange(n, dtype=cltypes.float) % 51) - 51 // 2)
        b = np.e * ((np.arange(n, dtype=cltypes.float) % 67) - 67 // 2)
        c = (np.arange(n, dtype=cltypes.float) % 19) - 19 // 2
        buf = [a, b, c]

        for i in range(13):
            buf.append(np.zeros(n, dtype=cltypes.float))

        for i in range(4):
            buf.append(
                np.sqrt(2) *
                ((np.arange(n, dtype=cltypes.float) % 29) - 29 // 2))

        run_kernel(self.ctx, src, (m, ), *[Mem(x) for x in buf])
        return buf
Ejemplo n.º 18
0
def run(ctx, src):
    w, h = 1024, 512
    depth = 1024
    img = np.zeros((h, w), dtype=cltypes.float)

    time = run_kernel(
        ctx,
        src,
        (w, h),
        Mem(img),
        *[cltypes.uint(k) for k in (w, h, depth)],
    )
    """
    for row in img[::16,::16]:
        for z in row:
            print("@" if z > 0.5 else ".", end="")
        print()
    """
    print("\t{:.3f} sec: {}".format(time, os.path.split(src)[1]))

    return (img, )
Ejemplo n.º 19
0
 def run(self, src, **kws):
     n = 64
     a = np.arange(n, dtype=cltypes.int)
     b = np.zeros(n, dtype=cltypes.int)
     run_kernel(self.ctx, src, (n, ), *[Mem(x) for x in [a, b]])
     return (a, b)
Ejemplo n.º 20
0
 def run(self, src, **kws):
     b = np.zeros(self.n, dtype=cltypes.int)
     a = np.zeros(self.n, dtype=cltypes.int)
     run_kernel(self.ctx, src, (self.n,), *[Mem(x) for x in [a, b]])
     return (a, b)
Ejemplo n.º 21
0
 def run(self, src, **kws):
     buffers = [b.copy() for b in self.input]
     run_kernel(self.ctx, src, (self.n, ), *[Mem(x) for x in buffers])
     return buffers
Ejemplo n.º 22
0
    def run(self, src, **kws):
        buf = self.ibuf + [np.zeros_like(x) for x in self.obuf]

        run_kernel(self.ctx, src, (self.n, ), *[Mem(x) for x in buf])

        return buf