Re: multiply into view

43 views
Skip to first unread message

Steven Dalton

unread,
Aug 1, 2016, 1:53:08 PM8/1/16
to cusp-...@googlegroups.com
Hello,

  Can you attach your example so I can reproduce the error? I generated an example below and the result matrix y appears to be updated correctly.

Steve

#include <cusp/csr_matrix.h>
#include <cusp/multiply.h>
#include <cusp/print.h>
#include <cusp/gallery/poisson.h>

int main(int argc, char ** argv)
{
    typedef int                 IndexType;
    typedef double              ValueType;
    typedef cusp::device_memory MemorySpace;
    typedef cusp::array2d<ValueType, MemorySpace>::column_view View;

    // create an empty sparse matrix structure
    cusp::csr_matrix<IndexType, ValueType, MemorySpace> A;

    size_t N = 10;

    // create 2D Poisson problem
    cusp::gallery::poisson5pt(A, N, N);
    cusp::array2d<ValueType, MemorySpace> x(A.num_cols, 10, 1);
    cusp::array2d<ValueType, MemorySpace> y(A.num_rows, 10, 0);

    std::cout << "Constructed test matrix with shape ("  << A.num_rows << "," << A.num_cols << ") and "
              << A.num_entries << " entries" << std::endl;

    View x_col(x.column(0));
    View y_col(y.column(0));

    cusp::multiply(A, x_col, y_col);

    cusp::print(y.column(0));

    return 0;
}


On Sun, Jul 31, 2016 at 9:27 PM, Lifeng Jin <lifen...@gmail.com> wrote:
Hi, I am trying to do this:
multiply(csr_matrix_view, array2d_row_view, array2d_row_view)
but it seems that the array2d as the result vector is not changed by the multiplication. Does this show that the result, i.e. y, must not be a view?
Thanks,
Lifeng

--
You received this message because you are subscribed to the Google Groups "cusp-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cusp-users+...@googlegroups.com.
To post to this group, send email to cusp-...@googlegroups.com.
Visit this group at https://groups.google.com/group/cusp-users.
For more options, visit https://groups.google.com/d/optout.

Lifeng Jin

unread,
Aug 2, 2016, 1:00:14 AM8/2/16
to cusp-users
Thanks for the example. I have figured out a little bit, but now error is actually failing to compile with my current setup. A small example:

#include <cusp/array1d.h>
#include <cusp/array2d.h>
#include <iostream>
#include <cusp/print.h>
#include <cusp/multiply.h>
using namespace cusp;
int main(int argc, char ** argv)
{  
    array1d<float, device_memory> A(4);
    A[0] = 1.0f;
    A[1] = 3.0f;
    A[2] = 4.0f;
    A[3] = 5.0f;
    array1d_view<array1d<float, device_memory>::iterator> Aview(A);

    array2d_view<array1d_view<array1d<float, device_memory>::iterator>, row_major> A2dview(2, 2, 2, Aview);
    array1d<float, device_memory> v(2);
    v[0] = 1.0f;
    v[1] = 2.0f;
    array1d_view<array1d<float, device_memory>::iterator> vview(v);
    array2d_view<array1d_view<array1d<float, device_memory>::iterator>, row_major> vview2d(1, 2, 2, vview);
    array1d<float, device_memory> w(2);
    array2d_view<array1d_view<array1d<float, device_memory>::iterator>, row_major> wview2d(1, 2, 2, vview);
    multiply(vview2d, A2dview, wview2d);
return 0;
}
So I have an array2d_view of 1*2 matrix and another array2d_view of 2*2 and want the result to go in another array2d_view of 1*2. The error message is:

