Browse Source

!15164 [CPU] Build nnacl as a dynamic library

From: @zhanyuan1
Reviewed-by: @zhaizhiqiang,@guoqi1024
Signed-off-by: @zhaizhiqiang
pull/15164/MERGE
mindspore-ci-bot Gitee 4 years ago
parent
commit
9fe10a19cd
5 changed files with 27 additions and 41 deletions
  1. +1
    -1
      build.sh
  2. +5
    -0
      cmake/package.cmake
  3. +3
    -5
      mindspore/ccsrc/CMakeLists.txt
  4. +2
    -26
      mindspore/ccsrc/backend/kernel_compiler/CMakeLists.txt
  5. +16
    -9
      mindspore/ccsrc/backend/kernel_compiler/cpu/nnacl/CMakeLists.txt

+ 1
- 1
build.sh View File

@@ -467,7 +467,7 @@ build_mindspore()
CMAKE_ARGS="${CMAKE_ARGS} -DENABLE_GPU=ON -DUSE_CUDA=ON -DCUDA_PATH=$CUDA_PATH -DMS_REQUIRE_CUDA_VERSION=${CUDA_VERSION}"
fi
if [[ "X$ENABLE_CPU" = "Xon" ]]; then
CMAKE_ARGS="${CMAKE_ARGS} -DENABLE_CPU=ON"
CMAKE_ARGS="${CMAKE_ARGS} -DENABLE_CPU=ON -DX86_64_SIMD=${X86_64_SIMD}"
fi
if [[ "X$COMPILE_MINDDATA" = "Xon" ]]; then
CMAKE_ARGS="${CMAKE_ARGS} -DENABLE_MINDDATA=ON"


+ 5
- 0
cmake/package.cmake View File

@@ -173,6 +173,11 @@ if(ENABLE_CPU)
DESTINATION ${INSTALL_LIB_DIR}
COMPONENT mindspore
)
install(
TARGETS nnacl
DESTINATION ${INSTALL_LIB_DIR}
COMPONENT mindspore
)
endif()

if(ENABLE_MPI)


+ 3
- 5
mindspore/ccsrc/CMakeLists.txt View File

@@ -7,15 +7,13 @@ if(ENABLE_CPU)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/backend/kernel_compiler/cpu)
if("${X86_64_SIMD}" STREQUAL "sse")
add_compile_definitions(ENABLE_SSE)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -msse4.2")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse4.2")
endif()
if("${X86_64_SIMD}" STREQUAL "avx")
add_compile_definitions(ENABLE_SSE)
add_compile_definitions(ENABLE_AVX)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -msse4.1 -mavx -mavx2")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse4.1 -mavx -mavx2")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mavx2")
endif()
add_subdirectory(backend/kernel_compiler/cpu/nnacl)
endif()

if(ENABLE_ACL)
@@ -415,7 +413,7 @@ if(CMAKE_SYSTEM_NAME MATCHES "Darwin")
endif()

if(ENABLE_CPU)
target_link_libraries(_c_expression PRIVATE mindspore::dnnl mindspore::mkldnn)
target_link_libraries(_c_expression PRIVATE mindspore::dnnl mindspore::mkldnn nnacl)
endif()

if(ENABLE_MINDDATA)


+ 2
- 26
mindspore/ccsrc/backend/kernel_compiler/CMakeLists.txt View File

@@ -29,30 +29,6 @@ if(ENABLE_D)
endif()

if(ENABLE_CPU)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
file(GLOB NNACL_C_SRC RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
"cpu/nnacl/*.c"
"cpu/nnacl/fp32/*.c"
"cpu/nnacl/int8/*.c"
"cpu/nnacl/infer/*.c"
"cpu/nnacl/base/*.c"
)
if("${X86_64_SIMD}" STREQUAL "sse")
file(GLOB NNACL_ASM_SRC RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
"cpu/nnacl/intrinsics/sse/*.c"
)
set_property(SOURCE ${NNACL_ASM_SRC} PROPERTY LANGUAGE C)
endif()
if("${X86_64_SIMD}" STREQUAL "avx")
file(GLOB NNACL_ASM_SRC RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
"cpu/nnacl/intrinsics/sse/*.c"
"cpu/nnacl/intrinsics/avx/*.c"
"cpu/nnacl/assembly/avx/*.S"
)
set_property(SOURCE ${NNACL_ASM_SRC} PROPERTY LANGUAGE C)
endif()
set(NNACL_SRC ${NNACL_C_SRC} ${NNACL_ASM_SRC})

