(q, maxiter, z)
return output
Calculate z using numpy on the GPU via gpuarray
Calculate z using numpy on the GPU via gpuarray
Calculate z using numpy on the GPU via gpuarray
def calculate_z_numpy_gpu(q, maxiter, z):
    """Calculate z using numpy on the GPU via gpuarray"""
    outputg = gpuarray.to_gpu(nm.resize(nm.array(0,), q.shape).astype(nm.int32))
    zg = gpuarray.to_gpu(z.astype(nm.complex64))
    qg = gpuarray.to_gpu(q.astype(nm.complex64))
    # 2.0 as an array
    twosg = gpuarray.to_gpu(nm.array([2.0]*zg.size).astype(nm.float32))
    # 0+0j as an array
    cmplx0sg = gpuarray.to_gpu(nm.array([0+0j]*zg.size).astype(nm.complex64))
    # for abs_zg > twosg result
    comparison_result = gpuarray.to_gpu(nm.array([False]*zg.size).astype(nm.bool))
    # we'll add 1 to iterg after each iteration
    iterg = gpuarray.to_gpu(nm.array([0]*zg.size).astype(nm.int32))

    for iter in range(maxiter):
        zg = zg*zg + qg

        # abs returns a complex (rather than a float) from the complex
        # input where the real component is the absolute value (which
        # looks like a bug) so I take the .real after abs()
        abs_zg = abs(zg).real

        comparison_result = abs_zg > twosg
        qg = gpuarray.if_positive(comparison_result, cmplx0sg, qg)
        zg = gpuarray.if_positive(comparison_result, cmplx0sg, zg)
        outputg = gpuarray.if_positive(comparison_result, iterg, outputg)
        iterg = iterg + 1
    output = outputg.get()
    return output
def calculate_z_numpy_gpu ( q , maxiter , z ) : outputg = gpuarray . to_gpu ( nm . resize ( nm . array ( 0 , ) , q . shape ) . astype ( nm . int32 ) ) zg = gpuarray . to_gpu ( z . astype ( nm . complex64 ) ) qg = gpuarray . to_gpu ( q . astype ( nm . complex64 ) ) # 2.0 as an array twosg = gpuarray . to_gpu ( nm . array ( [ 2.0 ] * zg . size ) . astype ( nm . float32 ) ) # 0+0j as an array cmplx0sg = gpuarray . to_gpu ( nm . array ( [ 0 + 0j ] * zg . size ) . astype ( nm . complex64 ) ) # for abs_zg > twosg result comparison_result = gpuarray . to_gpu ( nm . array ( [ False ] * zg . size ) . astype ( nm . bool ) ) # we'll add 1 to iterg after each iteration iterg = gpuarray . to_gpu ( nm . array ( [ 0 ] * zg . size ) . astype ( nm . int32 ) ) for iter in range ( maxiter ) : zg = zg * zg + qg # abs returns a complex (rather than a float) from the complex # input where the real component is the absolute value (which # looks like a bug) so I take the .real after abs() abs_zg = abs ( zg ) . real comparison_result = abs_zg > twosg qg = gpuarray . if_positive ( comparison_result , cmplx0sg , qg ) zg = gpuarray . if_positive ( comparison_result , cmplx0sg , zg ) outputg = gpuarray . if_positive ( comparison_result , iterg , outputg ) iterg = iterg + 1 output = outputg . get ( ) return output