How to use the OpenCL linear solvers

From KratosWiki
Jump to: navigation, search

Contents

How to use the OpenCL Linear Solvers

Experimental support was added to the Kratos to use modern GPU (or many-core CPUs) basing on the OpenCL programming model.

In order to provide basic linear system solving capabilities, the Kratos uses the ViennaCL library, recently developed at Vienna TU by Ing. Karl Rupp and others. The library, which features a MIT like license, can be currently downloaded from the Kratos SVN.

Compiling the library

ATI GPUs

The installation of the library requires the presence of an OpenCL compiler on the system, and of driver support to run on GPUs. If no GPU is present, a fallback on the CPU is provided by the AMD stream implementation.

In order to install the driver (under ubuntu linux 10.04) follow the following steps:

  • Download and install the deb package (X86 or x86_64 depending on your system) from the link

[1] , Post by "Nou". Install both "ati-opencl-runtime" and "ati-opencl-dev"

  • If you have a ATI high-end GPU, that you would like to use to accelerate the calculations, make sure you install the catalyst driver 10.4 or later versions

NVidia GPUs

  • In order to use NVIDIA GPUs install the driver version 195 or later

In Ubuntu 10.04, you can get a recent enough driver from the repository by typing in the console

 sudo apt-get install nvidia-current

You will also need the developer version of the drivers, obtained by

 sudo apt-get install nvidia-current-dev

Otherwise, the drivers can be downloaded from http://developer.nvidia.com/object/cuda_3_0_downloads.html#Linux

Compilation

Warn_icon.gif Warning. Please, note that:

Until we figure out the best way to point the compiler to the OpenCL include folder, this has to be done manually for each computer. For NVidia GPUs, edit the Jamfile in /home/.../kratos/applications/OpenCLapplication from

  requirements <include>.
               <include>custom_external_libraries
               <define>KRATOS_PYTHON
               ##<define>VIENNACL_EXPERIMENTAL_DOUBLE_PRECISION_WITH_STREAM_SDK
               <link>shared

to:

  requirements <include>.
               <include>custom_external_libraries
               <include>/usr/include/nvidia-current/
               <define>KRATOS_PYTHON
               ##<define>VIENNACL_EXPERIMENTAL_DOUBLE_PRECISION_WITH_STREAM_SDK
               <link>shared

For ATI GPUs, modify the include block to point to the folder containing your CL folder.

Once you have the required drivers, the compilation of the library has to be done manually by doing

 cd applications/OpenCLapplication
 bjam threading=multi -a 

please note that for the moment it can only be compiled with gcc as due to a bug the ATI stream SDK does not work together with the intel compiler

Using the library

The interface to the iterative solver library is very similar to the standard one for the Kratos internal linear solvers:

for example a call to the BICGStabSolver the standard python interface is

  linear_solver =  BICGSTABSolver(1e-3, 5000)

can be replaced by

  from KratosOpenCLApplication import *
  
  ##choice of the solver's settings
  precision = OpenCLPrecision.Single 
  solver_type = OpenCLSolverType.BiCGStab
  preconditioner_type = OpenCLPreconditionerType.NoPreconditioner
  
  ##creating the solver
  linear_solver = ViennaCLSolver(1e-3,5000,precision,solver_type,preconditioner_type)

the list of options that are currently available is:

  OpenCLPrecision.Single //to use single precision in the solution (available in most gpus)
  OpenCLPrecision.Double //requires hardware support
  OpenCLSolverType.CG
  OpenCLSolverType.BiCGStab
  OpenCLSolverType.GMRES
  OpenCLPreconditionerType.NoPreconditioner
  OpenCLPreconditionerType.ILU
Personal tools
Categories