From ca89b662e0b453307760d03d92e6a2000c03d164 Mon Sep 17 00:00:00 2001 From: 13611516375 Date: Thu, 17 Nov 2022 10:36:22 +0800 Subject: [PATCH] fix thrid --- CMakeLists.txt | 14 +-- build.sh | 32 ++++-- cmake/common_funcs.cmake | 132 ++++++++++++++++++++++++ cmake/dependencies.cmake | 66 ++++++++---- community/CMakeLists.txt | 9 +- community/framework/onnx/CMakeLists.txt | 2 +- community/framework/tf/CMakeLists.txt | 2 +- community/ops/CMakeLists.txt | 8 +- community/ops/aicpu.cmake | 8 +- 9 files changed, 229 insertions(+), 44 deletions(-) create mode 100644 cmake/common_funcs.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 4e89dd72..0bc048f9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -50,16 +50,16 @@ add_compile_options( -Werror=return-type -Werror=unused-value -Werror=deprecated-declarations) -include(ExternalProject) +include(cmake/common_funcs.cmake) include(cmake/util/intf_pub_linux.cmake) include(cmake/util/util.cmake) include(cmake/dependencies.cmake) -include(cmake/external/secure_c.cmake) -include(cmake/external/nlohmann_json.cmake) -include(cmake/external/protobuf.cmake) -include(cmake/external/gtest.cmake) -include(cmake/external/eigen.cmake) -include(cmake/external/protobuf_static.cmake) + +if(BUILD_AICPU) + include(ExternalProject) + include(cmake/external/secure_c.cmake) +endif() + if(ALL_UT OR PROTO_UT OR TILING_UT) include(cmake/util/intf_pub_llt_gccnative.cmake) endif() diff --git a/build.sh b/build.sh index faa13f81..fe687a71 100755 --- a/build.sh +++ b/build.sh @@ -25,19 +25,30 @@ mk_dir() { } # create build path -build_cann() { - echo "Create build directory and build CANN" +build_cann_tbe() { + echo "Create build directory and build tbe" mk_dir "${BUILD_PATH}/install/community/cpu/config" > /dev/null python3 scripts/parser_ini.py *.ini ${BUILD_PATH}/install/community/cpu/config/cust_aicpu_kernel.json mk_dir "${CMAKE_HOST_PATH}" + cd "${CMAKE_HOST_PATH}" && cmake ../.. make ${VERBOSE} -j${THREAD_NUM} if [ $? -ne 0 ];then - echo "CANN build faild" + echo "CANN tbe faild" + else + echo "CANN tbe success!" + fi +} + +build_cann_aicpu() { + cd "${CMAKE_HOST_PATH}" && cmake ../.. -D BUILD_AICPU=True + make ${VERBOSE} -j${THREAD_NUM} + if [ $? -ne 0 ];then + echo "CANN build aicpu faild" else - echo "CANN build success!" + echo "CANN build aicpu success!" fi } @@ -54,9 +65,6 @@ change_dir() if [ -d ${BUILD_PATH}/install/community/op_tiling ];then cp -r ${BUILD_PATH}/install/community/op_tiling ${TAR_DIR_PATH}/vendors/community/op_impl/ai_core/tbe > /dev/null fi - if [ -d ${BUILD_PATH}/install/community/cpu ];then - cp -r ${BUILD_PATH}/install/community/cpu ${TAR_DIR_PATH}/vendors/community/op_impl >/dev/null - fi if [ -d ${BUILD_PATH}/install/community/op_impl ];then cp -r ${BUILD_PATH}/install/community/op_impl ${TAR_DIR_PATH}/vendors/community/op_impl/ai_core/tbe > /dev/null mv ${TAR_DIR_PATH}/vendors/community/op_impl/ai_core/tbe/op_impl ${TAR_DIR_PATH}/vendors/community/op_impl/ai_core/tbe/impl @@ -67,10 +75,18 @@ change_dir() fi } +change_dir_aicpu() +{ + if [ -d ${BUILD_PATH}/install/community/cpu ];then + cp -r ${BUILD_PATH}/install/community/cpu ${TAR_DIR_PATH}/vendors/community/op_impl >/dev/null + fi +} main() { # CANN build start - build_cann + build_cann_tbe # Change dir change_dir + build_cann_aicpu + change_dir_aicpu } main diff --git a/cmake/common_funcs.cmake b/cmake/common_funcs.cmake new file mode 100644 index 00000000..e2a1118a --- /dev/null +++ b/cmake/common_funcs.cmake @@ -0,0 +1,132 @@ +# 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. +# ============================================================================ + +function(to_absolute_path input_sources source_dir out_arg) + set(output_sources) + FOREACH(source_file ${${input_sources}}) + if(IS_ABSOLUTE ${source_file}) + list(APPEND output_sources ${source_file}) + else() + if(${source_file} MATCHES ".cc$") + list(APPEND output_sources ${${source_dir}}/${source_file}) + else() + list(APPEND output_sources ${source_file}) + endif() + endif() + ENDFOREACH() + set(${out_arg} ${output_sources} PARENT_SCOPE) +endfunction() + + +function(target_clone original_library target_library libray_type) + get_target_property(sourceFiles ${original_library} SOURCES) + get_target_property(sourceDir ${original_library} SOURCE_DIR) + get_target_property(linkLibs ${original_library} LINK_LIBRARIES) + get_target_property(linkOpts ${original_library} LINK_OPTIONS) + get_target_property(includeDirs ${original_library} INCLUDE_DIRECTORIES) + get_target_property(compileDefinitions ${original_library} COMPILE_DEFINITIONS) + get_target_property(compileOptions ${original_library} COMPILE_OPTIONS) + + to_absolute_path(sourceFiles sourceDir absolute_sources_files) + + add_library(${target_library} ${libray_type} + ${absolute_sources_files} + ) + + target_include_directories(${target_library} PRIVATE + ${includeDirs} + ) + + target_link_libraries(${target_library} PRIVATE + ${linkLibs} + ) + + if (linkOpts) + target_link_options(${target_library} PRIVATE + ${linkOpts} + ) + endif() + if (compileOptions) + target_compile_options(${target_library} PRIVATE + ${compileOptions} + ) + endif() + if (compileDefinitions) + target_compile_definitions(${target_library} PRIVATE + ${compileDefinitions} + ) + endif() +endfunction() + +function(protobuf_generate comp c_var h_var) + if(NOT ARGN) + message(SEND_ERROR "Error: protobuf_generate() called without any proto files") + return() + endif() + set(${c_var}) + set(${h_var}) + set(_add_target FALSE) + + set(extra_option "") + foreach(arg ${ARGN}) + if ("${arg}" MATCHES "--proto_path") + set(extra_option ${arg}) + endif() + endforeach() + + foreach(file ${ARGN}) + if("${file}" STREQUAL "TARGET") + set(_add_target TRUE) + continue() + endif() + + if ("${file}" MATCHES "--proto_path") + continue() + endif() + + get_filename_component(abs_file ${file} ABSOLUTE) + get_filename_component(file_name ${file} NAME_WE) + get_filename_component(file_dir ${abs_file} PATH) + get_filename_component(parent_subdir ${file_dir} NAME) + + if("${parent_subdir}" STREQUAL "proto") + set(proto_output_path ${CMAKE_BINARY_DIR}/proto/${comp}/proto) + else() + set(proto_output_path ${CMAKE_BINARY_DIR}/proto/${comp}/proto/${parent_subdir}) + endif() + list(APPEND ${c_var} "${proto_output_path}/${file_name}.pb.cc") + list(APPEND ${h_var} "${proto_output_path}/${file_name}.pb.h") + + add_custom_command( + OUTPUT "${proto_output_path}/${file_name}.pb.cc" "${proto_output_path}/${file_name}.pb.h" + WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} + COMMAND ${CMAKE_COMMAND} -E make_directory "${proto_output_path}" + COMMAND ${CMAKE_COMMAND} -E echo "generate proto cpp_out ${comp} by ${abs_file}" + COMMAND ${PROTOC_PROGRAM} -I${file_dir} ${extra_option} --cpp_out=${proto_output_path} ${abs_file} + DEPENDS ${abs_file} + COMMENT "Running C++ protocol buffer compiler on ${file}" VERBATIM ) + endforeach() + + if(_add_target) + add_custom_target( + ${comp} DEPENDS ${${c_var}} ${${h_var}} + ) + endif() + + set_source_files_properties(${${c_var}} ${${h_var}} PROPERTIES GENERATED TRUE) + set(${c_var} ${${c_var}} PARENT_SCOPE) + set(${h_var} ${${h_var}} PARENT_SCOPE) + +endfunction() \ No newline at end of file diff --git a/cmake/dependencies.cmake b/cmake/dependencies.cmake index 54d0da9d..3259f86e 100644 --- a/cmake/dependencies.cmake +++ b/cmake/dependencies.cmake @@ -22,21 +22,51 @@ endif() message("Search libs under install path ${ASCEND_DIR}") set(ASCEND_ATC_DIR ${ASCEND_DIR}/compiler/lib64) -#set(ASCEND_OPENSDK_LIB ${ASCEND_DIR}/opensdk/opensdk/lib) -#set(CMAKE_PREFIX_PATH ${ASCEND_DIR}/opensdk/opensdk/cmake) - -find_module(graph libgraph.so ${ASCEND_ATC_DIR}) -find_module(register libregister.so ${ASCEND_ATC_DIR}) -find_module(exe_graph libexe_graph.so ${ASCEND_ATC_DIR}) - -#find_package(slog CONFIG REQUIRED) -#find_package(metadef CONFIG REQUIRED) -#find_module(ascend_protobuf libascend_protobuf.so.3.13.0.0 ${ASCEND_ATC_DIR}) -#find_package(mmpa CONFIG REQUIRED) -#find_package(parser CONFIG REQUIRED) -#find_package(opcompiler CONFIG REQUIRED) -#find_package(platform CONFIG REQUIRED) -#find_package(ascend_hal CONFIG REQUIRED) -#find_package(runtime CONFIG REQUIRED) -#find_package(air CONFIG REQUIRED) -#find_file(tbe_whl te-0.4.0-py3-none-any.whl ${ASCEND_ATC_DIR}) +set(ASCEND_OPENSDK_LIB ${ASCEND_DIR}/opensdk/opensdk/lib) +set(CMAKE_PREFIX_PATH ${ASCEND_DIR}/opensdk/opensdk/cmake) + + +list(APPEND CMAKE_PREFIX_PATH + ${ASCEND_DIR}/opensdk/opensdk/jpeg + ${ASCEND_DIR}/opensdk/opensdk/gtest + ${ASCEND_DIR}/opensdk/opensdk/json + ${ASCEND_DIR}/opensdk/opensdk/eigen/share/eigen3/cmake +) + + +set(CMAKE_MODULE_PATH ${ASCEND_DIR}/opensdk/opensdk/cmake/modules) +find_package(jpeg MODULE) +find_package(gtest MODULE) +find_package(json MODULE) + +if(NOT BUILD_AICPU) + list(APPEND CMAKE_PREFIX_PATH + ${ASCEND_DIR}/opensdk/opensdk/c_sec + ) + find_package(securec MODULE) +endif() + +list(APPEND CMAKE_PREFIX_PATH ${ASCEND_DIR}/opensdk/opensdk/eigen/share/eigen3/cmake) +find_package(Eigen3 CONFIG) +set(protoc_ROOT ${ASCEND_DIR}/opensdk/opensdk/protoc) +set(protobuf_grpc_ROOT ${ASCEND_DIR}/opensdk/opensdk/grpc) +set(ascend_protobuf_shared_ROOT ${ASCEND_DIR}/opensdk/opensdk/ascend_protobuf) +set(protobuf_static_ROOT ${ASCEND_DIR}/opensdk/opensdk/protobuf_static) +set(ascend_protobuf_static_ROOT ${ASCEND_DIR}/opensdk/opensdk/ascend_protobuf_static) +find_package(protoc MODULE) +find_package(protobuf_grpc MODULE) +find_package(protobuf_static MODULE) +find_package(ascend_protobuf_shared MODULE) +find_package(ascend_protobuf_static MODULE) +set(Protobuf_PROTOC_EXECUTABLE ${ASCEND_DIR}/opensdk/opensdk/protoc/bin/protoc) +find_package(slog CONFIG REQUIRED) +find_package(metadef CONFIG REQUIRED) +# find_module(ascend_protobuf libascend_protobuf.so.3.13.0.0 ${ASCEND_ATC_DIR}) +find_package(mmpa CONFIG REQUIRED) +find_package(parser CONFIG REQUIRED) +find_package(opcompiler CONFIG REQUIRED) +find_package(platform CONFIG REQUIRED) +find_package(ascend_hal CONFIG REQUIRED) +find_package(runtime CONFIG REQUIRED) +find_package(air CONFIG REQUIRED) +find_file(tbe_whl te-0.4.0-py3-none-any.whl ${ASCEND_ATC_DIR}) diff --git a/community/CMakeLists.txt b/community/CMakeLists.txt index 7b3acbae..55d60fe4 100644 --- a/community/CMakeLists.txt +++ b/community/CMakeLists.txt @@ -13,9 +13,12 @@ # limitations under the License. # ============================================================================ -add_subdirectory(framework) -add_subdirectory(ops) -include(ops/aicpu.cmake) +if(BUILD_AICPU) + include(ops/aicpu.cmake) +else() + add_subdirectory(framework) + add_subdirectory(ops) +endif() if(ALL_UT OR PROTO_UT OR TILING_UT) add_subdirectory(tests) endif() \ No newline at end of file diff --git a/community/framework/onnx/CMakeLists.txt b/community/framework/onnx/CMakeLists.txt index 6bd4c728..f4f56d23 100644 --- a/community/framework/onnx/CMakeLists.txt +++ b/community/framework/onnx/CMakeLists.txt @@ -41,7 +41,7 @@ add_library(onnx_plugin SHARED ${_proto_h} ) -add_dependencies(onnx_plugin secure_c external_protobuf external_gtest) +#add_dependencies(onnx_plugin secure_c external_protobuf external_gtest) target_include_directories(onnx_plugin PRIVATE ${ONNX_PLUGIN_INC} diff --git a/community/framework/tf/CMakeLists.txt b/community/framework/tf/CMakeLists.txt index 5ea3b4ba..501710b9 100644 --- a/community/framework/tf/CMakeLists.txt +++ b/community/framework/tf/CMakeLists.txt @@ -54,7 +54,7 @@ add_library(tf_plugin SHARED ${_proto_h} ) -add_dependencies(tf_plugin secure_c external_protobuf external_gtest) +#add_dependencies(tf_plugin secure_c external_protobuf external_gtest) target_include_directories(tf_plugin PRIVATE ${TF_PLUGIN_INC} diff --git a/community/ops/CMakeLists.txt b/community/ops/CMakeLists.txt index 7736e64f..895a28ab 100644 --- a/community/ops/CMakeLists.txt +++ b/community/ops/CMakeLists.txt @@ -73,7 +73,7 @@ add_library(op_proto SHARED ${_proto_h} ) -add_dependencies(op_proto secure_c external_protobuf external_gtest) +#add_dependencies(op_proto secure_c external_protobuf external_gtest) target_include_directories(op_proto PRIVATE ${PROTO_INC} @@ -110,7 +110,7 @@ if(ALL_UT OR PROTO_UT) ${PROTO_SRC} ${_proto_h} ) - add_dependencies(op_proto_llt secure_c external_protobuf external_gtest) + #add_dependencies(op_proto_llt secure_c external_protobuf external_gtest) if(NOT ${CMAKE_BUILD_MODE} STREQUAL "FALSE") set(compile_opt_mode ${CMAKE_BUILD_MODE}) else() @@ -168,7 +168,7 @@ add_library(optiling SHARED ${TILING_SRC} ) -add_dependencies(optiling secure_c external_protobuf external_gtest nlohmann_json) +#add_dependencies(optiling secure_c external_protobuf external_gtest nlohmann_json) target_include_directories(optiling PRIVATE ${TILING_INC} @@ -197,7 +197,7 @@ if(ALL_UT OR TILING_UT) add_library(op_tiling_llt STATIC ${TILING_SRC} ) - add_dependencies(op_tiling_llt secure_c external_protobuf external_gtest) + #add_dependencies(op_tiling_llt secure_c external_protobuf external_gtest) if(NOT ${CMAKE_BUILD_MODE} STREQUAL "FALSE") set(compile_opt_mode ${CMAKE_BUILD_MODE}) else() diff --git a/community/ops/aicpu.cmake b/community/ops/aicpu.cmake index f0aa32c5..58b5ae15 100644 --- a/community/ops/aicpu.cmake +++ b/community/ops/aicpu.cmake @@ -41,7 +41,6 @@ set(AICPU_INC ${CANN_ROOT_DIR}/community/common/inc ${CANN_ROOT_DIR}/community/common/src ${AICPU_INCLUDE} - ${EIGEN_INCLUDE} ${C_SEC_INCLUDE} ) @@ -49,7 +48,12 @@ set(AICPU_INC add_library(cust_aicpu_kernels SHARED ${AICPU_SRC} ) -add_dependencies(cust_aicpu_kernels eigen c_sec) +add_dependencies(cust_aicpu_kernels c_sec) +list(APPEND CMAKE_PREFIX_PATH ${ASCEND_DIR}/opensdk/opensdk/eigen/share/eigen3/cmake) + +target_link_libraries(cust_aicpu_kernels PRIVATE + Eigen3::Eigen +) target_include_directories(cust_aicpu_kernels PRIVATE ${AICPU_INC} ) -- Gitee