Skip to content

Commit

Permalink
update halide build
Browse files Browse the repository at this point in the history
  • Loading branch information
Marc-André Moreau committed Nov 7, 2023
1 parent 539c808 commit adc8493
Show file tree
Hide file tree
Showing 6 changed files with 267 additions and 29 deletions.
105 changes: 76 additions & 29 deletions .github/workflows/halide-prebuilt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
matrix:
arch: [ x86_64, aarch64 ]
os: [ windows, macos, ubuntu-20.04, ubuntu-22.04 ]
version: [ 14.0.0 ]
version: [ 16.0.0 ]

include:
- os: windows
Expand All @@ -35,6 +35,11 @@ jobs:
msvc_arch: amd64_arm64

steps:
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.9'

- name: Configure Windows runner
if: runner.os == 'Windows'
run: |
Expand All @@ -58,29 +63,46 @@ jobs:
- name: Install host clang+llvm
shell: pwsh
env:
GH_TOKEN: ${{ github.token }}
run: |
$CLANG_LLVM_OS='${{matrix.os}}'.ToLower()
$CLANG_LLVM_VERSION='14.0.6'
$CLANG_LLVM_BASE_URL="https://github.com/awakecoding/llvm-prebuilt/releases/download/v2022.2.0"
$CLANG_LLVM_NAME="clang+llvm-${CLANG_LLVM_VERSION}-x86_64-${CLANG_LLVM_OS}"
wget -q "${CLANG_LLVM_BASE_URL}/${CLANG_LLVM_NAME}.tar.xz"
$LlvmPlatform='${{matrix.os}}'
$LlvmArch='x86_64'
$LlvmVersion = if ('${{matrix.version}}' -eq "14.0.0") { "14.0.6" } else { "16.0.6" }
$LlvmName="clang+llvm-${LlvmVersion}-${LlvmArch}-${LlvmPlatform}"
$RunId = '${{ github.event.inputs.run_id }}'
if ($RunId -eq 'latest') {
$RunId = $(gh run list -w 'LLVM prebuilt' --json 'status,databaseId,conclusion') |
ConvertFrom-Json | Where-Object { ($_.status -eq 'completed') -and ($_.conclusion -eq 'success') } |
Select-Object -First 1 -ExpandProperty databaseId
}
& gh run download $RunId --repo $Env:GITHUB_REPOSITORY -n $LlvmName
if ($IsWindows) {
$LLVM_PREFIX="C:/llvm"
cmd.exe /c "7z.exe x ${CLANG_LLVM_NAME}.tar.xz -so | 7z x -si -ttar -o`"C:/temp`""
mv "C:/temp/${CLANG_LLVM_NAME}" $LLVM_PREFIX
$TempDir = "C:/temp"
$LLVM_PREFIX = "C:/llvm"
cmd.exe /c "7z.exe x ${LlvmName}.tar.xz -so | 7z x -si -ttar -o`"C:/temp`""
mv "$TempDir/${LlvmName}" $LLVM_PREFIX
} else {
$LLVM_PREFIX="/opt/llvm"
tar -xf "${CLANG_LLVM_NAME}.tar.xz" -C /tmp
sudo mv "/tmp/${CLANG_LLVM_NAME}" $LLVM_PREFIX
$TempDir = "/tmp"
$LLVM_PREFIX = "/opt/llvm"
tar -xvf "${LlvmName}.tar.xz" -C $TempDir
sudo mv "$TempDir/${LlvmName}" $LLVM_PREFIX
}
$LLVM_BIN_PATH="$LLVM_PREFIX/bin"
$LLVM_DIR="$LLVM_PREFIX/lib/cmake/llvm"
$CLANG_DIR="$LLVM_PREFIX/lib/cmake/clang"
echo "LLVM_X86_64_DIR=$LLVM_DIR" >> $Env:GITHUB_ENV
echo "CLANG_X86_64_DIR=$CLANG_DIR" >> $Env:GITHUB_ENV
echo "LLVM_DIR=$LLVM_DIR" >> $Env:GITHUB_ENV
echo "CLANG_DIR=$CLANG_DIR" >> $Env:GITHUB_ENV
echo "LLVM_HOST_DIR=$LLVM_DIR" >> $Env:GITHUB_ENV
echo "CLANG_HOST_DIR=$CLANG_DIR" >> $Env:GITHUB_ENV
if ('${{matrix.arch}}' -eq 'x86_64') {
echo "LLVM_TARGET_DIR=$LLVM_DIR" >> $Env:GITHUB_ENV
echo "CLANG_TARGET_DIR=$CLANG_DIR" >> $Env:GITHUB_ENV
}
echo "LLVM_HOST_BIN_DIR=$LLVM_BIN_PATH" >> $Env:GITHUB_ENV
echo "PATH=$LLVM_BIN_PATH$([IO.Path]::PathSeparator)$Env:PATH" >> $Env:GITHUB_ENV
- name: Install target clang+llvm
Expand All @@ -91,7 +113,7 @@ jobs:
run: |
$LlvmPlatform='${{matrix.os}}'
$LlvmArch='${{matrix.arch}}'
$LlvmVersion='14.0.6'
$LlvmVersion = if ('${{matrix.version}}' -eq "14.0.0") { "14.0.6" } else { "16.0.6" }
$LlvmName="clang+llvm-${LlvmVersion}-${LlvmArch}-${LlvmPlatform}"
$RunId = '${{ github.event.inputs.run_id }}'
if ($RunId -eq 'latest') {
Expand All @@ -101,22 +123,36 @@ jobs:
}
& gh run download $RunId --repo $Env:GITHUB_REPOSITORY -n $LlvmName
if ($IsWindows) {
$LLVM_PREFIX="C:/llvm-${LlvmArch}"
$TempDir = "C:/temp"
$LLVM_PREFIX = "C:/llvm-$LlvmArch"
cmd.exe /c "7z.exe x ${LlvmName}.tar.xz -so | 7z x -si -ttar -o`"C:/temp`""
mv "C:/temp/${LlvmName}" $LLVM_PREFIX
mv "$TempDir/${LlvmName}" $LLVM_PREFIX
} else {
$LLVM_PREFIX="/opt/llvm-${LlvmArch}"
tar -xf "${LlvmName}.tar.xz" -C /tmp
sudo mv "/tmp/${LlvmName}" $LLVM_PREFIX
$TempDir = "/tmp"
$LLVM_PREFIX = "/opt/llvm-$LlvmArch"
tar -xf "${LlvmName}.tar.xz" -C $TempDir
sudo mv "$TempDir/${LlvmName}" $LLVM_PREFIX
}
$LLVM_BIN_PATH="$LLVM_PREFIX/bin"
$LLVM_DIR="$LLVM_PREFIX/lib/cmake/llvm"
$CLANG_DIR="$LLVM_PREFIX/lib/cmake/clang"
echo "LLVM_AARCH64_DIR=$LLVM_DIR" >> $Env:GITHUB_ENV
echo "CLANG_AARCH64_DIR=$LLVM_DIR" >> $Env:GITHUB_ENV
echo "LLVM_DIR=$LLVM_DIR" >> $Env:GITHUB_ENV
#echo "CLANG_DIR=$CLANG_DIR" >> $Env:GITHUB_ENV
echo "LLVM_TARGET_DIR=$LLVM_DIR" >> $Env:GITHUB_ENV
echo "CLANG_TARGET_DIR=$CLANG_DIR" >> $Env:GITHUB_ENV
$LLVM_HOST_BIN_DIR=$Env:LLVM_HOST_BIN_DIR
$LLVM_TARGET_BIN_DIR=$LLVM_BIN_PATH
if ($IsWindows) {
@('llvm-as.exe', 'clang.exe', 'clang-format.exe') | ForEach-Object {
Copy-Item -Path "${LLVM_HOST_BIN_DIR}\$_" -Destination "${LLVM_TARGET_BIN_DIR}\$_" -Force
}
} else {
@('llvm-as', 'clang', 'clang-format') | ForEach-Object {
Copy-Item -Path "${LLVM_HOST_BIN_DIR}/$_" -Destination "${LLVM_TARGET_BIN_DIR}/$_" -Force
}
}
- name: Clone project
uses: actions/checkout@v3
Expand All @@ -133,10 +169,17 @@ jobs:
- name: Patch Halide
shell: pwsh
run: |
git -C halide apply ../llvm-prebuilt/patches/halide-14-add-halide-host-tools-dir-cmake-option.patch
git -C halide apply ../llvm-prebuilt/patches/halide-14-disable-autoschedulers.patch
git -C halide apply ../llvm-prebuilt/patches/halide-14-disable-imported-clang-llvm-executables.patch
git -C halide apply ../llvm-prebuilt/patches/halide-14-add-clang-no-unknown-warning-option.patch
if ('${{matrix.version}}' -eq '14.0.0') {
git -C halide apply ../llvm-prebuilt/patches/halide-14-add-halide-host-tools-dir-cmake-option.patch
git -C halide apply ../llvm-prebuilt/patches/halide-14-disable-autoschedulers.patch
git -C halide apply ../llvm-prebuilt/patches/halide-14-disable-imported-clang-llvm-executables.patch
git -C halide apply ../llvm-prebuilt/patches/halide-14-add-clang-no-unknown-warning-option.patch
} else {
git -C halide apply ../llvm-prebuilt/patches/halide-16-add-halide-host-tools-dir-cmake-option.patch
git -C halide apply ../llvm-prebuilt/patches/halide-16-disable-autoschedulers.patch
git -C halide apply ../llvm-prebuilt/patches/halide-16-add-llvm-host-bin-dir-cmake-option.patch
git -C halide apply ../llvm-prebuilt/patches/halide-16-disable-clang-verbose-build-warnings.patch
}
- name: Build Halide host tools
shell: pwsh
Expand All @@ -147,7 +190,10 @@ jobs:
cmake -G Ninja -S halide -B halide-host `
-DCMAKE_BUILD_TYPE=Release `
-DLLVM_DIR="$Env:LLVM_DIR" `
-DLLVM_DIR="$Env:LLVM_HOST_DIR" `
-DClang_DIR="$Env:CLANG_HOST_DIR" `
-DWITH_TESTS=OFF -DWITH_UTILS=OFF `
-DWITH_PYTHON_BINDINGS=OFF `
-Wno-dev
cmake --build halide-host --target build_halide_h binary2cpp regexp_replace
Expand Down Expand Up @@ -187,9 +233,10 @@ jobs:
}
cmake -G Ninja -S halide -B halide-build $CMakeArgs `
-DLLVM_DIR="$Env:LLVM_DIR" `
-DClang_DIR="$Env:CLANG_DIR" `
-DLLVM_DIR="$Env:LLVM_TARGET_DIR" `
-DClang_DIR="$Env:CLANG_HOST_DIR" `
-DHALIDE_HOST_TOOLS_DIR="$Env:HALIDE_HOST_TOOLS_DIR" `
-DLLVM_HOST_BIN_DIR="$Env:LLVM_HOST_BIN_DIR" `
-DCMAKE_INSTALL_PREFIX="halide-install" `
-DCMAKE_TOOLCHAIN_FILE="$CMakeToolchainFile"
Expand Down
51 changes: 51 additions & 0 deletions patches/halide-16-add-halide-host-tools-dir-cmake-option.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
From 58ad85758391a8058d6fdfebfefc0abae5539630 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Marc-Andr=C3=A9=20Moreau?= <[email protected]>
Date: Sat, 21 Jan 2023 10:15:38 -0500
Subject: [PATCH] add HALIDE_HOST_TOOLS_DIR cmake option

---
tools/CMakeLists.txt | 26 ++++++++++++++++++++------
1 file changed, 20 insertions(+), 6 deletions(-)

diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt
index 0d8ff8e8b..23d7b2496 100644
--- a/tools/CMakeLists.txt
+++ b/tools/CMakeLists.txt
@@ -2,14 +2,28 @@
# Build time tools
##

-add_executable(build_halide_h build_halide_h.cpp)
-target_compile_options(build_halide_h PRIVATE $<$<CXX_COMPILER_ID:MSVC>:/wd4996>)
+if(DEFINED HALIDE_HOST_TOOLS_DIR)
+ add_executable(build_halide_h IMPORTED GLOBAL)
+ set_property(TARGET build_halide_h PROPERTY IMPORTED_LOCATION
+ "${HALIDE_HOST_TOOLS_DIR}/build_halide_h${CMAKE_EXECUTABLE_SUFFIX}")

-add_executable(binary2cpp binary2cpp.cpp)
-target_compile_options(binary2cpp PRIVATE $<$<CXX_COMPILER_ID:MSVC>:/wd4996>)
+ add_executable(binary2cpp IMPORTED GLOBAL)
+ set_property(TARGET binary2cpp PROPERTY IMPORTED_LOCATION
+ "${HALIDE_HOST_TOOLS_DIR}/binary2cpp${CMAKE_EXECUTABLE_SUFFIX}")

