Example #1
0
def chunkwise_kernel():
    ast, env = compile(source)

    #Array = ca.carray(xrange(25000), rootdir='example1', mode='w',
                #dtype='int32', cparams=ca.cparams(clevel=0))
    Array = open('example1', mode='w')
    c = Array.data.ca
    ctx = Context(env)

    for i in range(c.nchunks):
        chunk = c.chunks[i]
        # read only access
        #x = c.chunks[0][:]
        # write access
        x = view(chunk)

        size = x.strides[0]
        args = (x, size)
        execute(ctx, args, fname='main')

        # this does a _save() behind the scenes
        c.chunks[i] = chunk

    ctx.destroy()

    rts = Runtime(1,2,3)
    rts.join()

    print Array
Example #2
0
def test_cgen2_add():
    with namesupply():

        krn = ElementwiseKernel(
            [
                (IN  , VectorArg((300,), 'array[int]')),
                (IN  , VectorArg((300,), 'array[int]')),
                (OUT , VectorArg((300,), 'array[int]')),
            ],
            '_out0[i0] = _in0[i0] + _in1[i0]',
        )

        krn.verify()
        ast, env = krn.compile()

        ctx = Context(env)

        a = np.array(xrange(300), dtype='int32')
        b = np.array(xrange(300), dtype='int32')
        c = np.empty_like(b)

        execute(ctx, args=(a,b,c), fname='kernel0', timing=False)
        assert np.allclose(c, a + b)
Example #3
0
    var int j;
    for i in range(n) {
        for j in range(n) {
            x[i,j] = i+j;
        }
    }
}
"""

N = 15
ast, env = compile(source)

arr = np.eye(N, dtype='int32')
args = (arr, N)

ctx = Context(env)
execute(ctx, args, timing=True)
ctx.destroy()

print arr

#------------------------------------------------------------------------
# Vector Dot Product
#------------------------------------------------------------------------

N = 50000
A = np.arange(N, dtype='double')
B = np.arange(N, dtype='double')

source = open('samples/blir/dot.bl')
ast, env = compile(source.read())
Example #4
0
    var int j;
    for i in range(n) {
        for j in range(n) {
            x[i,j] = i+j;
        }
    }
}
"""

N = 15
ast, env = compile(source)

arr = np.eye(N, dtype='int32')
args = (arr, N)

ctx = Context(env)
execute(ctx, args, timing=True)
ctx.destroy()

print arr

#------------------------------------------------------------------------
# Vector Dot Product
#------------------------------------------------------------------------

N = 50000
A = np.arange(N, dtype='double')
B = np.arange(N, dtype='double')

source = open('samples/blir/dot.bl')
ast, env = compile(source.read())