Page 1 of 1

How to use magma_*customspmv in the program?

Posted: Tue Nov 07, 2017 2:47 am
by mikemike10212003
Dear all,
magma_*customspmv give me to use a custom function to calculate spmv.
Do I need to edit the file "magma_*customspmv.cpp" to implement the function and recompile magma library?
Is there any more convenient method to achieve it?
Can I use two different custom spmv methods in one program?

Thanks,
Mike

Re: How to use magma_*customspmv in the program?

Posted: Tue Nov 07, 2017 3:22 am
by hartwig anzt
Dear Mike,
magma_*customspmv.cpp currently does nothing. The idea is that there you call your function.
Assume you have you awesome spmv library. Then, you add in this file:

#include awesome_spmv.h
...
awesome_spmv( alpha, A x, beta, b, );

Does this make sense?
Thanks, Hartwig

Re: How to use magma_*customspmv in the program?

Posted: Tue Nov 07, 2017 5:21 am
by mikemike10212003
Dear Hartwig,

Sorry about the unclear declaration.
The wrapper of BLAS will use the magma_*customspmv when the storage_type is Magma_SPMVFUNCTION.
I also want to use the CG solver of MAGMA on the custom spmv function.
Thus, I think I can not just build a new function.

Thanks,
Mike

Re: How to use magma_*customspmv in the program?

Posted: Tue Nov 07, 2017 5:41 am
by hartwig anzt
Mike,
I am not sure I understand correctly. You can use any SpMV inside the CG solver, the solver does not imply any restrictions on the matrix storage format or SpMV kernel.
Please specify.
Thanks!

Re: How to use magma_*customspmv in the program?

Posted: Tue Nov 07, 2017 7:52 am
by mikemike10212003
Dear Hartwig,
According to your first reply, I need to add awesome_spmv into magma_*customspmv.cpp.
And set magma_*_matrix type as the Magma_SPMVFUNCTION.
And I can use some routine like CG as I did before.
By doing so, I can not use two different spmv methods at the same time.
Is that correct?

Thanks,
Mike

Re: How to use magma_*customspmv in the program?

Posted: Sun Nov 12, 2017 11:15 am
by hartwig anzt
Mike,
sorry for late reply!
I think I do know what you mean now: you have two spmv kernels: spmv1 and spmv2, and you want to use them inside CG, time it, quickly switch between them. This would require recompiling magma-sparse.
So, yes, unfortunately it is currently not possible to use multiple SpMV at a time.
The only workaround I currently see is to define a second CUSTOMSPMV, but you would then have to introduce this into the magma_z_blaswrapper.cpp.
I will make sure we provide this possibility in future!
Thanks, Hartwig

Re: How to use magma_*customspmv in the program?

Posted: Sun Nov 12, 2017 1:56 pm
by mikemike10212003
Dear Hartwig,
Thanks a lot!
Mike

Re: How to use magma_*customspmv in the program?

Posted: Sat Jan 20, 2018 4:08 pm
by mikemike10212003
Dear Hartwig,

I use the function pointer to handle these things.
I also add Magma_USERSPMV = 633 in magma_storage_t and Magma_USERPRECOND = 430 in magma_solver_type for using them in wrapper.
USERSPMV will use userkernel to store the variables and userspmv to get the function.
USERPRECOND will also userkernel to store the variables and applyuserprecond_l, applyuserprecond_l_t, applyuserprecond_r, and applyuserprecond_r_t to get the functions.

For using USERSPMV,
Define some structures and some functions whose types are same as those in magma_*_spmv in program.
magma_*_matrix A;
A.userkernel = (void*) &kernel; // users define own structures
A.userspmv = &spmv; // spmv types are same as magma_*_spmv's.
A.storage_type = Magma_USERSPMV;
magma_*_spmv(..., A, ....); // it will run the user's spmv.
// magma_*userspmv(..., A, ...); // it is also okay.
Using the user preconditioner is similar.

The original file (sparse/blas/magma_z_blaswrapper.cpp) might be wrong.
I also do other changes besides the userspmv.
Add the "}" between line 211 and line 212, and delete the first "}" in line 226 or line 225 for Magma_CSC spmv (multiple vectors).
is it correct?

The attachments include the files I changed and a file for trying USERSPMV. Copy the files in "change" folder into the magma-2.3.0 folder for using them.
adduserfunc.zip
(59.38 KiB) Downloaded 87 times
Thanks,
Mike

Re: How to use magma_*customspmv in the program?

Posted: Tue Mar 20, 2018 7:43 am
by MokbulHosan48
Dear,
I am not sure I understand correctly. You can use any SpMV inside the CG solver, the solver does not imply any restrictions on the matrix storage format or SpMV kernel.
Please specify.
Thanks!