| @@ -6,9 +6,8 @@ TOP_PATH="${BASE_PATH}/../../.." | |||
| # build mindspore-lite arm64 | |||
| cd ${TOP_PATH} | |||
| bash build.sh -I arm64 | |||
| COMPILE_RET=$? | |||
| if [[ "${COMPILE_RET}" -ne 0 ]]; then | |||
| COMPILE_ARM64_RET=$? | |||
| if [[ "${COMPILE_ARM64_RET}" -ne 0 ]]; then | |||
| echo "---------------- mindspore lite: build failed ----------------" | |||
| exit | |||
| fi | |||
| @@ -19,6 +18,7 @@ rm -rf mindspore-lite-0.7.0 | |||
| tar -zxvf mindspore-lite-0.7.0-runtime-arm64-cpu.tar.gz | |||
| mkdir -p ${BASE_PATH}/lib/ | |||
| cp ${TOP_PATH}/output/mindspore-lite-0.7.0-runtime-arm64-cpu/lib/libmindspore-lite.so ${BASE_PATH}/lib/ | |||
| cp ${TOP_PATH}/output/mindspore-lite-0.7.0-runtime-arm64-cpu/lib/liboptimize.so ${BASE_PATH}/lib/ | |||
| cp ${ANDROID_NDK}/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/aarch64-linux-android/libc++_shared.so ${BASE_PATH}/lib/ | |||
| # build jni so | |||
| @@ -31,14 +31,48 @@ cmake -DCMAKE_TOOLCHAIN_FILE="${ANDROID_NDK}/build/cmake/android.toolchain.cmake | |||
| -DANDROID_STL="c++_shared" -DCMAKE_BUILD_TYPE=Debug .. | |||
| VERBOSE=2 make -j8 | |||
| cp ${BASE_PATH}/native/build/libmindspore-lite-jni.so ${BASE_PATH}/lib/ | |||
| mkdir -p ${BASE_PATH}/java/app/libs/arm64-v8a/ | |||
| rm -rf ${BASE_PATH}/java/app/libs/arm64-v8a/* | |||
| cp ${BASE_PATH}/lib/*.so ${BASE_PATH}/java/app/libs/arm64-v8a/ | |||
| rm -rf "${BASE_PATH:?}/lib/*" | |||
| # build mindspore-lite arm32 | |||
| cd ${TOP_PATH} | |||
| bash build.sh -I arm32 | |||
| COMPILE_ARM32_RET=$? | |||
| if [[ "${COMPILE_ARM32_RET}" -ne 0 ]]; then | |||
| echo "---------------- mindspore lite: build failed ----------------" | |||
| exit | |||
| fi | |||
| # copy arm32 so | |||
| cd ${TOP_PATH}/output/ | |||
| rm -rf mindspore-lite-0.7.0 | |||
| tar -zxvf mindspore-lite-0.7.0-runtime-arm32-cpu.tar.gz | |||
| mkdir -p ${BASE_PATH}/lib/ | |||
| cp ${TOP_PATH}/output/mindspore-lite-0.7.0-runtime-arm32-cpu/lib/libmindspore-lite.so ${BASE_PATH}/lib/ | |||
| cp ${ANDROID_NDK}/sources/cxx-stl/llvm-libc++/libs/armeabi-v7a/libc++_shared.so ${BASE_PATH}/lib/ | |||
| # build jni so | |||
| cd ${BASE_PATH}/native | |||
| rm -rf build | |||
| mkdir build | |||
| cd build | |||
| cmake -DCMAKE_TOOLCHAIN_FILE="${ANDROID_NDK}/build/cmake/android.toolchain.cmake" -DANDROID_NATIVE_API_LEVEL="19" \ | |||
| -DANDROID_NDK="${ANDROID_NDK}" -DANDROID_ABI="armeabi-v7a" -DANDROID_TOOLCHAIN_NAME="aarch64-linux-android-clang" \ | |||
| -DANDROID_STL="c++_shared" -DCMAKE_BUILD_TYPE=Debug .. | |||
| VERBOSE=2 make -j8 | |||
| cp ${BASE_PATH}/native/build/libmindspore-lite-jni.so ${BASE_PATH}/lib/ | |||
| mkdir -p ${BASE_PATH}/java/app/libs/armeabi-v7a/ | |||
| rm -rf ${BASE_PATH}/java/app/libs/armeabi-v7a/* | |||
| cp ${BASE_PATH}/lib/*.so ${BASE_PATH}/java/app/libs/armeabi-v7a/ | |||
| # build aar | |||
| ## check sdk gradle | |||
| cd ${BASE_PATH}/java | |||
| rm -rf .gradle build gradle gradlew gradlew.bat build app/build | |||
| mkdir -p ${BASE_PATH}/java/app/libs/arm64-v8a/ | |||
| rm -rf ${BASE_PATH}/java/app/libs/arm64-v8a/* | |||
| cp ${BASE_PATH}/lib/*.so ${BASE_PATH}/java/app/libs/arm64-v8a/ | |||
| gradle init | |||
| gradle wrapper | |||
| ./gradlew build | |||
| @@ -47,4 +81,4 @@ gradle wrapper | |||
| cd ${BASE_PATH}/ | |||
| rm -rf output | |||
| mkdir -pv output | |||
| cp ${BASE_PATH}/java/app/build/outputs/aar/mindspore-lite.aar ${BASE_PATH}/output/ | |||
| cp ${BASE_PATH}/java/app/build/outputs/aar/mindspore-lite.aar ${BASE_PATH}/output/ | |||
| @@ -18,6 +18,7 @@ android { | |||
| } | |||
| ndk { | |||
| abiFilters 'arm64-v8a' | |||
| abiFilters 'armeabi-v7a' | |||
| } | |||
| } | |||
| @@ -37,6 +38,9 @@ android { | |||
| outputFileName = "mindspore-lite.aar" | |||
| } | |||
| } | |||
| aaptOptions { | |||
| noCompress = ['.so'] | |||
| } | |||
| } | |||
| dependencies { | |||
| @@ -22,7 +22,7 @@ import java.util.List; | |||
| import java.util.Map; | |||
| import java.util.Set; | |||
| import com.mindspore.lite.context.Context; | |||
| import com.mindspore.lite.config.MSConfig; | |||
| public class LiteSession { | |||
| static { | |||
| @@ -35,8 +35,8 @@ public class LiteSession { | |||
| this.sessionPtr = 0; | |||
| } | |||
| public boolean init(Context context) { | |||
| this.sessionPtr = createSession(context.getContextPtr()); | |||
| public boolean init(MSConfig config) { | |||
| this.sessionPtr = createSession(config.getMSConfigPtr()); | |||
| return this.sessionPtr != 0; | |||
| } | |||
| @@ -129,7 +129,7 @@ public class LiteSession { | |||
| this.sessionPtr = 0; | |||
| } | |||
| private native long createSession(long contextPtr); | |||
| private native long createSession(long msConfigPtr); | |||
| private native boolean compileGraph(long sessionPtr, long modelPtr); | |||
| @@ -14,7 +14,7 @@ | |||
| * limitations under the License. | |||
| */ | |||
| package com.mindspore.lite.context; | |||
| package com.mindspore.lite.config; | |||
| public class CpuBindMode { | |||
| public static final int MID_CPU = -1; | |||
| @@ -14,7 +14,7 @@ | |||
| * limitations under the License. | |||
| */ | |||
| package com.mindspore.lite.context; | |||
| package com.mindspore.lite.config; | |||
| public class DeviceType { | |||
| public static final int DT_CPU = 0; | |||
| @@ -14,26 +14,26 @@ | |||
| * limitations under the License. | |||
| */ | |||
| package com.mindspore.lite.context; | |||
| package com.mindspore.lite.config; | |||
| public class Context { | |||
| private long contextPtr; | |||
| public class MSConfig { | |||
| private long msConfigPtr; | |||
| public Context() { | |||
| this.contextPtr = 0; | |||
| public MSConfig() { | |||
| this.msConfigPtr = 0; | |||
| } | |||
| public long getContextPtr() { | |||
| return contextPtr; | |||
| public long getMSConfigPtr() { | |||
| return msConfigPtr; | |||
| } | |||
| public void setContextPtr(long contextPtr) { | |||
| this.contextPtr = contextPtr; | |||
| public void setMSConfigPtr(long msConfigPtr) { | |||
| this.msConfigPtr = msConfigPtr; | |||
| } | |||
| public boolean init(int deviceType, int threadNum, int cpuBindMode) { | |||
| this.contextPtr = createContext(deviceType, threadNum, cpuBindMode); | |||
| return this.contextPtr != 0; | |||
| this.msConfigPtr = createMSConfig(deviceType, threadNum, cpuBindMode); | |||
| return this.msConfigPtr != 0; | |||
| } | |||
| public boolean init(int deviceType, int threadNum) { | |||
| @@ -49,11 +49,11 @@ public class Context { | |||
| } | |||
| public void free() { | |||
| this.free(this.contextPtr); | |||
| this.contextPtr = 0; | |||
| this.free(this.msConfigPtr); | |||
| this.msConfigPtr = 0; | |||
| } | |||
| private native long createContext(int deviceType, int threadNum, int cpuBindMode); | |||
| private native long createMSConfig(int deviceType, int threadNum, int cpuBindMode); | |||
| private native void free(long contextPtr); | |||
| private native void free(long msConfigPtr); | |||
| } | |||
| @@ -17,7 +17,7 @@ add_library(mindspore-lite-jni SHARED | |||
| ${CMAKE_CURRENT_SOURCE_DIR}/common/jni_utils.cpp | |||
| ${CMAKE_CURRENT_SOURCE_DIR}/runtime/model.cpp | |||
| ${CMAKE_CURRENT_SOURCE_DIR}/runtime/version.cpp | |||
| ${CMAKE_CURRENT_SOURCE_DIR}/runtime/context.cpp | |||
| ${CMAKE_CURRENT_SOURCE_DIR}/runtime/ms_config.cpp | |||
| ${CMAKE_CURRENT_SOURCE_DIR}/runtime/ms_tensor.cpp | |||
| ${CMAKE_CURRENT_SOURCE_DIR}/runtime/lite_session.cpp | |||
| ) | |||
| @@ -21,8 +21,8 @@ | |||
| #include "include/errorcode.h" | |||
| extern "C" JNIEXPORT jlong JNICALL Java_com_mindspore_lite_LiteSession_createSession(JNIEnv *env, jobject thiz, | |||
| jlong context_ptr) { | |||
| auto *pointer = reinterpret_cast<void *>(context_ptr); | |||
| jlong ms_config_ptr) { | |||
| auto *pointer = reinterpret_cast<void *>(ms_config_ptr); | |||
| if (pointer == nullptr) { | |||
| MS_LOGE("Context pointer from java is nullptr"); | |||
| return jlong(nullptr); | |||
| @@ -18,9 +18,8 @@ | |||
| #include <jni.h> | |||
| #include "common/ms_log.h" | |||
| #include "include/context.h" | |||
| #include "include/thread_pool_config.h" | |||
| extern "C" JNIEXPORT jlong JNICALL Java_com_mindspore_lite_context_Context_createContext(JNIEnv *env, jobject thiz, | |||
| extern "C" JNIEXPORT jlong JNICALL Java_com_mindspore_lite_config_MSConfig_createMSConfig(JNIEnv *env, jobject thiz, | |||
| jint device_type, | |||
| jint thread_num, | |||
| jint cpu_bind_mode) { | |||
| @@ -45,13 +44,13 @@ extern "C" JNIEXPORT jlong JNICALL Java_com_mindspore_lite_context_Context_creat | |||
| } | |||
| switch (cpu_bind_mode) { | |||
| case -1: | |||
| context->cpu_bind_mode_ = MID_CPU; | |||
| context->cpu_bind_mode_ = mindspore::lite::MID_CPU; | |||
| break; | |||
| case 0: | |||
| context->cpu_bind_mode_ = NO_BIND; | |||
| context->cpu_bind_mode_ = mindspore::lite::NO_BIND; | |||
| break; | |||
| case 1: | |||
| context->cpu_bind_mode_ = HIGHER_CPU; | |||
| context->cpu_bind_mode_ = mindspore::lite::HIGHER_CPU; | |||
| break; | |||
| default: | |||
| MS_LOGE("Invalid cpu_bind_mode : %d", cpu_bind_mode); | |||
| @@ -61,7 +60,7 @@ extern "C" JNIEXPORT jlong JNICALL Java_com_mindspore_lite_context_Context_creat | |||
| return (jlong)context; | |||
| } | |||
| extern "C" JNIEXPORT void JNICALL Java_com_mindspore_lite_context_Context_free(JNIEnv *env, jobject thiz, | |||
| extern "C" JNIEXPORT void JNICALL Java_com_mindspore_lite_config_MSConfig_free(JNIEnv *env, jobject thiz, | |||
| jlong context_ptr) { | |||
| auto *pointer = reinterpret_cast<void *>(context_ptr); | |||
| if (pointer == nullptr) { | |||