From b62a29fc501ec7aeb09e10642dd3a693fc58a419 Mon Sep 17 00:00:00 2001 From: looop5 Date: Wed, 5 Aug 2020 19:37:49 +0800 Subject: [PATCH] refine compiling to avoid duplicate compiling of isl and source code of akg --- CMakeLists.txt | 39 ++-- cmake/external_libs/isl.cmake | 14 +- cmake/utils.cmake | 85 ++++----- tests/test_env.sh | 9 +- third_party/apply_patches.sh | 88 --------- .../incubator-tvm/python/tvm/_ffi/base.py | 23 ++- .../topi/python/topi/cpp/impl.py | 27 ++- third_party/isl_wrap/CMakeLists.txt | 180 +++++++++--------- .../patch/incubator-tvm/incubator-tvm.patch | 74 ------- 9 files changed, 205 insertions(+), 334 deletions(-) delete mode 100644 third_party/apply_patches.sh delete mode 100644 third_party/patch/incubator-tvm/incubator-tvm.patch diff --git a/CMakeLists.txt b/CMakeLists.txt index 6f5c0d4..006878b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,21 +25,23 @@ project(akg C CXX) set(AKG_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}") +# Find gmp +find_path(GMP_INCLUDE_DIR NAME gmp.h HINTS /usr /usr/local PATH_SUFFIXES include include/x86_64-linux-gnu) +find_library(GMP_LIBRARY NAMES gmp HINTS /usr /usr/local PATH_SUFFIXES lib lib64 lib/x86_64-linux-gnu) +if(NOT GMP_INCLUDE_DIR) + message(FATAL_ERROR "Please export CMAKE_INCLUDE_PATH to directory where gmp.h locates at.") +endif() +if(NOT GMP_LIBRARY) + message(FATAL_ERROR "Please export CMAKE_LIBRARY_PATH to directory where libgmp.so locates at.") +endif() + include(cmake/RT.cmake) include(cmake/utils.cmake) include(cmake/external_libs/isl.cmake) -set(ISL_DIR "${CMAKE_BINARY_DIR}/isl") - -if(ENABLE_AKG) - message("-- Build akg in Mindspore") - execute_process(COMMAND bash ${AKG_SOURCE_DIR}/third_party/apply_patches.sh ${CMAKE_CURRENT_BINARY_DIR} "1") - set(TVM_DIR "${CMAKE_CURRENT_BINARY_DIR}/incubator-tvm") -else() +set(TVM_DIR "${AKG_SOURCE_DIR}/third_party/incubator-tvm") +if(NOT ENABLE_AKG) message("-- Build akg alone") - execute_process(COMMAND bash ${AKG_SOURCE_DIR}/third_party/apply_patches.sh ${CMAKE_CURRENT_BINARY_DIR} "akg") - set(TVM_DIR "${CMAKE_BINARY_DIR}/incubator-tvm") - include(cmake/external_libs/gtest.cmake) add_subdirectory(${AKG_SOURCE_DIR}/tests/unittest_cpp) set(GTEST_DIR "${CMAKE_CURRENT_BINARY_DIR}/_deps/gtest-src") @@ -78,21 +80,14 @@ include_directories(AFTER "${AKG_SOURCE_DIR}/src/include") include_directories(AFTER "${AKG_SOURCE_DIR}/third_party/fwkacllib/inc") include_directories(AFTER "${AKG_SOURCE_DIR}/third_party/fwkacllib/inc/toolchain") -# isl -include_directories(AFTER "${AKG_SOURCE_DIR}/third_party/isl_wrap/include") -include_directories(AFTER "${ISL_DIR}/include") -include_directories(AFTER "${ISL_DIR}") - include_directories(AFTER "${TVM_DIR}/3rdparty/dmlc-core/include") include_directories(AFTER "${TVM_DIR}/3rdparty/dlpack/include") include_directories(AFTER "${TVM_DIR}/3rdparty/compiler-rt") include_directories(AFTER "${TVM_DIR}/3rdparty/rang/include") include_directories(AFTER "${TVM_DIR}/3rdparty/picojson") -add_subdirectory(${AKG_SOURCE_DIR}/third_party/isl_wrap isl_fixed) - # initial variables -set(TVM_LINKER_LIBS isl_fixed) +set(TVM_LINKER_LIBS ) add_definitions(-DPICOJSON_USE_INT64=1) add_definitions(-DDMLC_LOG_CUSTOMIZE=1) @@ -235,9 +230,8 @@ endif(USE_CUDA) add_library(akg SHARED ${COMPILER_SRCS} ${RUNTIME_SRCS} ${TOPI_SRCS} ${RUNTIME_SRCS}) -add_dependencies(akg isl_fixed) - -target_link_libraries(akg ${TVM_LINKER_LIBS} ${TVM_RUNTIME_LINKER_LIBS}) +add_dependencies(akg akg::isl_fixed) +target_link_libraries(akg ${TVM_LINKER_LIBS} ${TVM_RUNTIME_LINKER_LIBS} akg::isl_fixed ${GMP_LIBRARY}) # Related headers target_include_directories(akg PRIVATE "${TVM_DIR}/topi/include") @@ -251,8 +245,5 @@ if(ENABLE_AKG) ${TVM_DIR}/python/tvm ${TVM_DIR}/topi/python/topi DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/akg) - #else() - #file(MAKE_DIRECTORY "${AKG_SOURCE_DIR}/output") - #file(COPY ${CMAKE_CURRENT_BINARY_DIR}/libakg.so DESTINATION "${AKG_SOURCE_DIR}/output") endif() diff --git a/cmake/external_libs/isl.cmake b/cmake/external_libs/isl.cmake index e9075f7..56574ee 100644 --- a/cmake/external_libs/isl.cmake +++ b/cmake/external_libs/isl.cmake @@ -1,5 +1,17 @@ +set(isl_USE_STATIC_LIBS ON) +set(isl_CONFIG_FILE_DIR "-DISL_WARP_DIR=${AKG_SOURCE_DIR}/third_party/isl_wrap") +set(isl_DEPEND_INCLUDE_DIR "-DGMP_INCLUDE_DIR=${GMP_INCLUDE_DIR}") +set(isl_DEPEND_LIB_DIR "-DGMP_LIBRARY=${GMP_LIBRARY}") akg_add_pkg(isl VER 0.22 + LIBS isl_fixed URL http://isl.gforge.inria.fr/isl-0.22.tar.gz MD5 671d0a5e10467a5c6db0893255278845 - PATCHES ${CMAKE_CURRENT_SOURCE_DIR}/third_party/patch/isl/isl.patch) + CUSTOM_CMAKE ${AKG_SOURCE_DIR}/third_party/isl_wrap + PATCHES ${AKG_SOURCE_DIR}/third_party/patch/isl/isl.patch + CMAKE_OPTION " ") +include_directories("${AKG_SOURCE_DIR}/third_party/isl_wrap/include") +include_directories("${isl_INC}/include") +include_directories("${isl_INC}") +link_directories("${isl_LIBPATH}") +add_library(akg::isl_fixed ALIAS isl::isl_fixed) \ No newline at end of file diff --git a/cmake/utils.cmake b/cmake/utils.cmake index a9bd5e0..afda95c 100644 --- a/cmake/utils.cmake +++ b/cmake/utils.cmake @@ -204,45 +204,44 @@ set(AKG_FIND_NO_DEFAULT_PATH NO_CMAKE_PATH NO_CMAKE_ENVIRONMENT_PATH NO_SYSTEM_E function(akg_add_pkg pkg_name ) set(options ) - set(oneValueArgs URL MD5 GIT_REPOSITORY GIT_TAG VER EXE DIR HEAD_ONLY CMAKE_PATH) - set(multiValueArgs CMAKE_OPTION LIBS PRE_CONFIGURE_COMMAND CONFIGURE_COMMAND BUILD_OPTION INSTALL_INCS INSTALL_LIBS PATCHES) + set(oneValueArgs URL MD5 GIT_REPOSITORY GIT_TAG VER EXE DIR CMAKE_PATH CUSTOM_CMAKE) + set(multiValueArgs CMAKE_OPTION LIBS PATCHES) cmake_parse_arguments(PKG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN} ) - if (NOT PKG_LIB_PATH) + if(NOT PKG_LIB_PATH) set(PKG_LIB_PATH lib) - endif () - + endif() set(__FIND_PKG_NAME ${pkg_name}) string(TOLOWER ${pkg_name} pkg_name) message("pkg name:${__FIND_PKG_NAME},${pkg_name}") + # Generate hash for current pkg + set(${pkg_name}_CUSTOM_CMAKE_HASH ) + if(PKG_CUSTOM_CMAKE) + file(MD5 ${PKG_CUSTOM_CMAKE}/CMakeLists.txt _CUSTOM_CMAKE_MD5) + set(${pkg_name}_CUSTOM_CMAKE_HASH "${_CUSTOM_CMAKE_MD5}") + endif() + set(${pkg_name}_PATCHES_HASH ) foreach(_PATCH ${PKG_PATCHES}) file(MD5 ${_PATCH} _PF_MD5) set(${pkg_name}_PATCHES_HASH "${${pkg_name}_PATCHES_HASH},${_PF_MD5}") endforeach(_PATCH) - # check options set(${pkg_name}_CONFIG_TXT "${CMAKE_CXX_COMPILER_VERSION}-${CMAKE_C_COMPILER_VERSION} - ${ARGN} - ${${pkg_name}_USE_STATIC_LIBS}- ${${pkg_name}_PATCHES_HASH} + ${ARGN} - ${${pkg_name}_USE_STATIC_LIBS}- ${${pkg_name}_PATCHES_HASH}- ${${pkg_name}_CUSTOM_CMAKE_HASH} ${${pkg_name}_CXXFLAGS}--${${pkg_name}_CFLAGS}--${${pkg_name}_LDFLAGS}") string(REPLACE ";" "-" ${pkg_name}_CONFIG_TXT ${${pkg_name}_CONFIG_TXT}) string(MD5 ${pkg_name}_CONFIG_HASH ${${pkg_name}_CONFIG_TXT}) message("${pkg_name} config hash: ${${pkg_name}_CONFIG_HASH}") + # Generate hash for current pkg end set(${pkg_name}_BASE_DIR ${_MS_LIB_CACHE}/${pkg_name}_${${pkg_name}_CONFIG_HASH}) set(${pkg_name}_DIRPATH ${${pkg_name}_BASE_DIR} CACHE STRING INTERNAL) - if(EXISTS ${${pkg_name}_BASE_DIR}/options.txt AND PKG_HEAD_ONLY) - set(${pkg_name}_INC ${${pkg_name}_BASE_DIR}/${PKG_HEAD_ONLY} PARENT_SCOPE) - add_library(${pkg_name} INTERFACE) - target_include_directories(${pkg_name} INTERFACE ${${pkg_name}_INC}) - return() - endif () - if(NOT PKG_EXE) set(PKG_EXE 0) endif() @@ -250,6 +249,7 @@ function(akg_add_pkg pkg_name ) set(${__FIND_PKG_NAME}_ROOT ${${pkg_name}_BASE_DIR}) set(${__FIND_PKG_NAME}_ROOT ${${pkg_name}_BASE_DIR} PARENT_SCOPE) + # Check if pkg exists in cache, if exists, use the cached one if (PKG_LIBS) __find_pkg_then_add_target(${pkg_name} ${PKG_EXE} ${PKG_LIB_PATH} ${PKG_LIBS}) if(${pkg_name}_LIBS) @@ -257,17 +257,11 @@ function(akg_add_pkg pkg_name ) message("Found libs: ${${pkg_name}_LIBS}") return() endif() - elseif(NOT PKG_HEAD_ONLY) - find_package(${__FIND_PKG_NAME} ${PKG_VER} ${AKG_FIND_NO_DEFAULT_PATH}) - if (${__FIND_PKG_NAME}_FOUND) - set(${pkg_name}_INC ${${pkg_name}_BASE_DIR}/include PARENT_SCOPE) - message("Found pkg: ${__FIND_PKG_NAME}") - return() - endif () - endif () + endif() - if (NOT PKG_DIR) - if (PKG_GIT_REPOSITORY) + # Download pkg + if(NOT PKG_DIR) + if(PKG_GIT_REPOSITORY) __download_pkg_with_git(${pkg_name} ${PKG_GIT_REPOSITORY} ${PKG_GIT_TAG} ${PKG_MD5}) else() message("--__download_pkg") @@ -281,30 +275,31 @@ function(akg_add_pkg pkg_name ) endforeach (_SUBMODULE_FILE) else() set(${pkg_name}_SOURCE_DIR ${PKG_DIR}) - endif () + endif() message("${pkg_name}_SOURCE_DIR : ${${pkg_name}_SOURCE_DIR}") + # Copy pkg to the build directory and uses the copied one set(${pkg_name}_PATCHED_DIR ${CMAKE_BINARY_DIR}/${pkg_name}) if(EXISTS ${${pkg_name}_PATCHED_DIR}) file(REMOVE_RECURSE ${${pkg_name}_PATCHED_DIR}) endif() - file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/${pkg_name}") + file(MAKE_DIRECTORY "${${pkg_name}_PATCHED_DIR}") file(COPY ${${pkg_name}_SOURCE_DIR}/ DESTINATION ${${pkg_name}_PATCHED_DIR}) - message("${pkg_name}_PATCHED_DIR : ${${pkg_name}_PATCHED_DIR}") set(${pkg_name}_SOURCE_DIR ${${pkg_name}_PATCHED_DIR}) message("${pkg_name}_SOURCE_DIR : ${${pkg_name}_SOURCE_DIR}") + # Apply patches on pkg foreach(_PATCH_FILE ${PKG_PATCHES}) get_filename_component(_PATCH_FILE_NAME ${_PATCH_FILE} NAME) set(_LF_PATCH_FILE ${CMAKE_BINARY_DIR}/_ms_patch/${_PATCH_FILE_NAME}) configure_file(${_PATCH_FILE} ${_LF_PATCH_FILE} NEWLINE_STYLE LF) - message("patching ${${pkg_name}_PATCHED_DIR} -p1 < ${_LF_PATCH_FILE}") + message("patching ${${pkg_name}_SOURCE_DIR} -p1 < ${_LF_PATCH_FILE}") execute_process(COMMAND patch -p1 INPUT_FILE ${_LF_PATCH_FILE} - WORKING_DIRECTORY ${${pkg_name}_PATCHED_DIR} + WORKING_DIRECTORY ${${pkg_name}_SOURCE_DIR} RESULT_VARIABLE Result) if(NOT Result EQUAL "0") message(FATAL_ERROR "Failed patch: ${_LF_PATCH_FILE}") - endif () + endif() endforeach(_PATCH_FILE) file(LOCK ${${pkg_name}_BASE_DIR} DIRECTORY GUARD FUNCTION RESULT_VARIABLE ${pkg_name}_LOCK_RET TIMEOUT 600) @@ -312,45 +307,39 @@ function(akg_add_pkg pkg_name ) message(FATAL_ERROR "error! when try lock ${${pkg_name}_BASE_DIR} : ${${pkg_name}_LOCK_RET}") endif() - if (PKG_CUSTOM_CMAKE) + if(PKG_CUSTOM_CMAKE) file(GLOB ${pkg_name}_cmake ${PKG_CUSTOM_CMAKE}/CMakeLists.txt) file(COPY ${${pkg_name}_cmake} DESTINATION ${${pkg_name}_SOURCE_DIR}) - endif () + endif() if(${pkg_name}_SOURCE_DIR) - if (PKG_HEAD_ONLY) - file(GLOB ${pkg_name}_SOURCE_SUBDIRS ${${pkg_name}_SOURCE_DIR}/*) - file(COPY ${${pkg_name}_SOURCE_SUBDIRS} DESTINATION ${${pkg_name}_BASE_DIR}) - set(${pkg_name}_INC ${${pkg_name}_BASE_DIR}/${PKG_HEAD_ONLY} PARENT_SCOPE) - add_library(${pkg_name} INTERFACE) - target_include_directories(${pkg_name} INTERFACE ${${pkg_name}_INC}) - - elseif (PKG_CMAKE_OPTION) + if(PKG_CMAKE_OPTION) # in cmake file(MAKE_DIRECTORY ${${pkg_name}_SOURCE_DIR}/_build) - if (${pkg_name}_CFLAGS) + if(${pkg_name}_CFLAGS) set(${pkg_name}_CMAKE_CFLAGS "-DCMAKE_C_FLAGS=${${pkg_name}_CFLAGS}") - endif () + endif() if (${pkg_name}_CXXFLAGS) set(${pkg_name}_CMAKE_CXXFLAGS "-DCMAKE_CXX_FLAGS=${${pkg_name}_CXXFLAGS}") - endif () + endif() if (${pkg_name}_LDFLAGS) if (${pkg_name}_USE_STATIC_LIBS) set(${pkg_name}_CMAKE_LDFLAGS "-DCMAKE_STATIC_LINKER_FLAGS=${${pkg_name}_LDFLAGS}") else() set(${pkg_name}_CMAKE_LDFLAGS "-DCMAKE_SHARED_LINKER_FLAGS=${${pkg_name}_LDFLAGS}") - endif () - endif () + endif() + endif() __exec_cmd(COMMAND ${CMAKE_COMMAND} ${PKG_CMAKE_OPTION} -G ${CMAKE_GENERATOR} ${${pkg_name}_CMAKE_CFLAGS} ${${pkg_name}_CMAKE_CXXFLAGS} ${${pkg_name}_CMAKE_LDFLAGS} + ${${pkg_name}_CONFIG_FILE_DIR} ${${pkg_name}_DEPEND_INCLUDE_DIR} ${${pkg_name}_DEPEND_LIB_DIR} -DCMAKE_INSTALL_PREFIX=${${pkg_name}_BASE_DIR} ${${pkg_name}_SOURCE_DIR}/${PKG_CMAKE_PATH} WORKING_DIRECTORY ${${pkg_name}_SOURCE_DIR}/_build) __exec_cmd(COMMAND ${CMAKE_COMMAND} --build . --target install -- -j${THNUM} WORKING_DIRECTORY ${${pkg_name}_SOURCE_DIR}/_build) - endif () + endif() endif() if (PKG_LIBS) @@ -365,6 +354,6 @@ function(akg_add_pkg pkg_name ) set(${pkg_name}_INC ${${pkg_name}_BASE_DIR}/include PARENT_SCOPE) message("Found pkg: ${${__FIND_PKG_NAME}_LIBRARIES}") return() - endif () - endif () + endif() + endif() endfunction() diff --git a/tests/test_env.sh b/tests/test_env.sh index b7b3adf..2a556af 100644 --- a/tests/test_env.sh +++ b/tests/test_env.sh @@ -26,13 +26,12 @@ usage() } CUR_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -MS_DIR="${CUR_DIR}/.." -AD_BUILD_DIR="${MS_DIR}/build" -TVM_ROOT="${AD_BUILD_DIR}/incubator-tvm" - +AKG_DIR="${CUR_DIR}/.." +AD_BUILD_DIR="${AKG_DIR}/build" +TVM_ROOT="${AKG_DIR}/third_party/incubator-tvm" export LD_LIBRARY_PATH=${AD_BUILD_DIR}:${LD_LIBRARY_PATH} -export PYTHONPATH=${TVM_ROOT}/python:${TVM_ROOT}/topi:${TVM_ROOT}/topi/python:${MS_DIR}/tests/common:${MS_DIR}/python:${MS_DIR}/tests/fuzz/tune:${PYTHONPATH} +export PYTHONPATH=${TVM_ROOT}/python:${TVM_ROOT}/topi:${TVM_ROOT}/topi/python:${AKG_DIR}/tests/common:${AKG_DIR}/python:${AKG_DIR}/tests/fuzz/tune:${PYTHONPATH} if [ $# -eq 1 ]; then case "$1" in diff --git a/third_party/apply_patches.sh b/third_party/apply_patches.sh deleted file mode 100644 index 6ed4fbc..0000000 --- a/third_party/apply_patches.sh +++ /dev/null @@ -1,88 +0,0 @@ -#!/bin/bash -# Copyright 2019 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. -# ============================================================================ - -PWD_PATH=`pwd` -THIRD_PARTY_PATH=$(cd "$(dirname $0)"; pwd) -if [ $# -lt 1 ]; then - echo "Usage: sh apply_patches.sh [build_dir]" - echo " build_dir is the directory where you type \"cmake\"" - echo " Open source software isl and incubator-tvm will be copied to build_dir" - echo " where patches will be applied on." - exit 1 -fi -BUILD_PATH=$1 -# 0 for build standalone, 1 for mega build in ms -BUILD_MODE=0 - -if [[ -n "$2" ]]; then - BUILD_MODE=$2 -fi - -if [ -d ${BUILD_PATH}/incubator-tvm ]; then - rm -rf ${BUILD_PATH}/incubator-tvm -fi -mkdir ${BUILD_PATH}/incubator-tvm -cp -rf ${THIRD_PARTY_PATH}/incubator-tvm/* ${BUILD_PATH}/incubator-tvm/ - -check_dir_not_empty() -{ - if [ ! $# -eq 1 ]; then - echo "Usage: check_dir_not_empty dir_path" - exit 1 - fi - - if [ ! -d $1 ]; then - echo "Directory $1 does not exist." - exit 1 - fi - - fileCounts=`ls $1 | wc -l` - if [ ${fileCounts} -eq 0 ]; then - echo "Directory $1 is empty." - exit 1 - fi -} - -apply_patch() -{ - if [ ! $# -eq 1 ]; then - echo "Usage: apply_patch patch_name" - exit 1 - fi - - if [ ! -f $1 ]; then - echo "Patch $1 does not exist." - exit 1 - fi - - patch -p1 < $1 - if [ $? -eq 0 ]; then - echo "Patch $1 applied successfully." - else - echo "Patch $1 not applied." - fi -} - -TVM_PATH=${BUILD_PATH}/incubator-tvm -TVM_PATCH_PATH=${THIRD_PARTY_PATH}/patch/incubator-tvm -check_dir_not_empty "${TVM_PATH}" -check_dir_not_empty "${TVM_PATCH_PATH}" -if [[ "${BUILD_MODE}" == "1" ]]; then - cd ${TVM_PATH} - apply_patch "${TVM_PATCH_PATH}/incubator-tvm.patch" -fi - -cd ${PWD_PATH} diff --git a/third_party/incubator-tvm/python/tvm/_ffi/base.py b/third_party/incubator-tvm/python/tvm/_ffi/base.py index c61c5c4..dfab74b 100644 --- a/third_party/incubator-tvm/python/tvm/_ffi/base.py +++ b/third_party/incubator-tvm/python/tvm/_ffi/base.py @@ -16,6 +16,11 @@ # under the License. # coding: utf-8 # pylint: disable=invalid-name + +# +# 2020.7.16 - Modify _load_lib function to find the correct library. +# + """Base library for TVM FFI.""" from __future__ import absolute_import @@ -48,7 +53,23 @@ else: def _load_lib(): """Load libary by searching possible path.""" - lib_path = libinfo.find_lib_path() + lib_path = [] + pwd = os.path.dirname(os.path.realpath(__file__)) + path = os.path.realpath(pwd + "/../../../mindspore/lib") + if os.path.exists(path): + tar_so = "libakg.so" + files = os.listdir(path) + for f in files: + if f == tar_so: + lib_path.append(path + "/" + f) + break + + if not lib_path: + lib_path = libinfo.find_lib_path() + + if not lib_path: + raise RuntimeError("Cannot find library {}.".format(tar_so)) + lib = ctypes.CDLL(lib_path[0], ctypes.RTLD_GLOBAL) # DMatrix functions lib.TVMGetLastError.restype = ctypes.c_char_p diff --git a/third_party/incubator-tvm/topi/python/topi/cpp/impl.py b/third_party/incubator-tvm/topi/python/topi/cpp/impl.py index 5eff604..80a7682 100644 --- a/third_party/incubator-tvm/topi/python/topi/cpp/impl.py +++ b/third_party/incubator-tvm/topi/python/topi/cpp/impl.py @@ -14,6 +14,11 @@ # KIND, either express or implied. See the License for the # specific language governing permissions and limitations # under the License. + +# +# 2020.7.16 - Modify _load_lib function to find the correct library. +# + """Load Lib for C++ TOPI ops and schedules""" import sys import os @@ -31,11 +36,23 @@ def _get_lib_names(): def _load_lib(): """Load libary by searching possible path.""" - curr_path = os.path.dirname(os.path.realpath(os.path.expanduser(__file__))) - lib_search = curr_path - lib_path = libinfo.find_lib_path(_get_lib_names(), lib_search, optional=True) - if lib_path is None: - return None, None + lib_path = [] + pwd = os.path.dirname(os.path.realpath(__file__)) + path = os.path.realpath(pwd + "/../../../mindspore/lib") + if os.path.exists(path): + tar_so = "libakg.so" + files = os.listdir(path) + for f in files: + if f == tar_so: + lib_path.append(path + "/" + f) + break + + if not lib_path: + lib_path = libinfo.find_lib_path() + + if not lib_path: + raise RuntimeError("Cannot find library {}.".format(tar_so)) + lib = ctypes.CDLL(lib_path[0], ctypes.RTLD_GLOBAL) return lib, os.path.basename(lib_path[0]) diff --git a/third_party/isl_wrap/CMakeLists.txt b/third_party/isl_wrap/CMakeLists.txt index 60b48fb..370bd36 100644 --- a/third_party/isl_wrap/CMakeLists.txt +++ b/third_party/isl_wrap/CMakeLists.txt @@ -1,94 +1,93 @@ -find_path(GMP_INCLUDE_DIR NAME gmp.h HINTS /usr /usr/local PATH_SUFFIXES include include/x86_64-linux-gnu) -find_library(GMP_LIBRARY NAMES gmp HINTS /usr /usr/local PATH_SUFFIXES lib lib64 lib/x86_64-linux-gnu) +set(ISL_DIR ${CMAKE_CURRENT_SOURCE_DIR}) -if(NOT GMP_INCLUDE_DIR) - message(FATAL_ERROR "Please export CMAKE_INCLUDE_PATH to directory where gmp.h locates at.") -endif() +message("ISL_DIR: ${ISL_DIR}") +message("GMP_INCLUDE_DIR: ${GMP_INCLUDE_DIR}") +message("GMP_LIBRARY: ${GMP_LIBRARY}") +message("ISL_WARP_DIR: ${ISL_WARP_DIR}") -if(NOT GMP_LIBRARY) - message(FATAL_ERROR "Please export CMAKE_LIBRARY_PATH to directory where libgmp.so locates at.") -endif() +include_directories("${ISL_WARP_DIR}/include") +include_directories("${ISL_DIR}/include") +include_directories("${ISL_DIR}") -set(ISL_SOURCE_DIR "${ISL_DIR}") set(ISL_SOURCES - ${ISL_SOURCE_DIR}/basis_reduction_tab.c - ${ISL_SOURCE_DIR}/isl_aff.c - ${ISL_SOURCE_DIR}/isl_aff_map.c - ${ISL_SOURCE_DIR}/isl_affine_hull.c - ${ISL_SOURCE_DIR}/isl_arg.c - ${ISL_SOURCE_DIR}/isl_ast_build.c - ${ISL_SOURCE_DIR}/isl_ast_build_expr.c - ${ISL_SOURCE_DIR}/isl_ast.c - ${ISL_SOURCE_DIR}/isl_ast_codegen.c - ${ISL_SOURCE_DIR}/isl_ast_graft.c - ${ISL_SOURCE_DIR}/isl_bernstein.c - ${ISL_SOURCE_DIR}/isl_blk.c - ${ISL_SOURCE_DIR}/isl_bound.c - ${ISL_SOURCE_DIR}/isl_box.c - ${ISL_SOURCE_DIR}/isl_coalesce.c - ${ISL_SOURCE_DIR}/isl_constraint.c - ${ISL_SOURCE_DIR}/isl_convex_hull.c - ${ISL_SOURCE_DIR}/isl_ctx.c - ${ISL_SOURCE_DIR}/isl_deprecated.c - ${ISL_SOURCE_DIR}/isl_dim_map.c - ${ISL_SOURCE_DIR}/isl_equalities.c - ${ISL_SOURCE_DIR}/isl_factorization.c - ${ISL_SOURCE_DIR}/isl_farkas.c - ${ISL_SOURCE_DIR}/isl_flow.c - ${ISL_SOURCE_DIR}/isl_fold.c - ${ISL_SOURCE_DIR}/isl_hash.c - ${ISL_SOURCE_DIR}/isl_id.c - ${ISL_SOURCE_DIR}/isl_id_to_ast_expr.c - ${ISL_SOURCE_DIR}/isl_id_to_id.c - ${ISL_SOURCE_DIR}/isl_id_to_pw_aff.c - ${ISL_SOURCE_DIR}/isl_ilp.c - ${ISL_SOURCE_DIR}/isl_input.c - ${ISL_SOURCE_DIR}/isl_local.c - ${ISL_SOURCE_DIR}/isl_local_space.c - ${ISL_SOURCE_DIR}/isl_lp.c - ${ISL_SOURCE_DIR}/isl_map.c - ${ISL_SOURCE_DIR}/isl_map_list.c - ${ISL_SOURCE_DIR}/isl_map_simplify.c - ${ISL_SOURCE_DIR}/isl_map_subtract.c - ${ISL_SOURCE_DIR}/isl_map_to_basic_set.c - ${ISL_SOURCE_DIR}/isl_mat.c - ${ISL_SOURCE_DIR}/isl_morph.c - ${ISL_SOURCE_DIR}/isl_obj.c - ${ISL_SOURCE_DIR}/isl_options.c - ${ISL_SOURCE_DIR}/isl_output.c - ${ISL_SOURCE_DIR}/isl_point.c - ${ISL_SOURCE_DIR}/isl_polynomial.c - ${ISL_SOURCE_DIR}/isl_printer.c - ${ISL_SOURCE_DIR}/isl_range.c - ${ISL_SOURCE_DIR}/isl_reordering.c - ${ISL_SOURCE_DIR}/isl_sample.c - ${ISL_SOURCE_DIR}/isl_scan.c - ${ISL_SOURCE_DIR}/isl_schedule.c - ${ISL_SOURCE_DIR}/isl_schedule_band.c - ${ISL_SOURCE_DIR}/isl_schedule_node.c - ${ISL_SOURCE_DIR}/isl_schedule_read.c - ${ISL_SOURCE_DIR}/isl_schedule_tree.c - ${ISL_SOURCE_DIR}/isl_scheduler.c - ${ISL_SOURCE_DIR}/isl_schedule_constraints.c - ${ISL_SOURCE_DIR}/isl_seq.c - ${ISL_SOURCE_DIR}/isl_set_list.c - ${ISL_SOURCE_DIR}/isl_set_to_ast_graft_list.c - ${ISL_SOURCE_DIR}/isl_sort.c - ${ISL_SOURCE_DIR}/isl_space.c - ${ISL_SOURCE_DIR}/isl_stream.c - ${ISL_SOURCE_DIR}/isl_stride.c - ${ISL_SOURCE_DIR}/isl_tab.c - ${ISL_SOURCE_DIR}/isl_tab_pip.c - ${ISL_SOURCE_DIR}/isl_tarjan.c - ${ISL_SOURCE_DIR}/isl_transitive_closure.c - ${ISL_SOURCE_DIR}/isl_union_map.c - ${ISL_SOURCE_DIR}/isl_val.c - ${ISL_SOURCE_DIR}/isl_vec.c - ${ISL_SOURCE_DIR}/isl_version.c - ${ISL_SOURCE_DIR}/isl_vertices.c - ${ISL_SOURCE_DIR}/print.c - ${ISL_SOURCE_DIR}/isl_gmp.c - ${ISL_SOURCE_DIR}/isl_val_gmp.c + ${ISL_DIR}/basis_reduction_tab.c + ${ISL_DIR}/isl_aff.c + ${ISL_DIR}/isl_aff_map.c + ${ISL_DIR}/isl_affine_hull.c + ${ISL_DIR}/isl_arg.c + ${ISL_DIR}/isl_ast_build.c + ${ISL_DIR}/isl_ast_build_expr.c + ${ISL_DIR}/isl_ast.c + ${ISL_DIR}/isl_ast_codegen.c + ${ISL_DIR}/isl_ast_graft.c + ${ISL_DIR}/isl_bernstein.c + ${ISL_DIR}/isl_blk.c + ${ISL_DIR}/isl_bound.c + ${ISL_DIR}/isl_box.c + ${ISL_DIR}/isl_coalesce.c + ${ISL_DIR}/isl_constraint.c + ${ISL_DIR}/isl_convex_hull.c + ${ISL_DIR}/isl_ctx.c + ${ISL_DIR}/isl_deprecated.c + ${ISL_DIR}/isl_dim_map.c + ${ISL_DIR}/isl_equalities.c + ${ISL_DIR}/isl_factorization.c + ${ISL_DIR}/isl_farkas.c + ${ISL_DIR}/isl_flow.c + ${ISL_DIR}/isl_fold.c + ${ISL_DIR}/isl_hash.c + ${ISL_DIR}/isl_id.c + ${ISL_DIR}/isl_id_to_ast_expr.c + ${ISL_DIR}/isl_id_to_id.c + ${ISL_DIR}/isl_id_to_pw_aff.c + ${ISL_DIR}/isl_ilp.c + ${ISL_DIR}/isl_input.c + ${ISL_DIR}/isl_local.c + ${ISL_DIR}/isl_local_space.c + ${ISL_DIR}/isl_lp.c + ${ISL_DIR}/isl_map.c + ${ISL_DIR}/isl_map_list.c + ${ISL_DIR}/isl_map_simplify.c + ${ISL_DIR}/isl_map_subtract.c + ${ISL_DIR}/isl_map_to_basic_set.c + ${ISL_DIR}/isl_mat.c + ${ISL_DIR}/isl_morph.c + ${ISL_DIR}/isl_obj.c + ${ISL_DIR}/isl_options.c + ${ISL_DIR}/isl_output.c + ${ISL_DIR}/isl_point.c + ${ISL_DIR}/isl_polynomial.c + ${ISL_DIR}/isl_printer.c + ${ISL_DIR}/isl_range.c + ${ISL_DIR}/isl_reordering.c + ${ISL_DIR}/isl_sample.c + ${ISL_DIR}/isl_scan.c + ${ISL_DIR}/isl_schedule.c + ${ISL_DIR}/isl_schedule_band.c + ${ISL_DIR}/isl_schedule_node.c + ${ISL_DIR}/isl_schedule_read.c + ${ISL_DIR}/isl_schedule_tree.c + ${ISL_DIR}/isl_scheduler.c + ${ISL_DIR}/isl_schedule_constraints.c + ${ISL_DIR}/isl_seq.c + ${ISL_DIR}/isl_set_list.c + ${ISL_DIR}/isl_set_to_ast_graft_list.c + ${ISL_DIR}/isl_sort.c + ${ISL_DIR}/isl_space.c + ${ISL_DIR}/isl_stream.c + ${ISL_DIR}/isl_stride.c + ${ISL_DIR}/isl_tab.c + ${ISL_DIR}/isl_tab_pip.c + ${ISL_DIR}/isl_tarjan.c + ${ISL_DIR}/isl_transitive_closure.c + ${ISL_DIR}/isl_union_map.c + ${ISL_DIR}/isl_val.c + ${ISL_DIR}/isl_vec.c + ${ISL_DIR}/isl_version.c + ${ISL_DIR}/isl_vertices.c + ${ISL_DIR}/print.c + ${ISL_DIR}/isl_gmp.c + ${ISL_DIR}/isl_val_gmp.c ) # The isl library is included in the (shared) library. @@ -128,4 +127,9 @@ execute_process( WORKING_DIRECTORY ${ISL_DIR} OUTPUT_VARIABLE ISL_GIT_VERSION OUTPUT_STRIP_TRAILING_WHITESPACE) -configure_file("gitversion.h.in" "gitversion.h") +configure_file("${ISL_WARP_DIR}/gitversion.h.in" "gitversion.h") + +install(TARGETS isl_fixed) +file(GLOB HEAD_FILE_LIST ${ISL_DIR}/*.h) +install(FILES ${HEAD_FILE_LIST} DESTINATION include) +install(DIRECTORY ${ISL_DIR}/include DESTINATION include) \ No newline at end of file diff --git a/third_party/patch/incubator-tvm/incubator-tvm.patch b/third_party/patch/incubator-tvm/incubator-tvm.patch deleted file mode 100644 index 20142d6..0000000 --- a/third_party/patch/incubator-tvm/incubator-tvm.patch +++ /dev/null @@ -1,74 +0,0 @@ -diff -Npur tvm_orig/python/tvm/_ffi/base.py tvm/python/tvm/_ffi/base.py ---- tvm_orig/python/tvm/_ffi/base.py 2020-07-16 14:39:28.859033775 +0800 -+++ tvm/python/tvm/_ffi/base.py 2020-07-16 14:42:26.594223690 +0800 -@@ -16,6 +16,11 @@ - # under the License. - # coding: utf-8 - # pylint: disable=invalid-name -+ -+# -+# 2020.7.16 - Modify _load_lib function to find the correct library. -+# -+ - """Base library for TVM FFI.""" - from __future__ import absolute_import - -@@ -48,7 +53,18 @@ else: - - def _load_lib(): - """Load libary by searching possible path.""" -- lib_path = libinfo.find_lib_path() -+ tar_so = "libakg.so" -+ pwd = os.path.dirname(os.path.realpath(__file__)) -+ path = os.path.realpath(pwd + "/../../../mindspore/lib") -+ lib_path = [] -+ files = os.listdir(path) -+ for f in files: -+ if f == tar_so: -+ lib_path.append(path + "/" + f) -+ break -+ if not lib_path: -+ raise RuntimeError("Cannot find library {}.".format(tar_so)) -+ - lib = ctypes.CDLL(lib_path[0], ctypes.RTLD_GLOBAL) - # DMatrix functions - lib.TVMGetLastError.restype = ctypes.c_char_p -diff -Npur tvm_orig/topi/python/topi/cpp/impl.py tvm/topi/python/topi/cpp/impl.py ---- tvm_orig/topi/python/topi/cpp/impl.py 2020-07-16 14:40:07.754722324 +0800 -+++ tvm/topi/python/topi/cpp/impl.py 2020-07-16 14:42:56.638225874 +0800 -@@ -14,6 +14,11 @@ - # KIND, either express or implied. See the License for the - # specific language governing permissions and limitations - # under the License. -+ -+# -+# 2020.7.16 - Modify _load_lib function to find the correct library. -+# -+ - """Load Lib for C++ TOPI ops and schedules""" - import sys - import os -@@ -31,11 +36,18 @@ def _get_lib_names(): - - def _load_lib(): - """Load libary by searching possible path.""" -- curr_path = os.path.dirname(os.path.realpath(os.path.expanduser(__file__))) -- lib_search = curr_path -- lib_path = libinfo.find_lib_path(_get_lib_names(), lib_search, optional=True) -- if lib_path is None: -- return None, None -+ tar_so = "libakg.so" -+ pwd = os.path.dirname(os.path.realpath(__file__)) -+ path = os.path.realpath(pwd + "/../../../mindspore/lib") -+ lib_path = [] -+ files = os.listdir(path) -+ for f in files: -+ if f == tar_so: -+ lib_path.append(path + "/" + f) -+ break -+ if not lib_path: -+ raise RuntimeError("Cannot find library {}.".format(tar_so)) -+ - lib = ctypes.CDLL(lib_path[0], ctypes.RTLD_GLOBAL) - return lib, os.path.basename(lib_path[0]) - -- GitLab