aboutsummaryrefslogtreecommitdiff
path: root/nerv/lib/matrix/generic/cukernel.cu
diff options
context:
space:
mode:
authorcloudygoose <cloudygooseg@gmail.com>2015-07-08 08:54:01 +0800
committercloudygoose <cloudygooseg@gmail.com>2015-07-08 08:54:01 +0800
commit72acf24e248cca7d69658d02939f99d57d02e9a9 (patch)
tree0c7e41df72957ee40998503160f9576f1da381a2 /nerv/lib/matrix/generic/cukernel.cu
parente599ae7524e0e21e2266f2419555865388bded40 (diff)
added matrix:clip, TODO:testing
Diffstat (limited to 'nerv/lib/matrix/generic/cukernel.cu')
-rw-r--r--nerv/lib/matrix/generic/cukernel.cu22
1 files changed, 22 insertions, 0 deletions
diff --git a/nerv/lib/matrix/generic/cukernel.cu b/nerv/lib/matrix/generic/cukernel.cu
index 6111193..e337798 100644
--- a/nerv/lib/matrix/generic/cukernel.cu
+++ b/nerv/lib/matrix/generic/cukernel.cu
@@ -213,6 +213,18 @@ __global__ void cudak_(fill)(MATRIX_ELEM *a,
a[j + i * stride] = val;
}
+__global__ void cudak_(clip)(MATRIX_ELEM *a,
+ int nrow, int ncol, int stride, double val_1, double val_2) {
+ int j = blockIdx.x * blockDim.x + threadIdx.x;
+ int i = blockIdx.y * blockDim.y + threadIdx.y;
+ if (i >= nrow || j >= ncol) return;
+ if (a[j + i * stride] > val_2)
+ a[j + i * stride] = val_2;
+ else
+ if (a[j + i * stride] < val_1)
+ a[j + i * stride] = val_1;
+}
+
__global__ void cudak_(expand_frm)(const MATRIX_ELEM *a, MATRIX_ELEM *b,
int nrow, int ncol,
int enrow, int encol,
@@ -510,6 +522,16 @@ extern "C" {
cudaStreamSynchronize(0);
}
+ void cudak_(cuda_clip)(Matrix *a, double val_1, double val_2) {
+ dim3 threadsPerBlock(CUDA_THREADS_N, CUDA_THREADS_N);
+ dim3 numBlocks(CEIL_DIV(a->ncol, threadsPerBlock.x),
+ CEIL_DIV(a->nrow, threadsPerBlock.y));
+ cudak_(clip)<<<numBlocks, threadsPerBlock>>> \
+ (MATRIX_ELEM_PTR(a), a->nrow, a->ncol,
+ a->stride / sizeof(MATRIX_ELEM), val_1, val_2);
+ cudaStreamSynchronize(0);
+ }
+
void cudak_(cuda_expand_frm)(const Matrix *a, Matrix *b, int context) {
dim3 threadsPerBlock(CUDA_THREADS_N, CUDA_THREADS_N);
dim3 numBlocks(CEIL_DIV(b->ncol, threadsPerBlock.x),