From da86901c88624ae678ea8598494d749b0fb8dc70 Mon Sep 17 00:00:00 2001 From: yeyunpeng Date: Wed, 14 Oct 2020 12:15:39 +0800 Subject: [PATCH] fix fp16 memory leaks and maven publish --- build.sh | 8 +++++-- mindspore/lite/java/java/app/build.gradle | 21 ++++++++++++++++++- .../com/mindspore/lite/config/MSConfig.java | 12 ++++------- .../java/app/src/main/native/CMakeLists.txt | 1 + .../src/main/native/runtime/lite_session.cpp | 15 +++++++------ .../fp32/convolution_depthwise_slidewindow.cc | 2 +- .../arm/fp32/deconvolution_depthwise.cc | 2 +- 7 files changed, 40 insertions(+), 21 deletions(-) diff --git a/build.sh b/build.sh index ac04797468..70b6b77fb3 100755 --- a/build.sh +++ b/build.sh @@ -304,7 +304,7 @@ checkopts() LITE_LANGUAGE="cpp" elif [[ "$OPTARG" == "java" ]]; then LITE_LANGUAGE="java" - ENABLE_CONVERTER="off" + ENABLE_CONVERTER="off" elif [[ "$OPTARG" == "object-c" ]]; then LITE_LANGUAGE="object-c" else @@ -795,8 +795,12 @@ build_java() { gradle wrapper ./gradlew build + gradle publish -PLITE_VERSION=${VERSION_STR}-SNAPSHOT + + cd ${JAVA_PATH}/java/app/build + zip -r mindspore-lite-maven-${VERSION_STR}.zip mindspore # copy output - cp ${JAVA_PATH}/java/app/build/outputs/aar/mindspore-lite.aar ${BASEPATH}/output/mindspore-lite-${VERSION_STR}.aar + cp mindspore-lite-maven-${VERSION_STR}.zip ${BASEPATH}/output/ exit 0 } diff --git a/mindspore/lite/java/java/app/build.gradle b/mindspore/lite/java/java/app/build.gradle index a3446ab0cb..0809ce526f 100644 --- a/mindspore/lite/java/java/app/build.gradle +++ b/mindspore/lite/java/java/app/build.gradle @@ -1,4 +1,5 @@ apply plugin: 'com.android.library' +apply plugin: 'maven-publish' android { compileSdkVersion 30 @@ -8,7 +9,7 @@ android { minSdkVersion 19 targetSdkVersion 30 versionCode 1 - versionName "1.0" + versionName project.hasProperty("LITE_VERSION") ? LITE_VERSION : "" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" externalNativeBuild { @@ -47,3 +48,21 @@ dependencies { implementation fileTree(dir: "libs", include: ["*.jar"]) testImplementation 'junit:junit:4.12' } + +publishing { + repositories { + maven { + url uri("build") + } + } + publications { + maven(MavenPublication) { + groupId = 'mindspore' + artifactId = 'mindspore-lite' + version = project.hasProperty("LITE_VERSION") ? LITE_VERSION : "" + String path = project.buildDir.path + File.separator + "outputs" + File.separator + "aar" + File.separator + "mindspore-lite.aar"; + artifact(path) + } + } +} + diff --git a/mindspore/lite/java/java/app/src/main/java/com/mindspore/lite/config/MSConfig.java b/mindspore/lite/java/java/app/src/main/java/com/mindspore/lite/config/MSConfig.java index cb79119864..549725e33d 100644 --- a/mindspore/lite/java/java/app/src/main/java/com/mindspore/lite/config/MSConfig.java +++ b/mindspore/lite/java/java/app/src/main/java/com/mindspore/lite/config/MSConfig.java @@ -23,14 +23,6 @@ public class MSConfig { this.msConfigPtr = 0; } - public long getMSConfigPtr() { - return msConfigPtr; - } - - public void setMSConfigPtr(long msConfigPtr) { - this.msConfigPtr = msConfigPtr; - } - public boolean init(int deviceType, int threadNum, int cpuBindMode) { this.msConfigPtr = createMSConfig(deviceType, threadNum, cpuBindMode); return this.msConfigPtr != 0; @@ -53,6 +45,10 @@ public class MSConfig { this.msConfigPtr = 0; } + public long getMSConfigPtr() { + return msConfigPtr; + } + private native long createMSConfig(int deviceType, int threadNum, int cpuBindMode); private native void free(long msConfigPtr); diff --git a/mindspore/lite/java/java/app/src/main/native/CMakeLists.txt b/mindspore/lite/java/java/app/src/main/native/CMakeLists.txt index 8bd1408982..5aa1ada0db 100644 --- a/mindspore/lite/java/java/app/src/main/native/CMakeLists.txt +++ b/mindspore/lite/java/java/app/src/main/native/CMakeLists.txt @@ -6,6 +6,7 @@ set(MS_VERSION_MINOR ${MS_VERSION_MINOR}) set(MS_VERSION_REVISION ${MS_VERSION_REVISION}) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DMS_VERSION_MAJOR=${MS_VERSION_MAJOR} -DMS_VERSION_MINOR=${MS_VERSION_MINOR} -DMS_VERSION_REVISION=${MS_VERSION_REVISION}") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DMS_VERSION_MAJOR=${MS_VERSION_MAJOR} -DMS_VERSION_MINOR=${MS_VERSION_MINOR} -DMS_VERSION_REVISION=${MS_VERSION_REVISION}") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17") if (ENABLE_VERBOSE) set(CMAKE_VERBOSE_MAKEFILE on) diff --git a/mindspore/lite/java/java/app/src/main/native/runtime/lite_session.cpp b/mindspore/lite/java/java/app/src/main/native/runtime/lite_session.cpp index 68f7b1192c..544b67650a 100644 --- a/mindspore/lite/java/java/app/src/main/native/runtime/lite_session.cpp +++ b/mindspore/lite/java/java/app/src/main/native/runtime/lite_session.cpp @@ -102,9 +102,10 @@ extern "C" JNIEXPORT jobject JNICALL Java_com_mindspore_lite_LiteSession_getInpu return ret; } -extern "C" JNIEXPORT jobject JNICALL Java_com_mindspore_lite_LiteSession_getInputsByName(JNIEnv *env, jobject thiz, - jlong session_ptr, - jstring node_name) { +extern "C" JNIEXPORT jobject JNICALL Java_com_mindspore_lite_LiteSession_getInputsByTensorName(JNIEnv *env, + jobject thiz, + jlong session_ptr, + jstring tensor_name) { jclass array_list = env->FindClass("java/util/ArrayList"); jmethodID array_list_construct = env->GetMethodID(array_list, "", "()V"); jobject ret = env->NewObject(array_list, array_list_construct); @@ -118,11 +119,9 @@ extern "C" JNIEXPORT jobject JNICALL Java_com_mindspore_lite_LiteSession_getInpu return ret; } auto *lite_session_ptr = static_cast(pointer); - auto inputs = lite_session_ptr->GetInputsByName(JstringToChar(env, node_name)); - for (auto input : inputs) { - jobject tensor_addr = env->NewObject(long_object, long_object_construct, jlong(input)); - env->CallBooleanMethod(ret, array_list_add, tensor_addr); - } + auto input = lite_session_ptr->GetInputsByTensorName(JstringToChar(env, tensor_name)); + jobject tensor_addr = env->NewObject(long_object, long_object_construct, jlong(input)); + env->CallBooleanMethod(ret, array_list_add, tensor_addr); return ret; } diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/convolution_depthwise_slidewindow.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/convolution_depthwise_slidewindow.cc index 0df3603639..350b9a440d 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/convolution_depthwise_slidewindow.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/convolution_depthwise_slidewindow.cc @@ -33,7 +33,7 @@ ConvolutionDepthwiseSWCPUKernel::~ConvolutionDepthwiseSWCPUKernel() { sliding_ = nullptr; } if (packed_weight_ != nullptr) { - delete packed_weight_; + free(packed_weight_); packed_weight_ = nullptr; } } diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/deconvolution_depthwise.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/deconvolution_depthwise.cc index fda740d99c..3f076152c0 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/deconvolution_depthwise.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/deconvolution_depthwise.cc @@ -33,7 +33,7 @@ DeconvolutionDepthwiseCPUKernel::~DeconvolutionDepthwiseCPUKernel() { sliding_ = nullptr; } if (packed_weight_ != nullptr) { - delete packed_weight_; + free(packed_weight_); packed_weight_ = nullptr; } }