add jar package for x86 and aarch64
This commit is contained in:
parent
b1cde285af
commit
31ab597b7f
|
@ -82,7 +82,9 @@ build_lite_x86_64_jni_and_jar() {
|
|||
fi
|
||||
cp ./libmindspore-lite-jni.so ${LITE_JAVA_PATH}/java/linux_x86/libs/
|
||||
cp ./libmindspore-lite-jni.so ${LITE_JAVA_PATH}/native/libs/linux_x86/
|
||||
cp ./libmindspore-lite-jni.so ${BASEPATH}/output/tmp/${pkg_name}/runtime/lib/
|
||||
cp ./libmindspore-lite-jni.so ${INSTALL_PREFIX}/${pkg_name}/runtime/lib/
|
||||
cp ./libmindspore-lite-jni.so ${LITE_JAVA_PATH}/src/main/resources/com/mindspore/lite/linux_x86_64/
|
||||
cp ${BASEPATH}/output/tmp/${pkg_name}/runtime/lib/libmindspore-lite.so ${LITE_JAVA_PATH}/src/main/resources/com/mindspore/lite/linux_x86_64/
|
||||
if [[ "X$is_train" = "Xon" ]]; then
|
||||
cp ./libmindspore-lite-train-jni.so ${LITE_JAVA_PATH}/java/linux_x86/libs/
|
||||
cp ./libmindspore-lite-train-jni.so ${LITE_JAVA_PATH}/native/libs/linux_x86/
|
||||
|
@ -137,6 +139,100 @@ build_lite_x86_64_jni_and_jar() {
|
|||
rm -rf ${LITE_JAVA_PATH}/native/libs/linux_x86/
|
||||
}
|
||||
|
||||
build_lite_aarch64_jni_and_jar() {
|
||||
ARM64_JNI_CMAKE_ARGS=$1
|
||||
export MSLITE_ENABLE_RUNTIME_CONVERT=off
|
||||
# copy arm64 so
|
||||
local is_train=on
|
||||
cd ${BASEPATH}/output/tmp
|
||||
local pkg_name=mindspore-lite-${VERSION_STR}-linux-aarch64
|
||||
|
||||
cd ${BASEPATH}/output/tmp/
|
||||
rm -rf ${pkg_name}
|
||||
tar -zxf ${BASEPATH}/output/tmp/${pkg_name}.tar.gz
|
||||
rm -rf ${LITE_JAVA_PATH}/java/linux_arm64/libs/ && mkdir -pv ${LITE_JAVA_PATH}/java/linux_arm64/libs/
|
||||
rm -rf ${LITE_JAVA_PATH}/native/libs/linux_arm64/ && mkdir -pv ${LITE_JAVA_PATH}/native/libs/linux_arm64/
|
||||
cp ./${pkg_name}/runtime/lib/*.so* ${LITE_JAVA_PATH}/java/linux_arm64/libs/
|
||||
cp ./${pkg_name}/runtime/lib/*.so* ${LITE_JAVA_PATH}/native/libs/linux_arm64/
|
||||
local train_so=$pkg_name/runtime/lib/libmindspore-lite-train.so
|
||||
if [ ! -f "$train_so" ]; then
|
||||
echo "not exist"
|
||||
is_train=off
|
||||
fi
|
||||
if [[ "X$is_train" = "Xon" ]]; then
|
||||
cp ./${pkg_name}/runtime/third_party/libjpeg-turbo/lib/*.so* ${LITE_JAVA_PATH}/java/linux_arm64/libs/
|
||||
cp ./${pkg_name}/runtime/third_party/libjpeg-turbo/lib/*.so* ${LITE_JAVA_PATH}/native/libs/linux_arm64/
|
||||
fi
|
||||
# build jni so
|
||||
cd ${BASEPATH}/mindspore/lite/build
|
||||
rm -rf java/jni && mkdir -pv java/jni
|
||||
cd java/jni
|
||||
cmake ${ARM64_JNI_CMAKE_ARGS} -DSUPPORT_TRAIN=${is_train} "${LITE_JAVA_PATH}/native/"
|
||||
export LIBRARY_PATH=${BASEPATH}/output/tmp/mindspore-lite-1.6.1-linux-aarch64/runtime/lib/:$LIBRARY_PATH
|
||||
make -j$THREAD_NUM
|
||||
if [[ $? -ne 0 ]]; then
|
||||
echo "---------------- mindspore lite: build jni arm64 failed----------------"
|
||||
exit 1
|
||||
fi
|
||||
cp ./libmindspore-lite-jni.so ${LITE_JAVA_PATH}/java/linux_arm64/libs/
|
||||
cp ./libmindspore-lite-jni.so ${LITE_JAVA_PATH}/native/libs/linux_arm64/
|
||||
cp ./libmindspore-lite-jni.so ${LITE_JAVA_PATH}/src/main/resources/com/mindspore/lite/linux_aarch64/
|
||||
cp ./libmindspore-lite-jni.so ${BASEPATH}/output/tmp/${pkg_name}/runtime/lib/
|
||||
cp ${BASEPATH}/output/tmp/${pkg_name}/runtime/lib/libmindspore-lite.so ${LITE_JAVA_PATH}/src/main/resources/com/mindspore/lite/linux_aarch64/
|
||||
if [[ "X$is_train" = "Xon" ]]; then
|
||||
cp ./libmindspore-lite-train-jni.so ${LITE_JAVA_PATH}/java/linux_arm64/libs/
|
||||
cp ./libmindspore-lite-train-jni.so ${LITE_JAVA_PATH}/native/libs/linux_arm64/
|
||||
cp ./libmindspore-lite-train-jni.so ${BASEPATH}/output/tmp/${pkg_name}/runtime/lib/
|
||||
fi
|
||||
|
||||
cd ${LITE_JAVA_PATH}/java
|
||||
rm -rf gradle .gradle gradlew gradlew.bat
|
||||
local gradle_version=`gradle --version | grep Gradle | awk '{print$2}'`
|
||||
if [[ ${gradle_version} == '6.6.1' ]]; then
|
||||
gradle_command=gradle
|
||||
else
|
||||
gradle wrapper --gradle-version 6.6.1 --distribution-type all
|
||||
gradle_command=${LITE_JAVA_PATH}/java/gradlew
|
||||
fi
|
||||
# build java common
|
||||
${gradle_command} clean -p ${LITE_JAVA_PATH}/java/common
|
||||
${gradle_command} build -p ${LITE_JAVA_PATH}/java/common
|
||||
cp ${LITE_JAVA_PATH}/java/common/build/libs/mindspore-lite-java-common.jar ${LITE_JAVA_PATH}/java/linux_arm64/libs/
|
||||
|
||||
# build java fl_client
|
||||
if [[ "X$is_train" = "Xon" ]]; then
|
||||
${gradle_command} clean -p ${LITE_JAVA_PATH}/java/fl_client
|
||||
${gradle_command} createFlatBuffers -p ${LITE_JAVA_PATH}/java/fl_client
|
||||
${gradle_command} build -p ${LITE_JAVA_PATH}/java/fl_client
|
||||
${gradle_command} clearJar -p ${LITE_JAVA_PATH}/java/fl_client
|
||||
${gradle_command} flReleaseJarX86 --rerun-tasks -p ${LITE_JAVA_PATH}/java/fl_client
|
||||
cp ${LITE_JAVA_PATH}/java/fl_client/build/libs/jarX86/mindspore-lite-java-flclient.jar ${BASEPATH}/output/tmp/${pkg_name}/runtime/lib/
|
||||
rm -rf ${LITE_JAVA_PATH}/java/fl_client/.gradle ${LITE_JAVA_PATH}/java/fl_client/src/main/java/mindspore
|
||||
fi
|
||||
|
||||
# build jar
|
||||
${gradle_command} clean -p ${LITE_JAVA_PATH}/
|
||||
if [[ "${ENABLE_ASAN}" == "ON" || "${ENABLE_ASAN}" == "on" ]] ; then
|
||||
${gradle_command} releaseJar -p ${LITE_JAVA_PATH}/ -x test
|
||||
else
|
||||
if [[ "${MSLITE_ENABLE_TESTCASES}" == "ON" || "${MSLITE_ENABLE_TESTCASES}" == "on" ]] ; then
|
||||
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:${LITE_JAVA_PATH}/native/libs/linux_arm64/
|
||||
${gradle_command} releaseJar -p ${LITE_JAVA_PATH}/
|
||||
else
|
||||
${gradle_command} releaseJar -p ${LITE_JAVA_PATH}/ -x test
|
||||
fi
|
||||
fi
|
||||
cp ${LITE_JAVA_PATH}/build/lib/jar/*.jar ${BASEPATH}/output/tmp/${pkg_name}/runtime/lib/
|
||||
|
||||
# package
|
||||
cd ${BASEPATH}/output/tmp
|
||||
rm -rf ${pkg_name}.tar.gz ${pkg_name}.tar.gz.sha256
|
||||
tar czf ${pkg_name}.tar.gz ${pkg_name}
|
||||
sha256sum ${pkg_name}.tar.gz > ${pkg_name}.tar.gz.sha256
|
||||
rm -rf ${LITE_JAVA_PATH}/java/linux_arm64/libs/
|
||||
rm -rf ${LITE_JAVA_PATH}/native/libs/linux_arm64/
|
||||
}
|
||||
|
||||
build_lite() {
|
||||
LITE_CMAKE_ARGS=${CMAKE_ARGS}
|
||||
[ -n "${BASEPATH}" ] && rm -rf ${BASEPATH}/output
|
||||
|
@ -314,6 +410,15 @@ build_lite() {
|
|||
echo -e "\e[31mIf you want to compile the JAR package, please set $JAVA_HOME. For example: export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-amd64 \e[0m"
|
||||
fi
|
||||
fi
|
||||
if [[ "${local_lite_platform}" == "arm64" ]] && [[ "${machine}" == "aarch64" ]]; then
|
||||
if [ "${JAVA_HOME}" ]; then
|
||||
echo -e "\e[31mJAVA_HOME=$JAVA_HOME \e[0m"
|
||||
build_lite_aarch64_jni_and_jar $1
|
||||
else
|
||||
echo -e "\e[31mJAVA_HOME is not set, so jni and jar packages will not be compiled \e[0m"
|
||||
echo -e "\e[31mIf you want to compile the JAR package, please set $JAVA_HOME. For example: export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-amd64 \e[0m"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
if [[ $? -ne 0 ]]; then
|
||||
echo "---------------- mindspore lite: build failed ----------------"
|
||||
|
@ -540,6 +645,93 @@ update_submodule()
|
|||
git submodule update --init metadef
|
||||
}
|
||||
|
||||
build_lite_x86_64_aarch64_jar()
|
||||
{
|
||||
echo "build_lite_x86_64_aarch64_jar start."
|
||||
if [[ ! -f ${SERVER_X86_64_PACKAGE_FILE} ]] || [[ ! -f ${SERVER_AARCH64_PACKAGE_FILE} ]]; then
|
||||
echo "x86_64_package aarch64_package file not exist."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
local x86_64_base_path=${SERVER_X86_64_PACKAGE_FILE%/*}
|
||||
local aarch64_base_path=${SERVER_AARCH64_PACKAGE_FILE%/*}
|
||||
echo "x86_64_base_path: "${x86_64_base_path}
|
||||
echo "aarch64_base_path: "${aarch64_base_path}
|
||||
|
||||
local x86_64_package_name=`basename ${SERVER_X86_64_PACKAGE_FILE} '.tar.gz'`
|
||||
local aarch64_package_name=`basename ${SERVER_AARCH64_PACKAGE_FILE} '.tar.gz'`
|
||||
echo "x86_64_package_name: "${x86_64_package_name}
|
||||
echo "aarch64_package_name: "${aarch64_package_name}
|
||||
|
||||
# unzip tar.gz, extract native libs(libmindspore-lite.so,libmindspore-lite-jni.so)
|
||||
rm -rf ${x86_64_base_path}/tmp ${aarch64_base_path}/tmp
|
||||
mkdir ${x86_64_base_path}/tmp ${aarch64_base_path}/tmp
|
||||
tar -zxvf ${SERVER_X86_64_PACKAGE_FILE} -C ${x86_64_base_path}/tmp
|
||||
tar -zxvf ${SERVER_AARCH64_PACKAGE_FILE} -C ${aarch64_base_path}/tmp
|
||||
|
||||
LITE_JAVA_PATH=${LITE_BASEPATH}/java
|
||||
local LITE_JAVA_NATIVE_RESOURCE_PATH=${LITE_JAVA_PATH}/src/main/resources/com/mindspore/lite
|
||||
rm -f ${LITE_JAVA_NATIVE_RESOURCE_PATH}/linux_x86_64/*.so
|
||||
rm -f ${LITE_JAVA_NATIVE_RESOURCE_PATH}/linux_aarch64/*.so
|
||||
cp ${x86_64_base_path}/tmp/${x86_64_package_name}/runtime/lib/*.so ${LITE_JAVA_NATIVE_RESOURCE_PATH}/linux_x86_64/
|
||||
cp ${aarch64_base_path}/tmp/${aarch64_package_name}/runtime/lib/*.so ${LITE_JAVA_NATIVE_RESOURCE_PATH}/linux_aarch64/
|
||||
echo "unzip tar success."
|
||||
|
||||
# compile jar package
|
||||
rm -rf ${LITE_JAVA_PATH}/build
|
||||
# build jar
|
||||
local gradle_version=`gradle --version | grep Gradle | awk '{print$2}'`
|
||||
if [[ ${gradle_version} == '6.6.1' ]]; then
|
||||
gradle_command=gradle
|
||||
else
|
||||
gradle wrapper --gradle-version 6.6.1 --distribution-type all
|
||||
gradle_command=${LITE_JAVA_PATH}/java/gradlew
|
||||
fi
|
||||
|
||||
${gradle_command} clean -p ${LITE_JAVA_PATH}/
|
||||
if [[ "${ENABLE_ASAN}" == "ON" || "${ENABLE_ASAN}" == "on" ]] ; then
|
||||
${gradle_command} releaseJar -p ${LITE_JAVA_PATH}/ -x test
|
||||
else
|
||||
if [[ "${MSLITE_ENABLE_TESTCASES}" == "ON" || "${MSLITE_ENABLE_TESTCASES}" == "on" ]] ; then
|
||||
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:${LITE_JAVA_PATH}/native/libs/linux_x86/
|
||||
${gradle_command} releaseJar -p ${LITE_JAVA_PATH}/
|
||||
else
|
||||
${gradle_command} releaseJar -p ${LITE_JAVA_PATH}/ -x test
|
||||
fi
|
||||
fi
|
||||
echo "compile jar success."
|
||||
|
||||
# update jar package, compress tar.gz, update tar.gz
|
||||
cp ${LITE_JAVA_PATH}/build/lib/jar/mindspore-lite-java.jar ${x86_64_base_path}/tmp/${x86_64_package_name}/runtime/lib/ -f
|
||||
cp ${LITE_JAVA_PATH}/build/lib/jar/mindspore-lite-java.jar ${aarch64_base_path}/tmp/${aarch64_package_name}/runtime/lib/ -f
|
||||
|
||||
cd ${x86_64_base_path}/tmp
|
||||
tar -zcvf ${x86_64_package_name}.tar.gz ${x86_64_package_name}/
|
||||
sha256sum ${x86_64_package_name}.tar.gz > ${x86_64_package_name}.tar.gz.sha256
|
||||
rm -f ../${x86_64_package_name}.tar.gz ../${x86_64_package_name}.tar.gz.sha256
|
||||
mv ${x86_64_package_name}.tar.gz ../
|
||||
mv ${x86_64_package_name}.tar.gz.sha256 ../
|
||||
|
||||
cd ${aarch64_base_path}/tmp
|
||||
tar -zcvf ${aarch64_package_name}.tar.gz ${aarch64_package_name}/
|
||||
sha256sum ${aarch64_package_name}.tar.gz > ${aarch64_package_name}.tar.gz.sha256
|
||||
rm -f ../${aarch64_package_name}.tar.gz ../${aarch64_package_name}.tar.gz.sha256
|
||||
mv ${aarch64_package_name}.tar.gz ../
|
||||
mv ${aarch64_package_name}.tar.gz.sha256 ../
|
||||
|
||||
cd ${LITE_BASEPATH}
|
||||
rm -rf ${x86_64_base_path}/tmp
|
||||
rm -rf ${aarch64_base_path}/tmp
|
||||
java -version
|
||||
}
|
||||
|
||||
LITE_BASEPATH=$(cd "$(dirname $0)"; pwd)
|
||||
echo "LITE_BASEPATH="${LITE_BASEPATH}
|
||||
if [[ -z "${BASEPATH}" ]]; then
|
||||
BASEPATH=${LITE_BASEPATH}/../..
|
||||
fi
|
||||
|
||||
INSTALL_PREFIX=${BASEPATH}/output/tmp
|
||||
LITE_JAVA_PATH=${BASEPATH}/mindspore/lite/java
|
||||
if [[ "${MSLITE_ENABLE_ACL}" == "on" ]]; then
|
||||
update_submodule
|
||||
|
@ -565,3 +757,7 @@ elif [[ "X$LITE_PLATFORM" != "X" ]]; then
|
|||
else
|
||||
echo "Invalid parameter"
|
||||
fi
|
||||
|
||||
if [[ -n "${SERVER_X86_64_PACKAGE_FILE}" ]] && [[ -n "${SERVER_AARCH64_PACKAGE_FILE}" ]]; then
|
||||
build_lite_x86_64_aarch64_jar
|
||||
fi
|
|
@ -1,7 +1,5 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<project>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>com.mindspore.lite.demo</groupId>
|
||||
|
|
|
@ -22,6 +22,7 @@ apply plugin: 'java'
|
|||
|
||||
dependencies {
|
||||
testImplementation 'junit:junit:4.13'
|
||||
implementation project(':common')
|
||||
|
||||
implementation fileTree(dir: "libs", include: ["*.jar"])
|
||||
implementation project(':linux_x86')
|
||||
|
@ -38,6 +39,7 @@ task releaseJar(type: Jar) {
|
|||
from('java/common/build/classes/java/main')
|
||||
from('java/linux_x86/build/classes/java/main')
|
||||
from('build/classes/java/main')
|
||||
from('src/main/resources')
|
||||
destinationDirectory = file('build/lib/jar')
|
||||
}
|
||||
releaseJar.dependsOn(build)
|
|
@ -4,6 +4,10 @@ plugins {
|
|||
|
||||
archivesBaseName = 'mindspore-lite-java-common'
|
||||
|
||||
dependencies {
|
||||
implementation group: 'commons-io', name: 'commons-io', version: '2.5'
|
||||
}
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
|
@ -0,0 +1,97 @@
|
|||
package com.mindspore.lite;
|
||||
|
||||
|
||||
import java.io.*;
|
||||
import java.util.Locale;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
|
||||
public class NativeLibrary {
|
||||
private static final Logger LOGGER = Logger.getLogger(NativeLibrary.class.toString());
|
||||
|
||||
private static final String MINDSPORE_LITE_LIBNAME = "mindspore-lite";
|
||||
private static final String MINDSPORE_LITE_JNI_LIBNAME = "mindspore-lite-jni";
|
||||
|
||||
private static final String MINDSPORE_LITE_LIBS = "mindspore_lite_libs";
|
||||
|
||||
public static void load() {
|
||||
if (isLoaded() || tryLoadLibrary()) {
|
||||
return;
|
||||
}
|
||||
loadLib(makeResourceDir(MINDSPORE_LITE_LIBS), makeResourceName("lib" + MINDSPORE_LITE_LIBNAME + ".so"));
|
||||
loadLib(makeResourceDir(MINDSPORE_LITE_LIBS), makeResourceName("lib" + MINDSPORE_LITE_JNI_LIBNAME + ".so"));
|
||||
}
|
||||
|
||||
private static boolean tryLoadLibrary() {
|
||||
try {
|
||||
System.loadLibrary(MINDSPORE_LITE_LIBNAME);
|
||||
System.loadLibrary(MINDSPORE_LITE_JNI_LIBNAME);
|
||||
LOGGER.info("LoadLibrary: success");
|
||||
return true;
|
||||
} catch (UnsatisfiedLinkError e) {
|
||||
LOGGER.warning("tryLoadLibraryFailed: " + e.getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isLoaded() {
|
||||
try {
|
||||
Version.version();
|
||||
LOGGER.info("isLoaded: true");
|
||||
return true;
|
||||
} catch (UnsatisfiedLinkError e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static void loadLib(String jniResourceDir, String jniResourceName) {
|
||||
final Integer BUFFER_SIZE = 8024;
|
||||
final String TMPDIR_PROPERTY = "java.io.tmpdir";
|
||||
try {
|
||||
InputStream in = NativeLibrary.class.getClassLoader().getResourceAsStream(jniResourceName);
|
||||
String tmpPath = System.getProperty(TMPDIR_PROPERTY) + "/" + jniResourceDir;
|
||||
File fileOutDir = new File(tmpPath);
|
||||
if (!fileOutDir.exists()) {
|
||||
fileOutDir.mkdirs();
|
||||
}
|
||||
File fileOut = new File(tmpPath + jniResourceName.substring(jniResourceName.lastIndexOf("/") + 1));
|
||||
if (!fileOut.exists()) {
|
||||
fileOut.createNewFile();
|
||||
}
|
||||
|
||||
OutputStream out = new FileOutputStream(fileOut);
|
||||
IOUtils.copy(in, out, BUFFER_SIZE);
|
||||
in.close();
|
||||
out.close();
|
||||
System.load(fileOut.getAbsolutePath());
|
||||
LOGGER.info(String.format("load file: %s success.", fileOut.getAbsolutePath()));
|
||||
} catch (IOException e) {
|
||||
throw new UnsatisfiedLinkError(String.format(
|
||||
"Unable to extract native library into a temporary file (%s)", e.getMessage()));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* get native lib dir, eg. temp/linux_x86_64
|
||||
* @param dir
|
||||
* @return
|
||||
*/
|
||||
private static String makeResourceDir(String dir) {
|
||||
return dir + "/" + String.format("linux_%s/", architecture());
|
||||
}
|
||||
|
||||
/**
|
||||
* get native lib file name, eg. com/mindspore/lite/linux_x86_64/libmindspore-lite.so
|
||||
* @param basename
|
||||
* @return
|
||||
*/
|
||||
private static String makeResourceName(String basename) {
|
||||
return "com/mindspore/lite/" + String.format("linux_%s/", architecture()) + basename;
|
||||
}
|
||||
|
||||
private static String architecture() {
|
||||
final String arch = System.getProperty("os.arch").toLowerCase();
|
||||
return (arch.equals("amd64")) ? "x86_64" : arch;
|
||||
}
|
||||
}
|
|
@ -23,7 +23,13 @@ package com.mindspore.lite;
|
|||
*/
|
||||
public class Version {
|
||||
static {
|
||||
System.loadLibrary("mindspore-lite-jni");
|
||||
try {
|
||||
NativeLibrary.load();
|
||||
} catch (Exception e) {
|
||||
System.err.println("Failed to load MindSporLite native library.");
|
||||
e.printStackTrace();
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -16,6 +16,8 @@
|
|||
|
||||
package com.mindspore.lite.config;
|
||||
|
||||
import com.mindspore.lite.NativeLibrary;
|
||||
|
||||
/**
|
||||
* MSConfig is defined for holding environment variables during runtime.
|
||||
*
|
||||
|
@ -23,7 +25,13 @@ package com.mindspore.lite.config;
|
|||
*/
|
||||
public class MSConfig {
|
||||
static {
|
||||
System.loadLibrary("mindspore-lite-jni");
|
||||
try {
|
||||
NativeLibrary.load();
|
||||
} catch (Exception e) {
|
||||
System.err.println("Failed to load MindSporLite native library.");
|
||||
e.printStackTrace();
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
private long msConfigPtr;
|
||||
|
|
|
@ -56,14 +56,17 @@ include_directories(${LITE_DIR}) ## lite include
|
|||
include_directories(${TOP_DIR}) ## api include
|
||||
include_directories(${TOP_DIR}/mindspore/core/) ## core include
|
||||
include_directories(${LITE_DIR}/build) ## flatbuffers
|
||||
|
||||
if(PLATFORM_ARM64 OR PLATFORM_ARM32)
|
||||
link_directories(${CMAKE_CURRENT_SOURCE_DIR}/libs/${ANDROID_ABI}/)
|
||||
else()
|
||||
link_directories(${CMAKE_CURRENT_SOURCE_DIR}/libs/linux_x86/)
|
||||
set(JAVA_HOME "$ENV{JAVA_HOME}")
|
||||
include_directories(${JAVA_HOME}/include/) ## jni
|
||||
include_directories(${JAVA_HOME}/include/linux) ## jni
|
||||
endif()
|
||||
|
||||
set(JAVA_HOME "$ENV{JAVA_HOME}")
|
||||
include_directories(${JAVA_HOME}/include/) ## jni
|
||||
include_directories(${JAVA_HOME}/include/linux) ## jni
|
||||
|
||||
set(JNI_SRC
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/runtime/model.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/runtime/version.cpp
|
||||
|
|
|
@ -16,9 +16,17 @@
|
|||
|
||||
package com.mindspore;
|
||||
|
||||
import com.mindspore.lite.NativeLibrary;
|
||||
|
||||
public class Graph {
|
||||
static {
|
||||
System.loadLibrary("mindspore-lite-jni");
|
||||
try {
|
||||
NativeLibrary.load();
|
||||
} catch (Exception e) {
|
||||
System.err.println("Failed to load MindSporLite native library.");
|
||||
e.printStackTrace();
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
private long graphPtr;
|
||||
|
@ -37,7 +45,7 @@ public class Graph {
|
|||
* @return load status.
|
||||
*/
|
||||
public boolean load(String file) {
|
||||
if(file == null) {
|
||||
if (file == null) {
|
||||
return false;
|
||||
}
|
||||
this.graphPtr = loadModel(file);
|
||||
|
|
|
@ -16,12 +16,19 @@
|
|||
|
||||
package com.mindspore;
|
||||
|
||||
import com.mindspore.lite.NativeLibrary;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.List;
|
||||
|
||||
public class MSTensor {
|
||||
static {
|
||||
System.loadLibrary("mindspore-lite-jni");
|
||||
try {
|
||||
NativeLibrary.load();
|
||||
} catch (Exception e) {
|
||||
System.err.println("Failed to load MindSporLite native library.");
|
||||
e.printStackTrace();
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
private long tensorPtr;
|
||||
|
|
|
@ -16,9 +16,9 @@
|
|||
|
||||
package com.mindspore;
|
||||
|
||||
import com.mindspore.config.ModelType;
|
||||
import com.mindspore.config.MSContext;
|
||||
import com.mindspore.config.TrainCfg;
|
||||
import com.mindspore.lite.NativeLibrary;
|
||||
|
||||
import java.nio.MappedByteBuffer;
|
||||
import java.util.ArrayList;
|
||||
|
@ -26,7 +26,13 @@ import java.util.List;
|
|||
|
||||
public class Model {
|
||||
static {
|
||||
System.loadLibrary("mindspore-lite-jni");
|
||||
try {
|
||||
NativeLibrary.load();
|
||||
} catch (Exception e) {
|
||||
System.err.println("Failed to load MindSporLite native library.");
|
||||
e.printStackTrace();
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
private long modelPtr = 0;
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
package com.mindspore;
|
||||
|
||||
import com.mindspore.config.RunnerConfig;
|
||||
import com.mindspore.lite.NativeLibrary;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
@ -28,7 +29,13 @@ import java.util.List;
|
|||
*/
|
||||
public class ModelParallelRunner {
|
||||
static {
|
||||
System.loadLibrary("mindspore-lite-jni");
|
||||
try {
|
||||
NativeLibrary.load();
|
||||
} catch (Exception e) {
|
||||
System.err.println("Failed to load MindSporLite native library.");
|
||||
e.printStackTrace();
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
private long modelParallelRunnerPtr;
|
||||
|
|
|
@ -16,9 +16,17 @@
|
|||
|
||||
package com.mindspore.config;
|
||||
|
||||
import com.mindspore.lite.NativeLibrary;
|
||||
|
||||
public class MSContext {
|
||||
static {
|
||||
System.loadLibrary("mindspore-lite-jni");
|
||||
try {
|
||||
NativeLibrary.load();
|
||||
} catch (Exception e) {
|
||||
System.err.println("Failed to load MindSporLite native library.");
|
||||
e.printStackTrace();
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
private long msContextPtr;
|
||||
|
|
|
@ -16,6 +16,8 @@
|
|||
|
||||
package com.mindspore.config;
|
||||
|
||||
import com.mindspore.lite.NativeLibrary;
|
||||
|
||||
/**
|
||||
* Configuration for ModelParallelRunner.
|
||||
*
|
||||
|
@ -23,7 +25,13 @@ package com.mindspore.config;
|
|||
*/
|
||||
public class RunnerConfig {
|
||||
static {
|
||||
System.loadLibrary("mindspore-lite-jni");
|
||||
try {
|
||||
NativeLibrary.load();
|
||||
} catch (Exception e) {
|
||||
System.err.println("Failed to load MindSporLite native library.");
|
||||
e.printStackTrace();
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
private long runnerConfigPtr;
|
||||
|
|
|
@ -16,15 +16,24 @@
|
|||
|
||||
package com.mindspore.config;
|
||||
|
||||
import com.mindspore.lite.NativeLibrary;
|
||||
|
||||
public class TrainCfg {
|
||||
// depend "mindspore-lite-train-jni"
|
||||
static {
|
||||
System.loadLibrary("mindspore-lite-train-jni");
|
||||
try {
|
||||
System.loadLibrary("mindspore-lite-train-jni");
|
||||
} catch (Exception e) {
|
||||
System.err.println("Failed to load MindSporLite native library.");
|
||||
e.printStackTrace();
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
private long trainCfgPtr;
|
||||
|
||||
/**
|
||||
* Construct function.
|
||||
* Construct function.
|
||||
*/
|
||||
public TrainCfg() {
|
||||
this.trainCfgPtr = 0;
|
||||
|
@ -63,7 +72,7 @@ public class TrainCfg {
|
|||
* Add mix precision config to train config.
|
||||
*
|
||||
* @param dynamicLossScale if dynamic or fix loss scale factor.
|
||||
* @param lossScale loss scale factor.
|
||||
* @param lossScale loss scale factor.
|
||||
* @param thresholdIterNum a threshold for modifying loss scale when dynamic loss scale is enabled.
|
||||
* @return add status.
|
||||
*/
|
||||
|
|
|
@ -16,6 +16,8 @@
|
|||
|
||||
package com.mindspore.config;
|
||||
|
||||
import com.mindspore.lite.NativeLibrary;
|
||||
|
||||
/**
|
||||
* Define mindspore version info.
|
||||
*
|
||||
|
@ -23,7 +25,13 @@ package com.mindspore.config;
|
|||
*/
|
||||
public class Version {
|
||||
static {
|
||||
System.loadLibrary("mindspore-lite-jni");
|
||||
try {
|
||||
NativeLibrary.load();
|
||||
} catch (Exception e) {
|
||||
System.err.println("Failed to load MindSporLite native library.");
|
||||
e.printStackTrace();
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue