clMAGMA passing existing opencl buffers

Open discussion for MAGMA library (Matrix Algebra on GPU and Multicore Architectures)

clMAGMA passing existing opencl buffers

Postby cdeterman » Wed Aug 24, 2016 2:50 pm

Greetings,

I am trying to interface with clMAGMA using existing OpenCL objects (via the ViennaCL library - https://github.com/viennacl/viennacl-dev). I have confirmed I can accomplish this with clBLAS and assumed I could do the same with clMAGMA. I can extract the relevant arguments from existing viennacl::matrix objects (One trival example with elements [5,1][1,3] and the other to be filled [0,0][0,0]):

Code: Select all
    // declare OpenCL objects
    int info;

    // Order of matrix (assuming square here)
    const int N = vcl_A.size2();

    // Get command queue
    cl_command_queue queue = vcl_A.handle().opencl_handle().context().get_queue().handle().get();

    /* Get OpenCL memory objects */
    const cl_mem *bufA = &vcl_A.handle().opencl_handle().get();
    const cl_mem *bufB = &vcl_B.handle().opencl_handle().get();


I then pass the objects to the cholesky decomposition function

Code: Select all
    /* Call clmagma. Perform cholesky decomp */
    magma_spotrs_gpu(MagmaUpper, N, N,
                     *bufA, 0, vcl_A.internal_size2(),
                     *bufB, 0, vcl_B.internal_size2(),
                     queue, &info);
    if (info < 0) {
       stop("magma_spotrs_gpu failed");
    }


This compiles and appears to run without a problem but after the above lines I try to print out the contents of matrix vcl_B

Code: Select all
    std::cout << "vcl_B" << std::endl;
    std::cout << vcl_B << std::endl;


Which oddly come out to all zeros. I have no idea why this is the case. Any insight would be appreciated.

Regards,
Charles
cdeterman
 
Posts: 10
Joined: Wed Aug 24, 2016 2:39 pm

Re: clMAGMA passing existing opencl buffers

Postby mgates3 » Wed Aug 24, 2016 8:39 pm

It should presumably work. vcl_A is the 2x2 matrix [ 5, 1 ; 1, 3 ], and vcl_B is the 2x2 matrix [ 0, 0 ; 0, 0 ] ?

First, spotrs assumes that the matrix has already been factored using spotrf. If you want to factor and solve it in one step, use sposv. Nonetheless, that matrix vcl_A will act as the Cholesky factor of [ 25, 5; 5, 10 ].

Second, if the right-hand side is all zeros, then the result will be zero. In Matlab:

Code: Select all
>> A = [ 5, 1 ; 1 3 ];

% potrs uses upper triangle as Cholesky factor
>> U = triu(A);

% solve with zero RHS
>> B = [ 0, 0 ; 0, 0 ];
>> U \ U' \ B
ans =
     0     0
     0     0

% solve with non-zero RHS
>> B = [ 1, 2 ; 3, 4 ];
>> U \ U' \ B
ans =
    1.6000    2.8000
    2.4667    3.0667

% matrix C that would give U as its Cholesky factor:
>> C = U' * U
C =
    25     5
     5    10
Last edited by mgates3 on Thu Aug 25, 2016 1:27 am, edited 1 time in total.
Reason: correct A
mgates3
 
Posts: 738
Joined: Fri Jan 06, 2012 2:13 pm

Re: clMAGMA passing existing opencl buffers

Postby cdeterman » Thu Aug 25, 2016 11:39 am

Ah, thank you, I was mistakenly using the wrong function. Switching to spotrf appears to have solved the problem. Glad it was such a simple solution.
cdeterman
 
Posts: 10
Joined: Wed Aug 24, 2016 2:39 pm


Return to User discussion

Who is online

Users browsing this forum: Bing [Bot] and 3 guests

cron