Skip to content

Commit

Permalink
Minimize allocs in reference kernel.
Browse files Browse the repository at this point in the history
  • Loading branch information
pratikvn committed Feb 27, 2022
1 parent 2a2a019 commit acd5d7c
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions reference/matrix/csr_kernels.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -637,13 +637,16 @@ void calculate_nonzeros_per_row_in_index_set(
auto row_subset_begin = row_index_set.get_subsets_begin();
auto row_subset_end = row_index_set.get_subsets_end();
auto src_ptrs = source->get_const_row_ptrs();
size_type max_row_nnz = 0;
for (size_type i = 1; i < source->get_size()[0] + 1; i++) {
max_row_nnz =
std::max<size_type>(max_row_nnz, src_ptrs[i] - src_ptrs[i - 1]);
}
Array<IndexType> l_idxs(exec, max_row_nnz);
for (size_type set = 0; set < num_row_subsets; ++set) {
for (size_type row = row_subset_begin[set]; row < row_subset_end[set];
++row) {
row_nnz->get_data()[res_row] = zero<IndexType>();
Array<IndexType> l_idxs(
exec,
static_cast<size_type>(src_ptrs[row + 1] - src_ptrs[row]));
gko::kernels::reference::index_set::global_to_local(
exec, col_index_set.get_size(), col_index_set.get_num_subsets(),
col_index_set.get_subsets_begin(),
Expand Down

0 comments on commit acd5d7c

Please sign in to comment.