Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
276 changes: 276 additions & 0 deletions .github/workflows/test-llvm23.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,276 @@
name: Test LLVM 23 (Fork-based)

on:
pull_request:
workflow_dispatch:

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.ref_name }}
cancel-in-progress: true

jobs:
step1-configure-linux:
if: github.event_name == 'pull_request' || github.event_name == 'workflow_dispatch'
name: 'Step 1: Configure LLVM 23 (${{ matrix.variant }})'
runs-on:
- self-hosted
- Linux
- X64
strategy:
matrix:
variant: [translator, native]
fail-fast: true
steps:
- uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.head.sha || github.sha }}
fetch-depth: 0
submodules: 'recursive'
- name: Configure LLVM 23 (${{ matrix.variant }})
run: |
BUILD_DIR="$HOME/llvm-builds/23-${{ matrix.variant }}"
rm -rf "$BUILD_DIR"
mkdir -p "$BUILD_DIR"
cd "$BUILD_DIR"
rm -rf scripts llvm-patches
cp -r ${{ github.workspace }}/scripts .
cp -r ${{ github.workspace }}/llvm-patches .
chmod +x scripts/configure_llvm.sh
./scripts/configure_llvm.sh --version 23 \
--install-dir $HOME/install/llvm/23.0-${{ matrix.variant }} \
--variant ${{ matrix.variant }} --configure-only

step2-build-test-linux:
needs: step1-configure-linux
if: github.event_name == 'pull_request' || github.event_name == 'workflow_dispatch'
name: Build LLVM 23 (${{ matrix.variant }}) and test chipStar
runs-on:
- self-hosted
- Linux
- X64
env:
IGC_EnableDPEmulation: 1
OverrideDefaultFP64Settings: 1
CHIP_LOGLEVEL: err
CHIP_MODULE_CACHE_DIR: ""
POCL_KERNEL_CACHE: 0
CHIP_L0_EVENT_TIMEOUT: 1790
strategy:
matrix:
variant: [translator, native]
fail-fast: false
steps:
- uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.head.sha || github.sha }}
fetch-depth: 0
submodules: 'recursive'
- name: Build LLVM 23 (${{ matrix.variant }})
id: build_llvm
continue-on-error: true
run: |
BUILD_DIR="$HOME/llvm-builds/23-${{ matrix.variant }}/llvm-project/llvm/build_23"
if [ ! -d "$BUILD_DIR" ]; then
echo "Error: Build directory $BUILD_DIR does not exist. Step 1 may have failed."
exit 1
fi
cd "$BUILD_DIR"
make -j$(nproc)
timeout-minutes: 300
- name: Build chipStar with LLVM 23 (${{ matrix.variant }})
id: build_chipstar
if: steps.build_llvm.outcome == 'success'
run: |
# Source modules for device drivers
if [ -f "$HOME/.local/init/bash" ]; then
export MODULESHOME=$HOME/.local
source "$MODULESHOME/init/bash"
elif [ -f /etc/profile.d/lmod.sh ]; then
source /etc/profile.d/lmod.sh &> /dev/null
else
source /etc/profile.d/modules.sh &> /dev/null
fi
module use ~/modulefiles
module load oneapi/2025.0.4 opencl/dgpu

