Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Greenplum
Opencv
提交
be37d995
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,发现更多精彩内容 >>
提交
be37d995
编写于
11月 05, 2013
作者:
A
Andrey Pavlenko
提交者:
OpenCV Buildbot
11月 05, 2013
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #1752 from alalek:ocl_memory_cleanup_workaround
上级
14c35607
691d5f41
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
34 addition
and
19 deletion
+34
-19
modules/ocl/src/cl_operations.cpp
modules/ocl/src/cl_operations.cpp
+34
-19
未找到文件。
modules/ocl/src/cl_operations.cpp
浏览文件 @
be37d995
...
...
@@ -109,12 +109,15 @@ cl_mem openCLCreateBuffer(Context *ctx, size_t flag , size_t size)
return
buffer
;
}
#define MEMORY_CORRUPTION_GUARD
#ifdef MEMORY_CORRUPTION_GUARD
//#define CHECK_MEMORY_CORRUPTION
#ifdef CHECK_MEMORY_CORRUPTION
//#define CHECK_MEMORY_CORRUPTION_PRINT_ERROR
#define CHECK_MEMORY_CORRUPTION_PRINT_ERROR
#define CHECK_MEMORY_CORRUPTION_RAISE_ERROR
static
const
int
__memory_corruption_check_bytes
=
1024
*
1024
;
static
const
int
__memory_corruption_guard_bytes
=
64
*
1024
;
#ifdef CHECK_MEMORY_CORRUPTION
static
const
int
__memory_corruption_check_pattern
=
0x14326547
;
// change pattern for sizeof(int)==8
#endif
struct
CheckBuffers
{
cl_mem
mainBuffer
;
...
...
@@ -128,7 +131,7 @@ struct CheckBuffers
CheckBuffers
(
cl_mem
_mainBuffer
,
size_t
_size
,
size_t
_widthInBytes
,
size_t
_height
)
:
mainBuffer
(
_mainBuffer
),
size
(
_size
),
widthInBytes
(
_widthInBytes
),
height
(
_height
)
{
// not
ih
ng
// not
hi
ng
}
};
static
std
::
map
<
cl_mem
,
CheckBuffers
>
__check_buffers
;
...
...
@@ -145,30 +148,33 @@ void openCLMallocPitchEx(Context *ctx, void **dev_ptr, size_t *pitch,
{
cl_int
status
;
size_t
size
=
widthInBytes
*
height
;
#ifndef
CHECK_MEMORY_CORRUPTION
#ifndef
MEMORY_CORRUPTION_GUARD
*
dev_ptr
=
clCreateBuffer
(
getClContext
(
ctx
),
gDevMemRWValueMap
[
rw_type
]
|
gDevMemTypeValueMap
[
mem_type
],
size
,
0
,
&
status
);
openCLVerifyCall
(
status
);
#else
size_t
allocSize
=
size
+
__memory_corruption_
check
_bytes
*
2
;
size_t
allocSize
=
size
+
__memory_corruption_
guard
_bytes
*
2
;
cl_mem
mainBuffer
=
clCreateBuffer
(
getClContext
(
ctx
),
gDevMemRWValueMap
[
rw_type
]
|
gDevMemTypeValueMap
[
mem_type
],
allocSize
,
0
,
&
status
);
openCLVerifyCall
(
status
);
cl_buffer_region
r
=
{
__memory_corruption_
check
_bytes
,
size
};
cl_buffer_region
r
=
{
__memory_corruption_
guard
_bytes
,
size
};
*
dev_ptr
=
clCreateSubBuffer
(
mainBuffer
,
gDevMemRWValueMap
[
rw_type
]
|
gDevMemTypeValueMap
[
mem_type
],
CL_BUFFER_CREATE_TYPE_REGION
,
&
r
,
&
status
);
openCLVerifyCall
(
status
);
std
::
vector
<
int
>
tmp
(
__memory_corruption_check_bytes
/
sizeof
(
int
),
#ifdef CHECK_MEMORY_CORRUPTION
std
::
vector
<
int
>
tmp
(
__memory_corruption_guard_bytes
/
sizeof
(
int
),
__memory_corruption_check_pattern
);
CV_Assert
(
tmp
.
size
()
*
sizeof
(
int
)
==
__memory_corruption_
check
_bytes
);
CV_Assert
(
tmp
.
size
()
*
sizeof
(
int
)
==
__memory_corruption_
guard
_bytes
);
openCLVerifyCall
(
clEnqueueWriteBuffer
(
getClCommandQueue
(
ctx
),
mainBuffer
,
CL_
TRUE
,
0
,
__memory_corruption_check
_bytes
,
&
tmp
[
0
],
mainBuffer
,
CL_
FALSE
,
0
,
__memory_corruption_guard
_bytes
,
&
tmp
[
0
],
0
,
NULL
,
NULL
));
openCLVerifyCall
(
clEnqueueWriteBuffer
(
getClCommandQueue
(
ctx
),
mainBuffer
,
CL_
TRUE
,
__memory_corruption_check_bytes
+
size
,
__memory_corruption_check
_bytes
,
&
tmp
[
0
],
mainBuffer
,
CL_
FALSE
,
__memory_corruption_guard_bytes
+
size
,
__memory_corruption_guard
_bytes
,
&
tmp
[
0
],
0
,
NULL
,
NULL
));
clFinish
(
getClCommandQueue
(
ctx
));
#endif
CheckBuffers
data
(
mainBuffer
,
size
,
widthInBytes
,
height
);
__check_buffers
.
insert
(
std
::
pair
<
cl_mem
,
CheckBuffers
>
((
cl_mem
)
*
dev_ptr
,
data
));
#endif
...
...
@@ -224,40 +230,49 @@ void openCLCopyBuffer2D(Context *ctx, void *dst, size_t dpitch, int dst_offset,
void
openCLFree
(
void
*
devPtr
)
{
#ifdef MEMORY_CORRUPTION_GUARD
#ifdef CHECK_MEMORY_CORRUPTION
bool
failBefore
=
false
,
failAfter
=
false
;
#endif
CheckBuffers
data
;
std
::
map
<
cl_mem
,
CheckBuffers
>::
iterator
i
=
__check_buffers
.
find
((
cl_mem
)
devPtr
);
if
(
i
!=
__check_buffers
.
end
())
{
data
=
i
->
second
;
#ifdef CHECK_MEMORY_CORRUPTION
Context
*
ctx
=
Context
::
getContext
();
std
::
vector
<
uchar
>
checkBefore
(
__memory_corruption_
check
_bytes
);
std
::
vector
<
uchar
>
checkAfter
(
__memory_corruption_
check
_bytes
);
std
::
vector
<
uchar
>
checkBefore
(
__memory_corruption_
guard
_bytes
);
std
::
vector
<
uchar
>
checkAfter
(
__memory_corruption_
guard
_bytes
);
openCLVerifyCall
(
clEnqueueReadBuffer
(
getClCommandQueue
(
ctx
),
data
.
mainBuffer
,
CL_
TRUE
,
0
,
__memory_corruption_check
_bytes
,
&
checkBefore
[
0
],
data
.
mainBuffer
,
CL_
FALSE
,
0
,
__memory_corruption_guard
_bytes
,
&
checkBefore
[
0
],
0
,
NULL
,
NULL
));
openCLVerifyCall
(
clEnqueueReadBuffer
(
getClCommandQueue
(
ctx
),
data
.
mainBuffer
,
CL_
TRUE
,
__memory_corruption_check_bytes
+
data
.
size
,
__memory_corruption_check
_bytes
,
&
checkAfter
[
0
],
data
.
mainBuffer
,
CL_
FALSE
,
__memory_corruption_guard_bytes
+
data
.
size
,
__memory_corruption_guard
_bytes
,
&
checkAfter
[
0
],
0
,
NULL
,
NULL
));
clFinish
(
getClCommandQueue
(
ctx
));
std
::
vector
<
int
>
tmp
(
__memory_corruption_
check
_bytes
/
sizeof
(
int
),
std
::
vector
<
int
>
tmp
(
__memory_corruption_
guard
_bytes
/
sizeof
(
int
),
__memory_corruption_check_pattern
);
if
(
memcmp
(
&
checkBefore
[
0
],
&
tmp
[
0
],
__memory_corruption_
check
_bytes
)
!=
0
)
if
(
memcmp
(
&
checkBefore
[
0
],
&
tmp
[
0
],
__memory_corruption_
guard
_bytes
)
!=
0
)
{
failBefore
=
true
;
}
if
(
memcmp
(
&
checkAfter
[
0
],
&
tmp
[
0
],
__memory_corruption_
check
_bytes
)
!=
0
)
if
(
memcmp
(
&
checkAfter
[
0
],
&
tmp
[
0
],
__memory_corruption_
guard
_bytes
)
!=
0
)
{
failAfter
=
true
;
}
#else
// TODO FIXIT Attach clReleaseMemObject call to event completion callback
Context
*
ctx
=
Context
::
getContext
();
clFinish
(
getClCommandQueue
(
ctx
));
#endif
openCLSafeCall
(
clReleaseMemObject
(
data
.
mainBuffer
));
__check_buffers
.
erase
(
i
);
}
#endif
openCLSafeCall
(
clReleaseMemObject
((
cl_mem
)
devPtr
));
#if
def CHECK_MEMORY_CORRUPTION
#if
defined(MEMORY_CORRUPTION_GUARD) && defined(CHECK_MEMORY_CORRUPTION)
if
(
failBefore
)
{
#ifdef CHECK_MEMORY_CORRUPTION_PRINT_ERROR
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录