chore: import upstream snapshot with attribution
This commit is contained in:
+273
@@ -0,0 +1,273 @@
|
||||
// Copyright (c) 2021 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.
|
||||
|
||||
#include "com_baidu_paddle_inference_Config.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include "jni_convert_util.h" // NOLINT
|
||||
#include "pd_inference_api.h" // NOLINT
|
||||
|
||||
JNIEXPORT void JNICALL Java_com_baidu_paddle_inference_Config_cppConfigDestroy(
|
||||
JNIEnv*, jobject, jlong cppPaddleConfigPointer) {
|
||||
PD_ConfigDestroy(reinterpret_cast<PD_Config*>(cppPaddleConfigPointer));
|
||||
}
|
||||
|
||||
// 1. create Config
|
||||
|
||||
JNIEXPORT jlong JNICALL Java_com_baidu_paddle_inference_Config_createCppConfig(
|
||||
JNIEnv* env, jobject obj) {
|
||||
jlong cppPaddleConfigPointer = reinterpret_cast<jlong>(PD_ConfigCreate());
|
||||
return cppPaddleConfigPointer;
|
||||
}
|
||||
|
||||
JNIEXPORT jboolean JNICALL
|
||||
Java_com_baidu_paddle_inference_Config_isCppConfigValid(
|
||||
JNIEnv* env, jobject obj, jlong cppPaddleConfigPointer) {
|
||||
bool flag =
|
||||
PD_ConfigIsValid(reinterpret_cast<PD_Config*>(cppPaddleConfigPointer));
|
||||
return cpp_bool_to_jboolean(env, flag);
|
||||
}
|
||||
|
||||
// 2. not combined model settings
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_baidu_paddle_inference_Config_setCppModel(JNIEnv* env,
|
||||
jobject obj,
|
||||
jlong cppPaddleConfigPointer,
|
||||
jstring modelFile,
|
||||
jstring paramsFile) {
|
||||
PD_ConfigSetModel(reinterpret_cast<PD_Config*>(cppPaddleConfigPointer),
|
||||
jstring_to_cpp_string(env, modelFile).c_str(),
|
||||
jstring_to_cpp_string(env, paramsFile).c_str());
|
||||
}
|
||||
|
||||
// 3. combined model settings
|
||||
|
||||
JNIEXPORT void JNICALL Java_com_baidu_paddle_inference_Config_setCppModelDir(
|
||||
JNIEnv* env, jobject obj, jlong cppPaddleConfigPointer, jstring modelDir) {
|
||||
PD_ConfigSetModelDir(reinterpret_cast<PD_Config*>(cppPaddleConfigPointer),
|
||||
jstring_to_cpp_string(env, modelDir).c_str());
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_com_baidu_paddle_inference_Config_setCppProgFile(
|
||||
JNIEnv* env, jobject obj, jlong cppPaddleConfigPointer, jstring progFile) {
|
||||
PD_ConfigSetProgFile(reinterpret_cast<PD_Config*>(cppPaddleConfigPointer),
|
||||
jstring_to_cpp_string(env, progFile).c_str());
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_com_baidu_paddle_inference_Config_setCppParamsFile(
|
||||
JNIEnv* env,
|
||||
jobject obj,
|
||||
jlong cppPaddleConfigPointer,
|
||||
jstring paramsFile) {
|
||||
PD_ConfigSetParamsFile(reinterpret_cast<PD_Config*>(cppPaddleConfigPointer),
|
||||
jstring_to_cpp_string(env, paramsFile).c_str());
|
||||
}
|
||||
|
||||
JNIEXPORT jstring JNICALL Java_com_baidu_paddle_inference_Config_modelDir(
|
||||
JNIEnv* env, jobject obj, jlong cppPaddleConfigPointer) {
|
||||
return cpp_string_to_jstring(
|
||||
env,
|
||||
PD_ConfigGetModelDir(
|
||||
reinterpret_cast<PD_Config*>(cppPaddleConfigPointer)));
|
||||
}
|
||||
|
||||
JNIEXPORT jstring JNICALL Java_com_baidu_paddle_inference_Config_progFile(
|
||||
JNIEnv* env, jobject obj, jlong cppPaddleConfigPointer) {
|
||||
return cpp_string_to_jstring(
|
||||
env,
|
||||
PD_ConfigGetProgFile(
|
||||
reinterpret_cast<PD_Config*>(cppPaddleConfigPointer)));
|
||||
}
|
||||
|
||||
JNIEXPORT jstring JNICALL Java_com_baidu_paddle_inference_Config_paramsFile(
|
||||
JNIEnv* env, jobject obj, jlong cppPaddleConfigPointer) {
|
||||
return cpp_string_to_jstring(
|
||||
env,
|
||||
PD_ConfigGetParamsFile(
|
||||
reinterpret_cast<PD_Config*>(cppPaddleConfigPointer)));
|
||||
}
|
||||
|
||||
// 4. cpu settings
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_baidu_paddle_inference_Config_setCpuMathLibraryNumThreads(
|
||||
JNIEnv* env,
|
||||
jobject obj,
|
||||
jlong cppPaddleConfigPointer,
|
||||
jint mathThreadsNum) {
|
||||
int math_threads_num = reinterpret_cast<int>(mathThreadsNum);
|
||||
PD_ConfigSetCpuMathLibraryNumThreads(
|
||||
reinterpret_cast<PD_Config*>(cppPaddleConfigPointer), math_threads_num);
|
||||
}
|
||||
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_com_baidu_paddle_inference_Config_cpuMathLibraryNumThreads(
|
||||
JNIEnv* env, jobject obj, jlong cppPaddleConfigPointer) {
|
||||
jint mathThreadsNum =
|
||||
reinterpret_cast<jint>(PD_ConfigGetCpuMathLibraryNumThreads(
|
||||
reinterpret_cast<PD_Config*>(cppPaddleConfigPointer)));
|
||||
return mathThreadsNum;
|
||||
}
|
||||
|
||||
// 5. OneDNN settings
|
||||
|
||||
JNIEXPORT void JNICALL Java_com_baidu_paddle_inference_Config_enableMKLDNN(
|
||||
JNIEnv* env, jobject obj, jlong cppPaddleConfigPointer) {
|
||||
PD_ConfigEnableONEDNN(reinterpret_cast<PD_Config*>(cppPaddleConfigPointer));
|
||||
}
|
||||
|
||||
JNIEXPORT jboolean JNICALL Java_com_baidu_paddle_inference_Config_mkldnnEnabled(
|
||||
JNIEnv* env, jobject obj, jlong cppPaddleConfigPointer) {
|
||||
bool flag = PD_ConfigMkldnnEnabled(
|
||||
reinterpret_cast<PD_Config*>(cppPaddleConfigPointer));
|
||||
return cpp_bool_to_jboolean(env, flag);
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_baidu_paddle_inference_Config_enableMkldnnBfloat16(
|
||||
JNIEnv* env, jobject obj, jlong cppPaddleConfigPointer) {
|
||||
PD_ConfigEnableMkldnnBfloat16(
|
||||
reinterpret_cast<PD_Config*>(cppPaddleConfigPointer));
|
||||
}
|
||||
|
||||
JNIEXPORT jboolean JNICALL
|
||||
Java_com_baidu_paddle_inference_Config_mkldnnBfloat16Enabled(
|
||||
JNIEnv* env, jobject obj, jlong cppPaddleConfigPointer) {
|
||||
bool flag = PD_ConfigMkldnnBfloat16Enabled(
|
||||
reinterpret_cast<PD_Config*>(cppPaddleConfigPointer));
|
||||
return cpp_bool_to_jboolean(env, flag);
|
||||
}
|
||||
|
||||
// 6. gpu setting
|
||||
|
||||
JNIEXPORT void JNICALL Java_com_baidu_paddle_inference_Config_enableUseGpu(
|
||||
JNIEnv* env,
|
||||
jobject obj,
|
||||
jlong cppPaddleConfigPointer,
|
||||
jlong memorySize,
|
||||
jint deviceId) {
|
||||
PD_ConfigEnableUseGpu(reinterpret_cast<PD_Config*>(cppPaddleConfigPointer),
|
||||
(uint64_t)memorySize,
|
||||
(int32_t)deviceId,
|
||||
0);
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_com_baidu_paddle_inference_Config_disableGpu(
|
||||
JNIEnv* env, jobject obj, jlong cppPaddleConfigPointer) {
|
||||
PD_ConfigDisableGpu(reinterpret_cast<PD_Config*>(cppPaddleConfigPointer));
|
||||
}
|
||||
|
||||
JNIEXPORT jboolean JNICALL Java_com_baidu_paddle_inference_Config_useGpu(
|
||||
JNIEnv* env, jobject obj, jlong cppPaddleConfigPointer) {
|
||||
bool flag =
|
||||
PD_ConfigUseGpu(reinterpret_cast<PD_Config*>(cppPaddleConfigPointer));
|
||||
return cpp_bool_to_jboolean(env, flag);
|
||||
}
|
||||
|
||||
JNIEXPORT jint JNICALL Java_com_baidu_paddle_inference_Config_gpuDeviceId(
|
||||
JNIEnv* env, jobject obj, jlong cppPaddleConfigPointer) {
|
||||
int device_id = PD_ConfigGpuDeviceId(
|
||||
reinterpret_cast<PD_Config*>(cppPaddleConfigPointer));
|
||||
return reinterpret_cast<jint>(device_id);
|
||||
}
|
||||
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_com_baidu_paddle_inference_Config_memoryPoolInitSizeMb(
|
||||
JNIEnv* env, jobject obj, jlong cppPaddleConfigPointer) {
|
||||
int memory_pool_init_size_mb = PD_ConfigMemoryPoolInitSizeMb(
|
||||
reinterpret_cast<PD_Config*>(cppPaddleConfigPointer));
|
||||
return reinterpret_cast<jint>(memory_pool_init_size_mb);
|
||||
}
|
||||
|
||||
JNIEXPORT jfloat JNICALL
|
||||
Java_com_baidu_paddle_inference_Config_fractionOfGpuMemoryForPool(
|
||||
JNIEnv* env, jobject obj, jlong cppPaddleConfigPointer) {
|
||||
float fraction_of_gpuMemory_for_pool = PD_ConfigFractionOfGpuMemoryForPool(
|
||||
reinterpret_cast<PD_Config*>(cppPaddleConfigPointer));
|
||||
return (jfloat)fraction_of_gpuMemory_for_pool;
|
||||
}
|
||||
|
||||
// 7. TensorRT To Do
|
||||
|
||||
// 8. optim setting
|
||||
|
||||
JNIEXPORT void JNICALL Java_com_baidu_paddle_inference_Config_switchIrOptim(
|
||||
JNIEnv* env, jobject obj, jlong cppPaddleConfigPointer, jboolean flag) {
|
||||
PD_ConfigSwitchIrOptim(reinterpret_cast<PD_Config*>(cppPaddleConfigPointer),
|
||||
jboolean_to_cpp_bool(env, flag));
|
||||
}
|
||||
|
||||
JNIEXPORT jboolean JNICALL Java_com_baidu_paddle_inference_Config_irOptim(
|
||||
JNIEnv* env, jobject obj, jlong cppPaddleConfigPointer) {
|
||||
bool flag =
|
||||
PD_ConfigIrOptim(reinterpret_cast<PD_Config*>(cppPaddleConfigPointer));
|
||||
return cpp_bool_to_jboolean(env, flag);
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_com_baidu_paddle_inference_Config_switchIrDebug(
|
||||
JNIEnv* env, jobject obj, jlong cppPaddleConfigPointer, jboolean flag) {
|
||||
PD_ConfigSwitchIrDebug(reinterpret_cast<PD_Config*>(cppPaddleConfigPointer),
|
||||
jboolean_to_cpp_bool(env, flag));
|
||||
}
|
||||
|
||||
// 9. enable memory optimization
|
||||
|
||||
JNIEXPORT void JNICALL Java_com_baidu_paddle_inference_Config_enableMemoryOptim(
|
||||
JNIEnv* env, jobject obj, jlong cppPaddleConfigPointer, jboolean flag) {
|
||||
PD_ConfigEnableMemoryOptim(
|
||||
reinterpret_cast<PD_Config*>(cppPaddleConfigPointer),
|
||||
jboolean_to_cpp_bool(env, flag));
|
||||
}
|
||||
|
||||
JNIEXPORT jboolean JNICALL
|
||||
Java_com_baidu_paddle_inference_Config_memoryOptimEnabled(
|
||||
JNIEnv* env, jobject obj, jlong cppPaddleConfigPointer) {
|
||||
bool flag = PD_ConfigMemoryOptimEnabled(
|
||||
reinterpret_cast<PD_Config*>(cppPaddleConfigPointer));
|
||||
return cpp_bool_to_jboolean(env, flag);
|
||||
}
|
||||
|
||||
// 10. profile setting
|
||||
|
||||
JNIEXPORT void JNICALL Java_com_baidu_paddle_inference_Config_enableProfile(
|
||||
JNIEnv* env, jobject obj, jlong cppPaddleConfigPointer) {
|
||||
PD_ConfigEnableProfile(reinterpret_cast<PD_Config*>(cppPaddleConfigPointer));
|
||||
}
|
||||
|
||||
JNIEXPORT jboolean JNICALL
|
||||
Java_com_baidu_paddle_inference_Config_profileEnabled(
|
||||
JNIEnv* env, jobject obj, jlong cppPaddleConfigPointer) {
|
||||
bool flag = PD_ConfigProfileEnabled(
|
||||
reinterpret_cast<PD_Config*>(cppPaddleConfigPointer));
|
||||
return cpp_bool_to_jboolean(env, flag);
|
||||
}
|
||||
|
||||
// 11. log setting
|
||||
|
||||
JNIEXPORT void JNICALL Java_com_baidu_paddle_inference_Config_disableGlogInfo(
|
||||
JNIEnv* env, jobject obj, jlong cppPaddleConfigPointer) {
|
||||
PD_ConfigDisableGlogInfo(
|
||||
reinterpret_cast<PD_Config*>(cppPaddleConfigPointer));
|
||||
}
|
||||
|
||||
// 12. view config configuration
|
||||
|
||||
JNIEXPORT jstring JNICALL Java_com_baidu_paddle_inference_Config_summary(
|
||||
JNIEnv* env, jobject obj, jlong cppPaddleConfigPointer) {
|
||||
return cpp_string_to_jstring(
|
||||
env,
|
||||
PD_ConfigSummary(reinterpret_cast<PD_Config*>(cppPaddleConfigPointer)));
|
||||
}
|
||||
+290
@@ -0,0 +1,290 @@
|
||||
// Copyright (c) 2021 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.
|
||||
|
||||
/* DO NOT EDIT THIS FILE - it is machine generated */
|
||||
#include <jni.h>
|
||||
/* Header for class com_baidu_paddle_inference_Config */
|
||||
#pragma once
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
/*
|
||||
* Class: com_baidu_paddle_inference_Config
|
||||
* Method: cppConfigDestroy
|
||||
* Signature: (J)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_com_baidu_paddle_inference_Config_cppConfigDestroy(
|
||||
JNIEnv *, jobject, jlong);
|
||||
|
||||
/*
|
||||
* Class: com_baidu_paddle_inference_Config
|
||||
* Method: createCppConfig
|
||||
* Signature: ()J
|
||||
*/
|
||||
JNIEXPORT jlong JNICALL
|
||||
Java_com_baidu_paddle_inference_Config_createCppConfig(JNIEnv *, jobject);
|
||||
|
||||
/*
|
||||
* Class: com_baidu_paddle_inference_Config
|
||||
* Method: isCppConfigValid
|
||||
* Signature: (J)Z
|
||||
*/
|
||||
JNIEXPORT jboolean JNICALL
|
||||
Java_com_baidu_paddle_inference_Config_isCppConfigValid(JNIEnv *,
|
||||
jobject,
|
||||
jlong);
|
||||
|
||||
/*
|
||||
* Class: com_baidu_paddle_inference_Config
|
||||
* Method: setCppModel
|
||||
* Signature: (JLjava/lang/String;Ljava/lang/String;)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_com_baidu_paddle_inference_Config_setCppModel(
|
||||
JNIEnv *, jobject, jlong, jstring, jstring);
|
||||
|
||||
/*
|
||||
* Class: com_baidu_paddle_inference_Config
|
||||
* Method: setCppModelDir
|
||||
* Signature: (JLjava/lang/String;)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_com_baidu_paddle_inference_Config_setCppModelDir(
|
||||
JNIEnv *, jobject, jlong, jstring);
|
||||
|
||||
/*
|
||||
* Class: com_baidu_paddle_inference_Config
|
||||
* Method: setCppProgFile
|
||||
* Signature: (JLjava/lang/String;)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_com_baidu_paddle_inference_Config_setCppProgFile(
|
||||
JNIEnv *, jobject, jlong, jstring);
|
||||
|
||||
/*
|
||||
* Class: com_baidu_paddle_inference_Config
|
||||
* Method: setCppParamsFile
|
||||
* Signature: (JLjava/lang/String;)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_com_baidu_paddle_inference_Config_setCppParamsFile(
|
||||
JNIEnv *, jobject, jlong, jstring);
|
||||
|
||||
/*
|
||||
* Class: com_baidu_paddle_inference_Config
|
||||
* Method: modelDir
|
||||
* Signature: (J)Ljava/lang/String;
|
||||
*/
|
||||
JNIEXPORT jstring JNICALL
|
||||
Java_com_baidu_paddle_inference_Config_modelDir(JNIEnv *, jobject, jlong);
|
||||
|
||||
/*
|
||||
* Class: com_baidu_paddle_inference_Config
|
||||
* Method: progFile
|
||||
* Signature: (J)Ljava/lang/String;
|
||||
*/
|
||||
JNIEXPORT jstring JNICALL
|
||||
Java_com_baidu_paddle_inference_Config_progFile(JNIEnv *, jobject, jlong);
|
||||
|
||||
/*
|
||||
* Class: com_baidu_paddle_inference_Config
|
||||
* Method: paramsFile
|
||||
* Signature: (J)Ljava/lang/String;
|
||||
*/
|
||||
JNIEXPORT jstring JNICALL
|
||||
Java_com_baidu_paddle_inference_Config_paramsFile(JNIEnv *, jobject, jlong);
|
||||
|
||||
/*
|
||||
* Class: com_baidu_paddle_inference_Config
|
||||
* Method: setCpuMathLibraryNumThreads
|
||||
* Signature: (JI)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_baidu_paddle_inference_Config_setCpuMathLibraryNumThreads(JNIEnv *,
|
||||
jobject,
|
||||
jlong,
|
||||
jint);
|
||||
|
||||
/*
|
||||
* Class: com_baidu_paddle_inference_Config
|
||||
* Method: cpuMathLibraryNumThreads
|
||||
* Signature: (J)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_com_baidu_paddle_inference_Config_cpuMathLibraryNumThreads(JNIEnv *,
|
||||
jobject,
|
||||
jlong);
|
||||
|
||||
/*
|
||||
* Class: com_baidu_paddle_inference_Config
|
||||
* Method: enableMKLDNN
|
||||
* Signature: (J)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_baidu_paddle_inference_Config_enableMKLDNN(JNIEnv *, jobject, jlong);
|
||||
|
||||
/*
|
||||
* Class: com_baidu_paddle_inference_Config
|
||||
* Method: mkldnnEnabled
|
||||
* Signature: (J)Z
|
||||
*/
|
||||
JNIEXPORT jboolean JNICALL
|
||||
Java_com_baidu_paddle_inference_Config_mkldnnEnabled(JNIEnv *, jobject, jlong);
|
||||
|
||||
/*
|
||||
* Class: com_baidu_paddle_inference_Config
|
||||
* Method: enableMkldnnBfloat16
|
||||
* Signature: (J)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_baidu_paddle_inference_Config_enableMkldnnBfloat16(JNIEnv *,
|
||||
jobject,
|
||||
jlong);
|
||||
|
||||
/*
|
||||
* Class: com_baidu_paddle_inference_Config
|
||||
* Method: mkldnnBfloat16Enabled
|
||||
* Signature: (J)Z
|
||||
*/
|
||||
JNIEXPORT jboolean JNICALL
|
||||
Java_com_baidu_paddle_inference_Config_mkldnnBfloat16Enabled(JNIEnv *,
|
||||
jobject,
|
||||
jlong);
|
||||
|
||||
/*
|
||||
* Class: com_baidu_paddle_inference_Config
|
||||
* Method: enableUseGpu
|
||||
* Signature: (JJI)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_com_baidu_paddle_inference_Config_enableUseGpu(
|
||||
JNIEnv *, jobject, jlong, jlong, jint);
|
||||
|
||||
/*
|
||||
* Class: com_baidu_paddle_inference_Config
|
||||
* Method: disableGpu
|
||||
* Signature: (J)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_baidu_paddle_inference_Config_disableGpu(JNIEnv *, jobject, jlong);
|
||||
|
||||
/*
|
||||
* Class: com_baidu_paddle_inference_Config
|
||||
* Method: useGpu
|
||||
* Signature: (J)Z
|
||||
*/
|
||||
JNIEXPORT jboolean JNICALL
|
||||
Java_com_baidu_paddle_inference_Config_useGpu(JNIEnv *, jobject, jlong);
|
||||
|
||||
/*
|
||||
* Class: com_baidu_paddle_inference_Config
|
||||
* Method: gpuDeviceId
|
||||
* Signature: (J)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_com_baidu_paddle_inference_Config_gpuDeviceId(JNIEnv *, jobject, jlong);
|
||||
|
||||
/*
|
||||
* Class: com_baidu_paddle_inference_Config
|
||||
* Method: memoryPoolInitSizeMb
|
||||
* Signature: (J)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_com_baidu_paddle_inference_Config_memoryPoolInitSizeMb(JNIEnv *,
|
||||
jobject,
|
||||
jlong);
|
||||
|
||||
/*
|
||||
* Class: com_baidu_paddle_inference_Config
|
||||
* Method: fractionOfGpuMemoryForPool
|
||||
* Signature: (J)F
|
||||
*/
|
||||
JNIEXPORT jfloat JNICALL
|
||||
Java_com_baidu_paddle_inference_Config_fractionOfGpuMemoryForPool(JNIEnv *,
|
||||
jobject,
|
||||
jlong);
|
||||
|
||||
/*
|
||||
* Class: com_baidu_paddle_inference_Config
|
||||
* Method: switchIrOptim
|
||||
* Signature: (JZ)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_com_baidu_paddle_inference_Config_switchIrOptim(
|
||||
JNIEnv *, jobject, jlong, jboolean);
|
||||
|
||||
/*
|
||||
* Class: com_baidu_paddle_inference_Config
|
||||
* Method: irOptim
|
||||
* Signature: (J)Z
|
||||
*/
|
||||
JNIEXPORT jboolean JNICALL
|
||||
Java_com_baidu_paddle_inference_Config_irOptim(JNIEnv *, jobject, jlong);
|
||||
|
||||
/*
|
||||
* Class: com_baidu_paddle_inference_Config
|
||||
* Method: switchIrDebug
|
||||
* Signature: (JZ)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_com_baidu_paddle_inference_Config_switchIrDebug(
|
||||
JNIEnv *, jobject, jlong, jboolean);
|
||||
|
||||
/*
|
||||
* Class: com_baidu_paddle_inference_Config
|
||||
* Method: enableMemoryOptim
|
||||
* Signature: (JZ)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_com_baidu_paddle_inference_Config_enableMemoryOptim(
|
||||
JNIEnv *, jobject, jlong, jboolean);
|
||||
|
||||
/*
|
||||
* Class: com_baidu_paddle_inference_Config
|
||||
* Method: memoryOptimEnabled
|
||||
* Signature: (J)Z
|
||||
*/
|
||||
JNIEXPORT jboolean JNICALL
|
||||
Java_com_baidu_paddle_inference_Config_memoryOptimEnabled(JNIEnv *,
|
||||
jobject,
|
||||
jlong);
|
||||
|
||||
/*
|
||||
* Class: com_baidu_paddle_inference_Config
|
||||
* Method: enableProfile
|
||||
* Signature: (J)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_baidu_paddle_inference_Config_enableProfile(JNIEnv *, jobject, jlong);
|
||||
|
||||
/*
|
||||
* Class: com_baidu_paddle_inference_Config
|
||||
* Method: profileEnabled
|
||||
* Signature: (J)Z
|
||||
*/
|
||||
JNIEXPORT jboolean JNICALL
|
||||
Java_com_baidu_paddle_inference_Config_profileEnabled(JNIEnv *, jobject, jlong);
|
||||
|
||||
/*
|
||||
* Class: com_baidu_paddle_inference_Config
|
||||
* Method: disableGlogInfo
|
||||
* Signature: (J)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_com_baidu_paddle_inference_Config_disableGlogInfo(
|
||||
JNIEnv *, jobject, jlong);
|
||||
|
||||
/*
|
||||
* Class: com_baidu_paddle_inference_Config
|
||||
* Method: summary
|
||||
* Signature: (J)Ljava/lang/String;
|
||||
*/
|
||||
JNIEXPORT jstring JNICALL
|
||||
Java_com_baidu_paddle_inference_Config_summary(JNIEnv *, jobject, jlong);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
+107
@@ -0,0 +1,107 @@
|
||||
// Copyright (c) 2021 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.
|
||||
|
||||
#include "com_baidu_paddle_inference_Predictor.h"
|
||||
|
||||
#include <jni.h>
|
||||
|
||||
#include "jni_convert_util.h" // NOLINT
|
||||
#include "pd_inference_api.h" // NOLINT
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_baidu_paddle_inference_Predictor_cppPredictorDestroy(
|
||||
JNIEnv*, jobject, jlong cppPaddlePredictorPointer) {
|
||||
PD_PredictorDestroy(
|
||||
reinterpret_cast<PD_Predictor*>(cppPaddlePredictorPointer));
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_baidu_paddle_inference_Predictor_predictorTryShrinkMemory(
|
||||
JNIEnv* env, jobject obj, jlong cppPaddlePredictorPointer) {
|
||||
PD_PredictorTryShrinkMemory(
|
||||
reinterpret_cast<PD_Predictor*>(cppPaddlePredictorPointer));
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_baidu_paddle_inference_Predictor_predictorClearIntermediateTensor(
|
||||
JNIEnv* env, jobject obj, jlong cppPaddlePredictorPointer) {
|
||||
PD_PredictorClearIntermediateTensor(
|
||||
reinterpret_cast<PD_Predictor*>(cppPaddlePredictorPointer));
|
||||
}
|
||||
|
||||
JNIEXPORT jlong JNICALL
|
||||
Java_com_baidu_paddle_inference_Predictor_createPredictor(
|
||||
JNIEnv* env, jobject obj, jlong cppPaddlePredictorPointer) {
|
||||
return (jlong)PD_PredictorCreate(
|
||||
reinterpret_cast<PD_Config*>(cppPaddlePredictorPointer));
|
||||
}
|
||||
|
||||
JNIEXPORT jlong JNICALL Java_com_baidu_paddle_inference_Predictor_getInputNum(
|
||||
JNIEnv* env, jobject obj, jlong cppPaddlePredictorPointer) {
|
||||
return (jlong)PD_PredictorGetInputNum(
|
||||
reinterpret_cast<PD_Predictor*>(cppPaddlePredictorPointer));
|
||||
}
|
||||
|
||||
JNIEXPORT jlong JNICALL Java_com_baidu_paddle_inference_Predictor_getOutputNum(
|
||||
JNIEnv* env, jobject obj, jlong cppPaddlePredictorPointer) {
|
||||
return (jlong)PD_PredictorGetOutputNum(
|
||||
reinterpret_cast<PD_Predictor*>(cppPaddlePredictorPointer));
|
||||
}
|
||||
|
||||
JNIEXPORT jstring JNICALL
|
||||
Java_com_baidu_paddle_inference_Predictor_getInputNameByIndex(
|
||||
JNIEnv* env, jobject obj, jlong cppPaddlePredictorPointer, jlong index) {
|
||||
const char* c_str = PD_PredictorGetInputNames(reinterpret_cast<PD_Predictor*>(
|
||||
cppPaddlePredictorPointer))
|
||||
->data[static_cast<int>(index)];
|
||||
return env->NewStringUTF(c_str);
|
||||
}
|
||||
|
||||
JNIEXPORT jstring JNICALL
|
||||
Java_com_baidu_paddle_inference_Predictor_getOutputNameByIndex(
|
||||
JNIEnv* env, jobject obj, jlong cppPaddlePredictorPointer, jlong index) {
|
||||
const char* c_str =
|
||||
PD_PredictorGetOutputNames(
|
||||
reinterpret_cast<PD_Predictor*>(cppPaddlePredictorPointer))
|
||||
->data[static_cast<int>(index)];
|
||||
return env->NewStringUTF(c_str);
|
||||
}
|
||||
|
||||
JNIEXPORT jlong JNICALL
|
||||
Java_com_baidu_paddle_inference_Predictor_getInputHandleByName(
|
||||
JNIEnv* env, jobject obj, jlong cppPaddlePredictorPointer, jstring name) {
|
||||
// const char* input_name = env->GetStringUTFChars(name, 0);
|
||||
PD_Predictor* pd_predictor =
|
||||
reinterpret_cast<PD_Predictor*>(cppPaddlePredictorPointer);
|
||||
jlong output_tensor = (jlong)PD_PredictorGetInputHandle(
|
||||
pd_predictor, jstring_to_cpp_string(env, name).c_str());
|
||||
return output_tensor;
|
||||
}
|
||||
|
||||
JNIEXPORT jlong JNICALL
|
||||
Java_com_baidu_paddle_inference_Predictor_getOutputHandleByName(
|
||||
JNIEnv* env, jobject obj, jlong cppPaddlePredictorPointer, jstring name) {
|
||||
// const char* output_name = env->GetStringUTFChars(name, 0);
|
||||
PD_Predictor* pd_predictor =
|
||||
reinterpret_cast<PD_Predictor*>(cppPaddlePredictorPointer);
|
||||
jlong output_tensor = (jlong)PD_PredictorGetOutputHandle(
|
||||
pd_predictor, jstring_to_cpp_string(env, name).c_str());
|
||||
return output_tensor;
|
||||
}
|
||||
|
||||
JNIEXPORT jboolean JNICALL Java_com_baidu_paddle_inference_Predictor_runPD(
|
||||
JNIEnv* env, jobject obj, jlong cppPaddlePredictorPointer) {
|
||||
return (jboolean)PD_PredictorRun(
|
||||
reinterpret_cast<PD_Predictor*>(cppPaddlePredictorPointer));
|
||||
}
|
||||
+132
@@ -0,0 +1,132 @@
|
||||
// Copyright (c) 2021 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.
|
||||
|
||||
/* DO NOT EDIT THIS FILE - it is machine generated */
|
||||
#include <jni.h>
|
||||
/* Header for class com_baidu_paddle_inference_Predictor */
|
||||
|
||||
#pragma once
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
/*
|
||||
* Class: com_baidu_paddle_inference_Predictor
|
||||
* Method: cppPredictorDestroy
|
||||
* Signature: (J)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_baidu_paddle_inference_Predictor_cppPredictorDestroy(JNIEnv *,
|
||||
jobject,
|
||||
jlong);
|
||||
|
||||
/*
|
||||
* Class: com_baidu_paddle_inference_Predictor
|
||||
* Method: predictorTryShrinkMemory
|
||||
* Signature: (J)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_baidu_paddle_inference_Predictor_predictorTryShrinkMemory(JNIEnv *,
|
||||
jobject,
|
||||
jlong);
|
||||
|
||||
/*
|
||||
* Class: com_baidu_paddle_inference_Predictor
|
||||
* Method: predictorClearIntermediateTensor
|
||||
* Signature: (J)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_baidu_paddle_inference_Predictor_predictorClearIntermediateTensor(
|
||||
JNIEnv *, jobject, jlong);
|
||||
|
||||
/*
|
||||
* Class: com_baidu_paddle_inference_Predictor
|
||||
* Method: createPredictor
|
||||
* Signature: (J)J
|
||||
*/
|
||||
JNIEXPORT jlong JNICALL
|
||||
Java_com_baidu_paddle_inference_Predictor_createPredictor(JNIEnv *,
|
||||
jobject,
|
||||
jlong);
|
||||
|
||||
/*
|
||||
* Class: com_baidu_paddle_inference_Predictor
|
||||
* Method: getInputNum
|
||||
* Signature: (J)J
|
||||
*/
|
||||
JNIEXPORT jlong JNICALL
|
||||
Java_com_baidu_paddle_inference_Predictor_getInputNum(JNIEnv *, jobject, jlong);
|
||||
|
||||
/*
|
||||
* Class: com_baidu_paddle_inference_Predictor
|
||||
* Method: getOutputNum
|
||||
* Signature: (J)J
|
||||
*/
|
||||
JNIEXPORT jlong JNICALL Java_com_baidu_paddle_inference_Predictor_getOutputNum(
|
||||
JNIEnv *, jobject, jlong);
|
||||
|
||||
/*
|
||||
* Class: com_baidu_paddle_inference_Predictor
|
||||
* Method: getInputNameByIndex
|
||||
* Signature: (JJ)Ljava/lang/String;
|
||||
*/
|
||||
JNIEXPORT jstring JNICALL
|
||||
Java_com_baidu_paddle_inference_Predictor_getInputNameByIndex(JNIEnv *,
|
||||
jobject,
|
||||
jlong,
|
||||
jlong);
|
||||
|
||||
/*
|
||||
* Class: com_baidu_paddle_inference_Predictor
|
||||
* Method: getOutputNameByIndex
|
||||
* Signature: (JJ)Ljava/lang/String;
|
||||
*/
|
||||
JNIEXPORT jstring JNICALL
|
||||
Java_com_baidu_paddle_inference_Predictor_getOutputNameByIndex(JNIEnv *,
|
||||
jobject,
|
||||
jlong,
|
||||
jlong);
|
||||
|
||||
/*
|
||||
* Class: com_baidu_paddle_inference_Predictor
|
||||
* Method: getInputHandleByName
|
||||
* Signature: (JLjava/lang/String;)J
|
||||
*/
|
||||
JNIEXPORT jlong JNICALL
|
||||
Java_com_baidu_paddle_inference_Predictor_getInputHandleByName(JNIEnv *,
|
||||
jobject,
|
||||
jlong,
|
||||
jstring);
|
||||
|
||||
/*
|
||||
* Class: com_baidu_paddle_inference_Predictor
|
||||
* Method: getOutputHandleByName
|
||||
* Signature: (JLjava/lang/String;)J
|
||||
*/
|
||||
JNIEXPORT jlong JNICALL
|
||||
Java_com_baidu_paddle_inference_Predictor_getOutputHandleByName(JNIEnv *,
|
||||
jobject,
|
||||
jlong,
|
||||
jstring);
|
||||
|
||||
/*
|
||||
* Class: com_baidu_paddle_inference_Predictor
|
||||
* Method: runPD
|
||||
* Signature: (J)Z
|
||||
*/
|
||||
JNIEXPORT jboolean JNICALL
|
||||
Java_com_baidu_paddle_inference_Predictor_runPD(JNIEnv *, jobject, jlong);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
+133
@@ -0,0 +1,133 @@
|
||||
// Copyright (c) 2021 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.
|
||||
|
||||
#include "com_baidu_paddle_inference_Tensor.h"
|
||||
|
||||
#include <jni.h>
|
||||
|
||||
#include "pd_inference_api.h" // NOLINT
|
||||
|
||||
JNIEXPORT void JNICALL Java_com_baidu_paddle_inference_Tensor_cppTensorDestroy(
|
||||
JNIEnv *, jobject, jlong tensorPointer) {
|
||||
PD_TensorDestroy(reinterpret_cast<PD_Tensor *>(tensorPointer));
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_com_baidu_paddle_inference_Tensor_cppTensorReshape(
|
||||
JNIEnv *env, jobject, jlong tensorPointer, jint dim, jintArray array) {
|
||||
int32_t *input_shape = env->GetIntArrayElements(array, nullptr);
|
||||
PD_TensorReshape(reinterpret_cast<PD_Tensor *>(tensorPointer),
|
||||
static_cast<int>(dim),
|
||||
input_shape);
|
||||
env->ReleaseIntArrayElements(array, input_shape, JNI_ABORT);
|
||||
}
|
||||
|
||||
JNIEXPORT jintArray JNICALL
|
||||
Java_com_baidu_paddle_inference_Tensor_cppTensorGetShape(JNIEnv *env,
|
||||
jobject,
|
||||
jlong tensorPointer) {
|
||||
PD_Tensor *tensor = reinterpret_cast<PD_Tensor *>(tensorPointer);
|
||||
PD_OneDimArrayInt32 *output_shape = PD_TensorGetShape(tensor);
|
||||
jintArray result = env->NewIntArray(output_shape->size);
|
||||
env->SetIntArrayRegion(result, 0, output_shape->size, output_shape->data);
|
||||
return result;
|
||||
}
|
||||
|
||||
JNIEXPORT jstring JNICALL
|
||||
Java_com_baidu_paddle_inference_Tensor_cppTensorGetName(JNIEnv *env,
|
||||
jobject,
|
||||
jlong tensorPointer) {
|
||||
const char *c_str =
|
||||
PD_TensorGetName(reinterpret_cast<PD_Tensor *>(tensorPointer));
|
||||
return env->NewStringUTF(c_str);
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_baidu_paddle_inference_Tensor_cppTensorCopyFromCpuFloat(
|
||||
JNIEnv *env, jobject, jlong tensorPointer, jfloatArray array) {
|
||||
float *data = env->GetFloatArrayElements(array, nullptr);
|
||||
PD_TensorCopyFromCpuFloat(reinterpret_cast<PD_Tensor *>(tensorPointer), data);
|
||||
env->ReleaseFloatArrayElements(array, data, JNI_ABORT);
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_baidu_paddle_inference_Tensor_cppTensorCopyFromCpuInt(
|
||||
JNIEnv *env, jobject, jlong tensorPointer, jintArray array) {
|
||||
int32_t *data = env->GetIntArrayElements(array, nullptr);
|
||||
PD_TensorCopyFromCpuInt32(reinterpret_cast<PD_Tensor *>(tensorPointer), data);
|
||||
env->ReleaseIntArrayElements(array, data, 0);
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_baidu_paddle_inference_Tensor_cppTensorCopyFromCpuLong(
|
||||
JNIEnv *env, jobject, jlong tensorPointer, jlongArray array) {
|
||||
int64_t *data = env->GetLongArrayElements(array, nullptr);
|
||||
PD_TensorCopyFromCpuInt64(reinterpret_cast<PD_Tensor *>(tensorPointer), data);
|
||||
env->ReleaseLongArrayElements(array, data, 0);
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_baidu_paddle_inference_Tensor_cppTensorCopyFromCpuByte(
|
||||
JNIEnv *env, jobject, jlong tensorPointer, jbyteArray array) {
|
||||
int8_t *data = env->GetByteArrayElements(array, nullptr);
|
||||
PD_TensorCopyFromCpuInt8(reinterpret_cast<PD_Tensor *>(tensorPointer), data);
|
||||
env->ReleaseByteArrayElements(array, data, 0);
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_baidu_paddle_inference_Tensor_cppTensorCopyFromCpuBoolean(
|
||||
JNIEnv *env, jobject, jlong tensorPointer, jbooleanArray array) {
|
||||
uint8_t *data = env->GetBooleanArrayElements(array, nullptr);
|
||||
PD_TensorCopyFromCpuUint8(reinterpret_cast<PD_Tensor *>(tensorPointer), data);
|
||||
env->ReleaseBooleanArrayElements(array, data, 0);
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_baidu_paddle_inference_Tensor_cppTensorCopyToCpuFloat(
|
||||
JNIEnv *env, jobject, jlong tensorPointer, jfloatArray array) {
|
||||
float *data = env->GetFloatArrayElements(array, nullptr);
|
||||
PD_TensorCopyToCpuFloat(reinterpret_cast<PD_Tensor *>(tensorPointer), data);
|
||||
env->ReleaseFloatArrayElements(array, data, 0);
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_baidu_paddle_inference_Tensor_cppTensorCopyToCpuInt(
|
||||
JNIEnv *env, jobject, jlong tensorPointer, jintArray array) {
|
||||
int32_t *data = env->GetIntArrayElements(array, nullptr);
|
||||
PD_TensorCopyToCpuInt32(reinterpret_cast<PD_Tensor *>(tensorPointer), data);
|
||||
env->ReleaseIntArrayElements(array, data, 0);
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_baidu_paddle_inference_Tensor_cppTensorCopyToCpuLong(
|
||||
JNIEnv *env, jobject, jlong tensorPointer, jlongArray array) {
|
||||
int64_t *data = env->GetLongArrayElements(array, nullptr);
|
||||
PD_TensorCopyToCpuInt64(reinterpret_cast<PD_Tensor *>(tensorPointer), data);
|
||||
env->ReleaseLongArrayElements(array, data, 0);
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_baidu_paddle_inference_Tensor_cppTensorCopyToCpuByte(
|
||||
JNIEnv *env, jobject, jlong tensorPointer, jbyteArray array) {
|
||||
int8_t *data = env->GetByteArrayElements(array, nullptr);
|
||||
PD_TensorCopyToCpuInt8(reinterpret_cast<PD_Tensor *>(tensorPointer), data);
|
||||
env->ReleaseByteArrayElements(array, data, 0);
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_baidu_paddle_inference_Tensor_cppTensorCopyToCpuBoolean(
|
||||
JNIEnv *env, jobject, jlong tensorPointer, jbooleanArray array) {
|
||||
uint8_t *data = env->GetBooleanArrayElements(array, nullptr);
|
||||
PD_TensorCopyToCpuUint8(reinterpret_cast<PD_Tensor *>(tensorPointer), data);
|
||||
env->ReleaseBooleanArrayElements(array, data, 0);
|
||||
}
|
||||
+169
@@ -0,0 +1,169 @@
|
||||
// Copyright (c) 2021 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.
|
||||
|
||||
/* DO NOT EDIT THIS FILE - it is machine generated */
|
||||
#include <jni.h>
|
||||
/* Header for class com_baidu_paddle_inference_Tensor */
|
||||
|
||||
#pragma once
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
/*
|
||||
* Class: com_baidu_paddle_inference_Tensor
|
||||
* Method: cppTensorDestroy
|
||||
* Signature: (J)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_com_baidu_paddle_inference_Tensor_cppTensorDestroy(
|
||||
JNIEnv *, jobject, jlong);
|
||||
|
||||
/*
|
||||
* Class: com_baidu_paddle_inference_Tensor
|
||||
* Method: cppTensorReshape
|
||||
* Signature: (JI[I)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_com_baidu_paddle_inference_Tensor_cppTensorReshape(
|
||||
JNIEnv *, jobject, jlong, jint, jintArray);
|
||||
|
||||
/*
|
||||
* Class: com_baidu_paddle_inference_Tensor
|
||||
* Method: cppTensorGetShape
|
||||
* Signature: (J)[I
|
||||
*/
|
||||
JNIEXPORT jintArray JNICALL
|
||||
Java_com_baidu_paddle_inference_Tensor_cppTensorGetShape(JNIEnv *,
|
||||
jobject,
|
||||
jlong);
|
||||
|
||||
/*
|
||||
* Class: com_baidu_paddle_inference_Tensor
|
||||
* Method: cppTensorGetName
|
||||
* Signature: (J)Ljava/lang/String;
|
||||
*/
|
||||
JNIEXPORT jstring JNICALL
|
||||
Java_com_baidu_paddle_inference_Tensor_cppTensorGetName(JNIEnv *,
|
||||
jobject,
|
||||
jlong);
|
||||
|
||||
/*
|
||||
* Class: com_baidu_paddle_inference_Tensor
|
||||
* Method: cppTensorCopyFromCpuFloat
|
||||
* Signature: (J[F)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_baidu_paddle_inference_Tensor_cppTensorCopyFromCpuFloat(JNIEnv *,
|
||||
jobject,
|
||||
jlong,
|
||||
jfloatArray);
|
||||
|
||||
/*
|
||||
* Class: com_baidu_paddle_inference_Tensor
|
||||
* Method: cppTensorCopyFromCpuInt
|
||||
* Signature: (J[I)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_baidu_paddle_inference_Tensor_cppTensorCopyFromCpuInt(JNIEnv *,
|
||||
jobject,
|
||||
jlong,
|
||||
jintArray);
|
||||
|
||||
/*
|
||||
* Class: com_baidu_paddle_inference_Tensor
|
||||
* Method: cppTensorCopyFromCpuLong
|
||||
* Signature: (J[J)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_baidu_paddle_inference_Tensor_cppTensorCopyFromCpuLong(JNIEnv *,
|
||||
jobject,
|
||||
jlong,
|
||||
jlongArray);
|
||||
|
||||
/*
|
||||
* Class: com_baidu_paddle_inference_Tensor
|
||||
* Method: cppTensorCopyFromCpuByte
|
||||
* Signature: (J[B)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_baidu_paddle_inference_Tensor_cppTensorCopyFromCpuByte(JNIEnv *,
|
||||
jobject,
|
||||
jlong,
|
||||
jbyteArray);
|
||||
|
||||
/*
|
||||
* Class: com_baidu_paddle_inference_Tensor
|
||||
* Method: cppTensorCopyFromCpuBoolean
|
||||
* Signature: (J[Z)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_baidu_paddle_inference_Tensor_cppTensorCopyFromCpuBoolean(
|
||||
JNIEnv *, jobject, jlong, jbooleanArray);
|
||||
|
||||
/*
|
||||
* Class: com_baidu_paddle_inference_Tensor
|
||||
* Method: cppTensorCopyToCpuFloat
|
||||
* Signature: (J[F)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_baidu_paddle_inference_Tensor_cppTensorCopyToCpuFloat(JNIEnv *,
|
||||
jobject,
|
||||
jlong,
|
||||
jfloatArray);
|
||||
|
||||
/*
|
||||
* Class: com_baidu_paddle_inference_Tensor
|
||||
* Method: cppTensorCopyToCpuInt
|
||||
* Signature: (J[I)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_baidu_paddle_inference_Tensor_cppTensorCopyToCpuInt(JNIEnv *,
|
||||
jobject,
|
||||
jlong,
|
||||
jintArray);
|
||||
|
||||
/*
|
||||
* Class: com_baidu_paddle_inference_Tensor
|
||||
* Method: cppTensorCopyToCpuLong
|
||||
* Signature: (J[J)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_baidu_paddle_inference_Tensor_cppTensorCopyToCpuLong(JNIEnv *,
|
||||
jobject,
|
||||
jlong,
|
||||
jlongArray);
|
||||
|
||||
/*
|
||||
* Class: com_baidu_paddle_inference_Tensor
|
||||
* Method: cppTensorCopyToCpuByte
|
||||
* Signature: (J[B)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_baidu_paddle_inference_Tensor_cppTensorCopyToCpuByte(JNIEnv *,
|
||||
jobject,
|
||||
jlong,
|
||||
jbyteArray);
|
||||
|
||||
/*
|
||||
* Class: com_baidu_paddle_inference_Tensor
|
||||
* Method: cppTensorCopyToCpuBoolean
|
||||
* Signature: (J[Z)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_baidu_paddle_inference_Tensor_cppTensorCopyToCpuBoolean(JNIEnv *,
|
||||
jobject,
|
||||
jlong,
|
||||
jbooleanArray);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,128 @@
|
||||
// Copyright (c) 2021 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.
|
||||
|
||||
#ifndef PADDLE_FLUID_INFERENCE_JAVAAPI_NATIVE_JNI_CONVERT_UTIL_H_ // NOLINT
|
||||
#define PADDLE_FLUID_INFERENCE_JAVAAPI_NATIVE_JNI_CONVERT_UTIL_H_
|
||||
|
||||
#include <jni.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#define PADDLE_WITH_CUDA PADDLE_WITH_CUDA
|
||||
|
||||
inline std::string jstring_to_cpp_string(JNIEnv *env, jstring jstr) {
|
||||
if (!jstr) {
|
||||
return "";
|
||||
}
|
||||
const jclass stringClass = env->GetObjectClass(jstr);
|
||||
const jmethodID getBytes =
|
||||
env->GetMethodID(stringClass, "getBytes", "(Ljava/lang/String;)[B");
|
||||
const jbyteArray stringJbytes = (jbyteArray)env->CallObjectMethod(
|
||||
jstr, getBytes, env->NewStringUTF("UTF-8"));
|
||||
|
||||
size_t length = static_cast<size_t>(env->GetArrayLength(stringJbytes));
|
||||
jbyte *pBytes = env->GetByteArrayElements(stringJbytes, NULL);
|
||||
|
||||
std::string ret = std::string(reinterpret_cast<char *>(pBytes), length);
|
||||
env->ReleaseByteArrayElements(stringJbytes, pBytes, JNI_ABORT);
|
||||
|
||||
env->DeleteLocalRef(stringJbytes);
|
||||
env->DeleteLocalRef(stringClass);
|
||||
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 jboolean cpp_bool_to_jboolean(JNIEnv *env, bool flag) {
|
||||
return flag ? JNI_TRUE : JNI_FALSE;
|
||||
}
|
||||
|
||||
inline bool jboolean_to_cpp_bool(JNIEnv *env, jboolean flag) {
|
||||
return flag == JNI_TRUE;
|
||||
}
|
||||
|
||||
inline jfloatArray cpp_array_to_jfloatarray(JNIEnv *env,
|
||||
const float *buf,
|
||||
int64_t len) {
|
||||
jfloatArray result = env->NewFloatArray(len);
|
||||
env->SetFloatArrayRegion(result, 0, len, buf);
|
||||
return result;
|
||||
}
|
||||
|
||||
inline jbyteArray cpp_array_to_jbytearray(JNIEnv *env,
|
||||
const int8_t *buf,
|
||||
int64_t len) {
|
||||
jbyteArray result = env->NewByteArray(len);
|
||||
env->SetByteArrayRegion(result, 0, len, buf);
|
||||
return result;
|
||||
}
|
||||
|
||||
inline jintArray cpp_array_to_jintarray(JNIEnv *env,
|
||||
const int *buf,
|
||||
int64_t len) {
|
||||
jintArray result = env->NewIntArray(len);
|
||||
env->SetIntArrayRegion(result, 0, len, buf);
|
||||
return result;
|
||||
}
|
||||
|
||||
inline jlongArray cpp_array_to_jlongarray(JNIEnv *env,
|
||||
const int64_t *buf,
|
||||
int64_t len) {
|
||||
jlongArray result = env->NewLongArray(len);
|
||||
env->SetLongArrayRegion(result, 0, len, buf);
|
||||
return result;
|
||||
}
|
||||
|
||||
inline jlongArray int64_vector_to_jlongarray(JNIEnv *env,
|
||||
const std::vector<int64_t> &vec) {
|
||||
jlongArray result = env->NewLongArray(vec.size());
|
||||
jlong *buf = new jlong[vec.size()];
|
||||
for (size_t i = 0; i < vec.size(); ++i) {
|
||||
buf[i] = (jlong)vec[i];
|
||||
}
|
||||
env->SetLongArrayRegion(result, 0, vec.size(), buf);
|
||||
delete[] buf;
|
||||
return result;
|
||||
}
|
||||
|
||||
inline std::vector<int64_t> jlongarray_to_int64_vector(JNIEnv *env,
|
||||
jlongArray dims) {
|
||||
int dim_size = env->GetArrayLength(dims);
|
||||
jlong *dim_nums = env->GetLongArrayElements(dims, nullptr);
|
||||
std::vector<int64_t> dim_vec(dim_nums, dim_nums + dim_size);
|
||||
env->ReleaseLongArrayElements(dims, dim_nums, 0);
|
||||
return dim_vec;
|
||||
}
|
||||
#endif // PADDLE_FLUID_INFERENCE_JAVAAPI_NATIVE_JNI_CONVERT_UTIL_H_ // NOLINT
|
||||
Reference in New Issue
Block a user