Using the CUDA Libraries with Scikit-CUDA

In this chapter, we will be taking a tour of three of the standard CUDA libraries intended for streamlined numerical and scientific computation. The first that we will look at is cuBLAS, which is NVIDIA's implementation of the Basic Linear Algebra Subprograms (BLAS) specification for CUDA. (cuBLAS is NVIDIA's answer to various optimized, CPU-based implementations of BLAS, such as the free/open source OpenBLAS or Intel's proprietary Math Kernel Library.) The next library that we will look at is cuFFT, which can perform virtually every variation of the fast Fourier transform (FFT) on the GPU. We'll look at how we can use cuFFT for filtering in image processing in particular. We will then look at cuSolver, which can perform more involved linear algebra operations than those featured in cuBLAS, such as singular value decomposition (SVD) or Cholesky factorization.

So far, we have been primarily dealing with one single Python module that acted as our gateway to CUDA—PyCUDA. While PyCUDA is a very powerful and versatile Python library, its main purpose is to provide a gateway to program, compile, and launch CUDA kernels, rather than provide an interface to the CUDA libraries. To this end, fortunately, there is a free Python module available that provides a user-friendly wrapper interface to these libraries. This is called Scikit-CUDA.

While you don't have to know PyCUDA or even understand GPU programming to appreciate Scikit-CUDA, it is conveniently compatible with PyCUDA; Scikit-CUDA, for instance, can operate easily with PyCUDA's gpuarray class, and this allows you to easily pass data between our own CUDA kernel routines and Scikit-CUDA. Additionally, most routines will also work with PyCUDA's stream class, which will allow us to properly synchronize our own custom CUDA kernels with Scikit-CUDA's wrappers.

Please note that, besides these three listed libraries, Scikit-CUDA also provides wrappers for the proprietary CULA library, as well as for the open source MAGMA library. Both have a lot of overlap with the functionality provided by the official NVIDIA libraries. Since these libraries are not installed by default with a standard CUDA installation, we will opt to not cover them in this chapter. Interested readers can learn more about CULA and MAGMA at http://www.culatools.com and http://icl.utk.edu/magma/, respectively. 
It is suggested that readers take a look at the official documentation for Scikit-CUDA, which is available here: https://media.readthedocs.org/pdf/scikit-cuda/latest/scikit-cuda.pdf.

The learning outcomes for this chapter are as follows:

  • To learn how to install Scikit-CUDA
  • To understand the basic purposes and differences between the standard CUDA libraries
  • To learn how to use low-level cuBLAS functions for basic linear algebra
  • To learn how to use the SGEMM and DGEMM operations to measure the performance of a GPU in FLOPS
  • To learn how to use cuFFT to perform 1D or 2D FFT operations on the GPU
  • To learn how to create a 2D convolutional filter using the FFT, and apply it to simple image processing
  • To understand how to perform a Singular Value Decomposition (SVD) with cuSolver
  • To learn how to use cuSolver's SVD algorithm to perform basic principal component analysis
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.16.139.8