-add_executable(regexp_replace regexp_replace.cpp)
-target_compile_options(regexp_replace PRIVATE $<$<CXX_COMPILER_ID:MSVC>:/wd4996>)
+ add_executable(regexp_replace IMPORTED GLOBAL)
+ set_property(TARGET regexp_replace PROPERTY IMPORTED_LOCATION
+ "${HALIDE_HOST_TOOLS_DIR}/regexp_replace${CMAKE_EXECUTABLE_SUFFIX}")
+else()
+ add_executable(build_halide_h build_halide_h.cpp)
+ target_compile_options(build_halide_h PRIVATE $<$<CXX_COMPILER_ID:MSVC>:/wd4996>)
+
+ add_executable(binary2cpp binary2cpp.cpp)
+ target_compile_options(binary2cpp PRIVATE $<$<CXX_COMPILER_ID:MSVC>:/wd4996>)
+
+ add_executable(regexp_replace regexp_replace.cpp)
+ target_compile_options(regexp_replace PRIVATE $<$<CXX_COMPILER_ID:MSVC>:/wd4996>)
+endif()

##
# Interface target for enabling PNG/JPEG support in Halide
--
2.25.1

54 changes: 54 additions & 0 deletions patches/halide-16-add-llvm-host-bin-dir-cmake-option.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
From 7c51e8dfd9fa384b8a46574412238f9f0a1b2595 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Marc-Andr=C3=A9=20Moreau?= <[email protected]>
Date: Tue, 7 Nov 2023 15:38:24 -0500
Subject: [PATCH] [PATCH] add LLVM_HOST_BIN_DIR cmake option

