提交 eaea1f87 authored 作者: Alexander Matyasko's avatar Alexander Matyasko

Add magma base class which add all the necessary headers/libs

上级 96ed9259
...@@ -353,6 +353,29 @@ def gpu_cholesky(A, lower=True): ...@@ -353,6 +353,29 @@ def gpu_cholesky(A, lower=True):
return GpuCholesky(lower)(A) return GpuCholesky(lower)(A)
class GpuMagmaBase(COp):
"""Base class for magma related operations. Add the necessary headers,
libraries and optionally the location of headers and library.
"""
def c_headers(self):
return ['gpuarray/types.h', 'gpuarray/array.h', 'gpuarray/ext_cuda.h',
'gpuarray_helper.h', 'magma.h']
def c_header_dirs(self):
dirs = [os.path.dirname(__file__), pygpu.get_include()]
if config.magma.include_path:
dirs.append(config.magma.include_path)
return dirs
def c_libraries(self):
return ['magma']
def c_lib_dirs(self):
if config.magma.library_path:
return [config.magma.library_path]
return []
class GpuMagmaSVD(COp): class GpuMagmaSVD(COp):
"""Computes the svd of a matrix :math:`A` using magma library. """Computes the svd of a matrix :math:`A` using magma library.
...@@ -374,24 +397,6 @@ class GpuMagmaSVD(COp): ...@@ -374,24 +397,6 @@ class GpuMagmaSVD(COp):
self.compute_uv = compute_uv self.compute_uv = compute_uv
COp.__init__(self, ['magma_svd.c'], 'APPLY_SPECIFIC(magma_svd)') COp.__init__(self, ['magma_svd.c'], 'APPLY_SPECIFIC(magma_svd)')
def c_headers(self):
return ['gpuarray/types.h', 'gpuarray/array.h', 'gpuarray/ext_cuda.h',
'gpuarray_helper.h', 'magma.h']
def c_header_dirs(self):
dirs = [os.path.dirname(__file__), pygpu.get_include()]
if config.magma.include_path:
dirs.append(config.magma.include_path)
return dirs
def c_libraries(self):
return ['magma']
def c_lib_dirs(self):
if config.magma.library_path:
return [config.magma.library_path]
return []
def make_node(self, A): def make_node(self, A):
ctx_name = infer_context_name(A) ctx_name = infer_context_name(A)
A = as_gpuarray_variable(A, ctx_name) A = as_gpuarray_variable(A, ctx_name)
...@@ -463,7 +468,7 @@ def gpu_svd(a, full_matrices=1, compute_uv=1): ...@@ -463,7 +468,7 @@ def gpu_svd(a, full_matrices=1, compute_uv=1):
return out return out
class GpuMagmaMatrixInverse(COp): class GpuMagmaMatrixInverse(GpuMagmaBase):
"""Computes the inverse of a matrix :math:`A` using magma library. """Computes the inverse of a matrix :math:`A` using magma library.
""" """
__props__ = ('inplace', ) __props__ = ('inplace', )
...@@ -476,24 +481,6 @@ class GpuMagmaMatrixInverse(COp): ...@@ -476,24 +481,6 @@ class GpuMagmaMatrixInverse(COp):
if self.inplace: if self.inplace:
self.destroy_map = {0: [0]} self.destroy_map = {0: [0]}
def c_headers(self):
return ['gpuarray/types.h', 'gpuarray/array.h', 'gpuarray/ext_cuda.h',
'gpuarray_helper.h', 'magma.h']
def c_header_dirs(self):
dirs = [os.path.dirname(__file__), pygpu.get_include()]
if config.magma.include_path:
dirs.append(config.magma.include_path)
return dirs
def c_libraries(self):
return ['magma']
def c_lib_dirs(self):
if config.magma.library_path:
return [config.magma.library_path]
return []
def clone_inplace(self): def clone_inplace(self):
return self.__class__(inplace=True) return self.__class__(inplace=True)
...@@ -524,12 +511,11 @@ def gpu_matrix_inverse(a): ...@@ -524,12 +511,11 @@ def gpu_matrix_inverse(a):
return GpuMagmaMatrixInverse()(a) return GpuMagmaMatrixInverse()(a)
class GpuMagmaCholesky(CGpuKernelBase): class GpuMagmaCholesky(GpuMagmaBase, CGpuKernelBase):
"""Computes the cholesky decomposition of a matrix :math:`A` using magma """Computes the cholesky decomposition of a matrix :math:`A` using magma
library. library.
""" """
params_type = gpu_context_type
__props__ = ('lower', 'inplace') __props__ = ('lower', 'inplace')
def __init__(self, lower=True, inplace=False): def __init__(self, lower=True, inplace=False):
...@@ -539,24 +525,6 @@ class GpuMagmaCholesky(CGpuKernelBase): ...@@ -539,24 +525,6 @@ class GpuMagmaCholesky(CGpuKernelBase):
if self.inplace: if self.inplace:
self.destroy_map = {0: [0]} self.destroy_map = {0: [0]}
def c_headers(self):
return ['gpuarray/types.h', 'gpuarray/array.h', 'gpuarray/ext_cuda.h',
'gpuarray_helper.h', 'magma.h']
def c_header_dirs(self):
dirs = [os.path.dirname(__file__), pygpu.get_include()]
if config.magma.include_path:
dirs.append(config.magma.include_path)
return dirs
def c_libraries(self):
return ['magma']
def c_lib_dirs(self):
if config.magma.library_path:
return [config.magma.library_path]
return []
def clone_inplace(self): def clone_inplace(self):
return self.__class__(lower=self.lower, inplace=True) return self.__class__(lower=self.lower, inplace=True)
...@@ -568,9 +536,6 @@ class GpuMagmaCholesky(CGpuKernelBase): ...@@ -568,9 +536,6 @@ class GpuMagmaCholesky(CGpuKernelBase):
raise LinAlgError("Matrix rank error") raise LinAlgError("Matrix rank error")
return theano.Apply(self, [A], [A.type()]) return theano.Apply(self, [A], [A.type()])
def get_params(self, node):
return node.inputs[0].type.context
def get_op_params(self): def get_op_params(self):
params = [] params = []
if self.lower: if self.lower:
...@@ -583,7 +548,7 @@ class GpuMagmaCholesky(CGpuKernelBase): ...@@ -583,7 +548,7 @@ class GpuMagmaCholesky(CGpuKernelBase):
return [shapes[0]] return [shapes[0]]
class GpuMagmaQR(CGpuKernelBase): class GpuMagmaQR(GpuMagmaBase, CGpuKernelBase):
"""Computes the qr decomposition of a matrix :math:`A` using magma """Computes the qr decomposition of a matrix :math:`A` using magma
library. library.
...@@ -592,31 +557,12 @@ class GpuMagmaQR(CGpuKernelBase): ...@@ -592,31 +557,12 @@ class GpuMagmaQR(CGpuKernelBase):
complete : If `False`, returns only r. complete : If `False`, returns only r.
""" """
params_type = gpu_context_type
__props__ = ('complete', ) __props__ = ('complete', )
def __init__(self, complete=True): def __init__(self, complete=True):
self.complete = complete self.complete = complete
COp.__init__(self, ['magma_qr.c'], 'APPLY_SPECIFIC(magma_qr)') COp.__init__(self, ['magma_qr.c'], 'APPLY_SPECIFIC(magma_qr)')
def c_headers(self):
return ['gpuarray/types.h', 'gpuarray/array.h', 'gpuarray/ext_cuda.h',
'gpuarray_helper.h', 'magma.h']
def c_header_dirs(self):
dirs = [os.path.dirname(__file__), pygpu.get_include()]
if config.magma.include_path:
dirs.append(config.magma.include_path)
return dirs
def c_libraries(self):
return ['magma']
def c_lib_dirs(self):
if config.magma.library_path:
return [config.magma.library_path]
return []
def make_node(self, A): def make_node(self, A):
ctx_name = infer_context_name(A) ctx_name = infer_context_name(A)
A = as_gpuarray_variable(A, ctx_name) A = as_gpuarray_variable(A, ctx_name)
...@@ -628,9 +574,6 @@ class GpuMagmaQR(CGpuKernelBase): ...@@ -628,9 +574,6 @@ class GpuMagmaQR(CGpuKernelBase):
else: else:
return theano.Apply(self, [A], [A.type()]) return theano.Apply(self, [A], [A.type()])
def get_params(self, node):
return node.inputs[0].type.context
def get_op_params(self): def get_op_params(self):
params = [] params = []
if self.complete: if self.complete:
...@@ -638,7 +581,7 @@ class GpuMagmaQR(CGpuKernelBase): ...@@ -638,7 +581,7 @@ class GpuMagmaQR(CGpuKernelBase):
return params return params
class GpuMagmaEigh(COp): class GpuMagmaEigh(GpuMagmaBase):
"""Computes the eigen decomposition of a symmetric matrix :math:`A` using magma """Computes the eigen decomposition of a symmetric matrix :math:`A` using magma
library. library.
...@@ -650,7 +593,6 @@ class GpuMagmaEigh(COp): ...@@ -650,7 +593,6 @@ class GpuMagmaEigh(COp):
default). If `False`, computes only eigenvalues of matrix. default). If `False`, computes only eigenvalues of matrix.
""" """
__props__ = ('lower', ) __props__ = ('lower', )
params_type = gpu_context_type
def __init__(self, UPLO='L', compute_v=True): def __init__(self, UPLO='L', compute_v=True):
assert UPLO in ['L', 'U'] assert UPLO in ['L', 'U']
...@@ -658,24 +600,6 @@ class GpuMagmaEigh(COp): ...@@ -658,24 +600,6 @@ class GpuMagmaEigh(COp):
self.compute_v = compute_v self.compute_v = compute_v
COp.__init__(self, ['magma_eigh.c'], 'APPLY_SPECIFIC(magma_eigh)') COp.__init__(self, ['magma_eigh.c'], 'APPLY_SPECIFIC(magma_eigh)')
def c_headers(self):
return ['gpuarray/types.h', 'gpuarray/array.h', 'gpuarray/ext_cuda.h',
'gpuarray_helper.h', 'magma.h']
def c_header_dirs(self):
dirs = [os.path.dirname(__file__), pygpu.get_include()]
if config.magma.include_path:
dirs.append(config.magma.include_path)
return dirs
def c_libraries(self):
return ['magma']
def c_lib_dirs(self):
if config.magma.library_path:
return [config.magma.library_path]
return []
def make_node(self, A): def make_node(self, A):
ctx_name = infer_context_name(A) ctx_name = infer_context_name(A)
A = as_gpuarray_variable(A, ctx_name) A = as_gpuarray_variable(A, ctx_name)
...@@ -691,9 +615,6 @@ class GpuMagmaEigh(COp): ...@@ -691,9 +615,6 @@ class GpuMagmaEigh(COp):
[GpuArrayType(A.dtype, broadcastable=[False], [GpuArrayType(A.dtype, broadcastable=[False],
context_name=ctx_name)()]) context_name=ctx_name)()])
def get_params(self, node):
return node.inputs[0].type.context
def get_op_params(self): def get_op_params(self):
params = [] params = []
if self.lower: if self.lower:
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论