/usr/local/cuda/bin/../include/cusp/detail/multiply.inl(48): error: no instance of overloaded function "multiply" matches the argument list

            argument types are: (thrust::system::cuda::detail::tag, const cusp::array2d_view<cusp::array1d_view<thrust::detail::normal_iterator<thrust::device_ptr<float>>>, cusp::row_major>, const cusp::array2d_view<cusp::array1d_view<thrust::detail::normal_iterator<thrust::device_ptr<float>>>, cusp::row_major>, cusp::array2d_view<cusp::array1d_view<thrust::detail::normal_iterator<thrust::device_ptr<float>>>, cusp::row_major>, Format1, Format2, Format3)

          detected during:

            instantiation of "void cusp::multiply(const thrust::detail::execution_policy_base<DerivedPolicy> &, const LinearOperator &, const MatrixOrVector1 &, MatrixOrVector2 &) [with DerivedPolicy=thrust::system::cuda::detail::tag, LinearOperator=cusp::array2d_view<cusp::array1d_view<thrust::detail::normal_iterator<thrust::device_ptr<float>>>, cusp::row_major>, MatrixOrVector1=cusp::array2d_view<cusp::array1d_view<thrust::detail::normal_iterator<thrust::device_ptr<float>>>, cusp::row_major>, MatrixOrVector2=cusp::array2d_view<cusp::array1d_view<thrust::detail::normal_iterator<thrust::device_ptr<float>>>, cusp::row_major>]" 

(70): here

            instantiation of "void cusp::multiply(const LinearOperator &, const MatrixOrVector1 &, MatrixOrVector2 &) [with LinearOperator=cusp::array2d_view<cusp::array1d_view<thrust::detail::normal_iterator<thrust::device_ptr<float>>>, cusp::row_major>, MatrixOrVector1=cusp::array2d_view<cusp::array1d_view<thrust::detail::normal_iterator<thrust::device_ptr<float>>>, cusp::row_major>, MatrixOrVector2=cusp::array2d_view<cusp::array1d_view<thrust::detail::normal_iterator<thrust::device_ptr<float>>>, cusp::row_major>]" 

version.cu(51): here


1 error detected in the compilation of "/var/folders/bq/02vpb7v14q589sb3mq27kl8w0000gn/T//tmpxft_0001730f_00000000-9_version.cpp1.ii".

Steven Dalton

unread,
Aug 2, 2016, 12:19:42 PM8/2/16
to cusp-...@googlegroups.com
Thanks, can you try compiling your code using the latest develop branch of the repo? What version of the CUDA toolkit are you using?

Steve

Lifeng Jin

unread,
Aug 2, 2016, 1:04:34 PM8/2/16
to cusp-users
Yes, I will try the dev branch today. I have been using the release branch. I am using CUDA 7.5.26

Lifeng Jin

unread,
Aug 2, 2016, 2:25:08 PM8/2/16
to cusp-users
Hi Steve,
Thanks for prompt replies. Using the dev branch, I can do array2d_view=array2d_view*array2d_view, but failed at array2d_view = csr_matrix_view*array2d_view. An example:


#include <cusp/array2d.h>
#include <cusp/print.h>
#include <cusp/csr_matrix.h>
#include <cusp/gallery/poisson.h>
#include <cusp/multiply.h>
using namespace cusp;
int main(void)
{  
   typedef cusp::array1d<int,cusp::device_memory> IndexArray;
   typedef cusp::array1d<float,cusp::device_memory> ValueArray;
   typedef typename IndexArray::view IndexArrayView;
   typedef typename ValueArray::view ValueArrayView;

    cusp::csr_matrix<int , float, device_memory> A;
    size_t N = 2;
    cusp::gallery::poisson5pt(A, N, N);
    cusp::csr_matrix_view<IndexArrayView,IndexArrayView,ValueArrayView> Aview(A);
    array1d<float, device_memory> v(2);
    v[0] = 1.0f;
    v[1] = 2.0f;
    array1d_view<array1d<float, device_memory>::iterator> vview(v);
    array2d_view<array1d_view<array1d<float, device_memory>::iterator>, row_major> vview2d(1, 2, 2, vview);
    array1d<float, device_memory> w(2);
    array1d_view<array1d<float, device_memory>::iterator> wview(w);
    array2d_view<array1d_view<array1d<float, device_memory>::iterator>, row_major> wview2d(1, 2, 2, vview);
    multiply(vview2d, Aview, wview2d);
    print(w);
    return 0;
}