LLVM_BIN="$HOME/llvm-builds/23-${{ matrix.variant }}/llvm-project/llvm/build_23/bin"
test -f "${LLVM_BIN}/clang" || exit 1
cd ${{ github.workspace }}
rm -rf build-llvm23-${{ matrix.variant }}
mkdir -p build-llvm23-${{ matrix.variant }}
cd build-llvm23-${{ matrix.variant }}
cmake .. -DLLVM_CONFIG_BIN=${LLVM_BIN}/llvm-config -GNinja \
-DCMAKE_BUILD_TYPE=Debug \
-DCHIP_BUILD_SAMPLES=ON -DCHIP_BUILD_TESTS=ON
ninja all install -j$(nproc)
ninja build_tests install -j$(nproc)
timeout-minutes: 60
- name: Test chipStar (iGPU OpenCL)
if: always() && steps.build_chipstar.outcome == 'success'
continue-on-error: true
run: |
if [ -f "$HOME/.local/init/bash" ]; then
export MODULESHOME=$HOME/.local; source "$MODULESHOME/init/bash"
elif [ -f /etc/profile.d/lmod.sh ]; then source /etc/profile.d/lmod.sh &> /dev/null
else source /etc/profile.d/modules.sh &> /dev/null; fi
module use ~/modulefiles
module load opencl/igpu
cd ${{ github.workspace }}/build-llvm23-${{ matrix.variant }}
../scripts/check.py ./ igpu opencl
timeout-minutes: 60
- name: Test chipStar (iGPU Level0)
if: always() && steps.build_chipstar.outcome == 'success'
continue-on-error: true
run: |
if [ -f "$HOME/.local/init/bash" ]; then
export MODULESHOME=$HOME/.local; source "$MODULESHOME/init/bash"
elif [ -f /etc/profile.d/lmod.sh ]; then source /etc/profile.d/lmod.sh &> /dev/null
else source /etc/profile.d/modules.sh &> /dev/null; fi
module use ~/modulefiles
module load level-zero/igpu
cd ${{ github.workspace }}/build-llvm23-${{ matrix.variant }}
../scripts/check.py ./ igpu level0
timeout-minutes: 60
- name: Test chipStar (dGPU Level0)
if: always() && steps.build_chipstar.outcome == 'success'
run: |
if [ -f "$HOME/.local/init/bash" ]; then
export MODULESHOME=$HOME/.local; source "$MODULESHOME/init/bash"
elif [ -f /etc/profile.d/lmod.sh ]; then source /etc/profile.d/lmod.sh &> /dev/null
else source /etc/profile.d/modules.sh &> /dev/null; fi
module use ~/modulefiles
module load level-zero/dgpu
cd ${{ github.workspace }}/build-llvm23-${{ matrix.variant }}
../scripts/check.py ./ dgpu level0
timeout-minutes: 60
- name: Test chipStar (dGPU OpenCL)
if: always() && steps.build_chipstar.outcome == 'success'
run: |
if [ -f "$HOME/.local/init/bash" ]; then
export MODULESHOME=$HOME/.local; source "$MODULESHOME/init/bash"
elif [ -f /etc/profile.d/lmod.sh ]; then source /etc/profile.d/lmod.sh &> /dev/null
else source /etc/profile.d/modules.sh &> /dev/null; fi
module use ~/modulefiles
module load opencl/dgpu
cd ${{ github.workspace }}/build-llvm23-${{ matrix.variant }}
../scripts/check.py ./ dgpu opencl
timeout-minutes: 60
- name: Test chipStar (CPU OpenCL)
if: always() && steps.build_chipstar.outcome == 'success'
run: |
if [ -f "$HOME/.local/init/bash" ]; then
export MODULESHOME=$HOME/.local; source "$MODULESHOME/init/bash"
elif [ -f /etc/profile.d/lmod.sh ]; then source /etc/profile.d/lmod.sh &> /dev/null
else source /etc/profile.d/modules.sh &> /dev/null; fi
module use ~/modulefiles
module load opencl/cpu
cd ${{ github.workspace }}/build-llvm23-${{ matrix.variant }}
../scripts/check.py ./ cpu opencl --num-tries=3
timeout-minutes: 60
- uses: actions/upload-artifact@v4
if: failure()
with:
name: test-logs-llvm23-${{ matrix.variant }}
path: |
${{ github.workspace }}/build-llvm23-${{ matrix.variant }}/checkpy_*.txt
${{ github.workspace }}/build-llvm23-${{ matrix.variant }}/Testing/Temporary/LastTest.log

step1-configure-macos:
if: github.event_name == 'pull_request' || github.event_name == 'workflow_dispatch'
name: 'Step 1: Configure LLVM 23 (macOS ${{ matrix.variant }})'
runs-on: [self-hosted, ARM64, MacOS]
strategy:
matrix:
variant: [translator, native]
fail-fast: true
steps:
- uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.head.sha || github.sha }}
fetch-depth: 0
submodules: 'recursive'
- name: Configure LLVM 23 (${{ matrix.variant }})
shell: /bin/bash {0}
run: |
export PATH="/opt/homebrew/bin:/opt/homebrew/sbin:$PATH"
BUILD_DIR="$HOME/llvm-builds/23-${{ matrix.variant }}"
rm -rf "$BUILD_DIR"
mkdir -p "$BUILD_DIR"
cd "$BUILD_DIR"
rm -rf scripts llvm-patches
cp -r ${{ github.workspace }}/scripts .
cp -r ${{ github.workspace }}/llvm-patches .
chmod +x scripts/configure_llvm.sh
./scripts/configure_llvm.sh --version 23 \
--install-dir $HOME/install/llvm/23.0-${{ matrix.variant }} \
--variant ${{ matrix.variant }} --configure-only

