summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortxh18 <[email protected]>2015-12-11 21:43:55 +0800
committertxh18 <[email protected]>2015-12-11 21:43:55 +0800
commit28bb2edd5ee81688f245cc89f872150db1e01e44 (patch)
treefcc74fd60db6aa99f6e483ae0d6e6dd35471a45d
parent7fd5c2c8672c8ac75348e2d51f56a72b5fd21b7b (diff)
bug fix: added check in the select_linear kernel
-rw-r--r--nerv/lib/matrix/generic/cukernel.cu17
1 files changed, 12 insertions, 5 deletions
diff --git a/nerv/lib/matrix/generic/cukernel.cu b/nerv/lib/matrix/generic/cukernel.cu
index aa830b5..552f7a4 100644
--- a/nerv/lib/matrix/generic/cukernel.cu
+++ b/nerv/lib/matrix/generic/cukernel.cu
@@ -263,11 +263,14 @@ __global__ void cudak_(clip)(MATRIX_ELEM *a,
#ifdef __NERV_FUTURE_CUDA_7
__global__ void cudak_(update_select_rows)(MATRIX_ELEM *c, const MATRIX_ELEM *a, const MATRIX_ELEM *idx,
- int nrow_a, int ncol_a, int stride_c, int stride_a, double alpha, double beta) {
+ int nrow_a, int ncol_a, int nrow_c, int stride_c, int stride_a, double alpha, double beta) {
int j = blockIdx.x * blockDim.x + threadIdx.x;
int i = blockIdx.y * blockDim.y + threadIdx.y;
if (i >= nrow_a || j >= ncol_a) return;
int i_c = lrintf(idx[i]);
+ if (i_c < 0 || i_c >= nrow_c) {
+ printf("ERROR inside kernel update_select_rows, i_c(%d) out of range!", i_c);
+ }
//critical: i_c could conflict among threads(same index in the idx array), so atomicAdd is used
//c[j + i_c * stride_c] = c[j + i_c * stride_c] * (1 - beta * alpha) + a[j + i * stride_a] * alpha;
atomicAdd_nvidia(c + j + i_c * stride_c, c[j + i_c * stride_c] * (- beta * alpha) + a[j + i * stride_a] * alpha);
@@ -335,11 +338,15 @@ __global__ void cudak_(gen_col_idx)(MATRIX_ELEM *b,
__global__ void cudak_(copy_rows_by_idx)(const MATRIX_ELEM *a, MATRIX_ELEM *b,
const MATRIX_ELEM *idx,
- int nrow, int ncol, int stride) {
+ int nrow, int ncol, int a_nrow, int stride) {
int j = blockIdx.x * blockDim.x + threadIdx.x;
int i = blockIdx.y * blockDim.y + threadIdx.y;
if (i >= nrow || j >= ncol) return;
- b[j + i * stride] = a[j + lrintf(idx[i]) * stride];
+ int k = lrintf(idx[i]);
+ if (k < 0 || k >= a_nrow) {
+ printf("error in kernel copy_rows_by_idx k(%d) out of range\n", k);
+ }
+ b[j + i * stride] = a[j + k * stride];
}
extern "C" {
@@ -639,7 +646,7 @@ extern "C" {
CEIL_DIV(a->nrow, threadsPerBlock.y));
cudak_(update_select_rows)<<<numBlocks, threadsPerBlock>>> \
(MATRIX_ELEM_PTR(c), MATRIX_ELEM_PTR(a), MATRIX_ELEM_PTR(idx),
- a->nrow, a->ncol, c->stride / sizeof(MATRIX_ELEM),
+ a->nrow, a->ncol, c->nrow, c->stride / sizeof(MATRIX_ELEM),
a->stride / sizeof(MATRIX_ELEM), alpha, beta);
cudaStreamSynchronize(0);
}
@@ -710,7 +717,7 @@ extern "C" {
cudak_(copy_rows_by_idx)<<<numBlocks, threadsPerBlock>>> \
(MATRIX_ELEM_PTR(a), MATRIX_ELEM_PTR(b),
MATRIX_ELEM_PTR(idx) + idx_begin,
- b->nrow, b->ncol, b->stride / sizeof(MATRIX_ELEM));
+ b->nrow, b->ncol, a->nrow, b->stride / sizeof(MATRIX_ELEM));
cudaStreamSynchronize(0);
}
}