diff --git a/mindspore/lite/java/src/main/java/com/mindspore/config/MSContext.java b/mindspore/lite/java/src/main/java/com/mindspore/config/MSContext.java index 835397ab534..ea6d6d0bcf2 100644 --- a/mindspore/lite/java/src/main/java/com/mindspore/config/MSContext.java +++ b/mindspore/lite/java/src/main/java/com/mindspore/config/MSContext.java @@ -67,7 +67,7 @@ public class MSContext { * @return init status. */ public boolean init() { - this.msContextPtr = createMSContext(2, 0, false); + this.msContextPtr = createDefaultMSContext(); return this.msContextPtr != 0; } @@ -115,6 +115,8 @@ public class MSContext { private native long createMSContext(int threadNum, int cpuBindMode, boolean enableParallel); + private native long createDefaultMSContext(); + private native boolean addDeviceInfo(long msContextPtr, int deviceType, boolean isEnableFloat16, int npuFrequency); private native void free(long msContextPtr); diff --git a/mindspore/lite/java/src/main/native/ms_context.cpp b/mindspore/lite/java/src/main/native/ms_context.cpp index 05ff8539e6a..0161b951576 100644 --- a/mindspore/lite/java/src/main/native/ms_context.cpp +++ b/mindspore/lite/java/src/main/native/ms_context.cpp @@ -34,6 +34,16 @@ extern "C" JNIEXPORT jlong JNICALL Java_com_mindspore_config_MSContext_createMSC return (jlong)context; } +extern "C" JNIEXPORT jlong JNICALL Java_com_mindspore_config_MSContext_createDefaultMSContext(JNIEnv *env, + jobject thiz) { + auto *context = new (std::nothrow) mindspore::Context(); + if (context == nullptr) { + MS_LOGE("new Context fail!"); + return (jlong) nullptr; + } + return (jlong)context; +} + extern "C" JNIEXPORT jboolean JNICALL Java_com_mindspore_config_MSContext_addDeviceInfo( JNIEnv *env, jobject thiz, jlong context_ptr, jint device_type, jboolean enable_fp16, jint npu_freq) { auto *pointer = reinterpret_cast(context_ptr); diff --git a/mindspore/lite/src/cxx_api/context.h b/mindspore/lite/src/cxx_api/context.h index 7dded21b518..dc6d3ecd055 100644 --- a/mindspore/lite/src/cxx_api/context.h +++ b/mindspore/lite/src/cxx_api/context.h @@ -31,10 +31,17 @@ namespace mindspore { struct Context::Data { std::vector> device_info_list; + +#ifdef PARALLEL_INFERENCE + int32_t thread_num = 8; + bool enable_parallel_ = true; + int affinity_mode_ = 1; +#else int32_t thread_num = 2; bool enable_parallel_ = false; - std::vector affinity_core_list_; int affinity_mode_ = 0; +#endif + std::vector affinity_core_list_; std::shared_ptr delegate = nullptr; bool float_mode = false; };