Showing results for

- Intel Community
- Software
- Software Development SDKs and Libraries
- Intel® oneAPI Math Kernel Library
- Return mkl_sparse_spmm Results?

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

cui__zhihao

Beginner

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

09-20-2018
01:11 AM

68 Views

Return mkl_sparse_spmm Results?

Hi all,

I am trying to use mkl_sparse_spmm **in a function**, to calculate C = A*B, where A, B, C are in CSR format.

I would like to return the information of C, i.e. rowIndex_C, column_C and values_C through the pointers that I passed to the function arguments.

However, it looks like only within the function, the info of C exists. When I try to print values_C outside of the function, the pointer seems to be NULL. It looks like that the memory is allocated by mkl_sparse_d_export_csr within the function, but no longer exists after the function call.

Here is the function:

void spmm(int M, int N, int K, int* rowIndex_A, int* columns_A, double* values_A, int* rowIndex_B, int* columns_B, double* values_B, int* pointerB_C, int* pointerE_C, int* columns_C, double* values_C){ int rows, cols; sparse_index_base_t indexing; sparse_matrix_t csrA = NULL, csrB = NULL, csrC = NULL; mkl_sparse_d_create_csr( &csrA, SPARSE_INDEX_BASE_ZERO, M, K, rowIndex_A, rowIndex_A+1, columns_A, values_A ); mkl_sparse_d_create_csr( &csrB, SPARSE_INDEX_BASE_ZERO, K, N, rowIndex_B, rowIndex_B+1, columns_B, values_B ); mkl_sparse_spmm( SPARSE_OPERATION_NON_TRANSPOSE, csrA, csrB, &csrC ); mkl_sparse_d_export_csr( csrC, &indexing, &rows, &cols, &pointerB_C, &pointerE_C, &columns_C, &values_C ) mkl_sparse_destroy( csrA ); mkl_sparse_destroy( csrB ); mkl_sparse_destroy( csrC ); }

Any suggestions on solving this issue? Thanks a lot! A relevant question is how to use spmm in python/scipy, which is purpose why I wrote such a function.

Best,

Zhihao

Link Copied

2 Replies

MariaZh

Employee

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

09-21-2018
12:11 PM

68 Views

Hi,

The memory for csrC and for the CSR representation, that you want to return (i.e. pointerB_C, pointerE_C, columns_C, values_C) is indeed allocated inside the mkl_sparse_spmm() routine.

In order to use the data outside of spmm() function, you should go with the next interface, using double pointers for C data:

void spmm(int M, int N, int K, int* rowIndex_A, int* columns_A, double* values_A, int* rowIndex_B, int* columns_B, double* values_B, int** pointerB_C, int** pointerE_C, int** columns_C, double** values_C)

Hope, this will help!

Best regards,

Maria

cui__zhihao

Beginner

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

09-21-2018
01:39 PM

68 Views

Zhukova, Maria (Intel) wrote:

Hi,

The memory for csrC and for the CSR representation, that you want to return (i.e. pointerB_C, pointerE_C, columns_C, values_C) is indeed allocated inside the mkl_sparse_spmm() routine.

In order to use the data outside of spmm() function, you should go with the next interface, using double pointers for C data:

void spmm(int M, int N, int K, int* rowIndex_A, int* columns_A, double* values_A, int* rowIndex_B, int* columns_B, double* values_B, int** pointerB_C, int** pointerE_C, int** columns_C, double** values_C)Hope, this will help!

Best regards,

Maria

Thanks for your reply, it works. The only question in Python side is that you have to free the memory by hand in this case. Is there already some API for MKL Sparse Blas in Python?

Best,

Zhihao

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

For more complete information about compiler optimizations, see our Optimization Notice.