!32261 [MS][LITE][parallel predict] set java default param for master

Merge pull request !32261 from yefeng/275-fix_java_default_param
This commit is contained in:
i-robot 2022-04-01 00:59:44 +00:00 committed by Gitee
commit e1e5875f78
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
3 changed files with 21 additions and 2 deletions

View File

@ -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);

View File

@ -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<void *>(context_ptr);

View File

@ -31,10 +31,17 @@
namespace mindspore {
struct Context::Data {
std::vector<std::shared_ptr<DeviceInfoContext>> 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<int32_t> affinity_core_list_;
int affinity_mode_ = 0;
#endif
std::vector<int32_t> affinity_core_list_;
std::shared_ptr<Delegate> delegate = nullptr;
bool float_mode = false;
};