kernel plugin
This commit is contained in:
parent
272f4be1ff
commit
28d6781416
|
@ -433,6 +433,10 @@ if(PLATFORM_ARM64)
|
|||
COMPONENT ${RUNTIME_COMPONENT_NAME})
|
||||
install(FILES ${TOP_DIR}/mindspore/lite/build/src/${MINDSPORE_LITE_LIB_NAME}.a DESTINATION ${RUNTIME_LIB_DIR}
|
||||
COMPONENT ${RUNTIME_COMPONENT_NAME})
|
||||
if(MSLITE_ENABLE_ACL)
|
||||
install(FILES ${TOP_DIR}/mindspore/lite/build/src/litert/kernel/ascend/libascend_kernel_plugin.so
|
||||
DESTINATION ${RUNTIME_LIB_DIR} COMPONENT ${RUNTIME_COMPONENT_NAME})
|
||||
endif()
|
||||
endif()
|
||||
if(MSLITE_ENABLE_MODEL_OBF)
|
||||
install(FILES ${TOP_DIR}/mindspore/lite/tools/obfuscator/lib/android-aarch64/libmsdeobfuscator-lite.so
|
||||
|
@ -678,6 +682,10 @@ elseif(PLATFORM_ARM32)
|
|||
COMPONENT ${RUNTIME_COMPONENT_NAME})
|
||||
install(FILES ${TOP_DIR}/mindspore/lite/build/src/${MINDSPORE_LITE_LIB_NAME}.a DESTINATION ${RUNTIME_LIB_DIR}
|
||||
COMPONENT ${RUNTIME_COMPONENT_NAME})
|
||||
if(MSLITE_ENABLE_ACL)
|
||||
install(FILES ${TOP_DIR}/mindspore/lite/build/src/litert/kernel/ascend/libascend_kernel_plugin.so
|
||||
DESTINATION ${RUNTIME_LIB_DIR} COMPONENT ${RUNTIME_COMPONENT_NAME})
|
||||
endif()
|
||||
endif()
|
||||
if(MSLITE_ENABLE_MODEL_OBF)
|
||||
install(FILES ${TOP_DIR}/mindspore/lite/tools/obfuscator/lib/android-aarch32/libmsdeobfuscator-lite.so
|
||||
|
@ -872,6 +880,10 @@ else()
|
|||
COMPONENT ${RUNTIME_COMPONENT_NAME})
|
||||
install(FILES ${TOP_DIR}/mindspore/lite/build/src/${MINDSPORE_LITE_LIB_NAME}.a DESTINATION ${RUNTIME_LIB_DIR}
|
||||
COMPONENT ${RUNTIME_COMPONENT_NAME})
|
||||
if(MSLITE_ENABLE_ACL)
|
||||
install(FILES ${TOP_DIR}/mindspore/lite/build/src/litert/kernel/ascend/libascend_kernel_plugin.so
|
||||
DESTINATION ${RUNTIME_LIB_DIR} COMPONENT ${RUNTIME_COMPONENT_NAME})
|
||||
endif()
|
||||
endif()
|
||||
if(MSLITE_ENABLE_MODEL_OBF)
|
||||
install(FILES ${TOP_DIR}/mindspore/lite/tools/obfuscator/bin/linux-x64/msobfuscator
|
||||
|
|
|
@ -143,6 +143,14 @@ set(LITE_SRC
|
|||
${CMAKE_CURRENT_SOURCE_DIR}/control_flow/control_subgraph_creator.cc
|
||||
)
|
||||
|
||||
if(NOT ANDROID_NDK_TOOLCHAIN_INCLUDED)
|
||||
set(LITE_SRC
|
||||
${LITE_SRC}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/common/dynamic_library_loader.cc
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/litert/kernel/ascend/plugin/ascend_kernel_plugin.cc
|
||||
)
|
||||
endif()
|
||||
|
||||
if(MSLITE_ENABLE_MODEL_PRE_INFERENCE)
|
||||
set(LITE_SRC
|
||||
${LITE_SRC}
|
||||
|
@ -165,7 +173,6 @@ if(MSLITE_ENABLE_MODEL_ENCRYPTION)
|
|||
set(LITE_SRC
|
||||
${LITE_SRC}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/common/decrypt.cc
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/common/dynamic_library_loader.cc
|
||||
)
|
||||
endif()
|
||||
|
||||
|
@ -645,9 +652,4 @@ if(MSLITE_ENABLE_MODEL_OBF)
|
|||
target_link_libraries(mindspore-lite_static ${OBF_LIB_DIR}/libmsdeobfuscator-lite.so)
|
||||
endif()
|
||||
|
||||
if(MSLITE_ENABLE_ACL AND (NOT MSLITE_ENABLE_CLOUD_FUSION_INFERENCE))
|
||||
target_link_libraries(mindspore-lite ascend_kernel_mid)
|
||||
target_link_libraries(mindspore-lite_static ascend_kernel_mid)
|
||||
endif()
|
||||
|
||||
add_subdirectory(extendrt)
|
||||
|
|
|
@ -17,13 +17,13 @@
|
|||
#define MINDSPORE_LITE_SRC_EXTENDRT_CXX_API_DLUTILS_H_
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "include/api/status.h"
|
||||
#include "src/common/file_utils.h"
|
||||
#if !defined(_WIN32) && !defined(_WIN64)
|
||||
#include <dlfcn.h>
|
||||
#include <dirent.h>
|
||||
#include <memory>
|
||||
#include <fstream>
|
||||
#include "utils/file_utils.h"
|
||||
#include "include/api/status.h"
|
||||
|
||||
namespace mindspore {
|
||||
inline Status FindSoPath(const std::string &parent_dir, const std::string &target_so, std::string *target_so_path) {
|
||||
|
@ -51,12 +51,12 @@ inline Status FindSoPath(const std::string &parent_dir, const std::string &targe
|
|||
return Status(kMEFailed, "Could not find target so " + target_so + " in " + parent_dir);
|
||||
}
|
||||
std::string unreal_path = parent_dir + found_target_so;
|
||||
auto realpath = FileUtils::GetRealPath(unreal_path.c_str());
|
||||
if (!realpath.has_value()) {
|
||||
auto realpath = lite::RealPath(unreal_path.c_str());
|
||||
if (realpath.empty()) {
|
||||
return Status(kMEFailed, "Get target so " + target_so + " real path failed, path: " + unreal_path);
|
||||
}
|
||||
|
||||
*target_so_path = realpath.value();
|
||||
*target_so_path = realpath;
|
||||
return kSuccess;
|
||||
}
|
||||
|
||||
|
@ -133,21 +133,22 @@ inline void DLSoClose(void *handle) {
|
|||
} while (false)
|
||||
} // namespace mindspore
|
||||
#else
|
||||
inline Status FindSoPath(const std::string &benchmark_so_path, const std::string &target_so,
|
||||
std::string *target_so_path) {
|
||||
inline mindspore::Status FindSoPath(const std::string &benchmark_so_path, const std::string &target_so,
|
||||
std::string *target_so_path) {
|
||||
MS_LOG(ERROR) << "Not support FindSoPath";
|
||||
return kMEFailed;
|
||||
return mindspore::kMEFailed;
|
||||
}
|
||||
|
||||
inline Status DLSoPath(const std::string &benchmark_so, const std::string &target_so, std::string *target_so_path) {
|
||||
inline mindspore::Status DLSoPath(const std::string &benchmark_so, const std::string &target_so,
|
||||
std::string *target_so_path) {
|
||||
MS_LOG(ERROR) << "Not support dlopen so";
|
||||
return kMEFailed;
|
||||
return mindspore::kMEFailed;
|
||||
}
|
||||
|
||||
inline Status DLSoOpen(const std::string &dl_path, const std::string &func_name, void **handle, void **function,
|
||||
bool runtime_convert = false) {
|
||||
inline mindspore::Status DLSoOpen(const std::string &dl_path, const std::string &func_name, void **handle,
|
||||
void **function, bool runtime_convert = false) {
|
||||
MS_LOG(ERROR) << "Not support dlopen so";
|
||||
return kMEFailed;
|
||||
return mindspore::kMEFailed;
|
||||
}
|
||||
#endif
|
||||
#endif // MINDSPORE_LITE_SRC_EXTENDRT_CXX_API_DLUTILS_H_
|
||||
|
|
|
@ -3,18 +3,19 @@ include_directories(${TOP_DIR}/graphengine/inc/external)
|
|||
find_library(ge_graph libgraph.so ${ASCEND_CANN_RUNTIME_PATH} ${ASCEND_TOOLKIT_RUNTIME_PATH})
|
||||
|
||||
aux_source_directory(src ACL_SRC)
|
||||
add_library(ascend_kernel_mid OBJECT ${ACL_SRC})
|
||||
aux_source_directory(plugin ACL_SRC)
|
||||
add_library(ascend_kernel_plugin SHARED ${ACL_SRC})
|
||||
add_dependencies(ascend_kernel_plugin fbs_inner_src)
|
||||
|
||||
add_dependencies(ascend_kernel_mid fbs_inner_src)
|
||||
if("${MSLITE_REGISTRY_DEVICE}" STREQUAL "SD3403" AND PLATFORM_ARM64)
|
||||
find_library(ge_graph libgraph.so ${ASCEND_CANN_RUNTIME_PATH} ${ASCEND_TOOLKIT_RUNTIME_PATH})
|
||||
find_library(acl libascendcl.so ${ASCEND_CANN_RUNTIME_PATH} ${ASCEND_TOOLKIT_RUNTIME_PATH})
|
||||
find_library(acl_retr libacl_retr.so ${ASCEND_CANN_RUNTIME_PATH} ${ASCEND_TOOLKIT_RUNTIME_PATH})
|
||||
find_library(acl_cblas libacl_cblas.so ${ASCEND_CANN_RUNTIME_PATH} ${ASCEND_TOOLKIT_RUNTIME_PATH})
|
||||
find_library(acl_runtime libruntime.so ${ASCEND_CANN_RUNTIME_PATH} ${ASCEND_TOOLKIT_RUNTIME_PATH})
|
||||
target_link_libraries(ascend_kernel_mid ${ge_graph} ${acl} ${acl_retr} ${acl_cblas} ${acl_runtime})
|
||||
target_link_libraries(ascend_kernel_plugin ${ge_graph} ${acl} ${acl_retr} ${acl_cblas} ${acl_runtime})
|
||||
else()
|
||||
target_link_libraries(ascend_kernel_mid ${ge_graph} ${ge_compiler}
|
||||
target_link_libraries(ascend_kernel_plugin ${ge_graph} ${ge_compiler}
|
||||
${acl_retr} ${acl_cblas} ${acl_dvpp} ${acl_runtime} ${libplatform}
|
||||
${libcompress} ${libopskernel} ${libaicore_utils} ${libaicpu_engine_common} ${acl})
|
||||
endif()
|
|
@ -0,0 +1,55 @@
|
|||
/**
|
||||
* Copyright 2022 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 <string>
|
||||
#include "litert/kernel/ascend/plugin/ascend_kernel_plugin.h"
|
||||
#include "extendrt/cxx_api/dlutils.h"
|
||||
#include "include/errorcode.h"
|
||||
|
||||
namespace mindspore {
|
||||
AscendKernelPlugin &AscendKernelPlugin::GetInstance() {
|
||||
static AscendKernelPlugin instance;
|
||||
return instance;
|
||||
}
|
||||
|
||||
AscendKernelPlugin::AscendKernelPlugin() : is_registered_(false) {}
|
||||
|
||||
AscendKernelPlugin::~AscendKernelPlugin() {}
|
||||
|
||||
int AscendKernelPlugin::Register() {
|
||||
if (is_registered_) {
|
||||
return lite::RET_OK;
|
||||
}
|
||||
std::string dl_so_path;
|
||||
auto get_path_ret = DLSoPath({"libmindspore-lite.so"}, "libascend_kernel_plugin.so", &dl_so_path);
|
||||
if (get_path_ret != kSuccess) {
|
||||
MS_LOG(ERROR) << "Get libascend_kernel_plugin.so path failed";
|
||||
return lite::RET_ERROR;
|
||||
}
|
||||
dl_loader_ = std::make_shared<lite::DynamicLibraryLoader>();
|
||||
if (dl_loader_ == nullptr) {
|
||||
MS_LOG(ERROR) << "Init dynamic library loader failed";
|
||||
return lite::RET_ERROR;
|
||||
}
|
||||
auto status = dl_loader_->Open(dl_so_path);
|
||||
if (status != lite::RET_OK) {
|
||||
MS_LOG(ERROR) << "Open libascend_kernel_plugin.so failed";
|
||||
return lite::RET_ERROR;
|
||||
}
|
||||
is_registered_ = true;
|
||||
return lite::RET_OK;
|
||||
}
|
||||
} // namespace mindspore
|
|
@ -0,0 +1,38 @@
|
|||
/**
|
||||
* Copyright 2022 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_LITERT_KERNEL_ASCEND_ASCEND_KERNEL_PLUGIN_H_
|
||||
#define MINDSPORE_LITE_SRC_LITERT_KERNEL_ASCEND_ASCEND_KERNEL_PLUGIN_H_
|
||||
|
||||
#include <memory>
|
||||
#include "src/common/dynamic_library_loader.h"
|
||||
|
||||
namespace mindspore {
|
||||
class AscendKernelPlugin {
|
||||
public:
|
||||
static AscendKernelPlugin &GetInstance();
|
||||
|
||||
int Register();
|
||||
|
||||
private:
|
||||
AscendKernelPlugin();
|
||||
~AscendKernelPlugin();
|
||||
|
||||
bool is_registered_;
|
||||
std::shared_ptr<lite::DynamicLibraryLoader> dl_loader_ = nullptr;
|
||||
};
|
||||
} // namespace mindspore
|
||||
#endif // MINDSPORE_LITE_SRC_LITERT_KERNEL_ASCEND_ASCEND_KERNEL_PLUGIN_H_
|
|
@ -54,6 +54,9 @@
|
|||
#endif
|
||||
#include "src/litert/runtime_convert.h"
|
||||
#include "extendrt/mindir_loader/model_loader.h"
|
||||
#ifndef __ANDROID__
|
||||
#include "kernel/ascend/plugin/ascend_kernel_plugin.h"
|
||||
#endif
|
||||
|
||||
using AbstractBaseModel = mindspore::infer::AbstractBaseModel;
|
||||
|
||||
|
@ -762,6 +765,18 @@ int LiteSession::ContextInit(const std::shared_ptr<InnerContext> &context) {
|
|||
return RET_OK;
|
||||
}
|
||||
|
||||
int LiteSession::AscendInit(const std::shared_ptr<InnerContext> &context) {
|
||||
#ifndef __ANDROID__
|
||||
if (!context->IsDeviceTypeEnabled(DT_ASCEND)) {
|
||||
MS_LOG(INFO) << "There is no Ascend device type.";
|
||||
return RET_OK;
|
||||
}
|
||||
return mindspore::AscendKernelPlugin::GetInstance().Register();
|
||||
#else
|
||||
return RET_OK;
|
||||
#endif
|
||||
}
|
||||
|
||||
int LiteSession::CreateTensorRTDelegate() {
|
||||
#if GPU_TENSORRT
|
||||
std::string cache_model_path;
|
||||
|
@ -906,6 +921,12 @@ int LiteSession::Init(const std::shared_ptr<InnerContext> &context) {
|
|||
return ret;
|
||||
}
|
||||
|
||||
ret = AscendInit(context);
|
||||
if (ret != RET_OK) {
|
||||
MS_LOG(ERROR) << "Open Ascend kernel plugin failed";
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = DelegateInit();
|
||||
if (ret != RET_OK) {
|
||||
MS_LOG(ERROR) << "Init delegate failed.";
|
||||
|
|
|
@ -31,6 +31,7 @@
|
|||
#include "src/litert/executor.h"
|
||||
#include "src/tensor.h"
|
||||
#include "src/tensorlist.h"
|
||||
#include "src/common/dynamic_library_loader.h"
|
||||
#include "include/api/delegate.h"
|
||||
#if GPU_OPENCL
|
||||
#include "src/litert/kernel/gpu/opencl/opencl_runtime.h"
|
||||
|
@ -170,6 +171,9 @@ class LiteSession {
|
|||
virtual int RuntimeAllocatorValid();
|
||||
RuntimeAllocatorPtr runtime_allocator_ = nullptr;
|
||||
|
||||
private:
|
||||
int AscendInit(const std::shared_ptr<InnerContext> &context);
|
||||
|
||||
protected:
|
||||
std::shared_ptr<InnerContext> context_ = nullptr;
|
||||
mindspore::Context *ms_context_ = nullptr;
|
||||
|
|
|
@ -166,8 +166,16 @@ set(LITE_SRC ${API_SRC}
|
|||
${LITE_DIR}/src/extendrt/mock/lite_runtime/populate/base_operator_populate_register.cc
|
||||
${SRC_DIR}/control_flow/control_flow_scheduler.cc
|
||||
${SRC_DIR}/control_flow/control_subgraph_creator.cc
|
||||
${SRC_DIR}/litert/kernel/ascend/plugin/ascend_kernel_plugin.cc
|
||||
)
|
||||
|
||||
if(NOT ANDROID_NDK_TOOLCHAIN_INCLUDED)
|
||||
set(LITE_SRC
|
||||
${LITE_SRC}
|
||||
${SRC_DIR}/litert/kernel/ascend/plugin/ascend_kernel_plugin.cc
|
||||
)
|
||||
endif()
|
||||
|
||||
if(MSLITE_ENABLE_MODEL_PRE_INFERENCE)
|
||||
set(LITE_SRC
|
||||
${LITE_SRC}
|
||||
|
|
Loading…
Reference in New Issue