AMGX icon indicating copy to clipboard operation
AMGX copied to clipboard

Can I solve Ax=b1,b2,b3 repeatedly on GPU?

Open ztdepztdep opened this issue 2 years ago • 6 comments

I need to solve a series of Ax=bi,i=1.....N with the matrix A unchanged. while(time<FianalTime) { solve Ax=bi; set bi; if(time=SaveTime) copy x to cpu for further treating } I want to know can i set the bi directly on the GPU without copying data between cpu and gpu.

ztdepztdep avatar May 16 '22 12:05 ztdepztdep

Yes it's a nice pattern from the perspective of performance - you should be able to just upload a new b with AMGX_vector_upload and call AMGX_solver_solve_with_0_guess again. Essentially, if A doesn't change you don't need to repeat the setup phase.

Does b already exist on the GPU? If so you can just pass the device pointer to AmgX and it will do a direct copy from GPU memory to GPU memory.

mattmartineau avatar May 16 '22 12:05 mattmartineau

great. Does AMGX has an example for this operations?

ztdepztdep avatar May 16 '22 12:05 ztdepztdep

You can just repeat steps for each of your data vector: https://github.com/NVIDIA/AMGX/blob/main/examples/amgx_mpi_capi_cla.c#L331 https://github.com/NVIDIA/AMGX/blob/main/examples/amgx_mpi_capi_cla.c#L530 https://github.com/NVIDIA/AMGX/blob/main/examples/amgx_mpi_capi_cla.c#L533 And it should be ready for solver: https://github.com/NVIDIA/AMGX/blob/main/examples/amgx_mpi_capi_cla.c#L545

marsaev avatar May 19 '22 11:05 marsaev

Yes it's a nice pattern from the perspective of performance - you should be able to just upload a new b with AMGX_vector_upload and call AMGX_solver_solve_with_0_guess again. Essentially, if A doesn't change you don't need to repeat the setup phase.

Does b already exist on the GPU? If so you can just pass the device pointer to AmgX and it will do a direct copy from GPU memory to GPU memory.

Hello. I tried to pass the b directly to the "AMGX_solver_solve(solver,b,x)" , but the API only accept the vector handle as parameters.

` //read in A ............. // double *d_values = NULL, *d_x = NULL, *d_b = NULL;

cudaMalloc((void **)&d_x, n * bsize_x * sizeof(double) );

cudaMalloc((void **)&d_b, n * bsize_x * sizeof(double) );

// do something about d_b, d_x;

/* solver setup */

AMGX_solver_setup(solver, A);

/* solver solve */

AMGX_solver_solve(solver, d_b, d_x);`

Could you please give me some suggestions.

ztdepztdep avatar May 21 '22 11:05 ztdepztdep

Try to follow the steps that are done for the d_b vector in the example. In order to copy your values into vector handle you need to do upload: https://github.com/NVIDIA/AMGX/blob/main/examples/amgx_mpi_capi_cla.c#L533

marsaev avatar May 23 '22 22:05 marsaev

Try to follow the steps that are done for the d_b vector in the example. In order to copy your values into vector handle you need to do upload: https://github.com/NVIDIA/AMGX/blob/main/examples/amgx_mpi_capi_cla.c#L533 Thank you very much. the upload works now. Now I want to conduct a download from AMGX solution "x" to the gpu vector "d_b" using the " AMGX_vector_download(x,d_b);" . but it seems nothing has been downloaded from the x. if d_b is located on the cpu, then it can give correct resutls. Could you please give me some advices about how to read the values of x on the gpu.

ztdepztdep avatar Jun 06 '22 05:06 ztdepztdep