Error message is:

/usr/local/cuda/bin/../include/cusp/system/detail/generic/multiply.inl(131): error: no instance of overloaded function "cusp::system::detail::generic::multiply" matches the argument list

            argument types are: (cusp::system::cuda::detail::par_t, const cusp::array2d_view<cusp::array1d_view<thrust::detail::normal_iterator<thrust::device_ptr<float>>>, cusp::row_major>, const cusp::csr_matrix_view<cusp::array1d_view<thrust::detail::normal_iterator<thrust::device_ptr<int>>>, cusp::array1d_view<thrust::detail::normal_iterator<thrust::device_ptr<int>>>, cusp::array1d_view<thrust::detail::normal_iterator<thrust::device_ptr<float>>>, int, float, cusp::device_memory>, cusp::array2d_view<cusp::array1d_view<thrust::detail::normal_iterator<thrust::device_ptr<float>>>, cusp::row_major>, cusp::constant_functor<float>, thrust::multiplies<float>, thrust::plus<float>, Format1, Format2, Format3)

          detected during:

            instantiation of "thrust::detail::disable_if_convertible<UnaryFunction, cusp::known_format, void>::type cusp::system::detail::generic::multiply(thrust::execution_policy<DerivedPolicy> &, const LinearOperator &, const MatrixOrVector1 &, MatrixOrVector2 &, UnaryFunction, BinaryFunction1, BinaryFunction2) [with DerivedPolicy=cusp::system::cuda::detail::par_t, LinearOperator=cusp::array2d_view<cusp::array1d_view<thrust::detail::normal_iterator<thrust::device_ptr<float>>>, cusp::row_major>, MatrixOrVector1=cusp::csr_matrix_view<cusp::array1d_view<thrust::detail::normal_iterator<thrust::device_ptr<int>>>, cusp::array1d_view<thrust::detail::normal_iterator<thrust::device_ptr<int>>>, cusp::array1d_view<thrust::detail::normal_iterator<thrust::device_ptr<float>>>, int, float, cusp::device_memory>, MatrixOrVector2=cusp::array2d_view<cusp::array1d_view<thrust::detail::normal_iterator<thrust::device_ptr<float>>>, cusp::row_major>, UnaryFunction=cusp::constant_functor<float>, BinaryFunction1=thrust::multiplies<float>, BinaryFunction2=thrust::plus<float>]" 

/usr/local/cuda/bin/../include/cusp/detail/multiply.inl(78): here

            instantiation of "void cusp::multiply(const thrust::detail::execution_policy_base<DerivedPolicy> &, const LinearOperator &, const MatrixOrVector1 &, MatrixOrVector2 &, UnaryFunction, BinaryFunction1, BinaryFunction2) [with DerivedPolicy=cusp::system::cuda::detail::par_t, LinearOperator=cusp::array2d_view<cusp::array1d_view<thrust::detail::normal_iterator<thrust::device_ptr<float>>>, cusp::row_major>, MatrixOrVector1=cusp::csr_matrix_view<cusp::array1d_view<thrust::detail::normal_iterator<thrust::device_ptr<int>>>, cusp::array1d_view<thrust::detail::normal_iterator<thrust::device_ptr<int>>>, cusp::array1d_view<thrust::detail::normal_iterator<thrust::device_ptr<float>>>, int, float, cusp::device_memory>, MatrixOrVector2=cusp::array2d_view<cusp::array1d_view<thrust::detail::normal_iterator<thrust::device_ptr<float>>>, cusp::row_major>, UnaryFunction=cusp::constant_functor<float>, BinaryFunction1=thrust::multiplies<float>, BinaryFunction2=thrust::plus<float>]" 

