From 16714ad629bba01c5cad3e46df6ac05022ce237e Mon Sep 17 00:00:00 2001 From: Junru Shao Date: Sun, 23 Jul 2023 14:17:59 -0700 Subject: [PATCH] Static link zstd; Switch to Python 3.11 --- .github/actions/setup/action.yml | 4 +- CMakeLists.txt | 1 + cmake/modules/Findzstd.cmake | 55 ++++++++++++++++++++++++++++ cmake/utils/FindLLVM.cmake | 8 +--- conda/build-environment.yaml | 18 +++++---- conda/recipe/conda_build_config.yaml | 4 +- 6 files changed, 70 insertions(+), 20 deletions(-) create mode 100644 cmake/modules/Findzstd.cmake diff --git a/.github/actions/setup/action.yml b/.github/actions/setup/action.yml index b32ff90325..fc603d88b1 100644 --- a/.github/actions/setup/action.yml +++ b/.github/actions/setup/action.yml @@ -16,7 +16,7 @@ runs: environment-file: conda/build-environment.yaml auto-activate-base: false use-only-tar-bz2: true - python-version: 3.7 + python-version: 3.11 condarc-file: conda/condarc - uses: conda-incubator/setup-miniconda@v2 if: steps.conda1.outcome == 'failure' @@ -26,7 +26,7 @@ runs: environment-file: conda/build-environment.yaml auto-activate-base: false use-only-tar-bz2: true - python-version: 3.7 + python-version: 3.11 condarc-file: conda/condarc - name: Conda info shell: pwsh diff --git a/CMakeLists.txt b/CMakeLists.txt index 389879a883..ceb955581f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,6 +2,7 @@ cmake_minimum_required(VERSION 3.18) project(tvm C CXX) # Utility functions +include(cmake/modules/Findzstd.cmake) include(cmake/utils/Utils.cmake) include(cmake/utils/Summary.cmake) include(cmake/utils/Linker.cmake) diff --git a/cmake/modules/Findzstd.cmake b/cmake/modules/Findzstd.cmake new file mode 100644 index 0000000000..f4a3615a1f --- /dev/null +++ b/cmake/modules/Findzstd.cmake @@ -0,0 +1,55 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you 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. +# +# This script provides: +# - zstd_FOUND +# - zstd_INCLUDE_DIR +# - zstd_LIBRARY +# - zstd_STATIC_LIBRARY +# +# And also defines the following targets: +# - zstd::libzstd_static +# - zstd::libzstd_shared (a dummy one to work around LLVM checking) +if(MSVC) + set(zstd_STATIC_LIBRARY_SUFFIX "\\${CMAKE_STATIC_LIBRARY_SUFFIX}$") +else() + set(zstd_STATIC_LIBRARY_SUFFIX "\\${CMAKE_STATIC_LIBRARY_SUFFIX}$") +endif() + +find_path(zstd_INCLUDE_DIR NAMES zstd.h) +find_library(zstd_LIBRARY NAMES zstd zstd_static) +find_library(zstd_STATIC_LIBRARY NAMES zstd_static + "${CMAKE_STATIC_LIBRARY_PREFIX}zstd${CMAKE_STATIC_LIBRARY_SUFFIX}") + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(zstd DEFAULT_MSG zstd_LIBRARY zstd_INCLUDE_DIR) + +if(zstd_FOUND) + message(STATUS "Found zstd_STATIC_LIBRARY: ${zstd_STATIC_LIBRARY}") + message(STATUS "Found zstd_INCLUDE_DIR: ${zstd_INCLUDE_DIR}") + if(zstd_STATIC_LIBRARY MATCHES "${zstd_STATIC_LIBRARY_SUFFIX}$" AND + NOT TARGET zstd::libzstd_static) + add_library(zstd::libzstd_static STATIC IMPORTED) + set_target_properties(zstd::libzstd_static PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${zstd_INCLUDE_DIR}" + IMPORTED_LOCATION "${zstd_STATIC_LIBRARY}") + add_library(zstd::libzstd_shared SHARED IMPORTED) + endif() +endif() + +unset(zstd_STATIC_LIBRARY_SUFFIX) +mark_as_advanced(zstd_INCLUDE_DIR zstd_LIBRARY zstd_STATIC_LIBRARY) diff --git a/cmake/utils/FindLLVM.cmake b/cmake/utils/FindLLVM.cmake index 2c70a3ae4a..2421dec520 100644 --- a/cmake/utils/FindLLVM.cmake +++ b/cmake/utils/FindLLVM.cmake @@ -154,13 +154,7 @@ macro(find_llvm use_llvm) list(APPEND LLVM_LIBS "ZLIB::ZLIB") elseif("${__flag}" STREQUAL "-lzstd" OR ("${__flag}" STREQUAL "zstd.dll.lib")) find_package(zstd REQUIRED) - if (TARGET "zstd::libzstd_static") - message(STATUS "LLVM links against static zstd") - list(APPEND LLVM_LIBS "zstd::libzstd_static") - else() - message(STATUS "LLVM links against shared zstd") - list(APPEND LLVM_LIBS "zstd::libzstd_shared") - endif() + list(APPEND LLVM_LIBS "zstd::libzstd_static") elseif("${__flag}" STREQUAL "-lxml2") message(STATUS "LLVM links against xml2") list(APPEND LLVM_LIBS "-lxml2") diff --git a/conda/build-environment.yaml b/conda/build-environment.yaml index a1b43eb6ef..9fb2b9f4f2 100644 --- a/conda/build-environment.yaml +++ b/conda/build-environment.yaml @@ -20,20 +20,22 @@ name: tvm-build # The conda channels to lookup the dependencies channels: - - anaconda - conda-forge + - anaconda # The packages to install to the environment dependencies: - - python=3.7 # or 3.8. See https://github.com/apache/tvm/issues/8577 for more details on >= 3.9 - - conda-build + - python=3.11 + - llvmdev>=15 + - cmake>=3.24 + - zlib + - zstd - git - - llvmdev >=11 + - conda-build + - anaconda-client - numpy - pytest - - cython - - cmake - bzip2 - - make - scipy - - pillow + - pip + - cython diff --git a/conda/recipe/conda_build_config.yaml b/conda/recipe/conda_build_config.yaml index 938d294da5..4085e82ec5 100644 --- a/conda/recipe/conda_build_config.yaml +++ b/conda/recipe/conda_build_config.yaml @@ -16,9 +16,7 @@ # under the License. python: - - 3.6 - - 3.7 - - 3.8 + - 3.11 cuda: - False