diff --git a/cmake/external/llvm.cmake b/cmake/external/llvm.cmake index 8fd4a0741eaba3d6b1c7205d5bfce32b31ef60a0..e080a7359af98276be2d6bfc53e6b5917f83bde9 100644 --- a/cmake/external/llvm.cmake +++ b/cmake/external/llvm.cmake @@ -106,5 +106,5 @@ endfunction() # @script: path to the mlir script file function (infrt_exec_check name script) add_test(NAME ${name} - COMMAND sh -c "${CMAKE_BINARY_DIR}/infrt/host_context/infrt-exec -i ${CMAKE_CURRENT_SOURCE_DIR}/${script}| ${LLVM_PATH}/bin/FileCheck ${CMAKE_CURRENT_SOURCE_DIR}/${script}") + COMMAND sh -c "${CMAKE_BINARY_DIR}/paddle/infrt/host_context/infrt-exec -i ${CMAKE_CURRENT_SOURCE_DIR}/${script}| ${LLVM_PATH}/bin/FileCheck ${CMAKE_CURRENT_SOURCE_DIR}/${script}") endfunction() diff --git a/cmake/infrt_lib.cmake b/cmake/infrt_lib.cmake new file mode 100644 index 0000000000000000000000000000000000000000..73a8cdbee51c12650c8dbf8c7e98256d9afad8b7 --- /dev/null +++ b/cmake/infrt_lib.cmake @@ -0,0 +1,77 @@ +# Copyright (c) 2021 PaddlePaddle Authors. All Rights Reserved. +# +# 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. + +set(PADDLE_INFRT_INSTALL_DIR "${CMAKE_BINARY_DIR}/paddle_infrt_install_dir" CACHE STRING + "A path setting paddle infrt shared and static libraries") + +function(copy TARGET) + set(options "") + set(oneValueArgs "") + set(multiValueArgs SRCS DSTS) + cmake_parse_arguments(copy_lib "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) + + list(LENGTH copy_lib_SRCS copy_lib_SRCS_len) + list(LENGTH copy_lib_DSTS copy_lib_DSTS_len) + if (NOT ${copy_lib_SRCS_len} EQUAL ${copy_lib_DSTS_len}) + message(FATAL_ERROR "${TARGET} source numbers are not equal to destination numbers") + endif () + math(EXPR len "${copy_lib_SRCS_len} - 1") + foreach (index RANGE ${len}) + list(GET copy_lib_SRCS ${index} src) + list(GET copy_lib_DSTS ${index} dst) + add_custom_command(TARGET ${TARGET} POST_BUILD + COMMAND mkdir -p "${dst}" + COMMAND cp -r "${src}" "${dst}" + COMMENT "copying ${src} -> ${dst}") + endforeach () +endfunction() + +function(copy_part_of_thrid_party TARGET DST) + set(dst_dir "${DST}/third_party/install/glog") + copy(${TARGET} + SRCS ${GLOG_INCLUDE_DIR} ${GLOG_LIBRARIES} + DSTS ${dst_dir} ${dst_dir}/lib) +endfunction() + +# inference library for only inference +set(infrt_lib_deps third_party infrt infrt_static) +add_custom_target(infrt_lib_dist DEPENDS ${infrt_lib_deps}) + + +# CMakeCache Info +copy(infrt_lib_dist + SRCS ${CMAKE_BINARY_DIR}/CMakeCache.txt + DSTS ${PADDLE_INFRT_INSTALL_DIR}) + +set(src_dir "${PADDLE_SOURCE_DIR}/paddle/infrt") +set(paddle_infrt_lib ${PADDLE_BINARY_DIR}/paddle/infrt/libinfrt.*) +copy(infrt_lib_dist + SRCS ${src_dir}/api/infrt_api.h ${paddle_infrt_lib} + DSTS ${PADDLE_INFRT_INSTALL_DIR}/infrt/include ${PADDLE_INFRT_INSTALL_DIR}/infrt/lib) + + +copy(infrt_lib_dist + SRCS ${CMAKE_BINARY_DIR}/paddle/infrt/paddle/framework.pb.h + DSTS ${PADDLE_INFRT_INSTALL_DIR}/infrt/include/internal) + +# paddle fluid version +function(version version_file) + execute_process( + COMMAND ${GIT_EXECUTABLE} log --pretty=format:%H -1 + WORKING_DIRECTORY ${PADDLE_SOURCE_DIR} + OUTPUT_VARIABLE PADDLE_GIT_COMMIT) + file(WRITE ${version_file} "GIT COMMIT ID: ${PADDLE_GIT_COMMIT}\n") + file(APPEND ${version_file} "CXX compiler version: ${CMAKE_CXX_COMPILER_VERSION}\n") +endfunction() +version(${PADDLE_INFRT_INSTALL_DIR}/version.txt) diff --git a/paddle/infrt/CMakeLists.txt b/paddle/infrt/CMakeLists.txt index d24c632a2c8465bad5e29faa3e26e6180182863a..465397977fb0784805453907eb1f898fd2c032e1 100644 --- a/paddle/infrt/CMakeLists.txt +++ b/paddle/infrt/CMakeLists.txt @@ -2,6 +2,8 @@ if (NOT WITH_INFRT) return() endif() +include(infrt_lib) + set(infrt_src CACHE INTERNAL "" FORCE) # Gather headers for library publish. @@ -75,5 +77,6 @@ set(infrt_mlir_incs ) message(STATUS "infrt srcs:\n${infrt_src}") -cc_library(infrt SRCS ${infrt_src} DEPS glog boost ${mlir_libs} paddle_framework_proto) +cc_library(infrt SHARED SRCS ${infrt_src} DEPS glog boost ${mlir_libs} paddle_framework_proto) +cc_library(infrt_static SRCS ${infrt_src} DEPS glog boost ${mlir_libs} paddle_framework_proto) add_dependencies(infrt ${infrt_mlir_incs}) diff --git a/paddle/infrt/dialect/CMakeLists.txt b/paddle/infrt/dialect/CMakeLists.txt index c1517beab0662b71b84432650d0e7f7b68670ba9..c06d77716356321c207809e5652c494be6f55daf 100644 --- a/paddle/infrt/dialect/CMakeLists.txt +++ b/paddle/infrt/dialect/CMakeLists.txt @@ -37,25 +37,17 @@ add_dependencies(print-ir pd_ops_inc) # MLIR opt tests # %{ -set(infrt_opt_path ${CMAKE_BINARY_DIR}/infrt/dialect/infrtopt) - -add_test(test_infrt_mlir_opt_on_basic ${infrt_opt_path} - ${CMAKE_SOURCE_DIR}/infrt/dialect/mlir_tests/basic.mlir) -add_test(test_infrt_mlir_opt_on_tensor_shape ${infrt_opt_path} - ${CMAKE_SOURCE_DIR}/infrt/dialect/mlir_tests/tensor_shape.mlir) -add_test(test_infrt_mlir_opt_on_paddle_ops - ${infrt_opt_path} - ${CMAKE_SOURCE_DIR}/infrt/dialect/mlir_tests/paddle_ops.mlir) +set(infrt_opt_path ${CMAKE_CURRENT_BINARY_DIR}/infrtopt) + +add_test(test_infrt_mlir_opt_on_basic ${infrt_opt_path} ${CMAKE_CURRENT_SOURCE_DIR}/mlir_tests/basic.mlir) +add_test(test_infrt_mlir_opt_on_tensor_shape ${infrt_opt_path} ${CMAKE_CURRENT_SOURCE_DIR}/mlir_tests/tensor_shape.mlir) +add_test(test_infrt_mlir_opt_on_paddle_op ${infrt_opt_path} ${CMAKE_CURRENT_SOURCE_DIR}/mlir_tests/paddle_ops.mlir) # %} cc_test_tiny(test_infrt_mlir_loader SRCS mlir_loader_test.cc DEPS infrt ${MLIR_IR_LIBS}) # execute mlir and run FileCheck -infrt_exec_check(run_and_check_tensor_type mlir_tests/tensor_type.mlir) -infrt_exec_check(run_and_check_basic mlir_tests/basic.mlir) -infrt_exec_check(run_and_check_benchmark mlir_tests/benchmark.mlir) -#infrt_exec_check(run_and_check_dense_tensor mlir_tests/dense_tensor.mlir) -add_test(test_infrt_mlir_dense_tensor - ${CMAKE_BINARY_DIR}/infrt/host_context/infrt-exec - -i - ${CMAKE_CURRENT_SOURCE_DIR}/mlir_tests/dense_tensor.mlir) +infrt_exec_check(test_infrt_tensor_type mlir_tests/tensor_type.mlir) +infrt_exec_check(test_infrt__basic mlir_tests/basic.mlir) +infrt_exec_check(test_infrt_benchmark mlir_tests/benchmark.mlir) +infrt_exec_check(test_infrt_mlir_dense_tensor mlir_tests/dense_tensor.mlir) diff --git a/paddle/infrt/dialect/mlir_tests/dense_tensor.mlir b/paddle/infrt/dialect/mlir_tests/dense_tensor.mlir index cca7445cd58d8fb854ba674e0bc7e0ef28ace920..f923ef3efefcccfd1afe802b8fbbc8fb870ebe26 100644 --- a/paddle/infrt/dialect/mlir_tests/dense_tensor.mlir +++ b/paddle/infrt/dialect/mlir_tests/dense_tensor.mlir @@ -1,3 +1,4 @@ +// CHECK-LABEL: dense_shape0 func @dense_shape0() { %shape = ts.build_shape [1:i64, 57:i64] %a = dt.create_uninit_tensor.f32 [12:i64, 23:i64] -> !infrt.tensor diff --git a/paddle/scripts/infrt_build.sh b/paddle/scripts/infrt_build.sh new file mode 100644 index 0000000000000000000000000000000000000000..0e386ef9506166e50d84978109d77fc0c28c20e4 --- /dev/null +++ b/paddle/scripts/infrt_build.sh @@ -0,0 +1,132 @@ +#!/usr/bin/env bash + +# Copyright (c) 2021 PaddlePaddle Authors. All Rights Reserved. +# +# 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. + +#================================================= +# Utils +#================================================= + +set -ex + +if [ -z ${BRANCH} ]; then + BRANCH="develop" +fi + +EXIT_CODE=0; +tmp_dir=`mktemp -d` + +function init() { + RED='\033[0;31m' + BLUE='\033[0;34m' + BOLD='\033[1m' + NONE='\033[0m' + + PADDLE_ROOT="$( cd "$( dirname "${BASH_SOURCE[0]}")/../../" && pwd )" + export PADDLE_ROOT + if [ -z "${SCRIPT_NAME}" ]; then + SCRIPT_NAME=$0 + fi + + ENABLE_MAKE_CLEAN=${ENABLE_MAKE_CLEAN:-ON} + + # NOTE(chenweihang): For easy debugging, CI displays the C++ error stacktrace by default + export FLAGS_call_stack_level=2 + + # set CI_SKIP_CPP_TEST if only *.py changed + # In order to avoid using in some CI(such as daily performance), the current + # branch must not be `${BRANCH}` which is usually develop. + if [ ${CI_SKIP_CPP_TEST:-ON} == "OFF" ];then + echo "CI_SKIP_CPP_TEST=OFF" + else + if [ "$(git branch | grep "^\*" | awk '{print $2}')" != "${BRANCH}" ]; then + git diff --name-only ${BRANCH} | grep -v "\.py$" || export CI_SKIP_CPP_TEST=ON + fi + fi +} + +function infrt_gen_and_build() { + if [ "$1" != "" ]; then + parallel_number=$1 + fi + startTime_s=`date +%s` + set +e + mkdir -p ${PADDLE_ROOT}/build + cd ${PADDLE_ROOT}/build + rm -f infrt_summary.txt + cmake .. -DWITH_MKL=OFF -DWITH_GPU=OFF -DCMAKE_BUILD_TYPE=Release -DWITH_INFRT=ON -DWITH_TESTING==${WITH_TESTING:-ON}; build_error=$? + if [ "$build_error" != 0 ];then + exit 7; + fi + + make -j ${parallel_number} infrt infrtopt infrt-exec;build_error=$? + make -j ${parallel_number} infrt_lib_dist;build_error=$? + if [ "$build_error" != 0 ];then + exit 7; + fi + endTime_s=`date +%s` + [ -n "$startTime_firstBuild" ] && startTime_s=$startTime_firstBuild + echo "Build Time: $[ $endTime_s - $startTime_s ]s" + echo "ipipe_log_param_Infrt_Build_Time: $[ $endTime_s - $startTime_s ]s" >> ${PADDLE_ROOT}/build/infrt_summary.txt +} + +function test_infrt() { + mkdir -p ${PADDLE_ROOT}/build + cd ${PADDLE_ROOT}/build + if [ ${WITH_TESTING:-ON} == "ON" ] ; then + cat <