Menu

Clarification: ViennaCL matrix&vector, ublas matrix¬vector, std matrix&vector which is for CPU/GPU?

tario
2017-08-30
2017-08-30
  • tario

    tario - 2017-08-30

    Hello,

    when I work with online examples I get somewhat confused and since I went down the wrong path once, and might be on the wrong track again, I'd need some clarification:

    Which matrix and vector objects are used with which backend (OpenMP, CUDA, OpenCL)?

    There are ViennaCL, std and ublas objects and e.g. example http://viennacl.sourceforge.net/viennacl-examples-vector.html uses

    // Define a few CPU vectors using the STL
    std::vector<ScalarType>      std_vec1(10); 
    
    // Define a few GPU vectors using ViennaCL
    viennacl::vector<ScalarType> vcl_vec1(10);
    

    while example http://viennacl.sourceforge.net/viennacl-examples-iterative.html works with

    ~~~
    // Set up some ublas objects (CPU):
    ublas::vector<ScalarType> ublas_rhs;

    // Set up some ViennaCL objects (GPU):
    viennacl::vector<ScalarType> vcl_rhs;
    ~~~

    What should I use to work with the OpenMP backend on the CPU utilising multiple CPU cores?
    matrix object?
    vector object?

    What should I use to work with the CUDA or OpenCL backend on the GPU using multiple GPUs?
    matrix object?
    vector object?

    T.

     
  • Karl Rupp

    Karl Rupp - 2017-08-30

    Hi Tario,

    for either of {CUDA,OpenCL,OpenMP} you need to use the ViennaCL-datatypes, i.e. viennacl::vector<>, viennacl::matrix<>, etc.
    ViennaCL used to be OpenCL-only in the early days, so there was a strict distinction between CPU types (std::vector, ublas::vector) necessary. With the addition of the OpenMP backend to ViennaCL, a strict CPU vs. GPU distinction was no longer necessary, but it still helped with the standard use-case of ViennaCL for GPUs.

    If you have any concrete suggestions on how to improve the documentation, we are more than happy to take your input :-)

    Best regards,
    Karli

     
  • tario

    tario - 2017-09-13

    About the documentation, an introduction that lowers the entry hurdle to a small step would help a lot.

    Scope: Iterative solvers

    Rules: Stick to best practices, the high speed options and restrict it to ViennaCL

    Audience: "KGVP" (Kinder, Greise, Vorstände und Partner) or "How to Explain your Grandma How to use ViennaCL iterative solvers?"

    Acceptance & Marketing effect: If people master this first step with ease, acceptance will go through the roof and the word will spread

    One page could be enough .. here we go...:

    Prerequisites: Install c++ (includes OpenMP to use multiple CPU cores), CUDA (optional for use of Nvidia GPUs), OpenCL (optional for use of Nvidia or AMD GPUs) on your computer

    Get ready!

    step 1: Download ViennaCL from the internet and extract it
    step 2: Create a project folder "myproject"
    step 3: Copy the folder "viennacl" which is inside the extracted directory from your download to "myproject", that's it, no "installation" required

    done

    Playtime!

    1: Copy the following code to "myproject"
    2: Compile it with the compiler flag for OpenMP and run it on the CPU first: ... - fopenmp, before you run it make sure you tell the computer how many cores or threads to use, on Linux that's done by executing the command 'export OMP_NUM_THREADS=8' ,here to use 8 threads, before you execute your programm
    3: Play with the different solvers, preconditioners and relevant types of matrices
    4: Compile it for GPUs and experience the difference

    Have fun.

    Code, we need to work out in detail: (for now just a proposed structure)

    // A) Define which "backend", OpenMP or CUDA or OpenCL you want to use, default is OpenMP
    
    #define VIENNACL_WITH_OPENMP 
    // #define VIENNACL_WITH_CUDA 
    // #define VIENNACL_WITH_OPENCL 
    
    // B) Add c++ includes if required
    
    Code goes here...
    
    // C) Add ViennaCL includes
    
    // For matrix, vectors and solvers
    #include "../viennacl/vector.hpp"
    #include "../viennacl/compressed_matrix.hpp"
    #include "../viennacl/linalg/gmres.hpp"
    #include "../viennacl/linalg/bicstab.hpp"
    #include "../viennacl/linalg/cg.hpp"
    #include "../viennacl/linalg/mixed_precision_cg.hpp"
    
    // For preconditioners
    #include "../viennacl/linalg/detail/ilu/block_ilu.hpp"
    #include "../viennacl/linalg/amg.hpp"
    #include "../viennacl/linalg/ichol.hpp"
    ... 
    
    note: all preconditioners should be included
    
    // D) Create the matrix and vector objects needed; we want to solve A x x = b
    
    // matrix
        viennacl::compressed_matrix<ScalarType> A(n,m,nnz); // sparse matrix A with size nxm and nnz nonzero values
    
    // vector(s) for x (soution) and right-hand-side often called rhs or b
        viennacl::vector<ScalarType> x(n); // size n
        viennacl::vector<ScalarType> b(n); // size n
    
    // E1) Code to load sample matrix from matrix market
    
    Code goes here...
    
    // E2) Code to load or generate b/rhs
    
    Code goes here...
    
    // F) Complete sample setup of all preconditioners
    
    // Preconditioner 1: name -----------------------------------------
    
    Code goes here...
    
    // Preconditioner 2: name ------------------------------------------
    
    Code goes here...
    
    ...
    
    // Preconditioner N: AMG -------------------------------------------
    
    Code goes here...
    
    // G) Create an (optional) initial guess for x
    
    Code goes here...
    
    // H) Complete sample setup of all four solvers incl. a preconditioner that works best for the selected matrix
    
    // Solver 1: GMRES ----------------------------------------------
    
    Code goes here...
    
    // Solver 2: bicstab --------------------------------------------
    
    Code goes here...
    
    // Solver 3: cg -------------------------------------------------
    
    Code goes here...
    
    // Solver 4: mixed_precision_cg ---------------------------------
    
    Code goes here...
    
    // I) Output that documents the performance
    
    Code goes here...
    

    note: The default settings should run out of the box, changes should be limited to copy/paste and commenting, uncommenting sections and there should be a youtube video showing a rookie doing the exercise. It should be like made of lego building blocks to play with.

    What do you think?

     
  • Karl Rupp

    Karl Rupp - 2017-09-28

    Thanks, tario, for the suggestion.

    I have a couple of questions:
    1.) In what way is the current "Installation" in the online manual insufficient? http://viennacl.sourceforge.net/doc/manual-installation.html It describes just the steps you mentioned above?
    2.) The suggested code is actually not too different from what is in examples/benchmark/solver.cpp - apparently it's not prominently placed. Did you find that example at all?
    3.) Would you watch a youtube video for a library installation? I think that written documentation is much more efficient in providing that information. But I'd like to get feedback, since my own views are not necessarily relevant ;-)

    Best regards,
    Karli

     
  • tario

    tario - 2017-09-28

    I am sure the information is somewhere on the website in the examples... sometimes easy to find and digest, at times "incomplete" at first sight with a reference to the "missing" bids...

    From my experience a quick, complete, step-by-step and modular introduction can lower the entry barrier for a newcomer a lot.

    Regarding your qustions:

    1: Yes, it's absolutely fine but it should be part of any introduction, it's step 1

    (What's not so good regarding examples is e.g., in the download package, there's a build directory but cmake works in the example directory so the build directory is of no use and confusing)

    2: Yes, there are examples, I liked the table showing what they are about and what's the related backend but what I'd like better is a toolbox with complete blocks of code and a note about the relevant header files. Some examples or code snippets on the website are followed by a note refering to another e.g. preconditioner regarding configuration details or configuration options are not fully exploited, covering 8 of 10 options, (where) would people search for more options if they are not mentioned in relevant examples?. It may be good programing style to avoid the same code in two places but I found it cumbersome to copy the bits and pieces from different locations and to get the syntax right. Also important I think, there's little information about how to copy matrices and vectors from/to ViennaCL, that's a gerenral problem of linear algebra libraries, usually (talking about libraries in general) examples show how to create and load some random numbers with a loop which I think is not really relevant. Big issues I encountered are the data formats COO, CSR ... more precisely, what's the exact data structure (usually a set of arrays[] for the matrix) that needs to be prepared and how to load/copy data into the ViennaCL objects. I have seen examples where people tried to develop extensions for their applications to be able to use external libraries/solvers and failed with 90% of the solution ready because they didn't get the data conversion right.

    3: I wouldn't watch a youtube video just about the installation (which is only copy/paste), written documentation is fine but is there an up-to-date version? The one I have is from version 1.5 which is fine for me so far.

    Does that help?

     

Log in to post a comment.