viennacl / viennacl-dev

Developer repository for ViennaCL. Visit http://viennacl.sourceforge.net/ for the latest releases.
Other
281 stars 89 forks source link

[Tutorial Request] Elementwise Operation #285

Open WenyinWei opened 4 years ago

WenyinWei commented 4 years ago

Hello Karl,

I am looking for the elementwise operation for a quick initialization of matrices on the GPU. And I found that viennacl uses the compile-time definitions to make these functions matrix_operations.hpp, line 701-825 . It is pretty concise, yeah, but it really needs a tutorial or some like that to illustrate how to use these functions. They even do not appear in the doxygen document that new comers would have no idea about how to do the function.

Best wishes, Wenyin

WenyinWei commented 4 years ago

Hello, Karl, @karlrupp I have some trouble while using element_op functions.

When I use the following command to get the element_geq, _greater, _less and etc, I got the result matrix_expression but I don't know how to handle it. I can't impose copy functions to fetch the result back to CPU or do other things. And I have no idea about what it would return, if 1 for geq, 0 for less or -1 for less?

karlrupp commented 4 years ago

Assign it to a matrix object, e.g. A = element_geq(B, C);

WenyinWei commented 4 years ago

2020-02-26 16-28-29 Screenshot Yeah, I have tried, but still stuck by a bug.

I tried to select the binary elementwise functions which can work. element_prod, _div, _pow works, _eq, _neq, _greater, etc. don't work.

2020-02-26 16-42-58 的屏幕截图

karlrupp commented 4 years ago

Uh, then I guess that these other operators have not been implemented for matrices yet.

WenyinWei commented 4 years ago

Uh, Karl, I found that arctan function works well. Maybe that could serve as a temporary workaround, but just temp.

WenyinWei commented 4 years ago

Hello Karl, would you mind requesting the original maintainers to have a minor update? Though atan function serves as a kind of workaround, it sacrifices too much performance.

WenyinWei commented 4 years ago

2020-03-01 16-49-14 的屏幕截图 Here is my test error of viennacl::linalg::element_abs on matrix.

WenyinWei commented 4 years ago

Hello @karlrupp , may I ask about whether viennacl is not maintained anymore and shall I turn to PETSc?

karlrupp commented 4 years ago

As I said, element_abs is not implemented for matrices yet. Thus, this is not a question about maintenance, but a feature request ;-)

Do you need abs for the full matrix, or just for a submatrix? For a full matrix you could reuse the existing vector kernels (I can show you how to do it).

WenyinWei commented 4 years ago

Yeah, Karl, I would appreciate it if you could show me how to do that when you are free. It would be better if the trick is generic for geq and max.