Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

question about storage of coordinate matrix #67

Closed
ghost opened this issue Mar 10, 2014 · 4 comments
Closed

question about storage of coordinate matrix #67

ghost opened this issue Mar 10, 2014 · 4 comments

Comments

@ghost
Copy link

ghost commented Mar 10, 2014

Hello, I need to write a kernel to subtract a sparse coordinate matrix from a dense matrix.
Is there some convention for sorting in the storage of the rows and columns in the mat.handle12() data structure? A small kernel snippet would be great.

@karlrupp
Copy link
Collaborator

Hey,
yes, the (necessary) requirement is that the triplets in the coordinate_matrix are sorted by ascending row index. The best piece of code to look at is the copy() implementation from host to device here:
https://github.com/viennacl/viennacl-dev/blob/master/viennacl/coordinate_matrix.hpp#L47

As you can see, there is also an additional group_boundaries array, which aligns the work for each OpenCL work group such that the different work groups write into distinct parts of the result vector for a sparse matrix-vector multiplication. The implementation for the CPU backend is pretty simple (cf. https://github.com/viennacl/viennacl-dev/blob/master/viennacl/linalg/host_based/sparse_matrix_operations.hpp#L981), but a parallel implementation (CUDA, OpenCL) gets quite involved when one wants to deal with corner cases correctly:
https://github.com/viennacl/viennacl-dev/blob/master/viennacl/linalg/opencl/kernels/coordinate_matrix.hpp#L25
https://github.com/viennacl/viennacl-dev/blob/master/viennacl/linalg/cuda/sparse_matrix_operations.hpp#L1010

@ghost
Copy link
Author

ghost commented Mar 13, 2014

Thanks. How do I pass the vcl_coordinate_matrix.handle12() to my kernel,
if I use viennacl::ocl::enqueue(subtract_sparse_coordinate(vcl_coordinate_matrix)). It automatically takes passes vcl_coordinate_matrix .handle() so I an access the values but not the coords from vcl_coordinate_matrix.handle12().

@karlrupp
Copy link
Collaborator

@ghost
Copy link
Author

ghost commented Mar 13, 2014

Thank you. I thought I looked but not hard enough clearly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant