Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Greenplum
Opencv
提交
1a93412e
O
Opencv
项目概览
Greenplum
/
Opencv
大约 1 年 前同步成功
通知
7
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
O
Opencv
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
1a93412e
编写于
12月 17, 2010
作者:
A
Alexey Spizhevoy
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactored bitwise operations in gpu module
上级
74197c5b
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
94 addition
and
30 deletion
+94
-30
modules/gpu/src/cuda/mathfunc.cu
modules/gpu/src/cuda/mathfunc.cu
+94
-30
未找到文件。
modules/gpu/src/cuda/mathfunc.cu
浏览文件 @
1a93412e
...
...
@@ -280,13 +280,19 @@ namespace cv { namespace gpu { namespace mathfunc
enum
{
UN_OP_NOT
};
template
<
typename
T
,
int
opid
>
struct
UnOp
{
__device__
T
operator
()(
T
lhs
,
T
rhs
);
}
;
struct
UnOp
;
template
<
typename
T
>
struct
UnOp
<
T
,
UN_OP_NOT
>
{
__device__
T
operator
()(
T
x
)
{
return
~
x
;
}
};
struct
UnOp
<
T
,
UN_OP_NOT
>
{
static
__device__
T
call
(
T
x
)
{
return
~
x
;
}
};
template
<
typename
T
,
int
cn
,
typename
UnOp
,
typename
Mask
>
__global__
void
bitwise_un_op
(
int
rows
,
int
cols
,
const
PtrStep
src
,
PtrStep
dst
,
UnOp
op
,
Mask
mask
)
__global__
void
bitwise_un_op
(
int
rows
,
int
cols
,
const
PtrStep
src
,
PtrStep
dst
,
Mask
mask
)
{
const
int
x
=
blockDim
.
x
*
blockIdx
.
x
+
threadIdx
.
x
;
const
int
y
=
blockDim
.
y
*
blockIdx
.
y
+
threadIdx
.
y
;
...
...
@@ -298,7 +304,7 @@ namespace cv { namespace gpu { namespace mathfunc
#pragma unroll
for
(
int
i
=
0
;
i
<
cn
;
++
i
)
dsty
[
cn
*
x
+
i
]
=
op
(
srcy
[
cn
*
x
+
i
]);
dsty
[
cn
*
x
+
i
]
=
UnOp
::
call
(
srcy
[
cn
*
x
+
i
]);
}
}
...
...
@@ -309,16 +315,36 @@ namespace cv { namespace gpu { namespace mathfunc
dim3
grid
(
divUp
(
cols
,
threads
.
x
),
divUp
(
rows
,
threads
.
y
));
switch
(
elem_size
)
{
case
1
:
bitwise_un_op
<
unsigned
char
,
1
><<<
grid
,
threads
>>>
(
rows
,
cols
,
src
,
dst
,
UnOp
<
unsigned
char
,
opid
>
(),
mask
);
break
;
case
2
:
bitwise_un_op
<
unsigned
short
,
1
><<<
grid
,
threads
>>>
(
rows
,
cols
,
src
,
dst
,
UnOp
<
unsigned
short
,
opid
>
(),
mask
);
break
;
case
3
:
bitwise_un_op
<
unsigned
char
,
3
><<<
grid
,
threads
>>>
(
rows
,
cols
,
src
,
dst
,
UnOp
<
unsigned
char
,
opid
>
(),
mask
);
break
;
case
4
:
bitwise_un_op
<
unsigned
int
,
1
><<<
grid
,
threads
>>>
(
rows
,
cols
,
src
,
dst
,
UnOp
<
unsigned
int
,
opid
>
(),
mask
);
break
;
case
6
:
bitwise_un_op
<
unsigned
short
,
3
><<<
grid
,
threads
>>>
(
rows
,
cols
,
src
,
dst
,
UnOp
<
unsigned
short
,
opid
>
(),
mask
);
break
;
case
8
:
bitwise_un_op
<
unsigned
int
,
2
><<<
grid
,
threads
>>>
(
rows
,
cols
,
src
,
dst
,
UnOp
<
unsigned
int
,
opid
>
(),
mask
);
break
;
case
12
:
bitwise_un_op
<
unsigned
int
,
3
><<<
grid
,
threads
>>>
(
rows
,
cols
,
src
,
dst
,
UnOp
<
unsigned
int
,
opid
>
(),
mask
);
break
;
case
16
:
bitwise_un_op
<
unsigned
int
,
4
><<<
grid
,
threads
>>>
(
rows
,
cols
,
src
,
dst
,
UnOp
<
unsigned
int
,
opid
>
(),
mask
);
break
;
case
24
:
bitwise_un_op
<
unsigned
int
,
6
><<<
grid
,
threads
>>>
(
rows
,
cols
,
src
,
dst
,
UnOp
<
unsigned
int
,
opid
>
(),
mask
);
break
;
case
32
:
bitwise_un_op
<
unsigned
int
,
8
><<<
grid
,
threads
>>>
(
rows
,
cols
,
src
,
dst
,
UnOp
<
unsigned
int
,
opid
>
(),
mask
);
break
;
case
1
:
bitwise_un_op
<
unsigned
char
,
1
,
UnOp
<
unsigned
char
,
opid
>
><<<
grid
,
threads
>>>
(
rows
,
cols
,
src
,
dst
,
mask
);
break
;
case
2
:
bitwise_un_op
<
unsigned
short
,
1
,
UnOp
<
unsigned
short
,
opid
>
><<<
grid
,
threads
>>>
(
rows
,
cols
,
src
,
dst
,
mask
);
break
;
case
3
:
bitwise_un_op
<
unsigned
char
,
3
,
UnOp
<
unsigned
char
,
opid
>
><<<
grid
,
threads
>>>
(
rows
,
cols
,
src
,
dst
,
mask
);
break
;
case
4
:
bitwise_un_op
<
unsigned
int
,
1
,
UnOp
<
unsigned
int
,
opid
>
><<<
grid
,
threads
>>>
(
rows
,
cols
,
src
,
dst
,
mask
);
break
;
case
6
:
bitwise_un_op
<
unsigned
short
,
3
,
UnOp
<
unsigned
short
,
opid
>
><<<
grid
,
threads
>>>
(
rows
,
cols
,
src
,
dst
,
mask
);
break
;
case
8
:
bitwise_un_op
<
unsigned
int
,
2
,
UnOp
<
unsigned
int
,
opid
>
><<<
grid
,
threads
>>>
(
rows
,
cols
,
src
,
dst
,
mask
);
break
;
case
12
:
bitwise_un_op
<
unsigned
int
,
3
,
UnOp
<
unsigned
int
,
opid
>
><<<
grid
,
threads
>>>
(
rows
,
cols
,
src
,
dst
,
mask
);
break
;
case
16
:
bitwise_un_op
<
unsigned
int
,
4
,
UnOp
<
unsigned
int
,
opid
>
><<<
grid
,
threads
>>>
(
rows
,
cols
,
src
,
dst
,
mask
);
break
;
case
24
:
bitwise_un_op
<
unsigned
int
,
6
,
UnOp
<
unsigned
int
,
opid
>
><<<
grid
,
threads
>>>
(
rows
,
cols
,
src
,
dst
,
mask
);
break
;
case
32
:
bitwise_un_op
<
unsigned
int
,
8
,
UnOp
<
unsigned
int
,
opid
>
><<<
grid
,
threads
>>>
(
rows
,
cols
,
src
,
dst
,
mask
);
break
;
}
if
(
stream
==
0
)
cudaSafeCall
(
cudaThreadSynchronize
());
}
...
...
@@ -338,19 +364,37 @@ namespace cv { namespace gpu { namespace mathfunc
enum
{
BIN_OP_OR
,
BIN_OP_AND
,
BIN_OP_XOR
};
template
<
typename
T
,
int
opid
>
struct
BinOp
{
__device__
T
operator
()(
T
lhs
,
T
rhs
);
}
;
struct
BinOp
;
template
<
typename
T
>
struct
BinOp
<
T
,
BIN_OP_OR
>
{
__device__
T
operator
()(
T
lhs
,
T
rhs
)
{
return
lhs
|
rhs
;
}
};
struct
BinOp
<
T
,
BIN_OP_OR
>
{
static
__device__
T
call
(
T
lhs
,
T
rhs
)
{
return
lhs
|
rhs
;
}
};
template
<
typename
T
>
struct
BinOp
<
T
,
BIN_OP_AND
>
{
__device__
T
operator
()(
T
lhs
,
T
rhs
)
{
return
lhs
&
rhs
;
}
};
struct
BinOp
<
T
,
BIN_OP_AND
>
{
static
__device__
T
call
(
T
lhs
,
T
rhs
)
{
return
lhs
&
rhs
;
}
};
template
<
typename
T
>
struct
BinOp
<
T
,
BIN_OP_XOR
>
{
__device__
T
operator
()(
T
lhs
,
T
rhs
)
{
return
lhs
^
rhs
;
}
};
struct
BinOp
<
T
,
BIN_OP_XOR
>
{
static
__device__
T
call
(
T
lhs
,
T
rhs
)
{
return
lhs
^
rhs
;
}
};
template
<
typename
T
,
int
cn
,
typename
BinOp
,
typename
Mask
>
__global__
void
bitwise_bin_op
(
int
rows
,
int
cols
,
const
PtrStep
src1
,
const
PtrStep
src2
,
PtrStep
dst
,
BinOp
op
,
Mask
mask
)
__global__
void
bitwise_bin_op
(
int
rows
,
int
cols
,
const
PtrStep
src1
,
const
PtrStep
src2
,
PtrStep
dst
,
Mask
mask
)
{
const
int
x
=
blockDim
.
x
*
blockIdx
.
x
+
threadIdx
.
x
;
const
int
y
=
blockDim
.
y
*
blockIdx
.
y
+
threadIdx
.
y
;
...
...
@@ -363,7 +407,7 @@ namespace cv { namespace gpu { namespace mathfunc
#pragma unroll
for
(
int
i
=
0
;
i
<
cn
;
++
i
)
dsty
[
cn
*
x
+
i
]
=
op
(
src1y
[
cn
*
x
+
i
],
src2y
[
cn
*
x
+
i
]);
dsty
[
cn
*
x
+
i
]
=
BinOp
::
call
(
src1y
[
cn
*
x
+
i
],
src2y
[
cn
*
x
+
i
]);
}
}
...
...
@@ -374,16 +418,36 @@ namespace cv { namespace gpu { namespace mathfunc
dim3
grid
(
divUp
(
cols
,
threads
.
x
),
divUp
(
rows
,
threads
.
y
));
switch
(
elem_size
)
{
case
1
:
bitwise_bin_op
<
unsigned
char
,
1
><<<
grid
,
threads
>>>
(
rows
,
cols
,
src1
,
src2
,
dst
,
BinOp
<
unsigned
char
,
opid
>
(),
mask
);
break
;
case
2
:
bitwise_bin_op
<
unsigned
short
,
1
><<<
grid
,
threads
>>>
(
rows
,
cols
,
src1
,
src2
,
dst
,
BinOp
<
unsigned
short
,
opid
>
(),
mask
);
break
;
case
3
:
bitwise_bin_op
<
unsigned
char
,
3
><<<
grid
,
threads
>>>
(
rows
,
cols
,
src1
,
src2
,
dst
,
BinOp
<
unsigned
char
,
opid
>
(),
mask
);
break
;
case
4
:
bitwise_bin_op
<
unsigned
int
,
1
><<<
grid
,
threads
>>>
(
rows
,
cols
,
src1
,
src2
,
dst
,
BinOp
<
unsigned
int
,
opid
>
(),
mask
);
break
;
case
6
:
bitwise_bin_op
<
unsigned
short
,
3
><<<
grid
,
threads
>>>
(
rows
,
cols
,
src1
,
src2
,
dst
,
BinOp
<
unsigned
short
,
opid
>
(),
mask
);
break
;
case
8
:
bitwise_bin_op
<
unsigned
int
,
2
><<<
grid
,
threads
>>>
(
rows
,
cols
,
src1
,
src2
,
dst
,
BinOp
<
unsigned
int
,
opid
>
(),
mask
);
break
;
case
12
:
bitwise_bin_op
<
unsigned
int
,
3
><<<
grid
,
threads
>>>
(
rows
,
cols
,
src1
,
src2
,
dst
,
BinOp
<
unsigned
int
,
opid
>
(),
mask
);
break
;
case
16
:
bitwise_bin_op
<
unsigned
int
,
4
><<<
grid
,
threads
>>>
(
rows
,
cols
,
src1
,
src2
,
dst
,
BinOp
<
unsigned
int
,
opid
>
(),
mask
);
break
;
case
24
:
bitwise_bin_op
<
unsigned
int
,
6
><<<
grid
,
threads
>>>
(
rows
,
cols
,
src1
,
src2
,
dst
,
BinOp
<
unsigned
int
,
opid
>
(),
mask
);
break
;
case
32
:
bitwise_bin_op
<
unsigned
int
,
8
><<<
grid
,
threads
>>>
(
rows
,
cols
,
src1
,
src2
,
dst
,
BinOp
<
unsigned
int
,
opid
>
(),
mask
);
break
;
case
1
:
bitwise_bin_op
<
unsigned
char
,
1
,
BinOp
<
unsigned
char
,
opid
>
><<<
grid
,
threads
>>>
(
rows
,
cols
,
src1
,
src2
,
dst
,
mask
);
break
;
case
2
:
bitwise_bin_op
<
unsigned
short
,
1
,
BinOp
<
unsigned
short
,
opid
>
><<<
grid
,
threads
>>>
(
rows
,
cols
,
src1
,
src2
,
dst
,
mask
);
break
;
case
3
:
bitwise_bin_op
<
unsigned
char
,
3
,
BinOp
<
unsigned
char
,
opid
>
><<<
grid
,
threads
>>>
(
rows
,
cols
,
src1
,
src2
,
dst
,
mask
);
break
;
case
4
:
bitwise_bin_op
<
unsigned
int
,
1
,
BinOp
<
unsigned
int
,
opid
>
><<<
grid
,
threads
>>>
(
rows
,
cols
,
src1
,
src2
,
dst
,
mask
);
break
;
case
6
:
bitwise_bin_op
<
unsigned
short
,
3
,
BinOp
<
unsigned
short
,
opid
>
><<<
grid
,
threads
>>>
(
rows
,
cols
,
src1
,
src2
,
dst
,
mask
);
break
;
case
8
:
bitwise_bin_op
<
unsigned
int
,
2
,
BinOp
<
unsigned
int
,
opid
>
><<<
grid
,
threads
>>>
(
rows
,
cols
,
src1
,
src2
,
dst
,
mask
);
break
;
case
12
:
bitwise_bin_op
<
unsigned
int
,
3
,
BinOp
<
unsigned
int
,
opid
>
><<<
grid
,
threads
>>>
(
rows
,
cols
,
src1
,
src2
,
dst
,
mask
);
break
;
case
16
:
bitwise_bin_op
<
unsigned
int
,
4
,
BinOp
<
unsigned
int
,
opid
>
><<<
grid
,
threads
>>>
(
rows
,
cols
,
src1
,
src2
,
dst
,
mask
);
break
;
case
24
:
bitwise_bin_op
<
unsigned
int
,
6
,
BinOp
<
unsigned
int
,
opid
>
><<<
grid
,
threads
>>>
(
rows
,
cols
,
src1
,
src2
,
dst
,
mask
);
break
;
case
32
:
bitwise_bin_op
<
unsigned
int
,
8
,
BinOp
<
unsigned
int
,
opid
>
><<<
grid
,
threads
>>>
(
rows
,
cols
,
src1
,
src2
,
dst
,
mask
);
break
;
}
if
(
stream
==
0
)
cudaSafeCall
(
cudaThreadSynchronize
());
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录