Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle-Lite
提交
99ee4ff3
P
Paddle-Lite
项目概览
PaddlePaddle
/
Paddle-Lite
通知
331
Star
4
Fork
1
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
271
列表
看板
标记
里程碑
合并请求
78
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle-Lite
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
271
Issue
271
列表
看板
标记
里程碑
合并请求
78
合并请求
78
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
99ee4ff3
编写于
4月 09, 2020
作者:
开心的小妮
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add left code. test=develop
上级
a59c5c10
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
58 addition
and
52 deletion
+58
-52
lite/backends/opencl/cl_runtime.cc
lite/backends/opencl/cl_runtime.cc
+4
-2
lite/kernels/opencl/layout_image_compute.cc
lite/kernels/opencl/layout_image_compute.cc
+54
-50
未找到文件。
lite/backends/opencl/cl_runtime.cc
浏览文件 @
99ee4ff3
...
@@ -49,6 +49,8 @@ void CLRuntime::ReleaseResources() {
...
@@ -49,6 +49,8 @@ void CLRuntime::ReleaseResources() {
command_queue_
->
flush
();
command_queue_
->
flush
();
command_queue_
->
finish
();
command_queue_
->
finish
();
}
}
LOG
(
INFO
)
<<
"kernels_.size():"
<<
kernels_
.
size
();
LOG
(
INFO
)
<<
"programs_.size():"
<<
programs_
.
size
();
for
(
size_t
kidx
=
0
;
kidx
<
kernels_
.
size
();
++
kidx
)
{
for
(
size_t
kidx
=
0
;
kidx
<
kernels_
.
size
();
++
kidx
)
{
clReleaseKernel
(
kernels_
[
kidx
]
->
get
());
clReleaseKernel
(
kernels_
[
kidx
]
->
get
());
kernels_
[
kidx
].
reset
();
kernels_
[
kidx
].
reset
();
...
@@ -56,9 +58,9 @@ void CLRuntime::ReleaseResources() {
...
@@ -56,9 +58,9 @@ void CLRuntime::ReleaseResources() {
kernels_
.
clear
();
kernels_
.
clear
();
kernel_offset_
.
clear
();
kernel_offset_
.
clear
();
for
(
auto
&
p
:
programs_
)
{
for
(
auto
&
p
:
programs_
)
{
clReleaseProgram
(
p
.
second
->
get
());
//
clReleaseProgram(p.second->get());
}
}
programs_
.
clear
();
//
programs_.clear();
LOG
(
INFO
)
<<
"release resources finished."
;
LOG
(
INFO
)
<<
"release resources finished."
;
is_resources_released_
=
true
;
is_resources_released_
=
true
;
}
}
...
...
lite/kernels/opencl/layout_image_compute.cc
浏览文件 @
99ee4ff3
...
@@ -37,6 +37,11 @@ class LayoutComputeBufferChwToImageDefault
...
@@ -37,6 +37,11 @@ class LayoutComputeBufferChwToImageDefault
public:
public:
using
param_t
=
operators
::
LayoutParam
;
using
param_t
=
operators
::
LayoutParam
;
~
LayoutComputeBufferChwToImageDefault
()
{
LOG
(
INFO
)
<<
"Release LayoutComputeBufferChwToImageDefault"
;
kernel_
.
reset
();
event_
.
reset
();
}
void
PrepareForRun
()
override
{
void
PrepareForRun
()
override
{
auto
&
param
=
Param
<
param_t
>
();
auto
&
param
=
Param
<
param_t
>
();
if
(
param
.
process_type
==
1
)
{
if
(
param
.
process_type
==
1
)
{
...
@@ -44,7 +49,7 @@ class LayoutComputeBufferChwToImageDefault
...
@@ -44,7 +49,7 @@ class LayoutComputeBufferChwToImageDefault
}
}
VLOG
(
1
)
<<
"kernel_func_name_:"
<<
kernel_func_name_
;
VLOG
(
1
)
<<
"kernel_func_name_:"
<<
kernel_func_name_
;
auto
&
context
=
ctx_
->
As
<
OpenCLContext
>
();
auto
&
context
=
ctx_
->
As
<
OpenCLContext
>
();
context
.
cl_context
()
->
Add
Kernel
(
kernel_
=
context
.
cl_context
()
->
Create
Kernel
(
kernel_func_name_
,
"image/layout_kernel.cl"
,
build_options_
);
kernel_func_name_
,
"image/layout_kernel.cl"
,
build_options_
);
}
}
...
@@ -90,40 +95,37 @@ class LayoutComputeBufferChwToImageDefault
...
@@ -90,40 +95,37 @@ class LayoutComputeBufferChwToImageDefault
VLOG
(
2
)
<<
"Stride2:"
<<
Stride2
;
VLOG
(
2
)
<<
"Stride2:"
<<
Stride2
;
VLOG
(
2
)
<<
"Stride1:"
<<
Stride1
;
VLOG
(
2
)
<<
"Stride1:"
<<
Stride1
;
VLOG
(
2
)
<<
"Stride0:"
<<
Stride0
;
VLOG
(
2
)
<<
"Stride0:"
<<
Stride0
;
VLOG
(
2
)
<<
"gws:[3D]"
<<
((
new_dims
[
1
]
+
3
)
/
4
)
<<
" "
<<
new_dims
[
3
]
<<
" "
<<
(
new_dims
[
0
]
*
new_dims
[
2
]);
#endif
#endif
auto
&
context
=
ctx_
->
As
<
OpenCLContext
>
();
auto
&
context
=
ctx_
->
As
<
OpenCLContext
>
();
CHECK
(
context
.
cl_context
()
!=
nullptr
);
CHECK
(
context
.
cl_context
()
!=
nullptr
);
STL
::
stringstream
kernel_key
;
kernel_key
<<
kernel_func_name_
<<
build_options_
;
auto
kernel
=
context
.
cl_context
()
->
GetKernel
(
kernel_key
.
str
());
int
arg_idx
=
0
;
cl_int
status
;
cl_int
status
=
kernel
.
setArg
(
arg_idx
,
*
x_data
);
status
=
kernel_
->
setArg
(
0
,
*
x_data
);
CL_CHECK_FATAL
(
status
);
CL_CHECK_FATAL
(
status
);
status
=
kernel
.
setArg
(
++
arg_idx
,
*
y_data
);
status
=
kernel
_
->
setArg
(
1
,
*
y_data
);
CL_CHECK_FATAL
(
status
);
CL_CHECK_FATAL
(
status
);
status
=
kernel
.
setArg
(
++
arg_idx
,
static_cast
<
const
int
>
(
out_H
)
);
status
=
kernel
_
->
setArg
(
2
,
out_H
);
CL_CHECK_FATAL
(
status
);
CL_CHECK_FATAL
(
status
);
status
=
kernel
.
setArg
(
++
arg_idx
,
static_cast
<
const
int
>
(
out_W
)
);
status
=
kernel
_
->
setArg
(
3
,
out_W
);
CL_CHECK_FATAL
(
status
);
CL_CHECK_FATAL
(
status
);
status
=
kernel
.
setArg
(
++
arg_idx
,
static_cast
<
const
int
>
(
out_C
)
);
status
=
kernel
_
->
setArg
(
4
,
out_C
);
CL_CHECK_FATAL
(
status
);
CL_CHECK_FATAL
(
status
);
status
=
kernel
.
setArg
(
++
arg_idx
,
static_cast
<
const
int
>
(
Stride0
)
);
status
=
kernel
_
->
setArg
(
5
,
Stride0
);
CL_CHECK_FATAL
(
status
);
CL_CHECK_FATAL
(
status
);
status
=
kernel
.
setArg
(
++
arg_idx
,
static_cast
<
const
int
>
(
Stride1
)
);
status
=
kernel
_
->
setArg
(
6
,
Stride1
);
CL_CHECK_FATAL
(
status
);
CL_CHECK_FATAL
(
status
);
status
=
kernel
.
setArg
(
++
arg_idx
,
static_cast
<
const
int
>
(
Stride2
)
);
status
=
kernel
_
->
setArg
(
7
,
Stride2
);
CL_CHECK_FATAL
(
status
);
CL_CHECK_FATAL
(
status
);
VLOG
(
2
)
<<
"gws:[3D]"
<<
((
new_dims
[
1
]
+
3
)
/
4
)
<<
" "
<<
new_dims
[
3
]
<<
" "
<<
(
new_dims
[
0
]
*
new_dims
[
2
]);
auto
global_work_size
=
auto
global_work_size
=
cl
::
NDRange
{
static_cast
<
cl
::
size_type
>
((
new_dims
[
1
]
+
3
)
/
4
),
cl
::
NDRange
{
static_cast
<
cl
::
size_type
>
((
new_dims
[
1
]
+
3
)
/
4
),
static_cast
<
cl
::
size_type
>
(
new_dims
[
3
]),
static_cast
<
cl
::
size_type
>
(
new_dims
[
3
]),
static_cast
<
cl
::
size_type
>
(
new_dims
[
0
]
*
new_dims
[
2
])};
static_cast
<
cl
::
size_type
>
(
new_dims
[
0
]
*
new_dims
[
2
])};
status
=
context
.
cl_context
()
->
GetCommandQueue
().
enqueueNDRangeKernel
(
status
=
context
.
cl_context
()
->
GetCommandQueue
().
enqueueNDRangeKernel
(
kernel
,
*
(
kernel_
.
get
())
,
cl
::
NullRange
,
cl
::
NullRange
,
global_work_size
,
global_work_size
,
cl
::
NullRange
,
cl
::
NullRange
,
...
@@ -142,6 +144,7 @@ class LayoutComputeBufferChwToImageDefault
...
@@ -142,6 +144,7 @@ class LayoutComputeBufferChwToImageDefault
std
::
string
kernel_func_name_
{
"buffer_to_image2d"
};
std
::
string
kernel_func_name_
{
"buffer_to_image2d"
};
std
::
string
build_options_
{
"-DCL_DTYPE_float"
};
std
::
string
build_options_
{
"-DCL_DTYPE_float"
};
std
::
shared_ptr
<
cl
::
Event
>
event_
{
new
cl
::
Event
};
std
::
shared_ptr
<
cl
::
Event
>
event_
{
new
cl
::
Event
};
std
::
shared_ptr
<
cl
::
Kernel
>
kernel_
;
};
};
// [ImageDefault] -> [NCHW]
// [ImageDefault] -> [NCHW]
...
@@ -157,7 +160,7 @@ class LayoutComputeImageDefaultToBufferChw
...
@@ -157,7 +160,7 @@ class LayoutComputeImageDefaultToBufferChw
}
}
VLOG
(
1
)
<<
"kernel_func_name_:"
<<
kernel_func_name_
;
VLOG
(
1
)
<<
"kernel_func_name_:"
<<
kernel_func_name_
;
auto
&
context
=
ctx_
->
As
<
OpenCLContext
>
();
auto
&
context
=
ctx_
->
As
<
OpenCLContext
>
();
context
.
cl_context
()
->
Add
Kernel
(
kernel_
=
context
.
cl_context
()
->
Create
Kernel
(
kernel_func_name_
,
"image/layout_kernel.cl"
,
build_options_
);
kernel_func_name_
,
"image/layout_kernel.cl"
,
build_options_
);
}
}
...
@@ -191,46 +194,45 @@ class LayoutComputeImageDefaultToBufferChw
...
@@ -191,46 +194,45 @@ class LayoutComputeImageDefaultToBufferChw
VLOG
(
2
)
<<
"param.y->memory_size():"
<<
param
.
y
->
memory_size
();
VLOG
(
2
)
<<
"param.y->memory_size():"
<<
param
.
y
->
memory_size
();
#endif
#endif
size_
t
C
=
new_dims
[
1
];
const
in
t
C
=
new_dims
[
1
];
size_
t
in_height
=
new_dims
[
2
];
const
in
t
in_height
=
new_dims
[
2
];
size_
t
in_width
=
new_dims
[
3
];
const
in
t
in_width
=
new_dims
[
3
];
int
size_ch
=
in_height
*
in_width
;
const
int
size_ch
=
in_height
*
in_width
;
int
size_block
=
size_ch
*
4
;
const
int
size_block
=
size_ch
*
4
;
int
size_batch
=
size_ch
*
C
;
const
int
size_batch
=
size_ch
*
C
;
auto
&
context
=
ctx_
->
As
<
OpenCLContext
>
();
auto
&
context
=
ctx_
->
As
<
OpenCLContext
>
();
CHECK
(
context
.
cl_context
()
!=
nullptr
);
CHECK
(
context
.
cl_context
()
!=
nullptr
);
STL
::
stringstream
kernel_key
;
kernel_key
<<
kernel_func_name_
<<
build_options_
;
auto
kernel
=
context
.
cl_context
()
->
GetKernel
(
kernel_key
.
str
());
int
arg_idx
=
0
;
cl_int
status
;
cl_int
status
=
kernel
.
setArg
(
arg_idx
,
*
x_data
);
status
=
kernel_
->
setArg
(
0
,
*
x_data
);
CL_CHECK_FATAL
(
status
);
CL_CHECK_FATAL
(
status
);
status
=
kernel
.
setArg
(
++
arg_idx
,
static_cast
<
const
int
>
(
in_width
)
);
status
=
kernel
_
->
setArg
(
1
,
in_width
);
CL_CHECK_FATAL
(
status
);
CL_CHECK_FATAL
(
status
);
status
=
kernel
.
setArg
(
++
arg_idx
,
static_cast
<
const
int
>
(
in_height
)
);
status
=
kernel
_
->
setArg
(
2
,
in_height
);
CL_CHECK_FATAL
(
status
);
CL_CHECK_FATAL
(
status
);
status
=
kernel
.
setArg
(
++
arg_idx
,
*
y_data
);
status
=
kernel
_
->
setArg
(
3
,
*
y_data
);
CL_CHECK_FATAL
(
status
);
CL_CHECK_FATAL
(
status
);
status
=
kernel
.
setArg
(
++
arg_idx
,
static_cast
<
const
int
>
(
size_ch
)
);
status
=
kernel
_
->
setArg
(
4
,
size_ch
);
CL_CHECK_FATAL
(
status
);
CL_CHECK_FATAL
(
status
);
status
=
kernel
.
setArg
(
++
arg_idx
,
static_cast
<
const
int
>
(
size_block
)
);
status
=
kernel
_
->
setArg
(
5
,
size_block
);
CL_CHECK_FATAL
(
status
);
CL_CHECK_FATAL
(
status
);
status
=
kernel
.
setArg
(
++
arg_idx
,
static_cast
<
const
int
>
(
size_batch
)
);
status
=
kernel
_
->
setArg
(
6
,
size_batch
);
CL_CHECK_FATAL
(
status
);
CL_CHECK_FATAL
(
status
);
status
=
kernel
.
setArg
(
++
arg_idx
,
static_cast
<
const
int
>
(
C
)
);
status
=
kernel
_
->
setArg
(
7
,
C
);
CL_CHECK_FATAL
(
status
);
CL_CHECK_FATAL
(
status
);
#ifndef LITE_SHUTDOWN_LOG
#ifndef LITE_SHUTDOWN_LOG
VLOG
(
2
)
<<
"gws:[3D]"
<<
((
new_dims
[
1
]
+
3
)
/
4
)
<<
" "
<<
new_dims
[
3
]
VLOG
(
2
)
<<
"gws:[3D]"
<<
((
new_dims
[
1
]
+
3
)
/
4
)
<<
" "
<<
new_dims
[
3
]
<<
" "
<<
(
new_dims
[
0
]
*
new_dims
[
2
]);
<<
" "
<<
(
new_dims
[
0
]
*
new_dims
[
2
]);
#endif
#endif
auto
global_work_size
=
auto
global_work_size
=
cl
::
NDRange
{
static_cast
<
cl
::
size_type
>
((
new_dims
[
1
]
+
3
)
/
4
),
cl
::
NDRange
{
static_cast
<
cl
::
size_type
>
((
new_dims
[
1
]
+
3
)
/
4
),
static_cast
<
cl
::
size_type
>
(
new_dims
[
3
]),
static_cast
<
cl
::
size_type
>
(
new_dims
[
3
]),
static_cast
<
cl
::
size_type
>
(
new_dims
[
0
]
*
new_dims
[
2
])};
static_cast
<
cl
::
size_type
>
(
new_dims
[
0
]
*
new_dims
[
2
])};
status
=
context
.
cl_context
()
->
GetCommandQueue
().
enqueueNDRangeKernel
(
status
=
context
.
cl_context
()
->
GetCommandQueue
().
enqueueNDRangeKernel
(
kernel
,
*
(
kernel_
.
get
())
,
cl
::
NullRange
,
cl
::
NullRange
,
global_work_size
,
global_work_size
,
cl
::
NullRange
,
cl
::
NullRange
,
...
@@ -249,6 +251,7 @@ class LayoutComputeImageDefaultToBufferChw
...
@@ -249,6 +251,7 @@ class LayoutComputeImageDefaultToBufferChw
std
::
string
kernel_func_name_
{
"image2d_to_buffer"
};
std
::
string
kernel_func_name_
{
"image2d_to_buffer"
};
std
::
string
build_options_
{
"-DCL_DTYPE_float"
};
std
::
string
build_options_
{
"-DCL_DTYPE_float"
};
std
::
shared_ptr
<
cl
::
Event
>
event_
{
new
cl
::
Event
};
std
::
shared_ptr
<
cl
::
Event
>
event_
{
new
cl
::
Event
};
std
::
shared_ptr
<
cl
::
Kernel
>
kernel_
;
};
};
// [NCHW] -> [ImageDW]
// [NCHW] -> [ImageDW]
...
@@ -261,7 +264,7 @@ class LayoutComputeBufferChwToImage2DNw
...
@@ -261,7 +264,7 @@ class LayoutComputeBufferChwToImage2DNw
void
PrepareForRun
()
override
{
void
PrepareForRun
()
override
{
auto
&
context
=
ctx_
->
As
<
OpenCLContext
>
();
auto
&
context
=
ctx_
->
As
<
OpenCLContext
>
();
context
.
cl_context
()
->
Add
Kernel
(
kernel_
=
context
.
cl_context
()
->
Create
Kernel
(
kernel_func_name_
,
"buffer/layout_kernel.cl"
,
build_options_
);
kernel_func_name_
,
"buffer/layout_kernel.cl"
,
build_options_
);
}
}
...
@@ -295,36 +298,36 @@ class LayoutComputeBufferChwToImage2DNw
...
@@ -295,36 +298,36 @@ class LayoutComputeBufferChwToImage2DNw
auto
&
context
=
ctx_
->
As
<
OpenCLContext
>
();
auto
&
context
=
ctx_
->
As
<
OpenCLContext
>
();
CHECK
(
context
.
cl_context
()
!=
nullptr
);
CHECK
(
context
.
cl_context
()
!=
nullptr
);
STL
::
stringstream
kernel_key
;
kernel_key
<<
kernel_func_name_
<<
build_options_
;
auto
kernel
=
context
.
cl_context
()
->
GetKernel
(
kernel_key
.
str
());
int
arg_idx
=
0
;
cl_int
status
;
cl_int
status
=
kernel
.
setArg
(
arg_idx
,
*
x_data
);
status
=
kernel_
->
setArg
(
0
,
*
x_data
);
CL_CHECK_FATAL
(
status
);
CL_CHECK_FATAL
(
status
);
status
=
kernel
.
setArg
(
++
arg_idx
,
*
y_data
);
status
=
kernel
_
->
setArg
(
1
,
*
y_data
);
CL_CHECK_FATAL
(
status
);
CL_CHECK_FATAL
(
status
);
status
=
kernel
.
setArg
(
++
arg_idx
,
static_cast
<
const
int
>
(
out_H
)
);
status
=
kernel
_
->
setArg
(
2
,
out_H
);
CL_CHECK_FATAL
(
status
);
CL_CHECK_FATAL
(
status
);
status
=
kernel
.
setArg
(
++
arg_idx
,
static_cast
<
const
int
>
(
out_W
)
);
status
=
kernel
_
->
setArg
(
3
,
out_W
);
CL_CHECK_FATAL
(
status
);
CL_CHECK_FATAL
(
status
);
status
=
kernel
.
setArg
(
++
arg_idx
,
static_cast
<
const
int
>
(
out_N
)
);
status
=
kernel
_
->
setArg
(
4
,
out_N
);
CL_CHECK_FATAL
(
status
);
CL_CHECK_FATAL
(
status
);
status
=
kernel
.
setArg
(
++
arg_idx
,
static_cast
<
const
int
>
(
Stride0
)
);
status
=
kernel
_
->
setArg
(
5
,
Stride0
);
CL_CHECK_FATAL
(
status
);
CL_CHECK_FATAL
(
status
);
status
=
kernel
.
setArg
(
++
arg_idx
,
static_cast
<
const
int
>
(
Stride1
)
);
status
=
kernel
_
->
setArg
(
6
,
Stride1
);
CL_CHECK_FATAL
(
status
);
CL_CHECK_FATAL
(
status
);
status
=
kernel
.
setArg
(
++
arg_idx
,
static_cast
<
const
int
>
(
Stride2
)
);
status
=
kernel
_
->
setArg
(
7
,
Stride2
);
CL_CHECK_FATAL
(
status
);
CL_CHECK_FATAL
(
status
);
#ifndef LITE_SHUTDOWN_LOG
VLOG
(
2
)
<<
"gws:[3D]"
<<
((
out_N
+
3
)
/
4
)
<<
" "
<<
out_W
<<
" "
VLOG
(
2
)
<<
"gws:[3D]"
<<
((
out_N
+
3
)
/
4
)
<<
" "
<<
out_W
<<
" "
<<
(
out_C
*
out_H
);
<<
(
out_C
*
out_H
);
#endif
auto
global_work_size
=
auto
global_work_size
=
cl
::
NDRange
{
static_cast
<
cl
::
size_type
>
((
out_N
+
3
)
/
4
),
// N blocks
cl
::
NDRange
{
static_cast
<
cl
::
size_type
>
((
out_N
+
3
)
/
4
),
// N blocks
static_cast
<
cl
::
size_type
>
(
out_W
),
// w
static_cast
<
cl
::
size_type
>
(
out_W
),
// w
static_cast
<
cl
::
size_type
>
(
out_C
*
out_H
)};
// ch
static_cast
<
cl
::
size_type
>
(
out_C
*
out_H
)};
// ch
status
=
context
.
cl_context
()
->
GetCommandQueue
().
enqueueNDRangeKernel
(
status
=
context
.
cl_context
()
->
GetCommandQueue
().
enqueueNDRangeKernel
(
kernel
,
*
(
kernel_
.
get
())
,
cl
::
NullRange
,
cl
::
NullRange
,
global_work_size
,
global_work_size
,
cl
::
NullRange
,
cl
::
NullRange
,
...
@@ -342,6 +345,7 @@ class LayoutComputeBufferChwToImage2DNw
...
@@ -342,6 +345,7 @@ class LayoutComputeBufferChwToImage2DNw
std
::
string
kernel_func_name_
{
"buffer_to_image2d_nw"
};
std
::
string
kernel_func_name_
{
"buffer_to_image2d_nw"
};
std
::
string
build_options_
{
"-DCL_DTYPE_float "
};
std
::
string
build_options_
{
"-DCL_DTYPE_float "
};
std
::
shared_ptr
<
cl
::
Event
>
event_
{
new
cl
::
Event
};
std
::
shared_ptr
<
cl
::
Event
>
event_
{
new
cl
::
Event
};
std
::
shared_ptr
<
cl
::
Kernel
>
kernel_
;
};
};
}
// namespace opencl
}
// namespace opencl
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录