Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle-Lite
提交
e91eef1c
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看板
未验证
提交
e91eef1c
编写于
8月 29, 2019
作者:
S
sangoly
提交者:
GitHub
8月 29, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[Java API] add setThreads & setPowerMode interface (#1907)
上级
178a93b9
变更
5
显示空白变更内容
内联
并排
Showing
5 changed file
with
105 addition
and
8 deletion
+105
-8
lite/api/android/jni/CMakeLists.txt
lite/api/android/jni/CMakeLists.txt
+1
-0
lite/api/android/jni/native/convert_util_jni.h
lite/api/android/jni/native/convert_util_jni.h
+18
-7
lite/api/android/jni/src/com/baidu/paddle/lite/MobileConfig.java
...i/android/jni/src/com/baidu/paddle/lite/MobileConfig.java
+48
-1
lite/api/android/jni/src/com/baidu/paddle/lite/PowerMode.java
.../api/android/jni/src/com/baidu/paddle/lite/PowerMode.java
+36
-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
+2
-0
未找到文件。
lite/api/android/jni/CMakeLists.txt
浏览文件 @
e91eef1c
...
@@ -21,6 +21,7 @@ add_jar(PaddlePredictor
...
@@ -21,6 +21,7 @@ add_jar(PaddlePredictor
src/com/baidu/paddle/lite/MobileConfig.java
src/com/baidu/paddle/lite/MobileConfig.java
src/com/baidu/paddle/lite/PaddleLiteInitializer.java
src/com/baidu/paddle/lite/PaddleLiteInitializer.java
src/com/baidu/paddle/lite/PaddlePredictor.java
src/com/baidu/paddle/lite/PaddlePredictor.java
src/com/baidu/paddle/lite/PowerMode.java
src/com/baidu/paddle/lite/Place.java
src/com/baidu/paddle/lite/Place.java
src/com/baidu/paddle/lite/Tensor.java
)
src/com/baidu/paddle/lite/Tensor.java
)
get_target_property
(
_jarFile PaddlePredictor JAR_FILE
)
get_target_property
(
_jarFile PaddlePredictor JAR_FILE
)
...
...
lite/api/android/jni/native/convert_util_jni.h
浏览文件 @
e91eef1c
...
@@ -11,6 +11,8 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
...
@@ -11,6 +11,8 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
See the License for the specific language governing permissions and
limitations under the License. */
limitations under the License. */
#pragma once
#include <jni.h>
#include <jni.h>
#include <string>
#include <string>
#include <vector>
#include <vector>
...
@@ -19,9 +21,6 @@ limitations under the License. */
...
@@ -19,9 +21,6 @@ limitations under the License. */
#include "lite/api/paddle_api.h"
#include "lite/api/paddle_api.h"
#include "lite/api/paddle_place.h"
#include "lite/api/paddle_place.h"
#ifndef PADDLE_FLUID_LITE_API_ANDROID_JNI_NATIVE_CONVERT_UTIL_JNI_H_
#define PADDLE_FLUID_LITE_API_ANDROID_JNI_NATIVE_CONVERT_UTIL_JNI_H_
namespace
paddle
{
namespace
paddle
{
namespace
lite_api
{
namespace
lite_api
{
...
@@ -167,20 +166,32 @@ inline MobileConfig jmobileconfig_to_cpp_mobileconfig(JNIEnv *env,
...
@@ -167,20 +166,32 @@ inline MobileConfig jmobileconfig_to_cpp_mobileconfig(JNIEnv *env,
jobject
jmobileconfig
)
{
jobject
jmobileconfig
)
{
jclass
mobileconfig_jclazz
=
env
->
GetObjectClass
(
jmobileconfig
);
jclass
mobileconfig_jclazz
=
env
->
GetObjectClass
(
jmobileconfig
);
jmethodID
model_dir_method
=
env
->
GetMethodID
(
mobileconfig_jclazz
,
"getModelDir"
,
"()Ljava/lang/String;"
);
MobileConfig
config
;
MobileConfig
config
;
// set model dir
jmethodID
model_dir_method
=
env
->
GetMethodID
(
mobileconfig_jclazz
,
"getModelDir"
,
"()Ljava/lang/String;"
);
jstring
java_model_dir
=
jstring
java_model_dir
=
(
jstring
)
env
->
CallObjectMethod
(
jmobileconfig
,
model_dir_method
);
(
jstring
)
env
->
CallObjectMethod
(
jmobileconfig
,
model_dir_method
);
if
(
java_model_dir
!=
nullptr
)
{
if
(
java_model_dir
!=
nullptr
)
{
std
::
string
cpp_model_dir
=
jstring_to_cpp_string
(
env
,
java_model_dir
);
std
::
string
cpp_model_dir
=
jstring_to_cpp_string
(
env
,
java_model_dir
);
config
.
set_model_dir
(
cpp_model_dir
);
config
.
set_model_dir
(
cpp_model_dir
);
}
}
// set threads
jmethodID
threads_method
=
env
->
GetMethodID
(
mobileconfig_jclazz
,
"getThreads"
,
"()I"
);
int
threads
=
env
->
CallIntMethod
(
jmobileconfig
,
threads_method
);
config
.
set_threads
(
threads
);
// set power mode
jmethodID
power_mode_method
=
env
->
GetMethodID
(
mobileconfig_jclazz
,
"getPowerModeInt"
,
"()I"
);
int
power_mode
=
env
->
CallIntMethod
(
jmobileconfig
,
power_mode_method
);
config
.
set_power_mode
(
static_cast
<
paddle
::
lite_api
::
PowerMode
>
(
power_mode
));
return
config
;
return
config
;
}
}
}
// namespace lite_api
}
// namespace lite_api
}
// namespace paddle
}
// namespace paddle
#endif // PADDLE_FLUID_LITE_API_ANDROID_JNI_NATIVE_CONVERT_UTIL_JNI_H_
lite/api/android/jni/src/com/baidu/paddle/lite/MobileConfig.java
浏览文件 @
e91eef1c
...
@@ -18,5 +18,52 @@ package com.baidu.paddle.lite;
...
@@ -18,5 +18,52 @@ package com.baidu.paddle.lite;
* optimization or other unnecessary stages.
* optimization or other unnecessary stages.
*/
*/
public
class
MobileConfig
extends
ConfigBase
{
public
class
MobileConfig
extends
ConfigBase
{
// Empty class
/**
* Set power mode.
*
* @return
*/
public
void
setPowerMode
(
PowerMode
powerMode
)
{
this
.
powerMode
=
powerMode
;
}
/**
* Returns power mode.
*
* @return power mode
*/
public
PowerMode
getPowerMode
()
{
return
powerMode
;
}
/**
* Set threads num.
*
* @return
*/
public
void
setThreads
(
int
threads
)
{
this
.
threads
=
threads
;
}
/**
* Returns threads num.
*
* @return threads num
*/
public
int
getThreads
()
{
return
threads
;
}
/**
* Returns power mode as enum int value.
*
* @return power mode as enum int value
*/
public
int
getPowerModeInt
()
{
return
powerMode
.
value
();
}
private
PowerMode
powerMode
=
PowerMode
.
LITE_POWER_HIGH
;
private
int
threads
=
1
;
}
}
lite/api/android/jni/src/com/baidu/paddle/lite/PowerMode.java
0 → 100644
浏览文件 @
e91eef1c
/* Copyright (c) 2019 PaddlePaddle Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. */
package
com.baidu.paddle.lite
;
/**
* PowerMode is the cpu runing mode for the light weight predictor.
*/
public
enum
PowerMode
{
LITE_POWER_HIGH
(
0
),
LITE_POWER_LOW
(
1
),
LITE_POWER_FULL
(
2
),
LITE_POWER_NO_BIND
(
3
),
LITE_POWER_RAND_HIGH
(
4
),
LITE_POWER_RAND_LOW
(
5
);
public
final
int
value
;
private
PowerMode
(
int
value
)
{
this
.
value
=
value
;
}
public
int
value
()
{
return
this
.
value
;
}
}
lite/demo/java/android/PaddlePredictor/app/src/main/java/com/baidu/paddle/lite/MainActivity.java
浏览文件 @
e91eef1c
...
@@ -91,6 +91,8 @@ public class MainActivity extends AppCompatActivity {
...
@@ -91,6 +91,8 @@ public class MainActivity extends AppCompatActivity {
MobileConfig
config
=
new
MobileConfig
();
MobileConfig
config
=
new
MobileConfig
();
config
.
setModelDir
(
modelPath
);
config
.
setModelDir
(
modelPath
);
config
.
setPowerMode
(
PowerMode
.
LITE_POWER_HIGH
);
config
.
setThreads
(
1
);
PaddlePredictor
predictor
=
PaddlePredictor
.
createPaddlePredictor
(
config
);
PaddlePredictor
predictor
=
PaddlePredictor
.
createPaddlePredictor
(
config
);
Tensor
input
=
predictor
.
getInput
(
0
);
Tensor
input
=
predictor
.
getInput
(
0
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录