Adjustment of chunk_fraction in cusparseSpGEMM

Hi, everyone.

I am using CUDA 12.2, HPC SDK 23.9 environment with CUDA Fortran to do sparse matrix sparse matrix multiplication.

I asked about the compilation problem before in this forum
, and also in the compiler forum, and solved the problem by writing an interface from CUDA C.

My question is, what is chunk_fraction mathematically?
Also, from a programmatic point of view, can I define any value within the range of (0,1]?
Can I save memory with smaller values?

Also, when I compute the matrix product in the github sample code, ALG1 gives buffersize1=1171, buffersize2=5687.

In contrast, for ALG3, chunk_fraction=0.2d0 or 1d0,
buffersize1=1171, buffersize3=37911, buffersize2=43358.
If chunk_fraction is set to 0.01, then
buffersize1=1171, buffersize3=48533271, buffersize2=48538718.

Would using ALG3 result in a smaller buffersize?
Also, is it possible to change the chunk_fraction to use less memory than ALG1?

Thanks.

Hi,
In ALG3, the work is divided into smaller chunks so that when the alg works on each chunk it’ll consume less memory. The chunk_fraction is the proportion of chunk size over the whole amount of work.
The value range of chunk_fraction is (0,1].
When you decrease the chunk_fraction value you’ll reduce used memory. However, there’s a certain amount of memory that we have to have regardless to the chunk_ratio, so you can’t lower the memory usage up to that point even when chunk_ratio → 0.
ALG3 is designed for very large SpGEMM that needs a lot of memory. For small matrices like in sample code, ALG3 won’t show its memory saving ability.

Thanks, @qanhpham .

I understand that the memory savings will not be effective for small sized matrices.

So I tried to compute a double precision matrix product of (44954,1136491)*(1136491,44954) with ALG3, chunk_fraction=1d-5.
The machine used is an NVIDIA A100 80GB.

This resulted in an error:7 on the second cusparseSpGEMM_estimateMemory.
What is the cause of this?

Thanks.

Hi,
What are the nnz of matrix A and B in your case?
What’s the number of products in this SpGEMM? You can get this number by calling cusparseSpGEMM_getNumProducts after calling cusparseSpGEMM_workEstimation (example).
Can you test with a higher chunk_fraction value, say 0.1?

Hi, @qanhpham !

The matrix A & B for that case is as follows :

A_rows        44954 A_cols      1136491 A_nnz      1136491
B_rows      1136491 B_cols        44954 B_nnz     13881459

And The parameters of SpGEMM are as follows :

chunk=   0.1000000000000000
bufferSize1=                 13659179
num_prods  =                  4019714
bufferSize3=                   335375

I set the chunk to 0.1 and got error:7 on the second estimatememory as well.

Thanks.

Hi.
The matrices look normal. The num_prods isn’t too high. Can you run with ALG1 and ALG2?

Hi!
When I try to calculate with ALG1, an error occurs during the second workestimation after calculating buffersize1 during the first workestimation.

bufferSize1=                 13659179
cusparseSpGEMM_workEstimation error:             7

And,

C_nnz=0

So,

 cusparseSpGEMM_copy error:             7

And, the program terminates.

Thanks.

matrix products that cannot be computed in ALG1 cannot be computed in ALG3?

Hi. Sorry for the late reply. Can you send me the input matrices. I’ll investigate the issue.