FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Fix issue 3542: fixed opencl, oneapi, and cuda sparse coo2dense launc… · arrayfire/arrayfire@989b71b · GitHub

Repository navigation

Commit 989b71b

Browse files
authored
Fix issue 3542: fixed opencl, oneapi, and cuda sparse coo2dense launch dimensions (#3583)
1 parent 90b27ac commit 989b71b

5 files changed

Lines changed: 21 additions & 28 deletions

File tree

‎src/backend/cuda/kernel/sparse.cuh‎

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,13 @@ namespace cuda {
1717
template<typename T>
1818
__global__ void coo2Dense(Param<T> output, CParam<T> values, CParam<int> rowIdx,
1919
CParam<int> colIdx) {
20-
int id = blockIdx.x * blockDim.x * reps + threadIdx.x;
21-
if (id >= values.dims[0]) return;
20+
for (int i = threadIdx.x; i < reps * blockDim.x; i += blockDim.x) {
21+
int id = i + blockIdx.x * blockDim.x * reps;
22+
if (id >= values.dims[0]) return;
2223

23-
for (int i = threadIdx.x; i <= reps * blockDim.x; i += blockDim.x) {
24-
if (i >= values.dims[0]) return;
25-
26-
T v = values.ptr[i];
27-
int r = rowIdx.ptr[i];
28-
int c = colIdx.ptr[i];
24+
T v = values.ptr[id];
25+
int r = rowIdx.ptr[id];
26+
int c = colIdx.ptr[id];
2927

3028
int offset = r + c * output.strides[1];
3129

‎src/backend/cuda/kernel/sparse.hpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ void coo2dense(Param<T> output, CParam<T> values, CParam<int> rowIdx,
3030

3131
dim3 threads(256, 1, 1);
3232

33-
dim3 blocks(divup(output.dims[0], threads.x * reps), 1, 1);
33+
dim3 blocks(divup(values.dims[0], threads.x * reps), 1, 1);
3434

3535
EnqueueArgs qArgs(blocks, threads, getActiveStream());
3636

‎src/backend/oneapi/kernel/sparse.hpp‎

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,19 +47,16 @@ class coo2DenseCreateKernel {
4747
void operator()(sycl::nd_item<2> it) const {
4848
sycl::group g = it.get_group();
4949

50-
const int id = g.get_group_id(0) * g.get_local_range(0) * REPEAT +
51-
it.get_local_id(0);
52-
53-
if (id >= values_.dims[0]) return;
54-
5550
const int dimSize = g.get_local_range(0);
5651

5752
for (int i = it.get_local_id(0); i < REPEAT * dimSize; i += dimSize) {
58-
if (i >= values_.dims[0]) return;
53+
const int id =
54+
g.get_group_id(0) * g.get_local_range(0) * REPEAT + i;
55+
if (id >= values_.dims[0]) return;
5956

60-
T v = vPtr_[i];
61-
int r = rPtr_[i];
62-
int c = cPtr_[i];
57+
T v = vPtr_[id];
58+
int r = rPtr_[id];
59+
int c = cPtr_[id];
6360

6461
int offset = r + c * output_.strides[1];
6562

@@ -83,7 +80,7 @@ void coo2dense(Param<T> out, const Param<T> values, const Param<int> rowIdx,
8380
const Param<int> colIdx) {
8481
auto local = sycl::range(THREADS_PER_BLOCK, 1);
8582
auto global = sycl::range(
86-
divup(out.info.dims[0], local[0] * REPEAT) * THREADS_PER_BLOCK, 1);
83+
divup(values.info.dims[0], local[0] * REPEAT) * THREADS_PER_BLOCK, 1);
8784

8885
getQueue().submit([&](auto &h) {
8986
sycl::accessor d_rowIdx{*rowIdx.data, h, sycl::read_only};

‎src/backend/opencl/kernel/coo2dense.cl‎

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,15 @@ kernel void coo2Dense(global T *oPtr, const KParam output, global const T *vPtr,
1111
const KParam values, global const int *rPtr,
1212
const KParam rowIdx, global const int *cPtr,
1313
const KParam colIdx) {
14-
const int id = get_group_id(0) * get_local_size(0) * reps + get_local_id(0);
15-
16-
if (id >= values.dims[0]) return;
17-
1814
const int dimSize = get_local_size(0);
1915

2016
for (int i = get_local_id(0); i < reps * dimSize; i += dimSize) {
21-
if (i >= values.dims[0]) return;
17+
const int id = i + get_group_id(0) * dimSize * reps;
18+
if (id >= values.dims[0]) return;
2219

23-
T v = vPtr[i];
24-
int r = rPtr[i];
25-
int c = cPtr[i];
20+
T v = vPtr[id];
21+
int r = rPtr[id];
22+
int c = cPtr[id];
2623

2724
int offset = r + c * output.strides[1];
2825

‎src/backend/opencl/kernel/sparse.hpp‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ void coo2dense(Param out, const Param values, const Param rowIdx,
4949
cl::NDRange local(THREADS_PER_GROUP, 1, 1);
5050

5151
cl::NDRange global(
52-
divup(out.info.dims[0], local[0] * REPEAT) * THREADS_PER_GROUP, 1, 1);
52+
divup(values.info.dims[0], local[0] * REPEAT) * THREADS_PER_GROUP, 1,
53+
1);
5354

5455
coo2dense(cl::EnqueueArgs(getQueue(), global, local), *out.data, out.info,
5556
*values.data, values.info, *rowIdx.data, rowIdx.info,

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL