You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

train_session.cpp 1.9 kB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /**
  2. * Copyright 2020 Huawei Technologies Co., Ltd
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #include <jni.h>
  17. #include "common/ms_log.h"
  18. #include "include/train/train_session.h"
  19. #include "include/train/train_cfg.h"
  20. #include "include/errorcode.h"
  21. extern "C" JNIEXPORT jlong JNICALL Java_com_mindspore_lite_TrainSession_createTrainSession(JNIEnv *env, jobject thiz,
  22. jstring file_name,
  23. jlong ms_context_ptr,
  24. jboolean train_mode,
  25. jlong train_config_ptr) {
  26. auto *pointer = reinterpret_cast<void *>(ms_context_ptr);
  27. if (pointer == nullptr) {
  28. MS_LOGE("Context pointer from java is nullptr");
  29. return jlong(nullptr);
  30. }
  31. auto *lite_context_ptr = static_cast<mindspore::lite::Context *>(pointer);
  32. auto session = mindspore::session::TrainSession::CreateTrainSession(env->GetStringUTFChars(file_name, JNI_FALSE),
  33. lite_context_ptr, train_mode, nullptr);
  34. if (session == nullptr) {
  35. MS_LOGE("CreateTrainSession failed");
  36. return jlong(nullptr);
  37. }
  38. return jlong(session);
  39. }