(104): here

            instantiation of "thrust::detail::disable_if_convertible<LinearOperator::format, cusp::unknown_format, void>::type cusp::system::detail::generic::multiply(thrust::execution_policy<DerivedPolicy> &, const LinearOperator &, const MatrixOrVector1 &, MatrixOrVector2 &) [with DerivedPolicy=cusp::system::cuda::detail::par_t, LinearOperator=cusp::array2d_view<cusp::array1d_view<thrust::detail::normal_iterator<thrust::device_ptr<float>>>, cusp::row_major>, MatrixOrVector1=cusp::csr_matrix_view<cusp::array1d_view<thrust::detail::normal_iterator<thrust::device_ptr<int>>>, cusp::array1d_view<thrust::detail::normal_iterator<thrust::device_ptr<int>>>, cusp::array1d_view<thrust::detail::normal_iterator<thrust::device_ptr<float>>>, int, float, cusp::device_memory>, MatrixOrVector2=cusp::array2d_view<cusp::array1d_view<thrust::detail::normal_iterator<thrust::device_ptr<float>>>, cusp::row_major>]" 

/usr/local/cuda/bin/../include/cusp/detail/multiply.inl(38): here

            instantiation of "void cusp::multiply(const thrust::detail::execution_policy_base<DerivedPolicy> &, const LinearOperator &, const MatrixOrVector1 &, MatrixOrVector2 &) [with DerivedPolicy=cusp::system::cuda::detail::par_t, LinearOperator=cusp::array2d_view<cusp::array1d_view<thrust::detail::normal_iterator<thrust::device_ptr<float>>>, cusp::row_major>, MatrixOrVector1=cusp::csr_matrix_view<cusp::array1d_view<thrust::detail::normal_iterator<thrust::device_ptr<int>>>, cusp::array1d_view<thrust::detail::normal_iterator<thrust::device_ptr<int>>>, cusp::array1d_view<thrust::detail::normal_iterator<thrust::device_ptr<float>>>, int, float, cusp::device_memory>, MatrixOrVector2=cusp::array2d_view<cusp::array1d_view<thrust::detail::normal_iterator<thrust::device_ptr<float>>>, cusp::row_major>]" 

/usr/local/cuda/bin/../include/cusp/detail/multiply.inl(58): here

            instantiation of "void cusp::multiply(const LinearOperator &, const MatrixOrVector1 &, MatrixOrVector2 &) [with LinearOperator=cusp::array2d_view<cusp::array1d_view<thrust::detail::normal_iterator<thrust::device_ptr<float>>>, cusp::row_major>, MatrixOrVector1=cusp::csr_matrix_view<cusp::array1d_view<thrust::detail::normal_iterator<thrust::device_ptr<int>>>, cusp::array1d_view<thrust::detail::normal_iterator<thrust::device_ptr<int>>>, cusp::array1d_view<thrust::detail::normal_iterator<thrust::device_ptr<float>>>, int, float, cusp::device_memory>, MatrixOrVector2=cusp::array2d_view<cusp::array1d_view<thrust::detail::normal_iterator<thrust::device_ptr<float>>>, cusp::row_major>]" 



On Monday, August 1, 2016 at 1:53:08 PM UTC-4, Steve wrote:

Steven Dalton

unread,
Aug 2, 2016, 2:54:09 PM8/2/16
to cusp-...@googlegroups.com
Ah, thanks, I see the issue now. Cusp does not support generalized multiply operations such as X*A=Y where X and Y are dense array2d or array1d types and A is a sparse matrix type. The current implementation only dispatches correctly for A*X=Y. This is a feature that could be added in the future. Your code should compile if you change multiply(vview2d, Aview, wview2d) to multiply(Aview, vview2d, wview2d) but that may not be the operation you really want to compute. You would have to either convert Aview to a dense type or explicitly transpose the inputs and outputs to ensure that Aview is the first operand in the multiply call.

Steve

Lifeng Jin

unread,
Aug 2, 2016, 9:30:50 PM8/2/16
to cusp-users
 I am going to transpose A to make it work. Thank you for your help. Awesome package.
Reply all
Reply to author
Forward
0 new messages