Menu

CUDA Compressed Matrix / OpenCL for CUDA/Nvidia GPUs

Alex Chow
2016-03-15
2016-03-16
  • Alex Chow

    Alex Chow - 2016-03-15

    Hi,

    Just two questions
    So I've managed to use the OpenMP AMG preconditioner and it works great, so thanks! But now I'm trying to use the CUDA backend for it now. I've got the matrix data setup on the GPU (Nvidia GeForce GTX 980) as raw pointers and I've been trying to put that data into a compressed matrix in the CUDA context. Am I right that this cannot be done?

    I've tried a variety of ways, wrapping the raw pointers in viennacl vectors; using the raw pointers; transferring data back to CPU and then trying that way etc. Each way compiles fine, only when I run the program do I get an "unknown memory handle" exception, or the program crashes.

    To work my way round this, I've tried to approach the problem using the opencl backend, however even using something like:
    viennacl::ocl::current_context();
    will give me compilation errors, all unresolved external symbols, clRetainContext, clCreateCommandQueue etc.

    I'm wondering if I need to install an opencl driver for my gpu or not?

    Thanks,
    Alex

     
  • Karl Rupp

    Karl Rupp - 2016-03-15

    Hi Alex,

    you are right that this cannot be done in the existing releases. As you probably noticed, the OpenCL contructors are there, but the CUDA constructors for wrapping existing memory were overseen. I will add the necessary code and an example demonstrating how to use it tomorrow.

    Best regards,
    Karli

     
  • Alex Chow

    Alex Chow - 2016-03-16

    Thanks for your quick response!

     
  • Karl Rupp

    Karl Rupp - 2016-03-16

    Hi,

    have a look here:
    https://github.com/viennacl/viennacl-dev/commit/02ea0f2264db906f5a691eaeb9d2543f3756b6ef

    The example in examples/tutorial/wrap-csr-cuda.cu should contain everything you need. Please let me know if you encounter any issues.

    Best regards,
    Karli

     
  • Alex Chow

    Alex Chow - 2016-03-16

    I will have a go at it later today, thank you.

    Alex

     
  • Alex Chow

    Alex Chow - 2016-03-16

    Hi Karli,
    So I've copied the extra code into compressed_matrix.hpp and then I ran a new CUDA 5.5 project in visual studio and just copy and pasted the example (with the addition of "#define VIENNACL_WITH_CUDA" at the begninning) into the .cu file. Everything works perfect from that perspective. So thank you for that.

    However, trying to do it in the code/project I'm working on still gives me the same error as before:
    "ViennaCL: Internal memory error: unknown memory handle!"

    This happens when I use my own variables and also copying the working example code into a subroutine to work on its own as a standalone function so there are no obvious conflicts with my code
    solveViennaCL(){
    example code here
    }

    I wonder if it's the configuration of the project.

    Alex

     
  • Karl Rupp

    Karl Rupp - 2016-03-16

    Hi,

    do you have VIENNACL_WITH_CUDA defined in your project? It needs to be compiled with NVCC. I can't say more than this given your limited description of how your code is set up.

    Best regards,
    Karli

     
  • Alex Chow

    Alex Chow - 2016-03-16

    Yes I do, I have #define VIENNACL_WITH_CUDA at the top of the .cu file that I use the viennacl library in.

    My project uses both CPU and GPU(CUDA) and compiles and has ran fine before now, so the setup for at least my project is correct. The project configuration was setup by someone else though as I'm merely modifying the code. I think they've used a few custom settings (leaving out some preprocessor definitions etc.) I'm an engineer as opposed to a computer scientist so I tend to leave that stuff alone unless told otherwise!

    If you have no other possible ideas then I understand as you can't see my setup/code, I appreciate all your help nevertheless anyway, so thank you.

    Just as a final question, do you have any idea which file the exception I am getting might appear in?
    "ViennaCL: Internal memory error: unknown memory handle!"
    Just so I can begin looking at where it's coming from.

    Thanks
    Alex

     
  • Karl Rupp

    Karl Rupp - 2016-03-16

    Run the code in a debugger and then print a backtrace as soon as you receive the error. On Linux this is:

    $> gdb ./your_application
    $> (gdb) r
    $> (gdb) bt

    This will print a backtrace for you. My guess is that VIENNACL_WITH_CUDA is not consistently defined. Make sure that all compilations of ViennaCL code receive the same set of preprocessor defines.

     
  • Alex Chow

    Alex Chow - 2016-03-16

    Yes you're correct with the preprocessor defines, although I've stated it in what I thought was the necessary files, it has not carried on through to mem_handle.hpp, so my guess is that I'm defining #VIENNACL_WITH CUDA too late in the project.

    Thanks!

     

Log in to post a comment.