step2-build-test-macos:
needs: step1-configure-macos
if: github.event_name == 'pull_request' || github.event_name == 'workflow_dispatch'
name: Build LLVM 23 (${{ matrix.variant }}) (macOS) and test chipStar
runs-on: [self-hosted, ARM64, MacOS]
env:
CHIP_DEVICE_TYPE: pocl
CHIP_MODULE_CACHE_DIR: ""
strategy:
matrix:
variant: [translator, native]
fail-fast: false
steps:
- uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.head.sha || github.sha }}
fetch-depth: 0
submodules: 'recursive'
- name: Build LLVM 23 (${{ matrix.variant }})
id: build_llvm
shell: /bin/bash {0}
continue-on-error: true
run: |
export PATH="/opt/homebrew/bin:/opt/homebrew/sbin:$PATH"
BUILD_DIR="$HOME/llvm-builds/23-${{ matrix.variant }}/llvm-project/llvm/build_23"
if [ ! -d "$BUILD_DIR" ]; then
echo "Error: Build directory $BUILD_DIR does not exist. Step 1 may have failed."
exit 1
fi
cd "$BUILD_DIR"
cmake --build . -j$(sysctl -n hw.ncpu)
timeout-minutes: 300
- name: Test chipStar with LLVM 23 (${{ matrix.variant }}) (PoCL OpenCL)
if: steps.build_llvm.outcome == 'success'
shell: /bin/bash {0}
run: |
source /opt/homebrew/Cellar/modules/5.6.0/init/bash
export MODULEPATH="/Users/paulius/modulefiles:$MODULEPATH"
module load pocl

LLVM_BIN="$HOME/llvm-builds/23-${{ matrix.variant }}/llvm-project/llvm/build_23/bin"
test -f "${LLVM_BIN}/clang" || exit 1

export PATH="/Users/paulius/.pyenv/shims:/opt/homebrew/bin:/opt/homebrew/sbin:$PATH"
export CHIP_DEVICE_TYPE=pocl
export OCL_ICD_VENDORS=/Users/paulius/install/pocl/etc/OpenCL/vendors/
export SPIRV_TOOLS_PREFIX=$(brew --prefix spirv-tools)
export CMAKE_PREFIX_PATH="${SPIRV_TOOLS_PREFIX}:${CMAKE_PREFIX_PATH}"

cd ${{ github.workspace }}
rm -rf build-23-${{ matrix.variant }}
mkdir -p build-23-${{ matrix.variant }}
cd build-23-${{ matrix.variant }}
/opt/homebrew/bin/cmake .. \
-DLLVM_CONFIG_BIN=${LLVM_BIN}/llvm-config \
-DOpenCL_LIBRARY=/Users/paulius/install/pocl/lib/libpocl.dylib \
-GNinja -DCMAKE_BUILD_TYPE=Debug
ninja CHIP
ninja build_tests
ninja
../scripts/check.py ./ pocl opencl
timeout-minutes: 60
- uses: actions/upload-artifact@v4
if: failure()
with:
name: test-logs-macos-llvm23-${{ matrix.variant }}
path: |
build-23-${{ matrix.variant }}/checkpy_*.txt
build-23-${{ matrix.variant }}/Testing/Temporary/LastTest.log
13 changes: 12 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ include(LLVMCheck)
include(chip_spv_cmake_macros)
enable_testing()

# Exclude ROCm-Device-Libs tests that target amdgcn (not applicable to SPIR-V builds).
file(WRITE "${CMAKE_BINARY_DIR}/CTestCustom.cmake"
"set(CTEST_CUSTOM_TESTS_IGNORE \"constant_fold_lgamma_r\")\n")

if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
set(CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}/install" CACHE PATH "..." FORCE)
endif()
Expand Down Expand Up @@ -236,7 +240,7 @@ set(CONFIG_PACKAGE_INSTALL_DIR ${LIB_INSTALL_DIR}/cmake/hip CACHE PATH "cmake co
set(CONFIG_LANG_PACKAGE_INSTALL_DIR ${LIB_INSTALL_DIR}/cmake/hip-lang CACHE PATH "cmake lang install dir")

set(HAVE_CLANG_NEW_OFFLOAD_DRIVER OFF)
if(LLVM_VERSION_MAJOR GREATER_EQUAL 23)
if(LLVM_VERSION_MAJOR GREATER_EQUAL 23 AND NOT APPLE)
# LLVM-22: The new offload driver exists on this version but HIPSPV
# toolchain doesn't support it.
#
Expand All @@ -246,6 +250,13 @@ if(LLVM_VERSION_MAJOR GREATER_EQUAL 23)
# link steps.
#
# LLVM-23+: the old offload driver may be removed.
#
# macOS (APPLE): the new offload driver crashes clang while building the
# offload compilation jobs. Constructing the host (Darwin) toolchain args
# for the SPIR-V offload kind re-enters Darwin::AddDeploymentTarget, which
# asserts in setTarget() ("Target already initialized!", Darwin.h:453).
# Until that upstream Darwin driver bug is fixed, fall back to the old
# offload driver on macOS (adds --no-offload-new-driver below).
set(HAVE_CLANG_NEW_OFFLOAD_DRIVER ON)
endif()

Expand Down
7 changes: 4 additions & 3 deletions bitcode/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,10 @@ set(RTDEVLIB_SOURCES_v1_2
set(RTDEVLIB_SOURCES_v1_3
ballot_native)

# Set rtdevlib compile triples. With integrated SPIR-V (LLVM 22+), use chipstar
# triples. With external translator, use OFFLOAD_TRIPLE (spirv64).
if(LLVM_VERSION_MAJOR GREATER_EQUAL 22 AND CHIP_LLVM_USE_INTERGRATED_SPIRV)
# Set rtdevlib compile triples. LLVM 23+ and integrated SPIR-V builds know the
# chipstar triples (spirv64v1.X-unknown-chipstar). Otherwise fall back to
# OFFLOAD_TRIPLE (spirv64).
if(LLVM_VERSION_MAJOR GREATER_EQUAL 23 OR CHIP_LLVM_USE_INTERGRATED_SPIRV)
set(RTDEVLIB_TRIPLE_v1_2 spirv64v1.2-unknown-chipstar)
set(RTDEVLIB_TRIPLE_v1_3 spirv64v1.3-unknown-chipstar)
else()
Expand Down
23 changes: 16 additions & 7 deletions llvm_passes/HipPrintf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,7 @@ getFormatStringPieces(Value *FmtStrArg, unsigned &NumberOfFormatSpecs) {
dyn_cast<ConstantDataSequential>(OrigFmtStr->getInitializer());

if (FmtStrData == nullptr) {
#if LLVM_VERSION_MAJOR >= 23
assert(OrigFmtStr->getInitializer()->isNullValue());
#else
assert(OrigFmtStr->getInitializer()->isZeroValue());
#endif
FmtStrPieces.push_back("");
NumberOfFormatSpecs = 0;
return FmtStrPieces;
Expand Down Expand Up @@ -430,9 +426,22 @@ PreservedAnalyses HipPrintfToOpenCLPrintfPass::run(Module &Mod,
GlobalValue *Printf = Mod.getNamedValue("printf");
GlobalValue *HipPrintf = Mod.getNamedValue(ORIG_PRINTF_FUNC_NAME);

// No printf decl in the module, no printf calls to handle.
// 1 use if the "printf" is only used by "_cl_printf"
if (Printf == nullptr || Printf->getNumUses() == 1)
// No printf decl in the module: no printf calls to handle.
if (Printf == nullptr)
return PreservedAnalyses::all();

// If the pass already ran on this module it created the "_cl_print_str"
// helper, whose body contains the only remaining printf("%c", ...) call.
// In that case the single printf use is already in the lowered (constant
// address space) form and there is nothing more to do. We must NOT use a
// bare "getNumUses() == 1" test here: a module with exactly one *genuine*
// printf call and no _cl_print_str yet (e.g. only the device-side
// __assert_fail printf) also has a single use, and skipping it would leave
// the format string in a non-constant address space. That forces the
// SPIR-V translator to emit SPV_EXT_relaxed_printf_string_address_space,
// which the consumer (e.g. IGC) then rejects at module load time.
if (Mod.getNamedValue(ORIG_PRINT_STRING_FUNC_NAME) != nullptr &&
Printf->getNumUses() == 1)
return PreservedAnalyses::all();
LLVM_DEBUG(dbgs() << "Found printf decl: "; Printf->dump());

Expand Down
12 changes: 11 additions & 1 deletion samples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,19 @@ include(mkl_and_icpx)
# Add samples that depend on Intel's oneAPI compiler - if available.
if (SYCL_AVAILABLE)
list(APPEND SAMPLES sycl_hip_interop)
if (LevelZero_LIBRARY)
# The hip_sycl_interop[_no_buffers] samples link their executables with
# -fsycl using chipStar's clang++ (not icpx). Starting with LLVM 23 the
# upstream -fsycl driver makes clang-linker-wrapper pull in libLLVMSYCL.so,
# which is only produced by an LLVM build that enables the SYCL project.
# chipStar's LLVM is built with LLVM_ENABLE_PROJECTS="clang;clang-tools-extra"
# (no SYCL), so the library does not exist and the link fails. Only build
# these -fsycl-linked samples on LLVM < 23.
if (LevelZero_LIBRARY AND LLVM_VERSION_MAJOR LESS 23)
list(APPEND SAMPLES hip_sycl_interop)
list(APPEND SAMPLES hip_sycl_interop_no_buffers)
elseif (LevelZero_LIBRARY)
message(STATUS "LLVM ${LLVM_VERSION_MAJOR}: not building hip_sycl_interop[_no_buffers] "
"(-fsycl link requires libLLVMSYCL.so, not provided by chipStar's LLVM build)")
endif()

else()
Expand Down
Loading
Loading