file(GLOB CPU_SRC_LIST RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
"cpu/*.cc"
"cpu/mkldnn/*.cc"
@@ -129,7 +105,7 @@ if(ENABLE_GPU)
# add_library(_mindspore_kernel_cuda_obj OBJECT ${CUDA_SRC_LIST})
endif()

set_property(SOURCE ${KERNEL_SRC_LIST} ${NNACL_SRC} ${CPU_SRC_LIST} ${GPU_SRC_LIST} ${D_SRC_LIST}
set_property(SOURCE ${KERNEL_SRC_LIST} ${CPU_SRC_LIST} ${GPU_SRC_LIST} ${D_SRC_LIST}
PROPERTY COMPILE_DEFINITIONS SUBMODULE_ID=mindspore::SubModuleId::SM_KERNEL)
add_library(_mindspore_backend_kernel_compiler_obj OBJECT ${KERNEL_SRC_LIST} ${NNACL_SRC} ${CPU_SRC_LIST}
add_library(_mindspore_backend_kernel_compiler_obj OBJECT ${KERNEL_SRC_LIST} ${CPU_SRC_LIST}
${GPU_SRC_LIST} ${D_SRC_LIST} ${QUANTUM_SRC_LIST})

+ 16
- 9
mindspore/ccsrc/backend/kernel_compiler/cpu/nnacl/CMakeLists.txt View File

@@ -7,19 +7,20 @@ if(PLATFORM_ARM32 OR PLATFORM_ARM64)
if("${CMAKE_BUILD_TYPE}" STREQUAL "Release" AND DEFINED ARCHS)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fstrict-aliasing \
-ffunction-sections -fdata-sections -ffast-math -Wno-shorten-64-to-32")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fstrict-aliasing \
-ffunction-sections -fdata-sections -ffast-math -Wno-shorten-64-to-32")
endif()
if("${CMAKE_BUILD_TYPE}" STREQUAL "Release" AND NOT DEFINED ARCHS)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fomit-frame-pointer -fstrict-aliasing \
-ffunction-sections -fdata-sections -ffast-math")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fomit-frame-pointer -fstrict-aliasing \
-ffunction-sections -fdata-sections -ffast-math")
endif()
endif()
if(ENABLE_CPU)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
endif()
if("${X86_64_SIMD}" STREQUAL "avx")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse4.1 -mavx -mavx2")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -msse4.1 -mavx -mavx2")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -msse4.1 -mavx -mavx2 -mfma")
endif()
if("${X86_64_SIMD}" STREQUAL "sse")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -msse4.1")
endif()

########################### files ###########################
@@ -63,10 +64,16 @@ endif()

########################### build nnacl static library ########################
string(REPLACE "-fvisibility=hidden" "-fvisibility=default" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
add_library(nnacl STATIC ${KERNEL_SRC} ${TRAIN_SRC} ${ASSEMBLY_SRC})
if(ENABLE_CPU)
add_library(nnacl SHARED ${KERNEL_SRC} ${TRAIN_SRC} ${ASSEMBLY_SRC})
else()
add_library(nnacl STATIC ${KERNEL_SRC} ${TRAIN_SRC} ${ASSEMBLY_SRC})
endif()
add_library(nnacl_mid OBJECT ${KERNEL_SRC} ${TRAIN_SRC} ${ASSEMBLY_SRC})
add_dependencies(nnacl fbs_src)
add_dependencies(nnacl_mid fbs_src)
if(NOT ENABLE_CPU)
add_dependencies(nnacl fbs_src)
add_dependencies(nnacl_mid fbs_src)
endif()

########################### arm fp16 build optimize library ########################
if(ENABLE_FP16)


Loading…
Cancel
Save