Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle-Lite
提交
5c39519e
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看板
未验证
提交
5c39519e
编写于
9月 21, 2020
作者:
H
huzhiqiang
提交者:
GitHub
9月 21, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[Framework] Add method for specifying initial size of `workspace_` (#4378)
上级
cda2e2d9
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
63 addition
and
3 deletion
+63
-3
lite/api/paddle_api.cc
lite/api/paddle_api.cc
+8
-0
lite/api/paddle_api.h
lite/api/paddle_api.h
+13
-0
lite/api/paddle_api_test.cc
lite/api/paddle_api_test.cc
+4
-1
lite/core/device_info.h
lite/core/device_info.h
+38
-2
未找到文件。
lite/api/paddle_api.cc
浏览文件 @
5c39519e
...
...
@@ -356,5 +356,13 @@ void MobileConfig::set_model_buffer(const char *model_buffer,
model_from_memory_
=
true
;
}
// This is the method for allocating workspace_size according to L3Cache size
void
MobileConfig
::
SetArmL3CacheSize
(
L3CacheSetMethod
method
,
int
absolute_val
)
{
#ifdef LITE_WITH_ARM
lite
::
DeviceInfo
::
Global
().
SetArmL3CacheSize
(
method
,
absolute_val
);
#endif
}
}
// namespace lite_api
}
// namespace paddle
lite/api/paddle_api.h
浏览文件 @
5c39519e
...
...
@@ -32,6 +32,14 @@ using shape_t = std::vector<int64_t>;
using
lod_t
=
std
::
vector
<
std
::
vector
<
uint64_t
>>
;
enum
class
LiteModelType
{
kProtobuf
=
0
,
kNaiveBuffer
,
UNK
};
// Methods for allocating L3Cache on Arm platform
enum
class
L3CacheSetMethod
{
kDeviceL3Cache
=
0
,
// Use the system L3 Cache size, best performance.
kDeviceL2Cache
=
1
,
// Use the system L2 Cache size, trade off performance
// with less memory consumption.
kAbsolute
=
2
,
// Use the external setting.
// kAutoGrow = 3, // Not supported yet, least memory consumption.
};
// return true if current device supports OpenCL model
LITE_API
bool
IsOpenCLBackendValid
();
...
...
@@ -294,6 +302,11 @@ class LITE_API MobileConfig : public ConfigBase {
// NOTE: This is a deprecated API and will be removed in latter release.
const
std
::
string
&
param_buffer
()
const
{
return
param_buffer_
;
}
// This is the method for allocating workspace_size according to L3Cache size
void
SetArmL3CacheSize
(
L3CacheSetMethod
method
=
L3CacheSetMethod
::
kDeviceL3Cache
,
int
absolute_val
=
-
1
);
};
template
<
typename
ConfigT
>
...
...
lite/api/paddle_api_test.cc
浏览文件 @
5c39519e
...
...
@@ -107,7 +107,8 @@ TEST(CxxApi, share_external_data) {
TEST
(
LightApi
,
run
)
{
lite_api
::
MobileConfig
config
;
config
.
set_model_from_file
(
FLAGS_model_dir
+
".opt2.naive.nb"
);
// disable L3 cache on workspace_ allocating
config
.
SetArmL3CacheSize
(
L3CacheSetMethod
::
kDeviceL2Cache
);
auto
predictor
=
lite_api
::
CreatePaddlePredictor
(
config
);
auto
inputs
=
predictor
->
GetInputNames
();
...
...
@@ -148,6 +149,8 @@ TEST(MobileConfig, LoadfromMemory) {
// set model buffer and run model
lite_api
::
MobileConfig
config
;
config
.
set_model_from_buffer
(
model_buffer
);
// allocate 1M initial space for workspace_
config
.
SetArmL3CacheSize
(
L3CacheSetMethod
::
kAbsolute
,
1024
*
1024
);
auto
predictor
=
lite_api
::
CreatePaddlePredictor
(
config
);
auto
input_tensor
=
predictor
->
GetInput
(
0
);
...
...
lite/core/device_info.h
浏览文件 @
5c39519e
...
...
@@ -17,6 +17,7 @@
#include <cstdarg>
#include <string>
#include <vector>
#include "lite/api/paddle_api.h"
#include "lite/core/tensor.h"
#include "lite/utils/cp_logging.h"
#ifdef LITE_WITH_MLU
...
...
@@ -27,6 +28,7 @@
namespace
paddle
{
namespace
lite
{
using
L3CacheSetMethod
=
lite_api
::
L3CacheSetMethod
;
#if ((defined LITE_WITH_ARM) || (defined LITE_WITH_MLU))
typedef
enum
{
...
...
@@ -65,11 +67,41 @@ class DeviceInfo {
int
l1_cache_size
()
const
{
return
L1_cache_
[
active_ids_
[
0
]];
}
int
l2_cache_size
()
const
{
return
L2_cache_
[
active_ids_
[
0
]];
}
int
l3_cache_size
()
const
{
return
L3_cache_
[
active_ids_
[
0
]];
}
// Methods for allocating L3Cache on Arm platform
// Enum class L3CacheSetMethod is declared in `lite/api/paddle_api.h`
void
SetArmL3CacheSize
(
L3CacheSetMethod
method
=
L3CacheSetMethod
::
kDeviceL3Cache
,
int
absolute_val
=
-
1
)
{
l3_cache_method_
=
method
;
absolute_l3cache_size_
=
absolute_val
;
// Realloc memory for sgemm in this context.
workspace_
.
clear
();
workspace_
.
Resize
({
llc_size
()});
workspace_
.
mutable_data
<
int8_t
>
();
}
int
llc_size
()
const
{
auto
size
=
L3_cache_
[
active_ids_
[
0
]]
>
0
?
L3_cache_
[
active_ids_
[
0
]]
:
L2_cache_
[
active_ids_
[
0
]];
auto
size
=
absolute_l3cache_size_
;
switch
(
l3_cache_method_
)
{
// kDeviceL3Cache = 0, use the system L3 Cache size, best performance.
case
L3CacheSetMethod
::
kDeviceL3Cache
:
size
=
L3_cache_
[
active_ids_
[
0
]]
>
0
?
L3_cache_
[
active_ids_
[
0
]]
:
L2_cache_
[
active_ids_
[
0
]];
break
;
// kDeviceL2Cache = 1, use the system L2 Cache size, trade off performance
// with less memory consumption.
case
L3CacheSetMethod
::
kDeviceL2Cache
:
size
=
L2_cache_
[
active_ids_
[
0
]];
break
;
// kAbsolute = 2, use the external setting.
case
L3CacheSetMethod
::
kAbsolute
:
break
;
default:
LOG
(
FATAL
)
<<
"Error: unknown l3_cache_method_ !"
;
}
return
size
>
0
?
size
:
512
*
1024
;
}
bool
has_dot
()
const
{
return
dot_
[
active_ids_
[
0
]];
}
bool
has_fp16
()
const
{
return
fp16_
[
active_ids_
[
0
]];
}
...
...
@@ -121,6 +153,10 @@ class DeviceInfo {
void
RequestPowerRandHighMode
(
int
shift_num
,
int
thread_num
);
void
RequestPowerRandLowMode
(
int
shift_num
,
int
thread_num
);
// Methods for allocating L3Cache on Arm platform
// Enum class L3CacheSetMethod is declared in `lite/api/paddle_api.h`
L3CacheSetMethod
l3_cache_method_
{
L3CacheSetMethod
::
kDeviceL3Cache
};
int
absolute_l3cache_size_
{
-
1
};
DeviceInfo
()
=
default
;
};
#endif // LITE_WITH_ARM
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录