Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
scikit-cuda
1. scikit-cuda
A Python Interface to GPU-Powered Libraries
Lev Givon
https://www.columbia.edu/~lev
Bionet Group
Department of Electrical Engineering
Columbia University
September 24, 2015
Lev Givon scikit-cuda
2. Motivation
NVIDIA CUDA contains a (growing) range of great GPU-based
libraries (CUBLAS, CUFFT, CURAND, CUSPARSE, CUSOLVER,
NPP) in addition to the core driver and runtime libraries.
Other libraries (both commercial and free) also available:
CULA - http://www.culatools.com/
MAGMA - http://icl.cs.utk.edu/magma/
PyCUDA (http://mathema.tician.de/software/pycuda/)
enables Python programmers to take advantage of CUDA, but
provides few interfaces to the above libraries.
Lev Givon scikit-cuda
3. Package Description
Exposes contents of various GPU-based libraries via both low-level
and high-level Python functions.
Project origin: using CULA’s GPU-based SVD routines to accelerate
time decoding algorithms implemented in Python. 1
Low-level functions
wrap C functions using ctypes
(https://docs.python.org/2/library/ctypes.html);
replicate C function signatures (with a few slight differences);
catch errors and map error codes to Python exceptions.
High-level functions
provide a similar interface to functions in scipy (http://scipy.org);
use PyCUDA’s GPUArray class to encapsulate matrices/vectors in
GPU memory.
1http://www.bionet.ee.columbia.edu/publications
Lev Givon scikit-cuda
4. Example
1 import pycuda.gpuarray as gpuarray
2 import pycuda.autoinit
3 import numpy as np
4 import skcuda.linalg as linalg
5
6 linalg.init()
7 a = np.random.randn(9, 6) + 1j*np.random.randn(9, 6)
8 a = np.asarray(a, np.complex64)
9 a_gpu = gpuarray.to_gpu(a)
10 u_gpu, s_gpu, vh_gpu = linalg.svd(a_gpu, ’S’, ’S’)
11 np.allclose(a, np.dot(u_gpu.get(), np.dot(np.diag(s_gpu.get()),
12 vh_gpu.get())), 1e-4)
Lev Givon scikit-cuda
5. Available High-Level Functions
FFT/IFFT
Numerical integration (trapezoidal 1D and 2D)
Linear algebra (dot, eig, qr, svd, transpose, etc.)
Randomized linear algebra (rdmd, rsvd)
Special element-wise functions (expi, sici, etc.)
Numpy-like helper routines not provided by PyCUDA (cumsum,
zeros, etc.)
Lev Givon scikit-cuda
6. Areas for Future Improvement
Improve maintainability and coverage of exposed functions in
supported libraries by automatically generating ctypes wrappers by
parsing C header files.
Alternately, use cffi (https://bitbucket.org/cffi/cffi) to
generate wrappers.
Provide full support for functions in MAGMA (possibly combined
with a Python-based MAGMA library installer) to enable folks
without access to CULA to run GPU-based LPAPACK.
Enable selection of library backend for functions that are provided by
more than one library (e.g., CULA, MAGMA).
Less naive automated block/grid selection mechanism for functions
that require it.
Lev Givon scikit-cuda