!29618 Fix aicpu x86 compile.
Merge pull request !29618 from linqingke/compile-aicpu
This commit is contained in:
commit
1cefcdc8c5
|
@ -83,6 +83,7 @@ file(GLOB DEBUG_STRIP_SYM
|
||||||
${MS_PACK_ROOT_DIR}/mindspore/*.so
|
${MS_PACK_ROOT_DIR}/mindspore/*.so
|
||||||
${MS_PACK_ROOT_DIR}/mindspore/lib/*.so*
|
${MS_PACK_ROOT_DIR}/mindspore/lib/*.so*
|
||||||
)
|
)
|
||||||
|
list(REMOVE_ITEM DEBUG_STRIP_SYM ${MS_PACK_ROOT_DIR}/mindspore/lib/libmindspore_aicpu_kernels.so)
|
||||||
|
|
||||||
set(CMAKE_OBJCOPY $ENV{CROSS_COMPILE}objcopy)
|
set(CMAKE_OBJCOPY $ENV{CROSS_COMPILE}objcopy)
|
||||||
set(CMAKE_STRIP $ENV{CROSS_COMPILE}strip)
|
set(CMAKE_STRIP $ENV{CROSS_COMPILE}strip)
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
set(NORMAL_CMAKE_C_COMPILER ${CMAKE_C_COMPILER})
|
|
||||||
set(NORMAL_CMAKE_CXX_COMPILER ${CMAKE_CXX_COMPILER})
|
|
||||||
if(DEFINED ENV{ASCEND_CUSTOM_PATH})
|
if(DEFINED ENV{ASCEND_CUSTOM_PATH})
|
||||||
set(TOOLCHAIN_PATH $ENV{ASCEND_CUSTOM_PATH}/toolkit/toolchain)
|
set(TOOLCHAIN_PATH $ENV{ASCEND_CUSTOM_PATH}/toolkit/toolchain)
|
||||||
else()
|
else()
|
||||||
|
@ -8,7 +6,10 @@ endif()
|
||||||
set(CMAKE_C_COMPILER ${TOOLCHAIN_PATH}/hcc/bin/aarch64-target-linux-gnu-gcc)
|
set(CMAKE_C_COMPILER ${TOOLCHAIN_PATH}/hcc/bin/aarch64-target-linux-gnu-gcc)
|
||||||
set(CMAKE_CXX_COMPILER ${TOOLCHAIN_PATH}/hcc/bin/aarch64-target-linux-gnu-g++)
|
set(CMAKE_CXX_COMPILER ${TOOLCHAIN_PATH}/hcc/bin/aarch64-target-linux-gnu-g++)
|
||||||
|
|
||||||
if(${CMAKE_HOST_SYSTEM_PROCESSOR} MATCHES "aarch64" AND EXISTS ${CMAKE_C_COMPILER} AND EXISTS ${CMAKE_CXX_COMPILER})
|
if(EXISTS ${CMAKE_C_COMPILER} AND EXISTS ${CMAKE_CXX_COMPILER})
|
||||||
|
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/dependency_securec_arm.cmake)
|
||||||
|
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/protobuf_arm.cmake)
|
||||||
|
|
||||||
set(AICPU_PROTO_SRC
|
set(AICPU_PROTO_SRC
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/aicpu_op_proto/aicpu_tensor.proto
|
${CMAKE_CURRENT_SOURCE_DIR}/aicpu_op_proto/aicpu_tensor.proto
|
||||||
)
|
)
|
||||||
|
@ -26,11 +27,11 @@ if(${CMAKE_HOST_SYSTEM_PROCESSOR} MATCHES "aarch64" AND EXISTS ${CMAKE_C_COMPILE
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/random_choice_with_mask_kernels.cc
|
${CMAKE_CURRENT_SOURCE_DIR}/random_choice_with_mask_kernels.cc
|
||||||
)
|
)
|
||||||
|
|
||||||
add_library(aicpu_kernels SHARED
|
add_library(mindspore_aicpu_kernels SHARED
|
||||||
${AICPU_SRC}
|
${AICPU_SRC}
|
||||||
)
|
)
|
||||||
|
|
||||||
target_compile_options(aicpu_kernels PRIVATE
|
target_compile_options(mindspore_aicpu_kernels PRIVATE
|
||||||
-march=armv8-a
|
-march=armv8-a
|
||||||
-O2
|
-O2
|
||||||
-fvisibility-inlines-hidden
|
-fvisibility-inlines-hidden
|
||||||
|
@ -39,26 +40,23 @@ if(${CMAKE_HOST_SYSTEM_PROCESSOR} MATCHES "aarch64" AND EXISTS ${CMAKE_C_COMPILE
|
||||||
-fno-common
|
-fno-common
|
||||||
)
|
)
|
||||||
|
|
||||||
target_link_libraries(aicpu_kernels PRIVATE
|
target_link_libraries(mindspore_aicpu_kernels PRIVATE
|
||||||
-ldl
|
-ldl
|
||||||
-shared
|
-shared
|
||||||
PUBLIC
|
PUBLIC
|
||||||
${SECUREC_LIBRARY}
|
${SECUREC_ARM_LIBRARY}
|
||||||
-Wl,--whole-archive
|
-Wl,--whole-archive
|
||||||
-Wl,--no-whole-archive
|
-Wl,--no-whole-archive
|
||||||
-Wl,-Bsymbolic
|
-Wl,-Bsymbolic
|
||||||
-rdynamic
|
-rdynamic
|
||||||
mindspore::protobuf
|
mindspore::protobuf_arm
|
||||||
-pthread
|
-pthread
|
||||||
)
|
)
|
||||||
|
|
||||||
set(INSTALL_LIBRARY_DIR lib)
|
set(INSTALL_LIBRARY_DIR lib)
|
||||||
install(TARGETS aicpu_kernels OPTIONAL
|
install(TARGETS mindspore_aicpu_kernels OPTIONAL
|
||||||
EXPORT aicpu_kernels-targets
|
EXPORT mindspore_aicpu_kernels-targets
|
||||||
LIBRARY DESTINATION ${INSTALL_LIBRARY_DIR}
|
LIBRARY DESTINATION ${INSTALL_LIBRARY_DIR}
|
||||||
)
|
)
|
||||||
|
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
set(CMAKE_C_COMPILER ${NORMAL_CMAKE_C_COMPILER})
|
|
||||||
set(CMAKE_CXX_COMPILER ${NORMAL_CMAKE_CXX_COMPILER})
|
|
||||||
|
|
|
@ -0,0 +1,47 @@
|
||||||
|
# securec arm library
|
||||||
|
#
|
||||||
|
#
|
||||||
|
# SECUREC_ARM_LIBRARY
|
||||||
|
#
|
||||||
|
|
||||||
|
if(NOT TARGET securec_arm)
|
||||||
|
set(_ms_tmp_CMAKE_POSITION_INDEPENDENT_CODE ${CMAKE_POSITION_INDEPENDENT_CODE})
|
||||||
|
set(_ms_tmp_CMAKE_C_FLAGS ${CMAKE_C_FLAGS})
|
||||||
|
|
||||||
|
if(TARGET_OHOS_LITE)
|
||||||
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${SECURE_CXX_FLAGS}")
|
||||||
|
else()
|
||||||
|
set(CMAKE_C_FLAGS "${SECURE_CXX_FLAGS}")
|
||||||
|
endif()
|
||||||
|
if(CMAKE_SYSTEM_NAME MATCHES "Windows")
|
||||||
|
add_compile_definitions(SECUREC_ONLY_DECLARE_MEMSET)
|
||||||
|
endif()
|
||||||
|
set(CMAKE_POSITION_INDEPENDENT_CODE ${_ms_tmp_CMAKE_POSITION_INDEPENDENT_CODE})
|
||||||
|
set(CMAKE_C_FLAGS ${_ms_tmp_CMAKE_C_FLAGS})
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(NOT MSVC)
|
||||||
|
SET(CMAKE_BUILD_TYPE "Debug")
|
||||||
|
if(CMAKE_SYSTEM_NAME MATCHES "Windows")
|
||||||
|
SET(CMAKE_C_FLAGS_DEBUG "$ENV{CFLAGS} -fPIC -O0 -Wall -Wno-deprecated-declarations -g2 -ggdb \
|
||||||
|
-fno-inline-functions -fno-omit-frame-pointer -fstack-protector-all")
|
||||||
|
else()
|
||||||
|
SET(CMAKE_C_FLAGS_DEBUG "$ENV{CFLAGS} -Wno-nullability-completeness -fPIC -O0 -Wall \
|
||||||
|
-Wno-deprecated-declarations -g2 -ggdb -fno-inline-functions -fno-omit-frame-pointer \
|
||||||
|
-fstack-protector-all -D_LIBCPP_INLINE_VISIBILITY='' -D'_LIBCPP_EXTERN_TEMPLATE(...)='")
|
||||||
|
endif()
|
||||||
|
SET(CMAKE_C_FLAGS_RELEASE "$ENV{CFLAGS} -fPIC -O3 -Wall -Wno-deprecated-declarations -fstack-protector-all")
|
||||||
|
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||||||
|
|
||||||
|
#add flags
|
||||||
|
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -I/usr/local/include -Werror")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
include_directories(${PROJECT_SOURCE_DIR}/third_party/securec/include)
|
||||||
|
if(CMAKE_SYSTEM_NAME MATCHES "Windows")
|
||||||
|
list(APPEND SECUREC_ARM_LIBRARY "memset_s.c")
|
||||||
|
else()
|
||||||
|
aux_source_directory(${PROJECT_SOURCE_DIR}/third_party/securec/src SECUREC_ARM_LIBRARY)
|
||||||
|
endif()
|
||||||
|
add_library(securec_arm STATIC ${SECUREC_ARM_LIBRARY})
|
||||||
|
set(SECUREC_ARM_LIBRARY securec_arm)
|
|
@ -0,0 +1,66 @@
|
||||||
|
set(protobuf_arm_USE_STATIC_LIBS ON)
|
||||||
|
if(BUILD_LITE)
|
||||||
|
if(MSVC)
|
||||||
|
set(protobuf_arm_CXXFLAGS "${CMAKE_CXX_FLAGS}")
|
||||||
|
set(protobuf_arm_CFLAGS "${CMAKE_C_FLAGS}")
|
||||||
|
set(protobuf_arm_LDFLAGS "${CMAKE_SHARED_LINKER_FLAGS}")
|
||||||
|
set(_ms_tmp_CMAKE_STATIC_LIBRARY_PREFIX ${CMAKE_STATIC_LIBRARY_PREFIX})
|
||||||
|
set(CMAKE_STATIC_LIBRARY_PREFIX "lib")
|
||||||
|
else()
|
||||||
|
set(protobuf_arm_CXXFLAGS "-fstack-protector-all -Wno-maybe-uninitialized -Wno-unused-parameter \
|
||||||
|
-fPIC -fvisibility=hidden -D_FORTIFY_SOURCE=2 -O2")
|
||||||
|
if(NOT ENABLE_GLIBCXX)
|
||||||
|
set(protobuf_arm_CXXFLAGS "${protobuf_arm_CXXFLAGS} -D_GLIBCXX_USE_CXX11_ABI=0")
|
||||||
|
endif()
|
||||||
|
set(protobuf_arm_LDFLAGS "-Wl,-z,relro,-z,now,-z,noexecstack")
|
||||||
|
endif()
|
||||||
|
else()
|
||||||
|
if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
|
||||||
|
set(protobuf_arm_CXXFLAGS "-fstack-protector-all -Wno-uninitialized -Wno-unused-parameter -fPIC \
|
||||||
|
-fvisibility=hidden -D_FORTIFY_SOURCE=2 -O2")
|
||||||
|
elseif(${CMAKE_SYSTEM_NAME} MATCHES "Windows")
|
||||||
|
set(protobuf_arm_CXXFLAGS "-fstack-protector-all -Wno-maybe-uninitialized -Wno-unused-parameter \
|
||||||
|
-fPIC -fvisibility=hidden -D_FORTIFY_SOURCE=2 -O2")
|
||||||
|
else()
|
||||||
|
set(protobuf_arm_CXXFLAGS "-fstack-protector-all -Wno-maybe-uninitialized -Wno-unused-parameter \
|
||||||
|
-fPIC -fvisibility=hidden -D_FORTIFY_SOURCE=2 -O2")
|
||||||
|
if(NOT ENABLE_GLIBCXX)
|
||||||
|
set(protobuf_arm_CXXFLAGS "${protobuf_arm_CXXFLAGS} -D_GLIBCXX_USE_CXX11_ABI=0")
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
set(protobuf_arm_LDFLAGS "-Wl,-z,relro,-z,now,-z,noexecstack")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
set(_ms_tmp_CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
|
||||||
|
set(CMAKE_CXX_FLAGS ${_ms_tmp_CMAKE_CXX_FLAGS})
|
||||||
|
string(REPLACE " -Wall" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
|
||||||
|
string(REPLACE " -Werror" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
|
||||||
|
|
||||||
|
if(ENABLE_GITEE)
|
||||||
|
set(REQ_URL "https://gitee.com/mirrors/protobuf_source/repository/archive/v3.13.0.tar.gz")
|
||||||
|
set(MD5 "53ab10736257b3c61749de9800b8ce97")
|
||||||
|
else()
|
||||||
|
set(REQ_URL "https://github.com/protocolbuffers/protobuf/archive/v3.13.0.tar.gz")
|
||||||
|
set(MD5 "1a6274bc4a65b55a6fa70e264d796490")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
mindspore_add_pkg(protobuf_arm
|
||||||
|
VER 3.13.0
|
||||||
|
LIBS protobuf
|
||||||
|
URL ${REQ_URL}
|
||||||
|
MD5 ${MD5}
|
||||||
|
CMAKE_PATH cmake/
|
||||||
|
CMAKE_OPTION
|
||||||
|
-Dprotobuf_BUILD_TESTS=OFF
|
||||||
|
-Dprotobuf_BUILD_SHARED_LIBS=OFF
|
||||||
|
-DCMAKE_BUILD_TYPE=Release
|
||||||
|
-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
|
||||||
|
-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
|
||||||
|
-Dprotobuf_WITH_ZLIB=OFF)
|
||||||
|
|
||||||
|
include_directories(${protobuf_arm_INC})
|
||||||
|
add_library(mindspore::protobuf_arm ALIAS protobuf_arm::protobuf)
|
||||||
|
set(CMAKE_CXX_FLAGS ${_ms_tmp_CMAKE_CXX_FLAGS})
|
||||||
|
if(MSVC)
|
||||||
|
set(CMAKE_STATIC_LIBRARY_PREFIX, ${_ms_tmp_CMAKE_STATIC_LIBRARY_PREFIX})
|
||||||
|
endif()
|
Loading…
Reference in New Issue