The implementation for the challenge is the sparse_multiply function in challenge.c.
It is somewhat of a straightforward implementation of muliplication of 2 matrices after transforming a sparse matrix into its Compressed Sparse Row form, by parsing each element of the matrix. After that it is a simple row by row multiplication with the given column matrix.
This program is a very simple implementation. However we ideally need to implement the RISC-V Vector extended version of the same. This can be done by using RVV C-intrinsics.
c
// Perform multiplication of non-sparse elements of the matrix
for (int cur_row = 0; cur_row < rows; cur_row++) {
y[cur_row] = 0;
int row_start = row_ptrs[cur_row];
int row_end = row_ptrs[cur_row + 1];
for (int i = row_start; i < row_end; i++) {
y[cur_row] += values[i] * x[col_indices[i]];
}
}
This part of the function can be accelerated, where instead of doing each multiplication one after another, we can parallely do multiple multiplications.
We can simultaneously load vl number of values from the CSR matrix row and X matrix column, into ALU registers, and simultaneously perform those many multiplications. For very large matrices this would happen in multiple iterations until all values are multiplied and summed up with each other.