I am trying to perform an out-of-memory Cholesky factorisation of a real positive definite matrix on a GPU from python. magma_dpotrf is a fantastic solution but I'm having trouble accessing it. This is an attempt to access it using ctypes (a derivative of an attempt to achieve something similar I found browsing for solutions online).
Code: Select all
import pycuda.driver as cuda
import pycuda.autoinit
import numpy as np
import ctypes
magma_path = '/path/to/libmagma.so'
libmagma = ctypes.cdll.LoadLibrary(magma_path)
int_pointer = lambda x: ctypes.pointer(ctypes.c_int(x))
char_pointer = lambda x: ctypes.pointer(ctypes.c_char(x))
_magma_dpotrf = libmagma.magma_spotrf_gpu
_magma_dpotrf.restype = ctypes.c_uint
_magma_dpotrf.argtypes = [ctypes.c_char_p,
ctypes.POINTER(ctypes.c_int),
ctypes.POINTER(ctypes.c_double),
ctypes.POINTER(ctypes.c_int),
ctypes.POINTER(ctypes.c_int)]
#magma_get_spotrf_nb = libmagma.magma_get_spotrf_nb
#magma_get_spotrf_nb.restype = ctypes.c_uint
#magma_get_spotrf_nb.argtypes = [ctypes.POINTER(ctypes.c_int)]
def magma_dpotrf(uplo, N, h_R, lda, info):
_magma_dpotrf(char_pointer(uplo),
int_pointer(N),
(ctypes.c_double * len(h_R))(*h_R),
int_pointer(lda),
int_pointer(info))
return info
if __name__ == '__main__':
N = 5
lda=N
# Create matrix to be factored
h_R = (np.eye(N) + np.ones((N,N))*0.5).astype('double').flatten()
libmagma.magma_init()
info = 1
# # Do Cholesky factorization
info = magma_dpotrf('L', N, h_R, lda, info)
magma_spotrf_gpu(char *uplo, int *n, float *a, int *lda,
float *work, int *info)
magma_dpotrf( opts.uplo, N, h_R, lda, &info );
Code: Select all
_magma_dpotrf(char_pointer(uplo), int_pointer(N), (ctypes.c_double * len(h_R))(*h_R), int_pointer(lda), int_pointer(info))python: constants.cpp:357: const char* lapack_uplo_const(magma_uplo_t): Assertion `magma_const <= MagmaFull' failed.
Aborted
I'm using MAGMA 1.6.2, cuda 6.5, python 2.7 and pycuda 2014.1.
Could anyone familiar with Magma and python help me with how to correct the issue(s) causing the segmentation fault?
Alternatively, I'm not wedded to ctypes for wrapping Magma (I initially tried SWIG but without success), if anyone could point me to a working example of wrapping Magma functions for Python that would also be much appreciated!
Thank you in advance,
Peter