How to use magma_*customspmv in the program?

Open discussion for MAGMA library (Matrix Algebra on GPU and Multicore Architectures)
Post Reply
mikemike10212003
Posts: 10
Joined: Mon Oct 10, 2016 4:47 am

How to use magma_*customspmv in the program?

Post by mikemike10212003 » Tue Nov 07, 2017 2:47 am

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

hartwig anzt
Posts: 90
Joined: Tue Sep 02, 2014 5:44 pm

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

Post by hartwig anzt » Tue Nov 07, 2017 3:22 am

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

mikemike10212003
Posts: 10
Joined: Mon Oct 10, 2016 4:47 am

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

Post by mikemike10212003 » Tue Nov 07, 2017 5:21 am

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

hartwig anzt
Posts: 90
Joined: Tue Sep 02, 2014 5:44 pm

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

Post by hartwig anzt » Tue Nov 07, 2017 5:41 am

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!

mikemike10212003
Posts: 10
Joined: Mon Oct 10, 2016 4:47 am

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

Post by mikemike10212003 » Tue Nov 07, 2017 7:52 am

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

hartwig anzt
Posts: 90
Joined: Tue Sep 02, 2014 5:44 pm

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

Post by hartwig anzt » Sun Nov 12, 2017 11:15 am

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

mikemike10212003
Posts: 10
Joined: Mon Oct 10, 2016 4:47 am

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

Post by mikemike10212003 » Sun Nov 12, 2017 1:56 pm

Dear Hartwig,
Thanks a lot!
Mike

mikemike10212003
Posts: 10
Joined: Mon Oct 10, 2016 4:47 am

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

Post by mikemike10212003 » Sat Jan 20, 2018 4:08 pm

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 37 times
Thanks,
Mike

MokbulHosan48
Posts: 1
Joined: Sun Aug 16, 2015 4:40 pm

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

Post by MokbulHosan48 » Tue Mar 20, 2018 7:43 am

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!

Post Reply