!22989 Add compilation option for mindspore lite
Merge pull request !22989 from liuluobin/master_openssl_option
This commit is contained in:
commit
86140d1c56
|
@ -492,8 +492,12 @@ else()
|
|||
COMPONENT ${RUNTIME_COMPONENT_NAME} FILES_MATCHING PATTERN "*.h")
|
||||
install(DIRECTORY ${protobuf_INC}/google DESTINATION ${CONVERTER_ROOT_DIR}/include/third_party
|
||||
COMPONENT ${RUNTIME_COMPONENT_NAME})
|
||||
install(DIRECTORY ${openssl_INC}/openssl DESTINATION ${CONVERTER_ROOT_DIR}/include/third_party
|
||||
COMPONENT ${RUNTIME_COMPONENT_NAME})
|
||||
if(MSLITE_ENABLE_MODEL_ENCRYPTION)
|
||||
install(DIRECTORY ${openssl_INC}/openssl DESTINATION ${CONVERTER_ROOT_DIR}/include/third_party
|
||||
COMPONENT ${RUNTIME_COMPONENT_NAME})
|
||||
install(FILES ${openssl_LIBPATH}/libcrypto.a DESTINATION ${CONVERTER_ROOT_DIR}/lib
|
||||
COMPONENT ${RUNTIME_COMPONENT_NAME})
|
||||
endif()
|
||||
install(DIRECTORY ${eigen3_INC}/eigen3 DESTINATION ${CONVERTER_ROOT_DIR}/include/third_party
|
||||
COMPONENT ${RUNTIME_COMPONENT_NAME})
|
||||
install(FILES ${TOP_DIR}/mindspore/lite/build/tools/converter/mindspore_core/${MINDSPORE_CORE_LIB_NAME}.a
|
||||
|
@ -506,8 +510,6 @@ else()
|
|||
COMPONENT ${RUNTIME_COMPONENT_NAME})
|
||||
install(FILES ${flatbuffers_LIBPATH}/libflatbuffers.a DESTINATION ${CONVERTER_ROOT_DIR}/lib
|
||||
COMPONENT ${RUNTIME_COMPONENT_NAME})
|
||||
install(FILES ${openssl_LIBPATH}/libcrypto.a DESTINATION ${CONVERTER_ROOT_DIR}/lib
|
||||
COMPONENT ${RUNTIME_COMPONENT_NAME})
|
||||
install(TARGETS converter_lite RUNTIME DESTINATION ${CONVERTER_ROOT_DIR}/converter
|
||||
COMPONENT ${RUNTIME_COMPONENT_NAME})
|
||||
install(FILES ${TOP_DIR}/mindspore/lite/build/tools/converter/registry/libmslite_converter_plugin.so
|
||||
|
|
|
@ -52,5 +52,8 @@ if(USE_GLOG)
|
|||
endif()
|
||||
|
||||
if(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
|
||||
target_link_libraries(mindspore_core PRIVATE mindspore::crypto -pthread)
|
||||
if((NOT BUILD_LITE) OR (BUILD_LITE AND MSLITE_ENABLE_MODEL_ENCRYPTION))
|
||||
target_link_libraries(mindspore_core PRIVATE mindspore::crypto -pthread)
|
||||
add_compile_definitions(ENABLE_OPENSSL)
|
||||
endif()
|
||||
endif()
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
#include <algorithm>
|
||||
#include "utils/log_adapter.h"
|
||||
|
||||
#if not defined(_WIN32)
|
||||
#ifdef ENABLE_OPENSSL
|
||||
#include <openssl/aes.h>
|
||||
#include <openssl/evp.h>
|
||||
#include <openssl/rand.h>
|
||||
|
@ -65,26 +65,28 @@ bool IsCipherFile(const Byte *model_data) {
|
|||
auto flag = ByteToInt(int_buf.data(), int_buf.size());
|
||||
return static_cast<unsigned int>(flag) == MAGIC_NUM;
|
||||
}
|
||||
#if defined(_WIN32)
|
||||
#ifndef ENABLE_OPENSSL
|
||||
std::unique_ptr<Byte[]> Encrypt(size_t *encrypt_len, const Byte *plain_data, size_t plain_len, const Byte *key,
|
||||
size_t key_len, const std::string &enc_mode) {
|
||||
MS_LOG(ERROR) << "Unsupported feature in Windows platform.";
|
||||
MS_LOG(ERROR) << "The feature is only supported on the Linux platform "
|
||||
"when the OPENSSL compilation option is enabled.";
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::unique_ptr<Byte[]> Decrypt(size_t *decrypt_len, const std::string &encrypt_data_path, const Byte *key,
|
||||
size_t key_len, const std::string &dec_mode) {
|
||||
MS_LOG(ERROR) << "Unsupported feature in Windows platform.";
|
||||
MS_LOG(ERROR) << "The feature is only supported on the Linux platform "
|
||||
"when the OPENSSL compilation option is enabled.";
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::unique_ptr<Byte[]> Decrypt(size_t *decrypt_len, const Byte *model_data, size_t data_size, const Byte *key,
|
||||
size_t key_len, const std::string &dec_mode) {
|
||||
MS_LOG(ERROR) << "Unsupported feature in Windows platform.";
|
||||
MS_LOG(ERROR) << "The feature is only supported on the Linux platform "
|
||||
"when the OPENSSL compilation option is enabled.";
|
||||
return nullptr;
|
||||
}
|
||||
#else
|
||||
|
||||
bool ParseEncryptData(const Byte *encrypt_data, size_t encrypt_len, std::vector<Byte> *iv,
|
||||
std::vector<Byte> *cipher_data) {
|
||||
// encrypt_data is organized in order to iv_len, iv, cipher_len, cipher_data
|
||||
|
|
|
@ -42,6 +42,7 @@ option(MSLITE_DELEGATE_USE "enable delegate use" on)
|
|||
option(MSLITE_ENABLE_V0 "support v0 schema" on)
|
||||
option(MSLITE_ENABLE_FP16 "Whether to compile Fp16 operator" off)
|
||||
option(MSLITE_ENABLE_ACL "enable ACL" off)
|
||||
option(MSLITE_ENABLE_MODEL_ENCRYPTION "enable model encryption, only converter support" on)
|
||||
|
||||
#Option that can be configured through manually
|
||||
option(ENABLE_VERBOSE "" off)
|
||||
|
@ -119,10 +120,12 @@ endif()
|
|||
if(DEFINED ENV{MSLITE_ENABLE_FP16})
|
||||
set(MSLITE_ENABLE_FP16 $ENV{MSLITE_ENABLE_FP16})
|
||||
endif()
|
||||
|
||||
if(DEFINED ENV{MSLITE_ENABLE_ACL})
|
||||
set(MSLITE_ENABLE_ACL $ENV{MSLITE_ENABLE_ACL})
|
||||
endif()
|
||||
if(DEFINED ENV{MSLITE_ENABLE_MODEL_ENCRYPTION})
|
||||
set(MSLITE_ENABLE_MODEL_ENCRYPTION $ENV{MSLITE_ENABLE_MODEL_ENCRYPTION})
|
||||
endif()
|
||||
|
||||
if(NOT MSLITE_ENABLE_ACL)
|
||||
set(ENABLE_GLIBCXX ON)
|
||||
|
@ -236,6 +239,7 @@ message(STATUS "\tMSLITE_ENABLE_V0 = \t${MSLITE_ENABLE_V0}")
|
|||
message(STATUS "\tBUILD_MINDDATA = \t${BUILD_MINDDATA}")
|
||||
message(STATUS "\tMSLITE_DELEGATE_USE = \t${MSLITE_DELEGATE_USE}")
|
||||
message(STATUS "\tMSLITE_ENABLE_FP16 = \t${MSLITE_ENABLE_FP16}")
|
||||
message(STATUS "\tMSLITE_ENABLE_MODEL_ENCRYPTION = \t${MSLITE_ENABLE_MODEL_ENCRYPTION}")
|
||||
|
||||
if(MSLITE_ENABLE_HIGH_PERFORMANCE)
|
||||
add_compile_definitions(ENABLE_HIGH_PERFORMANCE)
|
||||
|
@ -419,7 +423,9 @@ if(MSLITE_ENABLE_CONVERTER)
|
|||
include(${TOP_DIR}/cmake/external_libs/eigen.cmake)
|
||||
include(${TOP_DIR}/cmake/external_libs/protobuf.cmake)
|
||||
include(${TOP_DIR}/cmake/external_libs/glog.cmake)
|
||||
include(${TOP_DIR}/cmake/external_libs/openssl.cmake)
|
||||
if(MSLITE_ENABLE_MODEL_ENCRYPTION)
|
||||
include(${TOP_DIR}/cmake/external_libs/openssl.cmake)
|
||||
endif()
|
||||
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/tools/converter)
|
||||
endif()
|
||||
|
||||
|
|
Loading…
Reference in New Issue