Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
magicwindyyd
mindspore
提交
f459df18
M
mindspore
项目概览
magicwindyyd
/
mindspore
与 Fork 源项目一致
Fork自
MindSpore / mindspore
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
M
mindspore
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
f459df18
编写于
8月 20, 2020
作者:
M
mindspore-ci-bot
提交者:
Gitee
8月 20, 2020
浏览文件
操作
浏览文件
下载
差异文件
!4752 code clean for opencl
Merge pull request !4752 from chenzhongming/lite
上级
12847919
990c645c
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
68 addition
and
39 deletion
+68
-39
mindspore/lite/src/runtime/kernel/opencl/kernel/pooling2d.cc
mindspore/lite/src/runtime/kernel/opencl/kernel/pooling2d.cc
+0
-4
mindspore/lite/src/runtime/kernel/opencl/kernel/softmax.cc
mindspore/lite/src/runtime/kernel/opencl/kernel/softmax.cc
+1
-0
mindspore/lite/test/ut/src/runtime/kernel/opencl/avg_pooling_tests.cc
...te/test/ut/src/runtime/kernel/opencl/avg_pooling_tests.cc
+24
-5
mindspore/lite/test/ut/src/runtime/kernel/opencl/max_pooling_tests.cc
...te/test/ut/src/runtime/kernel/opencl/max_pooling_tests.cc
+23
-5
mindspore/lite/test/ut/src/runtime/kernel/opencl/softmax_tests.cc
...e/lite/test/ut/src/runtime/kernel/opencl/softmax_tests.cc
+20
-25
未找到文件。
mindspore/lite/src/runtime/kernel/opencl/kernel/pooling2d.cc
浏览文件 @
f459df18
...
...
@@ -112,7 +112,6 @@ int PoolingOpenCLKernel::Run() {
MS_LOG
(
DEBUG
)
<<
this
->
name
()
<<
" Running!"
;
auto
ocl_runtime
=
lite
::
opencl
::
OpenCLRuntime
::
GetInstance
();
// attribute
int
slices
=
UP_DIV
(
out_tensors_
[
0
]
->
Channel
(),
C4NUM
);
cl_int4
input_shape
=
{
in_tensors_
[
0
]
->
Height
(),
in_tensors_
[
0
]
->
Width
(),
in_tensors_
[
0
]
->
Channel
(),
slices
};
cl_int4
output_shape
=
{
out_tensors_
[
0
]
->
Height
(),
out_tensors_
[
0
]
->
Width
(),
out_tensors_
[
0
]
->
Channel
(),
slices
};
...
...
@@ -120,7 +119,6 @@ int PoolingOpenCLKernel::Run() {
cl_int2
kernel_size
=
{
parameter_
->
window_h_
,
parameter_
->
window_w_
};
cl_int2
padding
=
{
parameter_
->
pad_u_
,
parameter_
->
pad_l_
};
// binding parameters
int
arg_idx
=
0
;
ocl_runtime
->
SetKernelArg
(
kernel_
,
arg_idx
++
,
in_tensors_
[
0
]
->
Data
());
ocl_runtime
->
SetKernelArg
(
kernel_
,
arg_idx
++
,
out_tensors_
[
0
]
->
Data
());
...
...
@@ -130,14 +128,12 @@ int PoolingOpenCLKernel::Run() {
ocl_runtime
->
SetKernelArg
(
kernel_
,
arg_idx
++
,
kernel_size
);
ocl_runtime
->
SetKernelArg
(
kernel_
,
arg_idx
++
,
padding
);
// set work group size
std
::
vector
<
size_t
>
local_size
;
std
::
vector
<
size_t
>
global_size
=
InitGlobalSize
();
int
max_work_group_size
=
ocl_runtime
->
GetKernelMaxWorkGroupSize
(
kernel_
(),
(
*
ocl_runtime
->
Device
())());
local_size
=
GetCommonLocalSize
(
global_size
,
max_work_group_size
);
global_size
=
GetCommonGlobalSize
(
local_size
,
global_size
);
// run opengl kernel
ocl_runtime
->
RunKernel
(
kernel_
,
global_size
,
local_size
,
nullptr
);
return
RET_OK
;
}
...
...
mindspore/lite/src/runtime/kernel/opencl/kernel/softmax.cc
浏览文件 @
f459df18
...
...
@@ -171,6 +171,7 @@ kernel::LiteKernel *OpenCLSoftMaxKernelCreator(const std::vector<lite::tensor::T
auto
*
kernel
=
new
(
std
::
nothrow
)
SoftmaxOpenCLKernel
(
reinterpret_cast
<
OpParameter
*>
(
opParameter
),
inputs
,
outputs
);
if
(
kernel
==
nullptr
)
{
MS_LOG
(
ERROR
)
<<
"kernel "
<<
opParameter
->
name_
<<
"is nullptr."
;
delete
kernel
;
return
nullptr
;
}
if
(
inputs
[
0
]
->
shape
()[
0
]
>
1
)
{
...
...
mindspore/lite/test/ut/src/runtime/kernel/opencl/avg_pooling_tests.cc
浏览文件 @
f459df18
...
...
@@ -58,7 +58,7 @@ TEST_F(TestAvgPoolingOpenCL, AvgPoolFp32) {
ocl_runtime
->
Init
();
MS_LOG
(
INFO
)
<<
"create PoolingParameter"
;
auto
param
=
new
PoolingParameter
();
auto
param
=
new
(
std
::
nothrow
)
PoolingParameter
();
InitAvgPoolingParam
(
param
);
MS_LOG
(
INFO
)
<<
"create Tensors"
;
...
...
@@ -76,18 +76,37 @@ TEST_F(TestAvgPoolingOpenCL, AvgPoolFp32) {
};
auto
data_type
=
kNumberTypeFloat32
;
auto
tensorType
=
schema
::
NodeType_ValueNode
;
lite
::
tensor
::
Tensor
*
tensor_in
=
new
lite
::
tensor
::
Tensor
(
data_type
,
shape_in
,
schema
::
Format_NHWC
,
tensorType
);
lite
::
tensor
::
Tensor
*
tensor_out
=
new
lite
::
tensor
::
Tensor
(
data_type
,
shape_out
,
schema
::
Format_NHWC
,
tensorType
);
lite
::
tensor
::
Tensor
*
tensor_in
=
new
(
std
::
nothrow
)
lite
::
tensor
::
Tensor
(
data_type
,
shape_in
,
schema
::
Format_NHWC
,
tensorType
);
lite
::
tensor
::
Tensor
*
tensor_out
=
new
(
std
::
nothrow
)
lite
::
tensor
::
Tensor
(
data_type
,
shape_out
,
schema
::
Format_NHWC
,
tensorType
);
if
(
tensor_in
==
nullptr
)
{
MS_LOG
(
ERROR
)
<<
"tensor_in null"
;
return
;
}
if
(
tensor_out
==
nullptr
)
{
MS_LOG
(
ERROR
)
<<
"tensor_out null"
;
return
;
}
std
::
vector
<
lite
::
tensor
::
Tensor
*>
inputs
{
tensor_in
};
std
::
vector
<
lite
::
tensor
::
Tensor
*>
outputs
{
tensor_out
};
MS_LOG
(
INFO
)
<<
"create OpenCL Kernel"
;
auto
*
pooling_kernel
=
new
kernel
::
PoolingOpenCLKernel
(
reinterpret_cast
<
OpParameter
*>
(
param
),
inputs
,
outputs
);
auto
*
pooling_kernel
=
new
(
std
::
nothrow
)
kernel
::
PoolingOpenCLKernel
(
reinterpret_cast
<
OpParameter
*>
(
param
),
inputs
,
outputs
);
if
(
pooling_kernel
==
nullptr
)
{
MS_LOG
(
ERROR
)
<<
"pooling_kernel null"
;
return
;
}
pooling_kernel
->
Init
();
std
::
vector
<
kernel
::
LiteKernel
*>
kernels
{
pooling_kernel
};
MS_LOG
(
INFO
)
<<
"create SubGraphOpenCLKernel"
;
auto
*
pGraph
=
new
kernel
::
SubGraphOpenCLKernel
(
inputs
,
outputs
,
kernels
,
kernels
,
kernels
);
auto
*
pGraph
=
new
(
std
::
nothrow
)
kernel
::
SubGraphOpenCLKernel
(
inputs
,
outputs
,
kernels
,
kernels
,
kernels
);
if
(
pGraph
==
nullptr
)
{
MS_LOG
(
ERROR
)
<<
"pGraph null"
;
return
;
}
pGraph
->
Init
();
MS_LOG
(
INFO
)
<<
"initialize data"
;
...
...
mindspore/lite/test/ut/src/runtime/kernel/opencl/max_pooling_tests.cc
浏览文件 @
f459df18
...
...
@@ -46,7 +46,7 @@ TEST_F(TestMaxPoolingOpenCL, MaxPool_1_32_512_96) {
auto
allocator
=
ocl_runtime
->
GetAllocator
();
MS_LOG
(
INFO
)
<<
"PoolingParameter"
;
auto
param
=
new
PoolingParameter
;
auto
param
=
new
(
std
::
nothrow
)
PoolingParameter
;
InitParameter
(
param
);
// define tensor
...
...
@@ -56,21 +56,39 @@ TEST_F(TestMaxPoolingOpenCL, MaxPool_1_32_512_96) {
auto
data_type
=
kNumberTypeFloat32
;
auto
tensorType
=
schema
::
NodeType_ValueNode
;
MS_LOG
(
INFO
)
<<
"define tensor2"
;
auto
input_tensor
=
new
lite
::
tensor
::
Tensor
(
data_type
,
input_shape
,
schema
::
Format_NHWC4
,
tensorType
);
auto
output_tensor
=
new
lite
::
tensor
::
Tensor
(
data_type
,
output_shape
,
schema
::
Format_NHWC4
,
tensorType
);
auto
input_tensor
=
new
(
std
::
nothrow
)
lite
::
tensor
::
Tensor
(
data_type
,
input_shape
,
schema
::
Format_NHWC4
,
tensorType
);
auto
output_tensor
=
new
(
std
::
nothrow
)
lite
::
tensor
::
Tensor
(
data_type
,
output_shape
,
schema
::
Format_NHWC4
,
tensorType
);
if
(
input_tensor
==
nullptr
)
{
MS_LOG
(
ERROR
)
<<
"input_tensor null"
;
return
;
}
if
(
output_tensor
==
nullptr
)
{
MS_LOG
(
ERROR
)
<<
"output_tensor null"
;
return
;
}
MS_LOG
(
INFO
)
<<
"define input"
;
std
::
vector
<
lite
::
tensor
::
Tensor
*>
inputs
{
input_tensor
};
std
::
vector
<
lite
::
tensor
::
Tensor
*>
outputs
{
output_tensor
};
// run
MS_LOG
(
INFO
)
<<
"pooling_kernel"
;
auto
*
pooling_kernel
=
new
kernel
::
PoolingOpenCLKernel
(
reinterpret_cast
<
OpParameter
*>
(
param
),
inputs
,
outputs
);
auto
*
pooling_kernel
=
new
(
std
::
nothrow
)
kernel
::
PoolingOpenCLKernel
(
reinterpret_cast
<
OpParameter
*>
(
param
),
inputs
,
outputs
);
if
(
pooling_kernel
==
nullptr
)
{
MS_LOG
(
ERROR
)
<<
"pooling_kernel null"
;
return
;
}
MS_LOG
(
INFO
)
<<
"pooling_kernel init"
;
pooling_kernel
->
Init
();
std
::
vector
<
kernel
::
LiteKernel
*>
kernels
{
pooling_kernel
};
inputs
[
0
]
->
MallocData
(
allocator
);
auto
*
pGraph
=
new
kernel
::
SubGraphOpenCLKernel
(
inputs
,
outputs
,
kernels
,
kernels
,
kernels
);
auto
*
pGraph
=
new
(
std
::
nothrow
)
kernel
::
SubGraphOpenCLKernel
(
inputs
,
outputs
,
kernels
,
kernels
,
kernels
);
if
(
pGraph
==
nullptr
)
{
MS_LOG
(
ERROR
)
<<
"pGraph null"
;
return
;
}
MS_LOG
(
INFO
)
<<
"pGraph init"
;
pGraph
->
Init
();
...
...
mindspore/lite/test/ut/src/runtime/kernel/opencl/softmax_tests.cc
浏览文件 @
f459df18
...
...
@@ -28,41 +28,49 @@ class TestSoftmaxOpenCL : public mindspore::CommonTest {};
void
RunTestCase
(
std
::
vector
<
int
>
input_shape
,
std
::
vector
<
int
>
output_shape
,
std
::
string
input_file
,
std
::
string
expect_file
,
SoftmaxParameter
*
param
,
schema
::
Format
format
)
{
std
::
cout
<<
"runtime"
<<
std
::
endl
;
auto
ocl_runtime
=
lite
::
opencl
::
OpenCLRuntime
::
GetInstance
();
ocl_runtime
->
Init
();
auto
allocator
=
ocl_runtime
->
GetAllocator
();
// define tensor
MS_LOG
(
INFO
)
<<
"defineTensor"
;
std
::
cout
<<
"defineTensor"
<<
std
::
endl
;
auto
data_type
=
kNumberTypeFloat32
;
auto
tensorType
=
schema
::
NodeType_ValueNode
;
auto
input_tensor
=
new
lite
::
tensor
::
Tensor
(
data_type
,
input_shape
,
format
,
tensorType
);
auto
output_tensor
=
new
lite
::
tensor
::
Tensor
(
data_type
,
output_shape
,
format
,
tensorType
);
auto
input_tensor
=
new
(
std
::
nothrow
)
lite
::
tensor
::
Tensor
(
data_type
,
input_shape
,
format
,
tensorType
);
auto
output_tensor
=
new
(
std
::
nothrow
)
lite
::
tensor
::
Tensor
(
data_type
,
output_shape
,
format
,
tensorType
);
if
(
input_tensor
==
nullptr
)
{
MS_LOG
(
ERROR
)
<<
"input tensor null"
;
return
;
}
if
(
output_tensor
==
nullptr
)
{
MS_LOG
(
ERROR
)
<<
"output tensor null"
;
return
;
}
std
::
vector
<
lite
::
tensor
::
Tensor
*>
inputs
{
input_tensor
};
std
::
vector
<
lite
::
tensor
::
Tensor
*>
outputs
{
output_tensor
};
// run
MS_LOG
(
INFO
)
<<
"NewOpenCLKernel"
;
std
::
cout
<<
"NewOpenCLKernel"
<<
std
::
endl
;
auto
*
kernel
=
new
kernel
::
SoftmaxOpenCLKernel
(
reinterpret_cast
<
OpParameter
*>
(
param
),
inputs
,
outputs
);
if
(
kernel
==
nullptr
)
{
MS_LOG
(
ERROR
)
<<
"kernel null"
;
return
;
}
MS_LOG
(
INFO
)
<<
"KernelInit"
;
std
::
cout
<<
"KernelInit"
<<
std
::
endl
;
kernel
->
Init
();
std
::
cout
<<
"LiteKernel"
<<
std
::
endl
;
std
::
vector
<
kernel
::
LiteKernel
*>
kernels
{
kernel
};
inputs
[
0
]
->
MallocData
(
allocator
);
std
::
cout
<<
"SubGraphOpenCLKernel"
<<
std
::
endl
;
auto
*
pGraph
=
new
kernel
::
SubGraphOpenCLKernel
(
inputs
,
outputs
,
kernels
,
kernels
,
kernels
);
auto
*
pGraph
=
new
(
std
::
nothrow
)
kernel
::
SubGraphOpenCLKernel
(
inputs
,
outputs
,
kernels
,
kernels
,
kernels
);
if
(
pGraph
==
nullptr
)
{
MS_LOG
(
ERROR
)
<<
"pGraph null"
;
return
;
}
MS_LOG
(
INFO
)
<<
"pGraphinit"
;
pGraph
->
Init
();
// load data
MS_LOG
(
INFO
)
<<
"load data1"
;
LoadTestData
(
input_tensor
->
Data
(),
input_tensor
->
Size
(),
input_file
);
auto
*
input_data
=
reinterpret_cast
<
float
*>
(
input_tensor
->
Data
());
printf
(
"
\n
input[0:10]:"
);
...
...
@@ -75,7 +83,6 @@ void RunTestCase(std::vector<int> input_shape, std::vector<int> output_shape, st
pGraph
->
Run
();
MS_LOG
(
INFO
)
<<
"compare result"
;
std
::
cout
<<
"compare result"
<<
std
::
endl
;
CompareOutput
(
output_tensor
,
expect_file
);
for
(
auto
tensor
:
inputs
)
{
delete
tensor
;
...
...
@@ -93,23 +100,11 @@ TEST_F(TestSoftmaxOpenCL, Softmax_1) {
std
::
vector
<
int
>
output_shape
=
{
1
,
2
,
2
,
8
};
std
::
string
input_file
=
"softmax_in.bin"
;
std
::
string
expect_file
=
"softmax_out.bin"
;
auto
param
=
new
SoftmaxParameter
;
auto
param
=
new
(
std
::
nothrow
)
SoftmaxParameter
;
param
->
axis_
=
3
;
schema
::
Format
format
=
schema
::
Format_NHWC4
;
RunTestCase
(
input_shape
,
output_shape
,
input_file
,
expect_file
,
param
,
format
);
}
// TEST_F(TestSoftmaxOpenCL, Softmax_1x1) {
// std::vector<int> input_shape = {1, 100};
// std::vector<int> output_shape = {1, 100};
// std::string input_file = "softmax1x1_in.bin";
// std::string expect_file = "softmax1x1_out.bin";
// auto param = new SoftmaxParameter;
// param->axis_ = 1;
// schema::Format format = schema::Format_NHWC4;
//
// RunTestCase(input_shape, output_shape, input_file, expect_file, param, format);
//}
}
// namespace mindspore
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录