Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle-Lite
提交
71b05c94
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看板
提交
71b05c94
编写于
9月 19, 2019
作者:
S
sangoly
提交者:
Yan Chunwei
9月 19, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[Java API] add getVersion() interface to get c++ lib's version information test=develop (#2063)
上级
3569483a
变更
7
显示空白变更内容
内联
并排
Showing
7 changed file
with
60 addition
and
3 deletion
+60
-3
lite/CMakeLists.txt
lite/CMakeLists.txt
+1
-1
lite/api/android/jni/native/convert_util_jni.h
lite/api/android/jni/native/convert_util_jni.h
+21
-0
lite/api/android/jni/native/paddle_lite_jni.cc
lite/api/android/jni/native/paddle_lite_jni.cc
+10
-0
lite/api/android/jni/native/paddle_lite_jni.h
lite/api/android/jni/native/paddle_lite_jni.h
+8
-0
lite/api/android/jni/src/com/baidu/paddle/lite/PaddlePredictor.java
...ndroid/jni/src/com/baidu/paddle/lite/PaddlePredictor.java
+7
-0
lite/demo/java/android/PaddlePredictor/app/src/main/java/com/baidu/paddle/lite/MainActivity.java
...app/src/main/java/com/baidu/paddle/lite/MainActivity.java
+13
-1
lite/tools/cmake_tools/parse_kernel_registry.py
lite/tools/cmake_tools/parse_kernel_registry.py
+0
-1
未找到文件。
lite/CMakeLists.txt
浏览文件 @
71b05c94
...
@@ -58,7 +58,7 @@ if (LITE_WITH_LIGHT_WEIGHT_FRAMEWORK AND LITE_WITH_ARM)
...
@@ -58,7 +58,7 @@ if (LITE_WITH_LIGHT_WEIGHT_FRAMEWORK AND LITE_WITH_ARM)
endif
(
LITE_WITH_NPU
)
endif
(
LITE_WITH_NPU
)
if
(
LITE_WITH_FPGA
)
if
(
LITE_WITH_FPGA
)
set
(
INFER_LITE_PUBLISH_ROOT
"
${
INFER_LITE_PUBLISH_ROOT
}
.fpga"
)
set
(
INFER_LITE_PUBLISH_ROOT
"
${
INFER_LITE_PUBLISH_ROOT
}
.fpga"
)
endif
(
LITE_WITH_
NPU
)
endif
(
LITE_WITH_
FPGA
)
message
(
STATUS
"publish inference lib to
${
INFER_LITE_PUBLISH_ROOT
}
"
)
message
(
STATUS
"publish inference lib to
${
INFER_LITE_PUBLISH_ROOT
}
"
)
# The final target for publish lite lib
# The final target for publish lite lib
...
...
lite/api/android/jni/native/convert_util_jni.h
浏览文件 @
71b05c94
...
@@ -49,6 +49,27 @@ inline std::string jstring_to_cpp_string(JNIEnv *env, jstring jstr) {
...
@@ -49,6 +49,27 @@ inline std::string jstring_to_cpp_string(JNIEnv *env, jstring jstr) {
return
ret
;
return
ret
;
}
}
inline
jstring
cpp_string_to_jstring
(
JNIEnv
*
env
,
std
::
string
str
)
{
auto
*
data
=
str
.
c_str
();
jclass
strClass
=
env
->
FindClass
(
"java/lang/String"
);
jmethodID
strClassInitMethodID
=
env
->
GetMethodID
(
strClass
,
"<init>"
,
"([BLjava/lang/String;)V"
);
jbyteArray
bytes
=
env
->
NewByteArray
(
strlen
(
data
));
env
->
SetByteArrayRegion
(
bytes
,
0
,
strlen
(
data
),
reinterpret_cast
<
const
jbyte
*>
(
data
));
jstring
encoding
=
env
->
NewStringUTF
(
"UTF-8"
);
jstring
res
=
(
jstring
)(
env
->
NewObject
(
strClass
,
strClassInitMethodID
,
bytes
,
encoding
));
env
->
DeleteLocalRef
(
strClass
);
env
->
DeleteLocalRef
(
encoding
);
env
->
DeleteLocalRef
(
bytes
);
return
res
;
}
inline
jfloatArray
cpp_array_to_jfloatarray
(
JNIEnv
*
env
,
inline
jfloatArray
cpp_array_to_jfloatarray
(
JNIEnv
*
env
,
const
float
*
buf
,
const
float
*
buf
,
int64_t
len
)
{
int64_t
len
)
{
...
...
lite/api/android/jni/native/paddle_lite_jni.cc
浏览文件 @
71b05c94
...
@@ -50,6 +50,16 @@ JNIEXPORT jboolean JNICALL Java_com_baidu_paddle_lite_PaddlePredictor_run(
...
@@ -50,6 +50,16 @@ JNIEXPORT jboolean JNICALL Java_com_baidu_paddle_lite_PaddlePredictor_run(
return
JNI_TRUE
;
return
JNI_TRUE
;
}
}
JNIEXPORT
jstring
JNICALL
Java_com_baidu_paddle_lite_PaddlePredictor_getVersion
(
JNIEnv
*
env
,
jobject
jpaddle_predictor
)
{
std
::
shared_ptr
<
PaddlePredictor
>
*
predictor
=
getPaddlePredictorPointer
(
env
,
jpaddle_predictor
);
if
(
predictor
==
nullptr
||
(
*
predictor
==
nullptr
))
{
return
cpp_string_to_jstring
(
env
,
""
);
}
return
cpp_string_to_jstring
(
env
,
(
*
predictor
)
->
GetVersion
());
}
JNIEXPORT
jboolean
JNICALL
JNIEXPORT
jboolean
JNICALL
Java_com_baidu_paddle_lite_PaddlePredictor_saveOptimizedModel
(
Java_com_baidu_paddle_lite_PaddlePredictor_saveOptimizedModel
(
JNIEnv
*
env
,
jobject
jpaddle_predictor
,
jstring
model_dir
)
{
JNIEnv
*
env
,
jobject
jpaddle_predictor
,
jstring
model_dir
)
{
...
...
lite/api/android/jni/native/paddle_lite_jni.h
浏览文件 @
71b05c94
...
@@ -37,6 +37,14 @@ namespace lite_api {
...
@@ -37,6 +37,14 @@ namespace lite_api {
JNIEXPORT
jboolean
JNICALL
JNIEXPORT
jboolean
JNICALL
Java_com_baidu_paddle_lite_PaddlePredictor_run
(
JNIEnv
*
,
jobject
);
Java_com_baidu_paddle_lite_PaddlePredictor_run
(
JNIEnv
*
,
jobject
);
/*
* Class: com_baidu_paddle_lite_PaddlePredictor
* Method: getVersion
* Signature: ()Z
*/
JNIEXPORT
jstring
JNICALL
Java_com_baidu_paddle_lite_PaddlePredictor_getVersion
(
JNIEnv
*
,
jobject
);
/*
/*
* Class: com_baidu_paddle_lite_PaddlePredictor
* Class: com_baidu_paddle_lite_PaddlePredictor
* Method: saveOptimizedModel
* Method: saveOptimizedModel
...
...
lite/api/android/jni/src/com/baidu/paddle/lite/PaddlePredictor.java
浏览文件 @
71b05c94
...
@@ -82,6 +82,13 @@ public class PaddlePredictor {
...
@@ -82,6 +82,13 @@ public class PaddlePredictor {
*/
*/
public
native
boolean
run
();
public
native
boolean
run
();
/**
* Get c++ lib's version information.
*
* @return C++ lib's version information.
*/
public
native
String
getVersion
();
/**
/**
* Saves the optimized model. It is available only for {@link CxxConfig}
* Saves the optimized model. It is available only for {@link CxxConfig}
*
*
...
...
lite/demo/java/android/PaddlePredictor/app/src/main/java/com/baidu/paddle/lite/MainActivity.java
浏览文件 @
71b05c94
...
@@ -20,9 +20,13 @@ public class MainActivity extends AppCompatActivity {
...
@@ -20,9 +20,13 @@ public class MainActivity extends AppCompatActivity {
setContentView
(
R
.
layout
.
activity_main
);
setContentView
(
R
.
layout
.
activity_main
);
String
textOutput
=
""
;
String
textOutput
=
""
;
String
version
=
getVersionInfo
(
"lite_naive_model_opt.nb"
,
this
);
textOutput
+=
"Version: "
+
version
+
"\n"
;
Tensor
output
;
Tensor
output
;
output
=
setInputAndRunNaiveModel
(
"lite_naive_model_opt.nb"
,
this
);
output
=
setInputAndRunNaiveModel
(
"lite_naive_model_opt.nb"
,
this
);
textOutput
+=
"lite_naive_model output: "
+
output
.
getFloatData
()[
0
]
+
", "
textOutput
+=
"
\n
lite_naive_model output: "
+
output
.
getFloatData
()[
0
]
+
", "
+
output
.
getFloatData
()[
1
]
+
"\n"
;
+
output
.
getFloatData
()[
1
]
+
"\n"
;
textOutput
+=
"expected: 50.2132, -28.8729\n"
;
textOutput
+=
"expected: 50.2132, -28.8729\n"
;
...
@@ -54,6 +58,14 @@ public class MainActivity extends AppCompatActivity {
...
@@ -54,6 +58,14 @@ public class MainActivity extends AppCompatActivity {
textView
.
setText
(
textOutput
);
textView
.
setText
(
textOutput
);
}
}
public
static
String
getVersionInfo
(
String
modelName
,
Context
context
)
{
String
modelPath
=
copyFromAssetsToCache
(
modelName
,
context
);
MobileConfig
config
=
new
MobileConfig
();
config
.
setModelDir
(
modelPath
);
PaddlePredictor
predictor
=
PaddlePredictor
.
createPaddlePredictor
(
config
);
return
predictor
.
getVersion
();
}
public
static
String
copyFromAssetsToCache
(
String
modelPath
,
Context
context
)
{
public
static
String
copyFromAssetsToCache
(
String
modelPath
,
Context
context
)
{
String
newPath
=
context
.
getCacheDir
()
+
"/"
+
modelPath
;
String
newPath
=
context
.
getCacheDir
()
+
"/"
+
modelPath
;
// String newPath = "/sdcard/" + modelPath;
// String newPath = "/sdcard/" + modelPath;
...
...
lite/tools/cmake_tools/parse_kernel_registry.py
浏览文件 @
71b05c94
...
@@ -30,7 +30,6 @@ with open(ops_list_path) as f:
...
@@ -30,7 +30,6 @@ with open(ops_list_path) as f:
paths
=
set
([
path
for
path
in
f
])
paths
=
set
([
path
for
path
in
f
])
for
path
in
paths
:
for
path
in
paths
:
with
open
(
path
.
strip
())
as
g
:
with
open
(
path
.
strip
())
as
g
:
print
'path: '
,
path
c
=
g
.
read
()
c
=
g
.
read
()
kernel_parser
=
RegisterLiteKernelParser
(
c
)
kernel_parser
=
RegisterLiteKernelParser
(
c
)
kernel_parser
.
parse
()
kernel_parser
.
parse
()
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录