Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
2301_77200941
mindspore
提交
c19905ce
M
mindspore
项目概览
2301_77200941
/
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看板
体验新版 GitCode,发现更多精彩内容 >>
提交
c19905ce
编写于
8月 27, 2020
作者:
M
mindspore-ci-bot
提交者:
Gitee
8月 27, 2020
浏览文件
操作
浏览文件
下载
差异文件
!5356 add reference count for opencl runtime
Merge pull request !5356 from liuchao/master
上级
716329df
9062e0a7
变更
21
隐藏空白更改
内联
并排
Showing
21 changed file
with
61 addition
and
5 deletion
+61
-5
mindspore/lite/src/lite_session.cc
mindspore/lite/src/lite_session.cc
+5
-0
mindspore/lite/src/runtime/opencl/opencl_allocator.cc
mindspore/lite/src/runtime/opencl/opencl_allocator.cc
+1
-1
mindspore/lite/src/runtime/opencl/opencl_runtime.cc
mindspore/lite/src/runtime/opencl/opencl_runtime.cc
+30
-4
mindspore/lite/src/runtime/opencl/opencl_runtime.h
mindspore/lite/src/runtime/opencl/opencl_runtime.h
+3
-0
mindspore/lite/test/ut/src/runtime/kernel/opencl/activation_tests.cc
...ite/test/ut/src/runtime/kernel/opencl/activation_tests.cc
+2
-0
mindspore/lite/test/ut/src/runtime/kernel/opencl/arithmetic_tests.cc
...ite/test/ut/src/runtime/kernel/opencl/arithmetic_tests.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
+1
-0
mindspore/lite/test/ut/src/runtime/kernel/opencl/batchnorm_tests.cc
...lite/test/ut/src/runtime/kernel/opencl/batchnorm_tests.cc
+2
-0
mindspore/lite/test/ut/src/runtime/kernel/opencl/biasadd_tests.cc
...e/lite/test/ut/src/runtime/kernel/opencl/biasadd_tests.cc
+1
-0
mindspore/lite/test/ut/src/runtime/kernel/opencl/concat_tests.cc
...re/lite/test/ut/src/runtime/kernel/opencl/concat_tests.cc
+2
-0
mindspore/lite/test/ut/src/runtime/kernel/opencl/conv2d_transpose_tests.cc
...st/ut/src/runtime/kernel/opencl/conv2d_transpose_tests.cc
+1
-0
mindspore/lite/test/ut/src/runtime/kernel/opencl/convolution_tests.cc
...te/test/ut/src/runtime/kernel/opencl/convolution_tests.cc
+1
-0
mindspore/lite/test/ut/src/runtime/kernel/opencl/depthwise_conv2d_tests.cc
...st/ut/src/runtime/kernel/opencl/depthwise_conv2d_tests.cc
+2
-0
mindspore/lite/test/ut/src/runtime/kernel/opencl/matmul_tests.cc
...re/lite/test/ut/src/runtime/kernel/opencl/matmul_tests.cc
+1
-0
mindspore/lite/test/ut/src/runtime/kernel/opencl/max_pooling_tests.cc
...te/test/ut/src/runtime/kernel/opencl/max_pooling_tests.cc
+1
-0
mindspore/lite/test/ut/src/runtime/kernel/opencl/prelu_tests.cc
...ore/lite/test/ut/src/runtime/kernel/opencl/prelu_tests.cc
+1
-0
mindspore/lite/test/ut/src/runtime/kernel/opencl/reshape_tests.cc
...e/lite/test/ut/src/runtime/kernel/opencl/reshape_tests.cc
+1
-0
mindspore/lite/test/ut/src/runtime/kernel/opencl/slice_tests.cc
...ore/lite/test/ut/src/runtime/kernel/opencl/slice_tests.cc
+2
-0
mindspore/lite/test/ut/src/runtime/kernel/opencl/softmax_tests.cc
...e/lite/test/ut/src/runtime/kernel/opencl/softmax_tests.cc
+1
-0
mindspore/lite/test/ut/src/runtime/kernel/opencl/to_format_tests.cc
...lite/test/ut/src/runtime/kernel/opencl/to_format_tests.cc
+1
-0
mindspore/lite/test/ut/src/runtime/kernel/opencl/transpose_tests.cc
...lite/test/ut/src/runtime/kernel/opencl/transpose_tests.cc
+1
-0
未找到文件。
mindspore/lite/src/lite_session.cc
浏览文件 @
c19905ce
...
...
@@ -326,6 +326,11 @@ LiteSession::~LiteSession() {
}
}
input_vec_
.
clear
();
#if SUPPORT_GPU
if
(
context_
->
device_ctx_
.
type
==
DT_GPU
)
{
lite
::
opencl
::
OpenCLRuntime
::
DeleteInstance
();
}
#endif
delete
this
->
context_
;
delete
this
->
executor
;
this
->
executor
=
nullptr
;
...
...
mindspore/lite/src/runtime/opencl/opencl_allocator.cc
浏览文件 @
c19905ce
...
...
@@ -24,7 +24,7 @@
namespace
mindspore
::
lite
::
opencl
{
OpenCLAllocator
::
OpenCLAllocator
()
{}
OpenCLAllocator
::~
OpenCLAllocator
()
{}
OpenCLAllocator
::~
OpenCLAllocator
()
{
Clear
();
}
void
OpenCLAllocator
::
SetContext
(
const
AllocatorContext
&
ctx
)
{
lock_flag_
=
ctx
.
lockFlag
;
...
...
mindspore/lite/src/runtime/opencl/opencl_runtime.cc
浏览文件 @
c19905ce
...
...
@@ -40,12 +40,29 @@ static std::mutex g_mtx;
static
std
::
mutex
g_init_mtx
;
bool
OpenCLRuntime
::
init_done_
=
false
;
OpenCLRuntime
*
OpenCLRuntime
::
ocl_runtime_instance_
=
nullptr
;
size_t
OpenCLRuntime
::
instance_count_
=
0
;
OpenCLRuntime
*
OpenCLRuntime
::
GetInstance
()
{
std
::
unique_lock
<
std
::
mutex
>
lck
(
g_mtx
);
static
OpenCLRuntime
ocl_runtime
;
ocl_runtime
.
Init
();
return
&
ocl_runtime
;
if
(
instance_count_
==
0
)
{
ocl_runtime_instance_
=
&
ocl_runtime
;
ocl_runtime_instance_
->
Init
();
}
instance_count_
++
;
return
ocl_runtime_instance_
;
}
void
OpenCLRuntime
::
DeleteInstance
()
{
std
::
unique_lock
<
std
::
mutex
>
lck
(
g_mtx
);
if
(
instance_count_
==
0
)
{
MS_LOG
(
ERROR
)
<<
"No OpenCLRuntime instance could delete!"
;
}
instance_count_
--
;
if
(
instance_count_
==
0
)
{
ocl_runtime_instance_
->
Uninit
();
}
}
OpenCLRuntime
::
OpenCLRuntime
()
{
default_build_opts_
=
" -cl-mad-enable -cl-fast-relaxed-math -Werror"
;
}
...
...
@@ -207,16 +224,25 @@ int OpenCLRuntime::Init() {
return
RET_OK
;
}
OpenCLRuntime
::~
OpenCLRuntime
()
{
init_done_
=
false
;
int
OpenCLRuntime
::
Uninit
()
{
program_map_
.
clear
();
delete
allocator_
;
delete
default_command_queue_
;
delete
context_
;
delete
device_
;
allocator_
=
nullptr
;
default_command_queue_
=
nullptr
;
context_
=
nullptr
;
device_
=
nullptr
;
#ifdef USE_OPENCL_WRAPPER
OpenCLWrapper
::
GetInstance
()
->
UnLoadOpenCLLibrary
();
#endif
init_done_
=
false
;
return
RET_OK
;
}
OpenCLRuntime
::~
OpenCLRuntime
()
{
Uninit
();
}
cl
::
Context
*
OpenCLRuntime
::
Context
()
{
return
context_
;
}
cl
::
Device
*
OpenCLRuntime
::
Device
()
{
return
device_
;
}
...
...
mindspore/lite/src/runtime/opencl/opencl_runtime.h
浏览文件 @
c19905ce
...
...
@@ -47,6 +47,7 @@ class OpenCLRuntime {
OpenCLRuntime
&
operator
=
(
const
OpenCLRuntime
&
)
=
delete
;
int
Init
();
int
Uninit
();
cl
::
Context
*
Context
();
cl
::
Device
*
Device
();
...
...
@@ -143,6 +144,8 @@ class OpenCLRuntime {
private:
static
bool
init_done_
;
static
size_t
instance_count_
;
static
OpenCLRuntime
*
ocl_runtime_instance_
;
cl
::
CommandQueue
*
default_command_queue_
{
nullptr
};
cl
::
Context
*
context_
{
nullptr
};
cl
::
Device
*
device_
{
nullptr
};
...
...
mindspore/lite/test/ut/src/runtime/kernel/opencl/activation_tests.cc
浏览文件 @
c19905ce
...
...
@@ -377,6 +377,7 @@ TEST_F(TestActivationOpenCL, SigmoidFp32_dim4) {
delete
input_tensor
;
delete
output_tensor
;
delete
sub_graph
;
lite
::
opencl
::
OpenCLRuntime
::
DeleteInstance
();
}
TEST_F
(
TestActivationOpenCL
,
LeakyReluFp32_dim4
)
{
...
...
@@ -480,5 +481,6 @@ TEST_F(TestActivationOpenCL, LeakyReluFp32_dim4) {
delete
input_tensor
;
delete
output_tensor
;
delete
sub_graph
;
lite
::
opencl
::
OpenCLRuntime
::
DeleteInstance
();
}
}
// namespace mindspore
mindspore/lite/test/ut/src/runtime/kernel/opencl/arithmetic_tests.cc
浏览文件 @
c19905ce
...
...
@@ -202,6 +202,7 @@ void TestCase(const std::vector<int> &shape_a, const std::vector<int> &shape_b)
for
(
auto
tensor
:
outputs
)
{
delete
tensor
;
}
lite
::
opencl
::
OpenCLRuntime
::
DeleteInstance
();
}
class
TestArithmeticOpenCL
:
public
mindspore
::
CommonTest
{
...
...
mindspore/lite/test/ut/src/runtime/kernel/opencl/avg_pooling_tests.cc
浏览文件 @
c19905ce
...
...
@@ -142,6 +142,7 @@ TEST_F(TestAvgPoolingOpenCL, AvgPoolFp32) {
delete
pooling_kernel
;
delete
pGraph
;
delete
param
;
lite
::
opencl
::
OpenCLRuntime
::
DeleteInstance
();
}
}
// namespace mindspore
mindspore/lite/test/ut/src/runtime/kernel/opencl/batchnorm_tests.cc
浏览文件 @
c19905ce
...
...
@@ -158,6 +158,7 @@ TEST_F(TestBatchnormOpenCLfp16, Batchnormfp16input_dim4) {
delete
param
;
delete
batchnorm_kernel
;
delete
sub_graph
;
lite
::
opencl
::
OpenCLRuntime
::
DeleteInstance
();
}
TEST_F
(
TestBatchnormOpenCLfp32
,
Batchnormfp32input_dim4
)
{
MS_LOG
(
INFO
)
<<
"begin test"
;
...
...
@@ -277,5 +278,6 @@ TEST_F(TestBatchnormOpenCLfp32, Batchnormfp32input_dim4) {
delete
param
;
delete
batchnorm_kernel
;
delete
sub_graph
;
lite
::
opencl
::
OpenCLRuntime
::
DeleteInstance
();
}
}
// namespace mindspore
mindspore/lite/test/ut/src/runtime/kernel/opencl/biasadd_tests.cc
浏览文件 @
c19905ce
...
...
@@ -198,5 +198,6 @@ TEST_F(TestBiasAddOpenCL, BiasAddFp32_dim4) {
delete
sub_graph
;
delete
param
;
delete
biasadd_kernel
;
lite
::
opencl
::
OpenCLRuntime
::
DeleteInstance
();
}
}
// namespace mindspore
mindspore/lite/test/ut/src/runtime/kernel/opencl/concat_tests.cc
浏览文件 @
c19905ce
...
...
@@ -218,6 +218,7 @@ TEST_F(TestConcatOpenCLfp16, ConcatFp16_2input_dim4_axis3) {
delete
param
;
delete
concat_kernel
;
delete
sub_graph
;
lite
::
opencl
::
OpenCLRuntime
::
DeleteInstance
();
}
TEST_F
(
TestConcatOpenCLfp32
,
ConcatFp32_2input_dim4_axis3
)
{
...
...
@@ -338,5 +339,6 @@ TEST_F(TestConcatOpenCLfp32, ConcatFp32_2input_dim4_axis3) {
delete
param
;
delete
concat_kernel
;
delete
sub_graph
;
lite
::
opencl
::
OpenCLRuntime
::
DeleteInstance
();
}
}
// namespace mindspore
mindspore/lite/test/ut/src/runtime/kernel/opencl/conv2d_transpose_tests.cc
浏览文件 @
c19905ce
...
...
@@ -134,6 +134,7 @@ void RunTestCaseConv2dTranspose(const std::vector<int> &shape, void *input_data,
inputs
[
0
]
->
SetData
(
nullptr
);
outputs
[
0
]
->
SetData
(
nullptr
);
lite
::
opencl
::
OpenCLRuntime
::
DeleteInstance
();
}
void
RunTestCaseConv2dTranspose
(
const
std
::
vector
<
int
>
shape
,
const
std
::
vector
<
std
::
string
>
file_path
,
bool
fp16
)
{
...
...
mindspore/lite/test/ut/src/runtime/kernel/opencl/convolution_tests.cc
浏览文件 @
c19905ce
...
...
@@ -158,6 +158,7 @@ void TEST_MAIN(schema::Format input_format, schema::Format output_format, const
bias_tensor
.
SetData
(
nullptr
);
delete
param
;
delete
sub_graph
;
lite
::
opencl
::
OpenCLRuntime
::
DeleteInstance
();
}
TEST_F
(
TestConvolutionOpenCL
,
in1x224x224x3_out1x112x112x32_k33_s22_p0101_fp32
)
{
...
...
mindspore/lite/test/ut/src/runtime/kernel/opencl/depthwise_conv2d_tests.cc
浏览文件 @
c19905ce
...
...
@@ -162,6 +162,7 @@ void DepthWiseTestMain(ConvParameter *conv_param, T2 *input_data, T1 *weight_dat
inputs
[
1
]
->
SetData
(
nullptr
);
inputs
[
2
]
->
SetData
(
nullptr
);
delete
[]
packed_input
;
lite
::
opencl
::
OpenCLRuntime
::
DeleteInstance
();
return
;
}
...
...
@@ -587,5 +588,6 @@ TEST_F(TestConvolutionDwOpenCL, ProfilingMobilenetv2Fp32) {
}
delete
[]
input_data
;
delete
[]
weight_data
;
lite
::
opencl
::
OpenCLRuntime
::
DeleteInstance
();
}
}
// namespace mindspore
mindspore/lite/test/ut/src/runtime/kernel/opencl/matmul_tests.cc
浏览文件 @
c19905ce
...
...
@@ -111,6 +111,7 @@ void RunTestCaseMatMul(const std::vector<int> shape, const std::vector<std::stri
tensor_x
->
SetData
(
nullptr
);
tensor_out
->
SetData
(
nullptr
);
MS_LOG
(
INFO
)
<<
"TestMatMulFp32 passed"
;
lite
::
opencl
::
OpenCLRuntime
::
DeleteInstance
();
}
TEST_F
(
TestMatMulOpenCL
,
MatMulFp32
)
{
...
...
mindspore/lite/test/ut/src/runtime/kernel/opencl/max_pooling_tests.cc
浏览文件 @
c19905ce
...
...
@@ -118,6 +118,7 @@ TEST_F(TestMaxPoolingOpenCL, MaxPool_1_32_512_96) {
}
delete
pooling_kernel
;
delete
pGraph
;
lite
::
opencl
::
OpenCLRuntime
::
DeleteInstance
();
}
}
// namespace mindspore
mindspore/lite/test/ut/src/runtime/kernel/opencl/prelu_tests.cc
浏览文件 @
c19905ce
...
...
@@ -183,5 +183,6 @@ TEST_F(TestPReluOpenCL, PReluFp32_dim4) {
delete
param
;
delete
prelu_kernel
;
delete
sub_graph
;
lite
::
opencl
::
OpenCLRuntime
::
DeleteInstance
();
}
}
// namespace mindspore
mindspore/lite/test/ut/src/runtime/kernel/opencl/reshape_tests.cc
浏览文件 @
c19905ce
...
...
@@ -106,5 +106,6 @@ TEST_F(TestReshapeOpenCL, ReshapeFp32) {
outputs
[
0
]
->
SetData
(
nullptr
);
MS_LOG
(
INFO
)
<<
"Test ReshapeFp32 passed"
;
lite
::
opencl
::
OpenCLRuntime
::
DeleteInstance
();
}
}
// namespace mindspore
mindspore/lite/test/ut/src/runtime/kernel/opencl/slice_tests.cc
浏览文件 @
c19905ce
...
...
@@ -148,6 +148,7 @@ TEST_F(TestSliceOpenCLfp32, Slicefp32input_dim4) {
}
delete
slice_kernel
;
delete
sub_graph
;
lite
::
opencl
::
OpenCLRuntime
::
DeleteInstance
();
}
TEST_F
(
TestSliceOpenCLfp16
,
Slicefp16input_dim4
)
{
MS_LOG
(
INFO
)
<<
"begin test"
;
...
...
@@ -258,5 +259,6 @@ TEST_F(TestSliceOpenCLfp16, Slicefp16input_dim4) {
}
delete
slice_kernel
;
delete
sub_graph
;
lite
::
opencl
::
OpenCLRuntime
::
DeleteInstance
();
}
}
// namespace mindspore
mindspore/lite/test/ut/src/runtime/kernel/opencl/softmax_tests.cc
浏览文件 @
c19905ce
...
...
@@ -92,6 +92,7 @@ void RunTestCase(std::vector<int> input_shape, std::vector<int> output_shape, st
}
delete
kernel
;
delete
pGraph
;
lite
::
opencl
::
OpenCLRuntime
::
DeleteInstance
();
}
TEST_F
(
TestSoftmaxOpenCL
,
Softmax_1
)
{
...
...
mindspore/lite/test/ut/src/runtime/kernel/opencl/to_format_tests.cc
浏览文件 @
c19905ce
...
...
@@ -103,5 +103,6 @@ TEST_F(TestToFormatOpenCL, ToFormatNHWC2NCHW) {
// compare
CompareOutputData
(
output_data
,
correct_data
,
h
*
w
*
c
,
0.00001
);
MS_LOG
(
INFO
)
<<
"Test TransposeFp32 passed"
;
lite
::
opencl
::
OpenCLRuntime
::
DeleteInstance
();
}
}
// namespace mindspore
mindspore/lite/test/ut/src/runtime/kernel/opencl/transpose_tests.cc
浏览文件 @
c19905ce
...
...
@@ -108,5 +108,6 @@ TEST_F(TestTransposeOpenCL, TransposeFp32) {
outputs
[
0
]
->
SetData
(
nullptr
);
MS_LOG
(
INFO
)
<<
"Test TransposeFp32 passed"
;
lite
::
opencl
::
OpenCLRuntime
::
DeleteInstance
();
}
}
// namespace mindspore
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录