From c0686e867824494fed50e15f69d9433eb6f85f85 Mon Sep 17 00:00:00 2001 From: Neil Hickey Date: Wed, 14 Dec 2022 09:05:03 +0000 Subject: [PATCH 1/4] [Docker] Add script to build llvm from source This allows us to use the latest llvm and make sure it builds with the same configuration as the rest of tvm Change-Id: I004ec89700498167c632d25f4fdf667922ba4943 --- docker/Dockerfile.ci_arm | 4 +- .../ubuntu_install_llvm_from_source.sh | 99 +++++++++++++++++++ tests/scripts/task_config_build_arm.sh | 2 +- 3 files changed, 102 insertions(+), 3 deletions(-) create mode 100644 docker/install/ubuntu_install_llvm_from_source.sh diff --git a/docker/Dockerfile.ci_arm b/docker/Dockerfile.ci_arm index bd2b2d8fb145..238a8c2c1b28 100644 --- a/docker/Dockerfile.ci_arm +++ b/docker/Dockerfile.ci_arm @@ -50,8 +50,8 @@ COPY install/ubuntu_install_sccache.sh /install/ubuntu_install_sccache.sh RUN bash /install/ubuntu_install_sccache.sh ENV PATH /opt/sccache:$PATH -COPY install/ubuntu_install_llvm.sh /install/ubuntu_install_llvm.sh -RUN bash /install/ubuntu_install_llvm.sh +COPY install/ubuntu_install_llvm_from_source.sh /install/ubuntu_install_llvm_from_source.sh +RUN bash /install/ubuntu_install_llvm_from_source.sh 15.0 ENV TVM_VENV /venv/apache-tvm-py3.7 COPY python/bootstrap/lockfiles /install/python/bootstrap/lockfiles diff --git a/docker/install/ubuntu_install_llvm_from_source.sh b/docker/install/ubuntu_install_llvm_from_source.sh new file mode 100644 index 000000000000..e03a2a426ab3 --- /dev/null +++ b/docker/install/ubuntu_install_llvm_from_source.sh @@ -0,0 +1,99 @@ +#!/bin/bash + +# 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 builds LLVM and clang from the llvm-project tarball +# using CMake. It is tested with LLVM from version 15. + +set -e + +LLVM_VERSION_MAJOR=$1 + +detect_llvm_version() { + curl -sL "https://api.github.com/repos/llvm/llvm-project/releases?per_page=100" | \ + grep tag_name | \ + grep -o "llvmorg-${LLVM_VERSION_MAJOR}[^\"]*" | \ + grep -v rc | \ + sed -e "s/^llvmorg-//g" | \ + head -n 1 +} + +LLVM_VERSION=$(detect_llvm_version) +echo ${LLVM_VERSION} + +curl -sL \ + https://github.com/llvm/llvm-project/releases/download/llvmorg-${LLVM_VERSION}/llvm-project-${LLVM_VERSION}.src.tar.xz \ + -o llvm-project-${LLVM_VERSION}.src.tar.xz +unxz llvm-project-${LLVM_VERSION}.src.tar.xz +tar xf llvm-project-${LLVM_VERSION}.src.tar +pushd llvm-project-${LLVM_VERSION}.src + +pushd llvm +mkdir build +pushd build +cmake \ + -DCMAKE_BUILD_TYPE=Release \ + -DCMAKE_MODULE_PATH="/llvm-project-${LLVM_VERSION}.src/cmake/Modules" \ + -DCMAKE_INSTALL_PREFIX=/usr \ + -DLLVM_TARGETS_TO_BUILD="AArch64;ARM;X86" \ + -DLLVM_INCLUDE_DOCS=OFF \ + -DLLVM_INCLUDE_EXAMPLES=OFF \ + -DLLVM_INCLUDE_TESTS=OFF \ + -DLLVM_INCLUDE_UTILS=OFF \ + -DLLVM_ENABLE_TERMINFO=OFF \ + -DLLVM_ENABLE_ASSERTIONS=ON \ + -DLLVM_ENABLE_RTTI=ON \ + -DLLVM_ENABLE_OCAMLDOC=OFF \ + -DLLVM_USE_INTEL_JITEVENTS=ON \ + -DLLVM_TEMPORARILY_ALLOW_OLD_TOOLCHAIN=ON \ + -DPYTHON_EXECUTABLE="$(cpython_path 3.7)/bin/python" \ + -GNinja \ + .. +ninja install +popd +popd +rm -rf llvm-${LLVM_VERSION}.src.tar.xz llvm-${LLVM_VERSION}.src.tar llvm-${LLVM_VERSION}.src + +# clang is only used to precompile Gandiva bitcode +if [ ${LLVM_VERSION_MAJOR} -lt 9 ]; then + clang_package_name=cfe +else + clang_package_name=clang +fi + +pushd ${clang_package_name} +mkdir build +pushd build +cmake \ + -DCMAKE_BUILD_TYPE=Release \ + -DCMAKE_INSTALL_PREFIX=/usr \ + -DCMAKE_MODULE_PATH="/llvm-project-${LLVM_VERSION}.src/cmake/Modules" \ + -DCLANG_INCLUDE_TESTS=OFF \ + -DCLANG_INCLUDE_DOCS=OFF \ + -DLLVM_INCLUDE_TESTS=OFF \ + -DLLVM_INCLUDE_DOCS=OFF \ + -Wno-dev \ + -GNinja \ + .. + +ninja -w dupbuild=warn install # both clang and llvm builds generate llvm-config file +popd +popd + +# out of llvm-project-${LLVM_VERSION}.src +popd +rm -rf ${clang_package_name}-${LLVM_VERSION}.src.tar.xz ${clang_package_name}-${LLVM_VERSION}.src.tar ${clang_package_name}-${LLVM_VERSION}.src diff --git a/tests/scripts/task_config_build_arm.sh b/tests/scripts/task_config_build_arm.sh index 516e6ac86791..50b1a9553f27 100755 --- a/tests/scripts/task_config_build_arm.sh +++ b/tests/scripts/task_config_build_arm.sh @@ -28,7 +28,7 @@ echo set\(USE_RPC ON\) >> config.cmake echo set\(USE_MICRO ON\) >> config.cmake echo set\(USE_MICRO_STANDALONE_RUNTIME ON\) >> config.cmake echo set\(USE_PROFILER ON\) >> config.cmake -echo set\(USE_LLVM llvm-config-8\) >> config.cmake +echo set\(USE_LLVM llvm-config\) >> config.cmake echo set\(CMAKE_CXX_FLAGS -Werror\) >> config.cmake echo set\(USE_VTA_FSIM ON\) >> config.cmake echo set\(USE_ARM_COMPUTE_LIB ON\) >> config.cmake From d4646bfa0a56a72fc799cd61e36b0e11ab15c963 Mon Sep 17 00:00:00 2001 From: Neil Hickey Date: Tue, 31 Jan 2023 09:21:59 +0000 Subject: [PATCH 2/4] [Docker] Fixing scripts for llvm-config inclusion. Note: This will be undone once the docker images have been updated --- tests/scripts/task_config_build_arm.sh | 2 +- tests/scripts/task_config_build_minimal_cross_isa.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/scripts/task_config_build_arm.sh b/tests/scripts/task_config_build_arm.sh index 50b1a9553f27..bd14a91f251b 100755 --- a/tests/scripts/task_config_build_arm.sh +++ b/tests/scripts/task_config_build_arm.sh @@ -28,7 +28,7 @@ echo set\(USE_RPC ON\) >> config.cmake echo set\(USE_MICRO ON\) >> config.cmake echo set\(USE_MICRO_STANDALONE_RUNTIME ON\) >> config.cmake echo set\(USE_PROFILER ON\) >> config.cmake -echo set\(USE_LLVM llvm-config\) >> config.cmake +echo -e 'find_program(LLVM_CONFIG "llvm-config")\nif (LLVM_CONFIG) \n\tset(USE_LLVM llvm-config) \nelse() \n\tset(USE_LLVM llvm-config-8)\nendif()' >> config.cmake echo set\(CMAKE_CXX_FLAGS -Werror\) >> config.cmake echo set\(USE_VTA_FSIM ON\) >> config.cmake echo set\(USE_ARM_COMPUTE_LIB ON\) >> config.cmake diff --git a/tests/scripts/task_config_build_minimal_cross_isa.sh b/tests/scripts/task_config_build_minimal_cross_isa.sh index 1c08cb285d21..1b251632182a 100755 --- a/tests/scripts/task_config_build_minimal_cross_isa.sh +++ b/tests/scripts/task_config_build_minimal_cross_isa.sh @@ -46,5 +46,5 @@ if [ "$architecture_type" != "aarch64" ]; then echo set\(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY\) >> config.cmake else # This usually runs in the ci_arm docker image. - echo set\(USE_LLVM llvm-config-8\) >> config.cmake + echo -e 'find_program(LLVM_CONFIG "llvm-config")\nif (LLVM_CONFIG) \n\tset(USE_LLVM llvm-config) \nelse() \n\tset(USE_LLVM llvm-config-8)\nendif()' >> config.cmake fi From cf3ce968133748395881759657801b2aa1f424cd Mon Sep 17 00:00:00 2001 From: Neil Hickey Date: Mon, 6 Mar 2023 16:04:42 +0000 Subject: [PATCH 3/4] Making suggested fixes to docker files --- docker/Dockerfile.ci_arm | 2 +- .../ubuntu_install_llvm_from_source.sh | 27 +++++++++---------- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/docker/Dockerfile.ci_arm b/docker/Dockerfile.ci_arm index 238a8c2c1b28..16c9fcad051b 100644 --- a/docker/Dockerfile.ci_arm +++ b/docker/Dockerfile.ci_arm @@ -51,7 +51,7 @@ RUN bash /install/ubuntu_install_sccache.sh ENV PATH /opt/sccache:$PATH COPY install/ubuntu_install_llvm_from_source.sh /install/ubuntu_install_llvm_from_source.sh -RUN bash /install/ubuntu_install_llvm_from_source.sh 15.0 +RUN bash /install/ubuntu_install_llvm_from_source.sh 15.0.7 ENV TVM_VENV /venv/apache-tvm-py3.7 COPY python/bootstrap/lockfiles /install/python/bootstrap/lockfiles diff --git a/docker/install/ubuntu_install_llvm_from_source.sh b/docker/install/ubuntu_install_llvm_from_source.sh index e03a2a426ab3..82a964f613f6 100644 --- a/docker/install/ubuntu_install_llvm_from_source.sh +++ b/docker/install/ubuntu_install_llvm_from_source.sh @@ -21,25 +21,25 @@ set -e -LLVM_VERSION_MAJOR=$1 +LLVM_VERSION=$1 -detect_llvm_version() { - curl -sL "https://api.github.com/repos/llvm/llvm-project/releases?per_page=100" | \ - grep tag_name | \ - grep -o "llvmorg-${LLVM_VERSION_MAJOR}[^\"]*" | \ - grep -v rc | \ - sed -e "s/^llvmorg-//g" | \ - head -n 1 +echo ${LLVM_VERSION} + +tmpdir=$(mktemp -d) + +cleanup() +{ + rm -rf "$tmpdir" } -LLVM_VERSION=$(detect_llvm_version) -echo ${LLVM_VERSION} +trap cleanup 0 + +pushd "$tmpdir" curl -sL \ https://github.com/llvm/llvm-project/releases/download/llvmorg-${LLVM_VERSION}/llvm-project-${LLVM_VERSION}.src.tar.xz \ -o llvm-project-${LLVM_VERSION}.src.tar.xz -unxz llvm-project-${LLVM_VERSION}.src.tar.xz -tar xf llvm-project-${LLVM_VERSION}.src.tar +tar xf llvm-project-${LLVM_VERSION}.src.tar.xz pushd llvm-project-${LLVM_VERSION}.src pushd llvm @@ -66,7 +66,6 @@ cmake \ ninja install popd popd -rm -rf llvm-${LLVM_VERSION}.src.tar.xz llvm-${LLVM_VERSION}.src.tar llvm-${LLVM_VERSION}.src # clang is only used to precompile Gandiva bitcode if [ ${LLVM_VERSION_MAJOR} -lt 9 ]; then @@ -96,4 +95,4 @@ popd # out of llvm-project-${LLVM_VERSION}.src popd -rm -rf ${clang_package_name}-${LLVM_VERSION}.src.tar.xz ${clang_package_name}-${LLVM_VERSION}.src.tar ${clang_package_name}-${LLVM_VERSION}.src +popd From 1e6754c31c38fdfb86a2a8147d932a172fbd1e24 Mon Sep 17 00:00:00 2001 From: Neil Hickey Date: Tue, 7 Mar 2023 12:12:11 +0000 Subject: [PATCH 4/4] Add SHA checking for downloaded llvm source file --- docker/Dockerfile.ci_arm | 2 +- docker/install/ubuntu_install_llvm_from_source.sh | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/docker/Dockerfile.ci_arm b/docker/Dockerfile.ci_arm index 16c9fcad051b..26f8ef91969a 100644 --- a/docker/Dockerfile.ci_arm +++ b/docker/Dockerfile.ci_arm @@ -51,7 +51,7 @@ RUN bash /install/ubuntu_install_sccache.sh ENV PATH /opt/sccache:$PATH COPY install/ubuntu_install_llvm_from_source.sh /install/ubuntu_install_llvm_from_source.sh -RUN bash /install/ubuntu_install_llvm_from_source.sh 15.0.7 +RUN bash /install/ubuntu_install_llvm_from_source.sh 15.0.7 8b5fcb24b4128cf04df1b0b9410ce8b1a729cb3c544e6da885d234280dedeac6 ENV TVM_VENV /venv/apache-tvm-py3.7 COPY python/bootstrap/lockfiles /install/python/bootstrap/lockfiles diff --git a/docker/install/ubuntu_install_llvm_from_source.sh b/docker/install/ubuntu_install_llvm_from_source.sh index 82a964f613f6..854e74a4d824 100644 --- a/docker/install/ubuntu_install_llvm_from_source.sh +++ b/docker/install/ubuntu_install_llvm_from_source.sh @@ -22,6 +22,7 @@ set -e LLVM_VERSION=$1 +LLVM_FILE_SHA=$2 echo ${LLVM_VERSION} @@ -39,6 +40,7 @@ pushd "$tmpdir" curl -sL \ https://github.com/llvm/llvm-project/releases/download/llvmorg-${LLVM_VERSION}/llvm-project-${LLVM_VERSION}.src.tar.xz \ -o llvm-project-${LLVM_VERSION}.src.tar.xz +echo "$LLVM_FILE_SHA llvm-project-${LLVM_VERSION}.src.tar.xz" | sha256sum --check tar xf llvm-project-${LLVM_VERSION}.src.tar.xz pushd llvm-project-${LLVM_VERSION}.src