Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions src/backend/opencl/kernel/csr2dense.cl
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,16 @@

kernel void csr2Dense(global T *output, global const T *values,
global const int *rowidx, global const int *colidx,
const int M) {
const int M, const int v_off, const int r_off, const int c_off) {
T *v = values + v_off;
int *r = rowidx + r_off;
int *c = colidx + c_off;
int lid = get_local_id(0);
for (int rowId = get_group_id(0); rowId < M; rowId += get_num_groups(0)) {
int colStart = rowidx[rowId];
int colEnd = rowidx[rowId + 1];
int colStart = r[rowId];
int colEnd = r[rowId + 1];
for (int colId = colStart + lid; colId < colEnd; colId += THREADS) {
output[rowId + colidx[colId] * M] = values[colId];
output[rowId + c[colId] * M] = v[colId];
}
}
}
5 changes: 4 additions & 1 deletion src/backend/opencl/kernel/sparse.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,10 @@ void csr2dense(Param output, const Param values, const Param rowIdx,
cl::NDRange global(local[0] * groups_x, 1);

csr2dense(cl::EnqueueArgs(getQueue(), global, local), *output.data,
*values.data, *rowIdx.data, *colIdx.data, M);
*values.data, *rowIdx.data, *colIdx.data, M,
static_cast<int>(values.info.offset),
static_cast<int>(rowIdx.info.offset),
static_cast<int>(colIdx.info.offset));
CL_DEBUG_FINISH(getQueue());
}

Expand Down
21 changes: 21 additions & 0 deletions test/sparse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ using af::dtype_traits;
using af::identity;
using af::randu;
using af::span;
using af::seq;

#define SPARSE_TESTS(T, eps) \
TEST(Sparse, T##Square) { sparseTester<T>(1000, 1000, 100, 5, eps); } \
Expand Down Expand Up @@ -109,6 +110,26 @@ TEST(Sparse, ISSUE_1745) {
row_idx.get(), col_idx.get(), AF_STORAGE_CSR));
}

TEST(Sparse, ISSUE_1918) {
array reference(2,2);
reference(0, span) = 0;
reference(1, span) = 2;
array output;
float value[] = { 1, 1, 2, 2 };
int index[] = { -1, 1, 2 };
int row[] = { 0, 2, 2, 0, 0, 2 };
int col[] = { 0, 1, 0, 1 };
array values(4, 1, value, afHost);
array rows(6, 1, row, afHost);
array cols(4, 1, col, afHost);
array S;

S = sparse(2, 2, values(seq(2, 3)), rows(seq(3, 5)), cols(seq(2, 3)));
output = dense(S);

ASSERT_ARRAYS_EQ(reference, output);
}

TEST(Sparse, ISSUE_2134_COO) {
int rows[] = {0, 0, 0, 1, 1, 2, 2};
int cols[] = {0, 1, 2, 0, 1, 0, 2};
Expand Down