src/hmmmr/batched_functions.py
def massive_inverse_pycuda(handle, As_gpu):
    """
    Uses LU factorization and pycublas batched subroutines to calculate matrix inversions
    :param handle: Cublas handle
    :param As_gpu: Xs matrices in numpy
    :return: {
        'Xinvs_ptr': Pointer to array of inverses
        'Xinvs_gpu': Xinvs array in GPUs
        'return_codes': Array with return codes of the inverse results of each matrix
    }
    """
    # print "Starting pycuda inversion"
    n = As_gpu.shape[1] # Matrices should be nxn, number of cols
    batchSize = As_gpu.shape[0] # Number of matriecs
    # start = default_timer()
    # print "Total time to create cublas handler was {}s".format(default_timer()-start)
    # start = default_timer()
    Xs_ptr = bptrs(As_gpu)  # This is the only one that needs to be passed as the pointes
    info_rf = pycuda.gpuarray.zeros(batchSize, np.int32)  # Will contain the return code for each matrx LU factorization
    Ps_gpu = pycuda.gpuarray.empty((batchSize, n), np.int32)  # Stores the pivots from LU factorization
    Xinvs_gpu = pycuda.gpuarray.empty_like(As_gpu)  # Storage for inverted matrices
    Xinvs_ptr = bptrs(Xinvs_gpu)
    #  print "Total time to copy Xs/Create, Ps, Xinvs_gpu, and info arrrays to cpu was {} s".format(default_timer()-start)
    # start = default_timer()
    (getrf, getri) = get_batched_inverse_functions(As_gpu)
    getrf(handle, n, Xs_ptr.gpudata, n, Ps_gpu.gpudata, info_rf.gpudata, batchSize) # LU Factorization
    # print "Total time for LU factorization {}s. \n" \
    #       "Got this returns codes for LU factorization {}".format(default_timer()-start, info.get())
    # start = default_timer()
    # use factorization to perform inversion
    info_ri = pycuda.gpuarray.zeros(batchSize, np.int32)
    getri(handle, n, Xs_ptr.gpudata, n, Ps_gpu.gpudata, Xinvs_ptr.gpudata,
                               n, info_ri.gpudata, batchSize)
    # print "Total time was getRi: {}s \n " \
    #      "Got this returns codes for getRi batched {}".format(default_timer()-start, info.get())\
    # I will sum return codes in order to know which code results were > 0 for any of the cases
    resumed_info = vector_addition_pycuda(info_ri, info_rf, overwriteAs=False, handle=handle)
    return {
        'Xinvs_ptr': Xinvs_ptr,
        'Xinvs_gpu': Xinvs_gpu,
        'return_codes': resumed_info
    }

    Uses LU factorization and pycublas batched subroutines to calculate matrix inversions
    :param handle: Cublas handle
    :param As_gpu: Xs matrices in numpy
    :return: {
        'Xinvs_ptr': Pointer to array of inverses
        'Xinvs_gpu': Xinvs array in GPUs
        'return_codes': Array with return codes of the inverse results of each matrix
    }
    
Uses LU factorization and pycublas batched subroutines to calculate matrix inversions
Uses LU factorization and pycublas batched subroutines to calculate matrix inversions
def massive_inverse_pycuda(handle, As_gpu):
    n = As_gpu.shape[1] 
    batchSize = As_gpu.shape[0] 
    Xs_ptr = bptrs(As_gpu)  
    info_rf = pycuda.gpuarray.zeros(batchSize, np.int32)  
    Ps_gpu = pycuda.gpuarray.empty((batchSize, n), np.int32)  
    Xinvs_gpu = pycuda.gpuarray.empty_like(As_gpu)  
    Xinvs_ptr = bptrs(Xinvs_gpu)
    (getrf, getri) = get_batched_inverse_functions(As_gpu)
    getrf(handle, n, Xs_ptr.gpudata, n, Ps_gpu.gpudata, info_rf.gpudata, batchSize) 
    info_ri = pycuda.gpuarray.zeros(batchSize, np.int32)
    getri(handle, n, Xs_ptr.gpudata, n, Ps_gpu.gpudata, Xinvs_ptr.gpudata,
                               n, info_ri.gpudata, batchSize)
    resumed_info = vector_addition_pycuda(info_ri, info_rf, overwriteAs=False, handle=handle)
    return {
        'Xinvs_ptr': Xinvs_ptr,
        'Xinvs_gpu': Xinvs_gpu,
        'return_codes': resumed_info
    }
def massive_inverse_pycuda ( handle , As_gpu ) : n = As_gpu . shape [ 1 ] batchSize = As_gpu . shape [ 0 ] Xs_ptr = bptrs ( As_gpu ) info_rf = pycuda . gpuarray . zeros ( batchSize , np . int32 ) Ps_gpu = pycuda . gpuarray . empty ( ( batchSize , n ) , np . int32 ) Xinvs_gpu = pycuda . gpuarray . empty_like ( As_gpu ) Xinvs_ptr = bptrs ( Xinvs_gpu ) ( getrf , getri ) = get_batched_inverse_functions ( As_gpu ) getrf ( handle , n , Xs_ptr . gpudata , n , Ps_gpu . gpudata , info_rf . gpudata , batchSize ) info_ri = pycuda . gpuarray . zeros ( batchSize , np . int32 ) getri ( handle , n , Xs_ptr . gpudata , n , Ps_gpu . gpudata , Xinvs_ptr . gpudata , n , info_ri . gpudata , batchSize ) resumed_info = vector_addition_pycuda ( info_ri , info_rf , overwriteAs = False , handle = handle ) return { 'Xinvs_ptr' : Xinvs_ptr , 'Xinvs_gpu' : Xinvs_gpu , 'return_codes' : resumed_info }
Uses LU factorization and pycublas batched subroutines to calculate matrix inversions
Uses LU factorization and pycublas batched subroutines to calculate matrix inversions
"""
    Uses LU factorization and pycublas batched subroutines to calculate matrix inversions
    :param handle: Cublas handle
    :param As_gpu: Xs matrices in numpy
    :return: {
        'Xinvs_ptr': Pointer to array of inverses
        'Xinvs_gpu': Xinvs array in GPUs
        'return_codes': Array with return codes of the inverse results of each matrix
    }
    """ # print "Starting pycuda inversion" # Matrices should be nxn, number of cols # Number of matriecs # start = default_timer() # print "Total time to create cublas handler was {}s".format(default_timer()-start) # start = default_timer() # This is the only one that needs to be passed as the pointes # Will contain the return code for each matrx LU factorization # Stores the pivots from LU factorization # Storage for inverted matrices #  print "Total time to copy Xs/Create, Ps, Xinvs_gpu, and info arrrays to cpu was {} s".format(default_timer()-start) # start = default_timer() # LU Factorization # print "Total time for LU factorization {}s. \n" \ #       "Got this returns codes for LU factorization {}".format(default_timer()-start, info.get()) # start = default_timer() # use factorization to perform inversion # print "Total time was getRi: {}s \n " \ #      "Got this returns codes for getRi batched {}".format(default_timer()-start, info.get())\ # I will sum return codes in order to know which code results were > 0 for any of the cases
{
'Xinvs_ptr': Pointer to array of inverses
'Xinvs_gpu': Xinvs array in GPUs
'return_codes': Array with return codes of the inverse results of each matrix
}
{ ' Xinvs_ptr ' : Pointer to array of inverses ' Xinvs_gpu ' : Xinvs array in GPUs ' return_codes ' : Array with return codes of the inverse results of each matrix }
handle
None
As_gpu
Xs matrices in numpy
Xs matrices in numpy