Commit b449b0bf authored by Ilya Lavrenov's avatar Ilya Lavrenov

simplified cv::sepFilter2D OpenCL part

parent 82e6edfb
This diff is collapsed.
...@@ -36,16 +36,6 @@ ...@@ -36,16 +36,6 @@
#define READ_TIMES_COL ((2*(RADIUSY+LSIZE1)-1)/LSIZE1) #define READ_TIMES_COL ((2*(RADIUSY+LSIZE1)-1)/LSIZE1)
#define RADIUS 1 #define RADIUS 1
#if CN ==1
#define ALIGN (((RADIUS)+3)>>2<<2)
#elif CN==2
#define ALIGN (((RADIUS)+1)>>1<<1)
#elif CN==3
#define ALIGN (((RADIUS)+3)>>2<<2)
#elif CN==4
#define ALIGN (RADIUS)
#define READ_TIMES_ROW ((2*(RADIUS+LSIZE0)-1)/LSIZE0)
#endif
#define noconvert #define noconvert
...@@ -65,16 +55,8 @@ The info above maybe obsolete. ...@@ -65,16 +55,8 @@ The info above maybe obsolete.
#define DIG(a) a, #define DIG(a) a,
__constant float mat_kernel[] = { COEFF }; __constant float mat_kernel[] = { COEFF };
__kernel __attribute__((reqd_work_group_size(LSIZE0,LSIZE1,1))) void col_filter __kernel void col_filter(__global const srcT * src, int src_step_in_pixel, int src_whole_cols, int src_whole_rows,
(__global const GENTYPE_SRC * restrict src, __global dstT * dst, int dst_offset_in_pixel, int dst_step_in_pixel, int dst_cols, int dst_rows)
const int src_step_in_pixel,
const int src_whole_cols,
const int src_whole_rows,
__global GENTYPE_DST * dst,
const int dst_offset_in_pixel,
const int dst_step_in_pixel,
const int dst_cols,
const int dst_rows)
{ {
int x = get_global_id(0); int x = get_global_id(0);
int y = get_global_id(1); int y = get_global_id(1);
...@@ -85,35 +67,35 @@ __kernel __attribute__((reqd_work_group_size(LSIZE0,LSIZE1,1))) void col_filter ...@@ -85,35 +67,35 @@ __kernel __attribute__((reqd_work_group_size(LSIZE0,LSIZE1,1))) void col_filter
int start_addr = mad24(y, src_step_in_pixel, x); int start_addr = mad24(y, src_step_in_pixel, x);
int end_addr = mad24(src_whole_rows - 1, src_step_in_pixel, src_whole_cols); int end_addr = mad24(src_whole_rows - 1, src_step_in_pixel, src_whole_cols);
int i; srcT sum, temp[READ_TIMES_COL];
GENTYPE_SRC sum, temp[READ_TIMES_COL]; __local srcT LDS_DAT[LSIZE1 * READ_TIMES_COL][LSIZE0 + 1];
__local GENTYPE_SRC LDS_DAT[LSIZE1 * READ_TIMES_COL][LSIZE0 + 1];
//read pixels from src // read pixels from src
for(i = 0;i<READ_TIMES_COL;i++) for (int i = 0; i < READ_TIMES_COL; ++i)
{ {
int current_addr = start_addr+i*LSIZE1*src_step_in_pixel; int current_addr = mad24(i, LSIZE1 * src_step_in_pixel, start_addr);
current_addr = current_addr < end_addr ? current_addr : 0; current_addr = current_addr < end_addr ? current_addr : 0;
temp[i] = src[current_addr]; temp[i] = src[current_addr];
} }
//save pixels to lds
for(i = 0;i<READ_TIMES_COL;i++) // save pixels to lds
{ for (int i = 0; i < READ_TIMES_COL; ++i)
LDS_DAT[l_y+i*LSIZE1][l_x] = temp[i]; LDS_DAT[mad24(i, LSIZE1, l_y)][l_x] = temp[i];
}
barrier(CLK_LOCAL_MEM_FENCE); barrier(CLK_LOCAL_MEM_FENCE);
//read pixels from lds and calculate the result
sum = LDS_DAT[l_y+RADIUSY][l_x]*mat_kernel[RADIUSY]; // read pixels from lds and calculate the result
for(i=1;i<=RADIUSY;i++) sum = LDS_DAT[l_y + RADIUSY][l_x] * mat_kernel[RADIUSY];
for (int i = 1; i <= RADIUSY; ++i)
{ {
temp[0]=LDS_DAT[l_y+RADIUSY-i][l_x]; temp[0] = LDS_DAT[l_y + RADIUSY - i][l_x];
temp[1]=LDS_DAT[l_y+RADIUSY+i][l_x]; temp[1] = LDS_DAT[l_y + RADIUSY + i][l_x];
sum += temp[0] * mat_kernel[RADIUSY-i]+temp[1] * mat_kernel[RADIUSY+i]; sum += mad(temp[0], mat_kernel[RADIUSY - i], temp[1] * mat_kernel[RADIUSY + i]);
} }
//write the result to dst
if((x<dst_cols) & (y<dst_rows)) // write the result to dst
if (x < dst_cols && y < dst_rows)
{ {
start_addr = mad24(y, dst_step_in_pixel, x + dst_offset_in_pixel); start_addr = mad24(y, dst_step_in_pixel, x + dst_offset_in_pixel);
dst[start_addr] = convert_to_DST(sum); dst[start_addr] = convertToDstT(sum);
} }
} }
This diff is collapsed.
...@@ -75,6 +75,7 @@ ...@@ -75,6 +75,7 @@
#endif #endif
#define SRC(_x,_y) convertToWT(((global srcT*)(Src+(_y)*src_step))[_x]) #define SRC(_x,_y) convertToWT(((global srcT*)(Src+(_y)*src_step))[_x])
#define DST(_x,_y) (((global dstT*)(Dst+dst_offset+(_y)*dst_step))[_x])
#ifdef BORDER_CONSTANT #ifdef BORDER_CONSTANT
// CCCCCC|abcdefgh|CCCCCCC // CCCCCC|abcdefgh|CCCCCCC
...@@ -83,8 +84,6 @@ ...@@ -83,8 +84,6 @@
#define ELEM(_x,_y,r_edge,t_edge,const_v) SRC((_x),(_y)) #define ELEM(_x,_y,r_edge,t_edge,const_v) SRC((_x),(_y))
#endif #endif
#define DST(_x,_y) (((global dstT*)(Dst+dst_offset+(_y)*dst_step))[_x])
#define noconvert #define noconvert
// horizontal and vertical filter kernels // horizontal and vertical filter kernels
...@@ -101,15 +100,15 @@ __kernel void sep_filter(__global uchar* Src, int src_step, int srcOffsetX, int ...@@ -101,15 +100,15 @@ __kernel void sep_filter(__global uchar* Src, int src_step, int srcOffsetX, int
// all these should be defined on host during compile time // all these should be defined on host during compile time
// first lsmem array for source pixels used in first pass, // first lsmem array for source pixels used in first pass,
// second lsmemDy for storing first pass results // second lsmemDy for storing first pass results
__local WT lsmem[BLK_Y+2*RADIUSY][BLK_X+2*RADIUSX]; __local WT lsmem[BLK_Y + 2 * RADIUSY][BLK_X + 2 * RADIUSX];
__local WT lsmemDy[BLK_Y][BLK_X+2*RADIUSX]; __local WT lsmemDy[BLK_Y][BLK_X + 2 * RADIUSX];
// get local and global ids - used as image and local memory array indexes // get local and global ids - used as image and local memory array indexes
int lix = get_local_id(0); int lix = get_local_id(0);
int liy = get_local_id(1); int liy = get_local_id(1);
int x = (int)get_global_id(0); int x = get_global_id(0);
int y = (int)get_global_id(1); int y = get_global_id(1);
// calculate pixel position in source image taking image offset into account // calculate pixel position in source image taking image offset into account
int srcX = x + srcOffsetX - RADIUSX; int srcX = x + srcOffsetX - RADIUSX;
......
...@@ -79,12 +79,14 @@ PARAM_TEST_CASE(SepFilter2D, MatDepth, Channels, BorderType, bool, bool) ...@@ -79,12 +79,14 @@ PARAM_TEST_CASE(SepFilter2D, MatDepth, Channels, BorderType, bool, bool)
ksize.width++; ksize.width++;
if (1 != (ksize.height % 2)) if (1 != (ksize.height % 2))
ksize.height++; ksize.height++;
Mat temp = randomMat(Size(ksize.width, 1), CV_MAKE_TYPE(CV_32F, 1), -MAX_VALUE, MAX_VALUE); Mat temp = randomMat(Size(ksize.width, 1), CV_MAKE_TYPE(CV_32F, 1), -MAX_VALUE, MAX_VALUE);
cv::normalize(temp, kernelX, 1.0, 0.0, NORM_L1); cv::normalize(temp, kernelX, 1.0, 0.0, NORM_L1);
temp = randomMat(Size(1, ksize.height), CV_MAKE_TYPE(CV_32F, 1), -MAX_VALUE, MAX_VALUE); temp = randomMat(Size(1, ksize.height), CV_MAKE_TYPE(CV_32F, 1), -MAX_VALUE, MAX_VALUE);
cv::normalize(temp, kernelY, 1.0, 0.0, NORM_L1); cv::normalize(temp, kernelY, 1.0, 0.0, NORM_L1);
Size roiSize = randomSize(ksize.width, MAX_VALUE, ksize.height, MAX_VALUE); Size roiSize = randomSize(ksize.width + 16, MAX_VALUE, ksize.height + 20, MAX_VALUE);
std::cout << roiSize << std::endl;
int rest = roiSize.width % 4; int rest = roiSize.width % 4;
if (0 != rest) if (0 != rest)
roiSize.width += (4 - rest); roiSize.width += (4 - rest);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment