| @@ -48,6 +48,7 @@ set(LITE_SRC | |||||
| ${CMAKE_CURRENT_SOURCE_DIR}/common/string_util.cc | ${CMAKE_CURRENT_SOURCE_DIR}/common/string_util.cc | ||||
| ${CMAKE_CURRENT_SOURCE_DIR}/common/prim_util.cc | ${CMAKE_CURRENT_SOURCE_DIR}/common/prim_util.cc | ||||
| ${CMAKE_CURRENT_SOURCE_DIR}/common/tensor_util.cc | ${CMAKE_CURRENT_SOURCE_DIR}/common/tensor_util.cc | ||||
| ${CMAKE_CURRENT_SOURCE_DIR}/common/loader_util.cc | |||||
| ${CMAKE_CURRENT_SOURCE_DIR}/runtime/allocator.cc | ${CMAKE_CURRENT_SOURCE_DIR}/runtime/allocator.cc | ||||
| ${CMAKE_CURRENT_SOURCE_DIR}/runtime/runtime_api.cc | ${CMAKE_CURRENT_SOURCE_DIR}/runtime/runtime_api.cc | ||||
| ${CMAKE_CURRENT_SOURCE_DIR}/runtime/thread_pool.c | ${CMAKE_CURRENT_SOURCE_DIR}/runtime/thread_pool.c | ||||
| @@ -277,6 +278,10 @@ if(DEFINED ARCHS) | |||||
| target_link_libraries(mindspore_lite) | target_link_libraries(mindspore_lite) | ||||
| endif() | endif() | ||||
| if(NOT WIN32) | |||||
| target_link_libraries(mindspore-lite dl) | |||||
| endif() | |||||
| if(SUPPORT_TRAIN) | if(SUPPORT_TRAIN) | ||||
| set_target_properties(mindspore-lite PROPERTIES OUTPUT_NAME "mindspore-lite-train") | set_target_properties(mindspore-lite PROPERTIES OUTPUT_NAME "mindspore-lite-train") | ||||
| set_target_properties(mindspore-lite_static PROPERTIES OUTPUT_NAME "mindspore-lite-train") | set_target_properties(mindspore-lite_static PROPERTIES OUTPUT_NAME "mindspore-lite-train") | ||||
| @@ -0,0 +1,60 @@ | |||||
| /** | |||||
| * Copyright 2021 Huawei Technologies Co., Ltd | |||||
| * | |||||
| * Licensed under the Apache License, Version 2.0 (the "License"); | |||||
| * you may not use this file except in compliance with the License. | |||||
| * You may obtain a copy of the License at | |||||
| * | |||||
| * http://www.apache.org/licenses/LICENSE-2.0 | |||||
| * | |||||
| * Unless required by applicable law or agreed to in writing, software | |||||
| * distributed under the License is distributed on an "AS IS" BASIS, | |||||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||||
| * See the License for the specific language governing permissions and | |||||
| * limitations under the License. | |||||
| */ | |||||
| #include "src/common/loader_util.h" | |||||
| #include <string.h> | |||||
| #include <climits> | |||||
| #include "include/errorcode.h" | |||||
| #include "src/common/log_util.h" | |||||
| #ifndef _WIN32 | |||||
| namespace mindspore { | |||||
| namespace lite { | |||||
| int SoLoader::Open(const char *SoPath, int mode) { | |||||
| if ((strlen(SoPath)) >= PATH_MAX) { | |||||
| MS_LOG(ERROR) << "path is too long"; | |||||
| return RET_ERROR; | |||||
| } | |||||
| char resolved_path[PATH_MAX]; | |||||
| auto resolve_res = realpath(SoPath, resolved_path); | |||||
| if (resolve_res == nullptr) { | |||||
| MS_LOG(ERROR) << "PATH NOT EXITS"; | |||||
| return RET_ERROR; | |||||
| } | |||||
| handler_ = dlopen(SoPath, mode); | |||||
| if (handler_ == nullptr) { | |||||
| MS_LOG(ERROR) << "open path failed"; | |||||
| return RET_ERROR; | |||||
| } | |||||
| return RET_OK; | |||||
| } | |||||
| void *SoLoader::GetFunc(const char *FuncName) { return dlsym(handler_, FuncName); } | |||||
| int SoLoader::Close() { | |||||
| auto close_res = dlclose(handler_); | |||||
| if (close_res != 0) { | |||||
| MS_LOG(ERROR) << "can not close handler"; | |||||
| return RET_ERROR; | |||||
| } | |||||
| return RET_OK; | |||||
| } | |||||
| } // namespace lite | |||||
| } // namespace mindspore | |||||
| #endif | |||||
| @@ -0,0 +1,40 @@ | |||||
| /** | |||||
| * Copyright 2021 Huawei Technologies Co., Ltd | |||||
| * | |||||
| * Licensed under the Apache License, Version 2.0 (the "License"); | |||||
| * you may not use this file except in compliance with the License. | |||||
| * You may obtain a copy of the License at | |||||
| * | |||||
| * http://www.apache.org/licenses/LICENSE-2.0 | |||||
| * | |||||
| * Unless required by applicable law or agreed to in writing, software | |||||
| * distributed under the License is distributed on an "AS IS" BASIS, | |||||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||||
| * See the License for the specific language governing permissions and | |||||
| * limitations under the License. | |||||
| */ | |||||
| #ifndef MINDSPORE_LITE_SRC_COMMON_LOADER_UTIL_H_ | |||||
| #define MINDSPORE_LITE_SRC_COMMON_LOADER_UTIL_H_ | |||||
| #ifndef _WIN32 | |||||
| #include <dlfcn.h> | |||||
| namespace mindspore { | |||||
| namespace lite { | |||||
| class SoLoader { | |||||
| public: | |||||
| int Open(const char *SoPath, int mode = RTLD_LAZY); | |||||
| void *GetFunc(const char *FuncName); | |||||
| int Close(); | |||||
| private: | |||||
| void *handler_; | |||||
| }; | |||||
| } // namespace lite | |||||
| } // namespace mindspore | |||||
| #endif | |||||
| #endif | |||||
| @@ -155,6 +155,7 @@ set(TEST_LITE_SRC | |||||
| ${LITE_DIR}/src/common/tensor_util.cc | ${LITE_DIR}/src/common/tensor_util.cc | ||||
| ${LITE_DIR}/src/common/file_utils.cc | ${LITE_DIR}/src/common/file_utils.cc | ||||
| ${LITE_DIR}/src/common/utils.cc | ${LITE_DIR}/src/common/utils.cc | ||||
| ${LITE_DIR}/src/common/loader_util.cc | |||||
| ${LITE_DIR}/src/common/string_util.cc | ${LITE_DIR}/src/common/string_util.cc | ||||
| ${LITE_DIR}/tools/common/flag_parser.cc | ${LITE_DIR}/tools/common/flag_parser.cc | ||||
| ${LITE_DIR}/tools/benchmark/benchmark.cc | ${LITE_DIR}/tools/benchmark/benchmark.cc | ||||
| @@ -316,6 +317,7 @@ set(TEST_SRC | |||||
| ${TEST_DIR}/common/common_test.cc | ${TEST_DIR}/common/common_test.cc | ||||
| ${TEST_DIR}/ut/src/infer_test.cc | ${TEST_DIR}/ut/src/infer_test.cc | ||||
| ${TEST_DIR}/ut/src/utils_test.cc | ${TEST_DIR}/ut/src/utils_test.cc | ||||
| ${TEST_DIR}/ut/src/loader_util_test.cc | |||||
| ${TEST_DIR}/ut/src/scheduler_test.cc | ${TEST_DIR}/ut/src/scheduler_test.cc | ||||
| ) | ) | ||||
| @@ -55,6 +55,7 @@ ml_video_edit_imitate_filter.onnx 103 | |||||
| ml_facedetector.onnx 3 | ml_facedetector.onnx 3 | ||||
| ml_ei_facedetection.onnx 2 | ml_ei_facedetection.onnx 2 | ||||
| #ml_video_edit_art_generate.onnx #mul operator overflows, not suitable for fp16 | #ml_video_edit_art_generate.onnx #mul operator overflows, not suitable for fp16 | ||||
| #ml_voice_detect.onnx #conv operator overflows, not suitable for fp16 | |||||
| ml_location_lane_counter.onnx 6 | ml_location_lane_counter.onnx 6 | ||||
| ml_location_lane_counter0.onnx 0.5 | ml_location_lane_counter0.onnx 0.5 | ||||
| #The encoder an decoder model are used in ml_asr scene, both have value overflow. Not suitable for fp16. | #The encoder an decoder model are used in ml_asr scene, both have value overflow. Not suitable for fp16. | ||||
| @@ -0,0 +1,45 @@ | |||||
| /** | |||||
| * Copyright 2021 Huawei Technologies Co., Ltd | |||||
| * | |||||
| * Licensed under the Apache License, Version 2.0 (the "License"); | |||||
| * you may not use this file except in compliance with the License. | |||||
| * You may obtain a copy of the License at | |||||
| * | |||||
| * http://www.apache.org/licenses/LICENSE-2.0 | |||||
| * | |||||
| * Unless required by applicable law or agreed to in writing, software | |||||
| * distributed under the License is distributed on an "AS IS" BASIS, | |||||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||||
| * See the License for the specific language governing permissions and | |||||
| * limitations under the License. | |||||
| */ | |||||
| #include "mindspore/lite/src/common/loader_util.h" | |||||
| #include "common/common_test.h" | |||||
| namespace mindspore { | |||||
| class LoaderUtilTest : public mindspore::CommonTest { | |||||
| public: | |||||
| LoaderUtilTest() {} | |||||
| }; | |||||
| /* | |||||
| in file add.cc, the code is: | |||||
| int add(int a, int b) {return a + b;} | |||||
| use this command to generate so file: | |||||
| gcc add.cc -fPIC -shared -o libadd.so | |||||
| use this command to see the symbol table: | |||||
| nm -D libadd.so | |||||
| */ | |||||
| TEST_F(LoaderUtilTest, TestAdd) { | |||||
| #ifndef _WIN32 | |||||
| lite::SoLoader loader; | |||||
| loader.Open("./libadd.so"); | |||||
| int (*add)(int a, int b); | |||||
| add = (int (*)(int, int))loader.GetFunc("_Z3addii"); | |||||
| int res = add(7, 8); | |||||
| loader.Close(); | |||||
| ASSERT_EQ(15, res); | |||||
| #endif | |||||
| } | |||||
| } // namespace mindspore | |||||