Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Greenplum
Opencv
提交
c1a5d1c4
O
Opencv
项目概览
Greenplum
/
Opencv
11 个月 前同步成功
通知
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,发现更多精彩内容 >>
提交
c1a5d1c4
编写于
2月 21, 2013
作者:
A
Andrey Kamaev
提交者:
OpenCV Buildbot
2月 21, 2013
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #508 from bitwangyaoyao:2.4_interpKernel
上级
6ebb0e2a
429ae44a
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
151 addition
and
1 deletion
+151
-1
modules/ocl/include/opencv2/ocl/ocl.hpp
modules/ocl/include/opencv2/ocl/ocl.hpp
+18
-0
modules/ocl/src/initialization.cpp
modules/ocl/src/initialization.cpp
+133
-1
未找到文件。
modules/ocl/include/opencv2/ocl/ocl.hpp
浏览文件 @
c1a5d1c4
...
...
@@ -125,6 +125,24 @@ namespace cv
Impl
*
impl
;
};
//! Calls a kernel, by string. Pass globalThreads = NULL, and cleanUp = true, to finally clean-up without executing.
CV_EXPORTS
double
openCLExecuteKernelInterop
(
Context
*
clCxt
,
const
char
**
source
,
string
kernelName
,
size_t
globalThreads
[
3
],
size_t
localThreads
[
3
],
std
::
vector
<
std
::
pair
<
size_t
,
const
void
*>
>
&
args
,
int
channels
,
int
depth
,
const
char
*
build_options
,
bool
finish
=
true
,
bool
measureKernelTime
=
false
,
bool
cleanUp
=
true
);
//! Calls a kernel, by file. Pass globalThreads = NULL, and cleanUp = true, to finally clean-up without executing.
CV_EXPORTS
double
openCLExecuteKernelInterop
(
Context
*
clCxt
,
const
char
**
fileName
,
const
int
numFiles
,
string
kernelName
,
size_t
globalThreads
[
3
],
size_t
localThreads
[
3
],
std
::
vector
<
std
::
pair
<
size_t
,
const
void
*>
>
&
args
,
int
channels
,
int
depth
,
const
char
*
build_options
,
bool
finish
=
true
,
bool
measureKernelTime
=
false
,
bool
cleanUp
=
true
);
class
CV_EXPORTS
oclMatExpr
;
//////////////////////////////// oclMat ////////////////////////////////
class
CV_EXPORTS
oclMat
...
...
modules/ocl/src/initialization.cpp
浏览文件 @
c1a5d1c4
...
...
@@ -47,6 +47,7 @@
#include "precomp.hpp"
#include <iomanip>
#include <fstream>
#include "binarycaching.hpp"
using
namespace
cv
;
...
...
@@ -729,8 +730,139 @@ namespace cv
cout
<<
"average kernel total time: "
<<
total_kernel_time
/
RUN_TIMES
<<
endl
;
// "ms" << endl;
#endif
}
double
openCLExecuteKernelInterop
(
Context
*
clCxt
,
const
char
**
source
,
string
kernelName
,
size_t
globalThreads
[
3
],
size_t
localThreads
[
3
],
vector
<
pair
<
size_t
,
const
void
*>
>
&
args
,
int
channels
,
int
depth
,
const
char
*
build_options
,
bool
finish
,
bool
measureKernelTime
,
bool
cleanUp
)
cl_mem
load_constant
(
cl_context
context
,
cl_command_queue
command_queue
,
const
void
*
value
,
{
//construct kernel name
//The rule is functionName_Cn_Dn, C represent Channels, D Represent DataType Depth, n represent an integer number
//for exmaple split_C2_D2, represent the split kernel with channels =2 and dataType Depth = 2(Data type is char)
stringstream
idxStr
;
if
(
channels
!=
-
1
)
idxStr
<<
"_C"
<<
channels
;
if
(
depth
!=
-
1
)
idxStr
<<
"_D"
<<
depth
;
kernelName
+=
idxStr
.
str
();
cl_kernel
kernel
;
kernel
=
openCLGetKernelFromSource
(
clCxt
,
source
,
kernelName
,
build_options
);
double
kernelTime
=
0.0
;
if
(
globalThreads
!=
NULL
)
{
if
(
localThreads
!=
NULL
)
{
globalThreads
[
0
]
=
divUp
(
globalThreads
[
0
],
localThreads
[
0
])
*
localThreads
[
0
];
globalThreads
[
1
]
=
divUp
(
globalThreads
[
1
],
localThreads
[
1
])
*
localThreads
[
1
];
globalThreads
[
2
]
=
divUp
(
globalThreads
[
2
],
localThreads
[
2
])
*
localThreads
[
2
];
//size_t blockSize = localThreads[0] * localThreads[1] * localThreads[2];
cv
::
ocl
::
openCLVerifyKernel
(
clCxt
,
kernel
,
localThreads
);
}
for
(
size_t
i
=
0
;
i
<
args
.
size
();
i
++
)
openCLSafeCall
(
clSetKernelArg
(
kernel
,
i
,
args
[
i
].
first
,
args
[
i
].
second
));
if
(
measureKernelTime
==
false
)
{
openCLSafeCall
(
clEnqueueNDRangeKernel
(
clCxt
->
impl
->
clCmdQueue
,
kernel
,
3
,
NULL
,
globalThreads
,
localThreads
,
0
,
NULL
,
NULL
));
}
else
{
cl_event
event
=
NULL
;
openCLSafeCall
(
clEnqueueNDRangeKernel
(
clCxt
->
impl
->
clCmdQueue
,
kernel
,
3
,
NULL
,
globalThreads
,
localThreads
,
0
,
NULL
,
&
event
));
cl_ulong
end_time
,
queue_time
;
openCLSafeCall
(
clWaitForEvents
(
1
,
&
event
));
openCLSafeCall
(
clGetEventProfilingInfo
(
event
,
CL_PROFILING_COMMAND_END
,
sizeof
(
cl_ulong
),
&
end_time
,
0
));
openCLSafeCall
(
clGetEventProfilingInfo
(
event
,
CL_PROFILING_COMMAND_QUEUED
,
sizeof
(
cl_ulong
),
&
queue_time
,
0
));
kernelTime
=
(
double
)(
end_time
-
queue_time
)
/
(
1000
*
1000
);
clReleaseEvent
(
event
);
}
}
if
(
finish
)
{
clFinish
(
clCxt
->
impl
->
clCmdQueue
);
}
if
(
cleanUp
)
{
openCLSafeCall
(
clReleaseKernel
(
kernel
));
}
return
kernelTime
;
}
// Converts the contents of a file into a string
static
int
convertToString
(
const
char
*
filename
,
std
::
string
&
s
)
{
size_t
size
;
char
*
str
;
std
::
fstream
f
(
filename
,
(
std
::
fstream
::
in
|
std
::
fstream
::
binary
));
if
(
f
.
is_open
())
{
size_t
fileSize
;
f
.
seekg
(
0
,
std
::
fstream
::
end
);
size
=
fileSize
=
(
size_t
)
f
.
tellg
();
f
.
seekg
(
0
,
std
::
fstream
::
beg
);
str
=
new
char
[
size
+
1
];
if
(
!
str
)
{
f
.
close
();
return
-
1
;
}
f
.
read
(
str
,
fileSize
);
f
.
close
();
str
[
size
]
=
'\0'
;
s
=
str
;
delete
[]
str
;
return
0
;
}
printf
(
"Error: Failed to open file %s
\n
"
,
filename
);
return
-
1
;
}
double
openCLExecuteKernelInterop
(
Context
*
clCxt
,
const
char
**
fileName
,
const
int
numFiles
,
string
kernelName
,
size_t
globalThreads
[
3
],
size_t
localThreads
[
3
],
vector
<
pair
<
size_t
,
const
void
*>
>
&
args
,
int
channels
,
int
depth
,
const
char
*
build_options
,
bool
finish
,
bool
measureKernelTime
,
bool
cleanUp
)
{
std
::
vector
<
std
::
string
>
fsource
;
for
(
int
i
=
0
;
i
<
numFiles
;
i
++
)
{
std
::
string
str
;
if
(
convertToString
(
fileName
[
i
],
str
)
>=
0
)
fsource
.
push_back
(
str
);
}
const
char
**
source
=
new
const
char
*
[
numFiles
];
for
(
int
i
=
0
;
i
<
numFiles
;
i
++
)
source
[
i
]
=
fsource
[
i
].
c_str
();
double
kernelTime
=
openCLExecuteKernelInterop
(
clCxt
,
source
,
kernelName
,
globalThreads
,
localThreads
,
args
,
channels
,
depth
,
build_options
,
finish
,
measureKernelTime
,
cleanUp
);
fsource
.
clear
();
delete
[]
source
;
return
kernelTime
;
}
cl_mem
load_constant
(
cl_context
context
,
cl_command_queue
command_queue
,
const
void
*
value
,
const
size_t
size
)
{
int
status
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录