Menu

extracting individual columns from compressed_matrix()

suchismit
2014-06-02
2014-06-03
  • suchismit

    suchismit - 2014-06-02

    hi folks,
    i was wondering if it would be possible individual columns of a compressed_matrix() using handle1(), handle2() and handle() fields.


    const viennacl::ocl::handle<cl_mem> & handle1() const { return _row_buffer; }
    const viennacl::ocl::handle<cl_mem> & handle2() const { return _col_buffer; }

    private:
    viennacl::ocl::handle<cl_mem> _row_buffer;
    viennacl::ocl::handle<cl_mem> _col_buffer;


    i was hoping the row(Matrix, row#) method (i.e. viennacl::vector<T> r = viennacl::row(A, 4);) to work for non dense matrix data structures but the compiler complains.


    hrm.cu(220): error: no instance of function template "viennacl::row" matches the argument list
    argument types are: (viennacl::compressed_matrix<float, 1U="">, int)


    essentially i want to recreate/populate a viennacl::vector<float> with the entries of individual columns which i can use to make conjugate gradient calls using these individual columns as b vectors i.e.
    my original requirement is to solve A*X = B; but viennacl::linalg::solve() blasts me with errors when i pass b as a matrix. (see below) :(

    so i am doing it using individual columns i.e. A*[x1,x2,x3, ... xn] = [b1,b2,b3, ... bn]
    where B and X are both compressed_matrices.

    i needed to get a hold of how to use handle1(), handle2() to get the individual nonzero entries and populate bi (to get xi, where A*xi = bi). once i have xi's i can create a compressed_matrix() using these xi's as columns. essentially i want to understand to play around with the viennacl::ocl::handle<cl_mem> type.

    can someone help ? :)

    suchismit


    /projects/ch/ViennaCL-1.5.1/viennacl/traits/size.hpp(146): error: class "viennacl::compressed_matrix<float, 1U="">" has no member "size"
    detected during:
    instantiation of "viennacl::vcl_size_t viennacl::traits::size(const VectorType &) [with VectorType=viennacl::compressed_matrix<float, 1U="">]"
    /projects/ch/ViennaCL-1.5.1/viennacl/traits/clear.hpp(61): here
    instantiation of "void viennacl::traits::clear(VectorType &) [with VectorType=viennacl::compressed_matrix<float, 1U="">]"
    /projects/ch/ViennaCL-1.5.1/viennacl/linalg/cg.hpp(97): here
    instantiation of "VectorType viennacl::linalg::solve(const MatrixType &, const VectorType &, const viennacl::linalg::cg_tag &) [with MatrixType=viennacl::compressed_matrix<float, 1U="">, VectorType=viennacl::compressed_matrix<float, 1U="">]"
    hrm.cu(221): here

    /projects/ch/ViennaCL-1.5.1/viennacl/traits/clear.hpp(62): error: no operator "[]" matches these operands
    operand types are: viennacl::compressed_matrix<float, 1U=""> [ size_type ]
    detected during:
    instantiation of "void viennacl::traits::clear(VectorType &) [with VectorType=viennacl::compressed_matrix<float, 1U="">]"
    /projects/ch/ViennaCL-1.5.1/viennacl/linalg/cg.hpp(97): here
    instantiation of "VectorType viennacl::linalg::solve(const MatrixType &, const VectorType &, const viennacl::linalg::cg_tag &) [with MatrixType=viennacl::compressed_matrix<float, 1U="">, VectorType=viennacl::compressed_matrix<float, 1U="">]"
    hrm.cu(221): here

    /projects/ch/ViennaCL-1.5.1/viennacl/linalg/cg.hpp(103): error: no instance of overloaded function "viennacl::linalg::inner_prod" matches the argument list
    argument types are: (const viennacl::compressed_matrix<float, 1U="">, const viennacl::compressed_matrix<float, 1U="">)
    detected during instantiation of "VectorType viennacl::linalg::solve(const MatrixType &, const VectorType &, const viennacl::linalg::cg_tag &) [with MatrixType=viennacl::compressed_matrix<float, 1U="">, VectorType=viennacl::compressed_matrix<float, 1U="">]"
    hrm.cu(221): here

    /projects/ch/ViennaCL-1.5.1/viennacl/linalg/cg.hpp(116): error: no instance of overloaded function "viennacl::linalg::prod" matches the argument list
    argument types are: (const viennacl::compressed_matrix<float, 1U="">, viennacl::compressed_matrix<float, 1U="">)
    detected during instantiation of "VectorType viennacl::linalg::solve(const MatrixType &, const VectorType &, const viennacl::linalg::cg_tag &) [with MatrixType=viennacl::compressed_matrix<float, 1U="">, VectorType=viennacl::compressed_matrix<float, 1U="">]"
    hrm.cu(221): here

    /projects/ch/ViennaCL-1.5.1/viennacl/linalg/cg.hpp(118): error: no instance of overloaded function "viennacl::linalg::inner_prod" matches the argument list
    argument types are: (viennacl::compressed_matrix<float, 1U="">, viennacl::compressed_matrix<float, 1U="">)
    detected during instantiation of "VectorType viennacl::linalg::solve(const MatrixType &, const VectorType &, const viennacl::linalg::cg_tag &) [with MatrixType=viennacl::compressed_matrix<float, 1U="">, VectorType=viennacl::compressed_matrix<float, 1U="">]"
    hrm.cu(221): here

    /projects/ch/ViennaCL-1.5.1/viennacl/linalg/cg.hpp(119): error: no operator "*" matches these operands
    operand types are: CPU_ScalarType * viennacl::compressed_matrix<float, 1U="">
    detected during instantiation of "VectorType viennacl::linalg::solve(const MatrixType &, const VectorType &, const viennacl::linalg::cg_tag &) [with MatrixType=viennacl::compressed_matrix<float, 1U="">, VectorType=viennacl::compressed_matrix<float, 1U="">]"
    hrm.cu(221): here

    /projects/ch/ViennaCL-1.5.1/viennacl/linalg/cg.hpp(120): error: no operator "*" matches these operands
    operand types are: CPU_ScalarType * viennacl::compressed_matrix<float, 1U="">
    detected during instantiation of "VectorType viennacl::linalg::solve(const MatrixType &, const VectorType &, const viennacl::linalg::cg_tag &) [with MatrixType=viennacl::compressed_matrix<float, 1U="">, VectorType=viennacl::compressed_matrix<float, 1U="">]"
    hrm.cu(221): here

    /projects/ch/ViennaCL-1.5.1/viennacl/linalg/cg.hpp(122): error: no instance of overloaded function "viennacl::linalg::norm_2" matches the argument list
    argument types are: (viennacl::compressed_matrix<float, 1U="">)
    detected during instantiation of "VectorType viennacl::linalg::solve(const MatrixType &, const VectorType &, const viennacl::linalg::cg_tag &) [with MatrixType=viennacl::compressed_matrix<float, 1U="">, VectorType=viennacl::compressed_matrix<float, 1U="">]"
    hrm.cu(221): here

    /projects/ch/ViennaCL-1.5.1/viennacl/linalg/cg.hpp(130): error: no operator "*" matches these operands
    operand types are: CPU_ScalarType * viennacl::compressed_matrix<float, 1U="">
    detected during instantiation of "VectorType viennacl::linalg::solve(const MatrixType &, const VectorType &, const viennacl::linalg::cg_tag &) [with MatrixType=viennacl::compressed_matrix<float, 1U="">, VectorType=viennacl::compressed_matrix<float, 1U="">]"
    hrm.cu(221): here


     
  • Karl Rupp

    Karl Rupp - 2014-06-03

    Hi,

    the iterative solvers indeed only support a vector as right hand side. For you application, I suggest not worry about the handle() member functions at all, but instead just create a separate right hand side vector. This can be achieved by multiplying the right hand side matrix B with a unit vector, To extract the i-th column:

    viennacl::vector<T> e_i = viennacl::unit_vector<T>(B.size2(), i);
    viennacl::vector<T> b = viennacl::linalg::prod(B, e_i);
    viennacl::vector<T> x = viennacl::linalg::solve(A, b);
    

    and loop over i as needed. The cost of this extra matrix-vector product for setting up b is usually negligible. Also, this way you can run the code with all backends.

    Keep in mind that A should still be sufficiently large (say, at least 100k nonzeros) in order to see performance benefits on GPUs, otherwise latency induced by PCI-Express will dominate.

    Best regards,
    Karli

     

Log in to post a comment.