How to use accelerate - 8 common examples

To help you get started, we’ve selected a few accelerate examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github diku-dk / futhark-benchmarks / accelerate / fluid / fluid-gui.py View on Github external
def react(self):
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                raise FluidQuit()
            elif event.type == pygame.MOUSEBUTTONDOWN:
                if pygame.mouse.get_pressed()[0]:
                    self.making_forces = True
                    self.making_densities = False
                elif pygame.mouse.get_pressed()[2]:
                    self.making_densities = True
                    self.making_forces = False
            elif event.type == pygame.MOUSEBUTTONUP:
                self.making_forces = False
                self.making_densities = False
            elif event.type == pygame.KEYDOWN:
                if event.key == pygame.K_c:
                    self.clear()
                if event.key == pygame.K_q:
                    self.diffusion_rate += 0.00001
                if event.key == pygame.K_a:
github diku-dk / futhark-benchmarks / accelerate / fluid / fluid-gui.py View on Github external
def run(self):
        self.clear()
        self.futhark = futhark_object()

        pygame.init()
        pygame.display.set_caption('Fluid Simulation GUI!')
        size = (self.grid_resolution, self.grid_resolution)
        self.screen = pygame.display.set_mode(size)
        self.surface = pygame.Surface(size)
        self.font = pygame.font.Font(None, 26)

        try:
            self.loop()
        except FluidQuit:
            return
github scivision / python-performance / matmul / matmul_pycuda.py View on Github external
p.add_argument('Nrun', nargs='?', default=10, type=int)
    p = p.parse_args()

    N = p.N
    Nrun = p.Nrun

    test_pycuda()  # not necessary, just FYI

    A = np.asfortranarray(rand(N, N).astype(np.float32))
    B = np.asfortranarray(rand(N, N).astype(np.float32))
    D = np.asfortranarray(np.zeros_like(A, order='F'))

    s = timer()
    dA = cuda.cuda.to_device(A)             # alloc and copy input data
    dB = cuda.cuda.to_device(B)
    dD = cuda.cuda.to_device(D, copy=False)  # alloc only
    print(timer() - s)
    # NumPy
    numpy_time = 1000000
    for _ in range(Nrun):
        start = timer()
        E = A.dot(B)
        T = timer() - start
        if T < numpy_time:
            numpy_time = T
    print("Numpy  took %f seconds" % numpy_time)

    gemm(dA, dB, dD)
github scivision / python-performance / matmul / matmul_pycuda.py View on Github external
p = ArgumentParser(description='Matmul benchmark')
    p.add_argument('N', nargs='?', default=1000, type=int)
    p.add_argument('Nrun', nargs='?', default=10, type=int)
    p = p.parse_args()

    N = p.N
    Nrun = p.Nrun

    test_pycuda()  # not necessary, just FYI

    A = np.asfortranarray(rand(N, N).astype(np.float32))
    B = np.asfortranarray(rand(N, N).astype(np.float32))
    D = np.asfortranarray(np.zeros_like(A, order='F'))

    s = timer()
    dA = cuda.cuda.to_device(A)             # alloc and copy input data
    dB = cuda.cuda.to_device(B)
    dD = cuda.cuda.to_device(D, copy=False)  # alloc only
    print(timer() - s)
    # NumPy
    numpy_time = 1000000
    for _ in range(Nrun):
        start = timer()
        E = A.dot(B)
        T = timer() - start
        if T < numpy_time:
            numpy_time = T
    print("Numpy  took %f seconds" % numpy_time)

    gemm(dA, dB, dD)
github scivision / python-performance / matmul / matmul_pycuda.py View on Github external
p.add_argument('N', nargs='?', default=1000, type=int)
    p.add_argument('Nrun', nargs='?', default=10, type=int)
    p = p.parse_args()

    N = p.N
    Nrun = p.Nrun

    test_pycuda()  # not necessary, just FYI

    A = np.asfortranarray(rand(N, N).astype(np.float32))
    B = np.asfortranarray(rand(N, N).astype(np.float32))
    D = np.asfortranarray(np.zeros_like(A, order='F'))

    s = timer()
    dA = cuda.cuda.to_device(A)             # alloc and copy input data
    dB = cuda.cuda.to_device(B)
    dD = cuda.cuda.to_device(D, copy=False)  # alloc only
    print(timer() - s)
    # NumPy
    numpy_time = 1000000
    for _ in range(Nrun):
        start = timer()
        E = A.dot(B)
        T = timer() - start
        if T < numpy_time:
            numpy_time = T
    print("Numpy  took %f seconds" % numpy_time)

    gemm(dA, dB, dD)
github scivision / python-performance / matmul / matmul_pycuda.py View on Github external
def gemm(A, B, dD):
    N = A.shape[0]  # square matrices
    '''
    Note that all arrays are in Fortran order.
    '''

    # cuBLAS
    blas = Blas()

    start = timer()
    blas.gemm('N', 'N', N, N, N, 1.0, A, B, 1.0, dD)
    cuda_time = timer() - start

    D = dD.copy_to_host()
    print("CUBLAS took %f seconds" % cuda_time)
    diff = np.abs(D - E)
    print("Maximum error %f" % np.max(diff))
    return D
github fbpic / fbpic / fbpic / particles / cuda_methods.py View on Github external
"""
    Sort the cell index of the particles and
    modify the sorted index array accordingly.

    Parameters
    ----------
    cell_idx : 1darray of integers
        The cell index of the particle

    sorted_idx : 1darray of integers
        Represents the original index of the
        particle before the sorting.
    """
    Ntot = cell_idx.shape[0]
    if Ntot > 0:
        sorter = sorting.RadixSort(Ntot, dtype = np.int32)
        sorter.sort(cell_idx, vals = sorted_idx)
github diku-dk / futhark-benchmarks / accelerate / fluid / fluid-gui.py View on Github external
def main(args):
    try:
        grid_resolution = int(args[0])
    except IndexError:
        print('Usage: ./fluid-gui.py GRID_RESOLUTION')
        print()
        print('Add particles with right click.')
        print('Add forces with left click.')
        print('Press C to clear all particles and forces.')
        print('Press Q/A and W/S to modify diffusion rate and viscosity.')
        print()
        print('Example: Create a 256x256 fluid simulation.')
        print('  ./fluid-gui.py 256')
        return 1
    f = FluidGUI(grid_resolution=grid_resolution)
    f.run()
    return 0

accelerate

Accelerate

Apache-2.0
Latest version published 10 days ago

Package Health Score

100 / 100
Full package analysis