---
dependencies/llvm/CMakeLists.txt | 22 ++++++++++++++++++----
1 file changed, 18 insertions(+), 4 deletions(-)

diff --git a/dependencies/llvm/CMakeLists.txt b/dependencies/llvm/CMakeLists.txt
index bfb6967f3..85609e652 100644
--- a/dependencies/llvm/CMakeLists.txt
+++ b/dependencies/llvm/CMakeLists.txt
@@ -11,7 +11,7 @@ set(CMAKE_MAP_IMPORTED_CONFIG_RELWITHDEBINFO RelWithDebInfo Release MinSizeRel "
set(CMAKE_MAP_IMPORTED_CONFIG_RELEASE Release MinSizeRel RelWithDebInfo "")

find_package(LLVM ${Halide_REQUIRE_LLVM_VERSION} REQUIRED)
-find_package(Clang REQUIRED CONFIG HINTS "${LLVM_DIR}/../clang" "${LLVM_DIR}/../lib/cmake/clang")
+find_package(Clang REQUIRED CONFIG HINTS "${Clang_DIR}" "${LLVM_DIR}/../clang" "${LLVM_DIR}/../lib/cmake/clang")

set(LLVM_PACKAGE_VERSION "${LLVM_PACKAGE_VERSION}"
CACHE INTERNAL "LLVM version")
@@ -58,11 +58,25 @@ cmake_dependent_option(Halide_BUNDLE_LLVM "When built as a static library, inclu
# Promote LLVM/Clang executable targets
##

-set_target_properties(llvm-as clang PROPERTIES IMPORTED_GLOBAL TRUE)
+if (LLVM_HOST_BIN_DIR)
+ set_target_properties(llvm-as clang PROPERTIES IMPORTED_GLOBAL TRUE)
+ set_property(TARGET llvm-as PROPERTY IMPORTED_LOCATION
+ "${LLVM_HOST_BIN_DIR}/llvm-as${CMAKE_EXECUTABLE_SUFFIX}")
+ set_property(TARGET clang PROPERTY IMPORTED_LOCATION
+ "${LLVM_HOST_BIN_DIR}/clang${CMAKE_EXECUTABLE_SUFFIX}")

-# clang-tools-extra is optional, but provides the clang-format target
-if (TARGET clang-format)
+ if (TARGET clang-format)
set_target_properties(clang-format PROPERTIES IMPORTED_GLOBAL TRUE)
+ set_property(TARGET clang-format PROPERTY IMPORTED_LOCATION
+ "${LLVM_HOST_BIN_DIR}/clang-format${CMAKE_EXECUTABLE_SUFFIX}")
+ endif ()
+else ()
+ set_target_properties(llvm-as clang PROPERTIES IMPORTED_GLOBAL TRUE)
+
+ # clang-tools-extra is optional, but provides the clang-format target
+ if (TARGET clang-format)
+ set_target_properties(clang-format PROPERTIES IMPORTED_GLOBAL TRUE)
+ endif ()
endif ()

##
--
2.25.1

27 changes: 27 additions & 0 deletions patches/halide-16-disable-autoschedulers.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
From 644b27083565e1f6f2b010dc3cdc21259ade9880 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Marc-Andr=C3=A9=20Moreau?= <[email protected]>
Date: Sun, 22 Jan 2023 08:01:56 -0500
Subject: [PATCH] disable autoschedulers

---
src/CMakeLists.txt | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 809b3efdd..8202c49d5 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -524,8 +524,8 @@ endif ()
##

if (BUILD_SHARED_LIBS)
- message(STATUS "Building autoschedulers enabled")
- add_subdirectory(autoschedulers)
+ #message(STATUS "Building autoschedulers enabled")
+ #add_subdirectory(autoschedulers)
else ()
message(STATUS "Building autoschedulers disabled (static Halide)")
endif ()
--
2.25.1

25 changes: 25 additions & 0 deletions patches/halide-16-disable-clang-verbose-build-warnings.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
From b44261e5846f054b16901e6fe0d31d23cee8e74b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Marc-Andr=C3=A9=20Moreau?= <[email protected]>
Date: Tue, 7 Nov 2023 11:07:53 -0500
Subject: [PATCH] [PATCH] disable clang verbose build warnings

---
src/CMakeLists.txt | 2 ++
1 file changed, 2 insertions(+)

diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 84f98033a..8fda27e5b 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -521,6 +521,8 @@ target_compile_options(
$<$<CXX_COMPILER_ID:Clang,AppleClang>:-Wno-undefined-func-template>
$<$<CXX_COMPILER_ID:Clang,AppleClang>:-Wno-unused-member-function>
$<$<CXX_COMPILER_ID:Clang,AppleClang>:-Wno-unused-template>
+ $<$<CXX_COMPILER_ID:Clang,AppleClang>:-Wno-unknown-warning-option>
+ $<$<CXX_COMPILER_ID:Clang,AppleClang>:-Wno-unsafe-buffer-usage>

# This warning was removed in Clang 13
$<$<AND:$<CXX_COMPILER_ID:Clang,AppleClang>,$<VERSION_LESS:$<CXX_COMPILER_VERSION>,13.0>>:-Wno-return-std-move-in-c++11>
--
2.25.1

34 changes: 34 additions & 0 deletions patches/halide-16-disable-imported-clang-llvm-executables.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
From dfcb3a317b420e1e5b4f98506f0e9d12a4adb406 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Marc-Andr=C3=A9=20Moreau?= <[email protected]>
Date: Sun, 22 Jan 2023 14:40:59 -0500
Subject: [PATCH] disable imported clang+llvm executable promotion

---
dependencies/llvm/CMakeLists.txt | 4 ++++
1 file changed, 4 insertions(+)

diff --git a/dependencies/llvm/CMakeLists.txt b/dependencies/llvm/CMakeLists.txt
index 248aaf9ea..a8e613a37 100644
--- a/dependencies/llvm/CMakeLists.txt
+++ b/dependencies/llvm/CMakeLists.txt
@@ -42,6 +42,8 @@ cmake_dependent_option(Halide_BUNDLE_LLVM "When built as a static library, inclu
# Promote LLVM/Clang executable targets
##

+if(PROMOTE_IMPORTED_CLANG_LLVM)
+
set_target_properties(llvm-as clang PROPERTIES IMPORTED_GLOBAL TRUE)

# clang-tools-extra is optional, but provides the clang-format target
@@ -49,6 +51,8 @@ if (TARGET clang-format)
set_target_properties(clang-format PROPERTIES IMPORTED_GLOBAL TRUE)
endif ()

+endif()
+
##
# Create options for including or excluding LLVM backends.
##
--
2.25.1

0 comments on commit adc8493

Please sign in to comment.