Ejemplo n.º 1
0
def main():

    N = 1e+8 // 2
    print 'Data size', N

    targets = ['cpu', 'stream', 'parallel']

    # run just one target if is specified in the argument
    for t in targets:
        if t in sys.argv[1:]:
            targets = [t]
            break

    for target in targets:
        print '== Target', target
        vect_discriminant = vectorize(
            [f4(f4, f4, f4), f8(f8, f8, f8)], target=target)(discriminant)

        A, B, C = generate_input(N, dtype=np.float32)
        D = np.empty(A.shape, dtype=A.dtype)

        ts = time()
        D = vect_discriminant(A, B, C)
        te = time()

        total_time = (te - ts)

        print 'Execution time %.4f' % total_time
        print 'Throughput %.4f' % (N / total_time)

        if '-verify' in sys.argv[1:]:
            check_answer(D, A, B, C)
Ejemplo n.º 2
0
def main():
    targets = ['cpu', 'stream', 'parallel']
    
    # run just one target if is specified in the argument
    for t in targets:
        if t in sys.argv[1:]:
            targets = [t]
            break

    for target in targets:
        print '== Target', target
        vect_sum = vectorize([f4(f4, f4), f8(f8, f8)],
                             target=target)(sum)

        A = np.random.random(N).astype(np.float32)
        B = np.random.random(N).astype(np.float32)
        assert A.shape == B.shape
        assert A.dtype ==  B.dtype
        assert len(A.shape) == 1

        D = np.empty(A.shape, dtype=A.dtype)

        print 'Data size', N

        ts = time()
        D = vect_sum(A, B)
        te = time()

        total_time = (te - ts)

        print 'Execution time %.4f' % total_time
        print 'Throughput %.4f' % (N / total_time)

        if '-verify' in sys.argv[1:]:
            assert np.allclose
Ejemplo n.º 3
0
def main():

    N = 1e+8 // 2
    print 'Data size', N

    targets = ['cpu', 'stream', 'parallel']
    
    # run just one target if is specified in the argument
    for t in targets:
        if t in sys.argv[1:]:
            targets = [t]
            break

    for target in targets:
        print '== Target', target
        vect_discriminant = vectorize([f4(f4, f4, f4), f8(f8, f8, f8)],
                                    target=target)(discriminant)

        A, B, C = generate_input(N, dtype=np.float32)
        D = np.empty(A.shape, dtype=A.dtype)

        ts = time()
        D = vect_discriminant(A, B, C)
        te = time()

        total_time = (te - ts)

        print 'Execution time %.4f' % total_time
        print 'Throughput %.4f' % (N / total_time)



        if '-verify' in sys.argv[1:]:
            check_answer(D, A, B, C)
Ejemplo n.º 4
0
def run_target(N, target):
    print '== Target', target
    vect_discriminant = vectorize([f4(f4, f4, f4), f8(f8, f8, f8)],
                                target=target)(discriminant)

    A, B, C = generate_input(N, dtype=np.float32)
    D = np.empty(A.shape, dtype=A.dtype)

    ts = time()
    D = vect_discriminant(A, B, C)
    te = time()

    total_time = (te - ts)

    print 'Execution time %.4f' % total_time
    print 'Throughput %.4f' % (N / total_time)

    if '-verify' in sys.argv[1:]:
        check_answer(D, A, B, C)
Ejemplo n.º 5
0
def main():
    cu_discriminant = vectorize([f4(f4, f4, f4), f8(f8, f8, f8)],
                                target='gpu')(poly.discriminant)

    N = 1e+8 // 2

    print 'Data size', N
    
    A, B, C = poly.generate_input(N, dtype=np.float32)
    D = np.empty(A.shape, dtype=A.dtype)

    stream = cuda.stream()

    print '== One'

    ts = time()

    with stream.auto_synchronize():
        dA = cuda.to_device(A, stream)
        dB = cuda.to_device(B, stream)
        dC = cuda.to_device(C, stream)
        dD = cuda.to_device(D, stream, copy=False)
        cu_discriminant(dA, dB, dC, out=dD, stream=stream)
        dD.to_host(stream)

    te = time()
    

    total_time = (te - ts)

    print 'Execution time %.4f' % total_time
    print 'Throughput %.2f' % (N / total_time)

    print '== Chunked'

    chunksize = 1e+7
    chunkcount = N // chunksize

    print 'Chunk size', chunksize

    sA = np.split(A, chunkcount)
    sB = np.split(B, chunkcount)
    sC = np.split(C, chunkcount)
    sD = np.split(D, chunkcount)

    device_ptrs = []

    ts = time()

    with stream.auto_synchronize():
        for a, b, c, d in zip(sA, sB, sC, sD):
            dA = cuda.to_device(a, stream)
            dB = cuda.to_device(b, stream)
            dC = cuda.to_device(c, stream)
            dD = cuda.to_device(d, stream, copy=False)
            cu_discriminant(dA, dB, dC, out=dD, stream=stream)
            dD.to_host(stream)
            device_ptrs.extend([dA, dB, dC, dD])

    te = time()

    total_time = (te - ts)

    print 'Execution time %.4f' % total_time
    print 'Throughput %.2f' % (N / total_time)


    if '-verify' in sys.argv[1:]:
        poly.check_answer(D, A, B, C)
Ejemplo n.º 6
0
def main():
    cu_discriminant = vectorize(
        [f4(f4, f4, f4), f8(f8, f8, f8)], target='gpu')(poly.discriminant)

    N = 1e+8 // 2

    print 'Data size', N

    A, B, C = poly.generate_input(N, dtype=np.float32)
    D = np.empty(A.shape, dtype=A.dtype)

    stream = cuda.stream()

    print '== One'

    ts = time()

    with stream.auto_synchronize():
        dA = cuda.to_device(A, stream)
        dB = cuda.to_device(B, stream)
        dC = cuda.to_device(C, stream)
        dD = cuda.to_device(D, stream, copy=False)
        cu_discriminant(dA, dB, dC, out=dD, stream=stream)
        dD.to_host(stream)

    te = time()

    total_time = (te - ts)

    print 'Execution time %.4f' % total_time
    print 'Throughput %.2f' % (N / total_time)

    print '== Chunked'

    chunksize = 1e+7
    chunkcount = N // chunksize

    print 'Chunk size', chunksize

    sA = np.split(A, chunkcount)
    sB = np.split(B, chunkcount)
    sC = np.split(C, chunkcount)
    sD = np.split(D, chunkcount)

    device_ptrs = []

    ts = time()

    with stream.auto_synchronize():
        for a, b, c, d in zip(sA, sB, sC, sD):
            dA = cuda.to_device(a, stream)
            dB = cuda.to_device(b, stream)
            dC = cuda.to_device(c, stream)
            dD = cuda.to_device(d, stream, copy=False)
            cu_discriminant(dA, dB, dC, out=dD, stream=stream)
            dD.to_host(stream)
            device_ptrs.extend([dA, dB, dC, dD])

    te = time()

    total_time = (te - ts)

    print 'Execution time %.4f' % total_time
    print 'Throughput %.2f' % (N / total_time)

    if '-verify' in sys.argv[1:]:
        poly.check_answer(D, A, B, C)