Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Greenplum
Opencv
提交
392991fa
O
Opencv
项目概览
Greenplum
/
Opencv
10 个月 前同步成功
通知
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,发现更多精彩内容 >>
提交
392991fa
编写于
12月 13, 2020
作者:
A
Alexander Alekhin
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
core(opencl): add version check before clCreateFromGLTexture() call
上级
1bfc75ac
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
68 addition
and
9 deletion
+68
-9
modules/core/include/opencv2/core/ocl.hpp
modules/core/include/opencv2/core/ocl.hpp
+5
-0
modules/core/src/ocl.cpp
modules/core/src/ocl.cpp
+30
-9
modules/core/src/opengl.cpp
modules/core/src/opengl.cpp
+33
-0
未找到文件。
modules/core/include/opencv2/core/ocl.hpp
浏览文件 @
392991fa
...
...
@@ -720,7 +720,12 @@ public:
String
name
()
const
;
String
vendor
()
const
;
/// See CL_PLATFORM_VERSION
String
version
()
const
;
int
versionMajor
()
const
;
int
versionMinor
()
const
;
int
deviceNumber
()
const
;
void
getDevice
(
Device
&
device
,
int
d
)
const
;
...
...
modules/core/src/ocl.cpp
浏览文件 @
392991fa
...
...
@@ -1162,25 +1162,27 @@ Platform& Platform::getDefault()
/////////////////////////////////////// Device ////////////////////////////////////////////
//
deviceVersion has format
//
Version has format:
// OpenCL<space><major_version.minor_version><space><vendor-specific information>
// by specification
// http://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clGetDeviceInfo.html
// http://www.khronos.org/registry/cl/sdk/1.2/docs/man/xhtml/clGetDeviceInfo.html
static
void
parseDeviceVersion
(
const
String
&
deviceVersion
,
int
&
major
,
int
&
minor
)
// https://www.khronos.org/registry/OpenCL/sdk/1.1/docs/man/xhtml/clGetPlatformInfo.html
// https://www.khronos.org/registry/OpenCL/sdk/1.2/docs/man/xhtml/clGetPlatformInfo.html
static
void
parseOpenCLVersion
(
const
String
&
version
,
int
&
major
,
int
&
minor
)
{
major
=
minor
=
0
;
if
(
10
>=
deviceV
ersion
.
length
())
if
(
10
>=
v
ersion
.
length
())
return
;
const
char
*
pstr
=
deviceV
ersion
.
c_str
();
const
char
*
pstr
=
v
ersion
.
c_str
();
if
(
0
!=
strncmp
(
pstr
,
"OpenCL "
,
7
))
return
;
size_t
ppos
=
deviceV
ersion
.
find
(
'.'
,
7
);
size_t
ppos
=
v
ersion
.
find
(
'.'
,
7
);
if
(
String
::
npos
==
ppos
)
return
;
String
temp
=
deviceV
ersion
.
substr
(
7
,
ppos
-
7
);
String
temp
=
v
ersion
.
substr
(
7
,
ppos
-
7
);
major
=
atoi
(
temp
.
c_str
());
temp
=
deviceV
ersion
.
substr
(
ppos
+
1
);
temp
=
v
ersion
.
substr
(
ppos
+
1
);
minor
=
atoi
(
temp
.
c_str
());
}
...
...
@@ -1203,7 +1205,7 @@ struct Device::Impl
addressBits_
=
getProp
<
cl_uint
,
int
>
(
CL_DEVICE_ADDRESS_BITS
);
String
deviceVersion_
=
getStrProp
(
CL_DEVICE_VERSION
);
parse
Device
Version
(
deviceVersion_
,
deviceVersionMajor_
,
deviceVersionMinor_
);
parse
OpenCL
Version
(
deviceVersion_
,
deviceVersionMajor_
,
deviceVersionMinor_
);
size_t
pos
=
0
;
while
(
pos
<
extensions_
.
size
())
...
...
@@ -5958,6 +5960,9 @@ struct PlatformInfo::Impl
refcount
=
1
;
handle
=
*
(
cl_platform_id
*
)
id
;
getDevices
(
devices
,
handle
);
version_
=
getStrProp
(
CL_PLATFORM_VERSION
);
parseOpenCLVersion
(
version_
,
versionMajor_
,
versionMinor_
);
}
String
getStrProp
(
cl_platform_info
prop
)
const
...
...
@@ -5971,6 +5976,10 @@ struct PlatformInfo::Impl
IMPLEMENT_REFCOUNTABLE
();
std
::
vector
<
cl_device_id
>
devices
;
cl_platform_id
handle
;
String
version_
;
int
versionMajor_
;
int
versionMinor_
;
};
PlatformInfo
::
PlatformInfo
()
...
...
@@ -6033,7 +6042,19 @@ String PlatformInfo::vendor() const
String
PlatformInfo
::
version
()
const
{
return
p
?
p
->
getStrProp
(
CL_PLATFORM_VERSION
)
:
String
();
return
p
?
p
->
version_
:
String
();
}
int
PlatformInfo
::
versionMajor
()
const
{
CV_Assert
(
p
);
return
p
->
versionMajor_
;
}
int
PlatformInfo
::
versionMinor
()
const
{
CV_Assert
(
p
);
return
p
->
versionMinor_
;
}
static
void
getPlatforms
(
std
::
vector
<
cl_platform_id
>&
platforms
)
...
...
modules/core/src/opengl.cpp
浏览文件 @
392991fa
...
...
@@ -1575,6 +1575,7 @@ void cv::ogl::render(const ogl::Arrays& arr, InputArray indices, int mode, Scala
// CL-GL Interoperability
#ifdef HAVE_OPENCL
# include "opencv2/core/opencl/runtime/opencl_core.hpp"
# include "opencv2/core/opencl/runtime/opencl_gl.hpp"
# ifdef cl_khr_gl_sharing
# define HAVE_OPENCL_OPENGL_SHARING
...
...
@@ -1595,6 +1596,34 @@ void cv::ogl::render(const ogl::Arrays& arr, InputArray indices, int mode, Scala
namespace
cv
{
namespace
ogl
{
#if defined(HAVE_OPENCL) && defined(HAVE_OPENGL) && defined(HAVE_OPENCL_OPENGL_SHARING)
// Check to avoid crash in OpenCL runtime: https://github.com/opencv/opencv/issues/5209
static
void
checkOpenCLVersion
()
{
using
namespace
cv
::
ocl
;
const
Device
&
device
=
Device
::
getDefault
();
//CV_Assert(!device.empty());
cl_device_id
dev
=
(
cl_device_id
)
device
.
ptr
();
CV_Assert
(
dev
);
cl_platform_id
platform_id
=
0
;
size_t
sz
=
0
;
cl_int
status
=
clGetDeviceInfo
(
dev
,
CL_DEVICE_PLATFORM
,
sizeof
(
platform_id
),
&
platform_id
,
&
sz
);
CV_Assert
(
status
==
CL_SUCCESS
&&
sz
==
sizeof
(
cl_platform_id
));
CV_Assert
(
platform_id
);
PlatformInfo
pi
(
&
platform_id
);
int
versionMajor
=
pi
.
versionMajor
();
int
versionMinor
=
pi
.
versionMinor
();
if
(
versionMajor
<
1
||
(
versionMajor
==
1
&&
versionMinor
<=
1
))
CV_Error_
(
cv
::
Error
::
OpenCLApiCallError
,
(
"OpenCL: clCreateFromGLTexture requires OpenCL 1.2+ version: %d.%d - %s (%s)"
,
versionMajor
,
versionMinor
,
pi
.
name
().
c_str
(),
pi
.
version
().
c_str
())
);
}
#endif
namespace
ocl
{
Context
&
initializeContextFromGL
()
...
...
@@ -1714,6 +1743,8 @@ void convertToGLTexture2D(InputArray src, Texture2D& texture)
Context
&
ctx
=
Context
::
getDefault
();
cl_context
context
=
(
cl_context
)
ctx
.
ptr
();
checkOpenCLVersion
();
// clCreateFromGLTexture requires OpenCL 1.2
UMat
u
=
src
.
getUMat
();
// TODO Add support for roi
...
...
@@ -1772,6 +1803,8 @@ void convertFromGLTexture2D(const Texture2D& texture, OutputArray dst)
Context
&
ctx
=
Context
::
getDefault
();
cl_context
context
=
(
cl_context
)
ctx
.
ptr
();
checkOpenCLVersion
();
// clCreateFromGLTexture requires OpenCL 1.2
// TODO Need to specify ACCESS_WRITE here somehow to prevent useless data copying!
dst
.
create
(
texture
.
size
(),
textureType
);
UMat
u
=
dst
.
getUMat
();
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录