From ad8010b7ac975bcd0520b9a0bd802d8e39eb647e Mon Sep 17 00:00:00 2001 From: Igor Chorazewicz Date: Mon, 18 Aug 2025 20:22:57 +0000 Subject: [PATCH 1/6] [SYCL][UR][L0 v2] use counter based provider for immediate queue It offers better performance (no need to create event pools) --- .../source/adapters/level_zero/v2/context.cpp | 11 +++-- .../adapters/level_zero/v2/event_provider.hpp | 5 +++ .../level_zero/v2/event_provider_counter.cpp | 43 ++++++++++++++----- .../level_zero/v2/event_provider_counter.hpp | 11 +++-- .../level_zero/v2/event_provider_normal.cpp | 3 +- .../level_zero/v2/event_provider_normal.hpp | 6 +-- 6 files changed, 54 insertions(+), 25 deletions(-) diff --git a/unified-runtime/source/adapters/level_zero/v2/context.cpp b/unified-runtime/source/adapters/level_zero/v2/context.cpp index 3d2a7758d6be4..acd84bf36015e 100644 --- a/unified-runtime/source/adapters/level_zero/v2/context.cpp +++ b/unified-runtime/source/adapters/level_zero/v2/context.cpp @@ -80,11 +80,14 @@ ur_context_handle_t_::ur_context_handle_t_(ze_context_handle_t hContext, phDevices[0]->Platform->ZeMutableCmdListExt.Supported}), eventPoolCacheImmediate( this, phDevices[0]->Platform->getNumDevices(), - [context = this](DeviceId /* deviceId*/, v2::event_flags_t flags) - -> std::unique_ptr { + [context = this, platform = phDevices[0]->Platform]( + DeviceId deviceId, + v2::event_flags_t flags) -> std::unique_ptr { + auto device = platform->getDeviceById(deviceId); + // TODO: just use per-context id? - return std::make_unique( - context, v2::QUEUE_IMMEDIATE, flags); + return std::make_unique( + platform, context, v2::QUEUE_IMMEDIATE, device, flags); }), eventPoolCacheRegular(this, phDevices[0]->Platform->getNumDevices(), [context = this, platform = phDevices[0]->Platform]( diff --git a/unified-runtime/source/adapters/level_zero/v2/event_provider.hpp b/unified-runtime/source/adapters/level_zero/v2/event_provider.hpp index c6bedb8fc1cf8..2c7529d6cb288 100644 --- a/unified-runtime/source/adapters/level_zero/v2/event_provider.hpp +++ b/unified-runtime/source/adapters/level_zero/v2/event_provider.hpp @@ -28,6 +28,11 @@ enum event_flag_t { }; static constexpr size_t EVENT_FLAGS_USED_BITS = 2; +enum queue_type { + QUEUE_REGULAR, + QUEUE_IMMEDIATE, +}; + class event_provider; namespace raii { diff --git a/unified-runtime/source/adapters/level_zero/v2/event_provider_counter.cpp b/unified-runtime/source/adapters/level_zero/v2/event_provider_counter.cpp index 886fd53db4b4c..8a94a3131c12d 100644 --- a/unified-runtime/source/adapters/level_zero/v2/event_provider_counter.cpp +++ b/unified-runtime/source/adapters/level_zero/v2/event_provider_counter.cpp @@ -22,9 +22,14 @@ namespace v2 { provider_counter::provider_counter(ur_platform_handle_t platform, ur_context_handle_t context, - ur_device_handle_t device) { + queue_type queueType, + ur_device_handle_t device, + event_flags_t flags) + : queueType(queueType), flags(flags) { + assert(flags & EVENT_FLAGS_COUNTER); + ZE2UR_CALL_THROWS(zeDriverGetExtensionFunctionAddress, - (platform->ZeDriver, "zexCounterBasedEventCreate", + (platform->ZeDriver, "zexCounterBasedEventCreate2", (void **)&this->eventCreateFunc)); ZE2UR_CALL_THROWS(zelLoaderTranslateHandle, (ZEL_HANDLE_CONTEXT, context->getZeHandle(), @@ -34,17 +39,35 @@ provider_counter::provider_counter(ur_platform_handle_t platform, (ZEL_HANDLE_DEVICE, device->ZeDevice, (void **)&translatedDevice)); } +static zex_counter_based_event_exp_flags_t createZeFlags(queue_type queueType, + event_flags_t flags) { + zex_counter_based_event_exp_flags_t zeFlags = + ZEX_COUNTER_BASED_EVENT_FLAG_HOST_VISIBLE; + if (flags & EVENT_FLAGS_PROFILING_ENABLED) { + zeFlags |= ZE_EVENT_POOL_FLAG_KERNEL_TIMESTAMP; + } + + if (queueType == QUEUE_IMMEDIATE) { + zeFlags |= ZEX_COUNTER_BASED_EVENT_FLAG_IMMEDIATE; + } else { + zeFlags |= ZEX_COUNTER_BASED_EVENT_FLAG_NON_IMMEDIATE; + } + + return zeFlags; +} + raii::cache_borrowed_event provider_counter::allocate() { if (freelist.empty()) { - ZeStruct desc; - desc.index = 0; - desc.signal = ZE_EVENT_SCOPE_FLAG_HOST; - desc.wait = 0; + zex_counter_based_event_desc_t desc = {}; + desc.stype = ZEX_STRUCTURE_COUNTER_BASED_EVENT_DESC; + desc.flags = createZeFlags(queueType, flags); + desc.signalScope = ZE_EVENT_SCOPE_FLAG_HOST; + ze_event_handle_t handle; // TODO: allocate host and device buffers to use here - ZE2UR_CALL_THROWS(eventCreateFunc, (translatedContext, translatedDevice, - nullptr, nullptr, 0, &desc, &handle)); + ZE2UR_CALL_THROWS(eventCreateFunc, + (translatedContext, translatedDevice, &desc, &handle)); freelist.emplace_back(handle); } @@ -57,8 +80,6 @@ raii::cache_borrowed_event provider_counter::allocate() { [this](ze_event_handle_t handle) { freelist.push_back(handle); }); } -event_flags_t provider_counter::eventFlags() const { - return EVENT_FLAGS_COUNTER; -} +event_flags_t provider_counter::eventFlags() const { return flags; } } // namespace v2 diff --git a/unified-runtime/source/adapters/level_zero/v2/event_provider_counter.hpp b/unified-runtime/source/adapters/level_zero/v2/event_provider_counter.hpp index bb46cb5daf42b..baa4d5875507a 100644 --- a/unified-runtime/source/adapters/level_zero/v2/event_provider_counter.hpp +++ b/unified-runtime/source/adapters/level_zero/v2/event_provider_counter.hpp @@ -25,22 +25,27 @@ #include "../device.hpp" +#include +#include + namespace v2 { typedef ze_result_t (*zexCounterBasedEventCreate)( ze_context_handle_t hContext, ze_device_handle_t hDevice, - uint64_t *deviceAddress, uint64_t *hostAddress, uint64_t completionValue, - const ze_event_desc_t *desc, ze_event_handle_t *phEvent); + const zex_counter_based_event_desc_t *desc, ze_event_handle_t *phEvent); class provider_counter : public event_provider { public: provider_counter(ur_platform_handle_t platform, ur_context_handle_t, - ur_device_handle_t); + queue_type, ur_device_handle_t, event_flags_t); raii::cache_borrowed_event allocate() override; event_flags_t eventFlags() const override; private: + queue_type queueType; + event_flags_t flags; + ze_context_handle_t translatedContext; ze_device_handle_t translatedDevice; diff --git a/unified-runtime/source/adapters/level_zero/v2/event_provider_normal.cpp b/unified-runtime/source/adapters/level_zero/v2/event_provider_normal.cpp index 6239f3f5f7412..06267059dc91b 100644 --- a/unified-runtime/source/adapters/level_zero/v2/event_provider_normal.cpp +++ b/unified-runtime/source/adapters/level_zero/v2/event_provider_normal.cpp @@ -17,9 +17,8 @@ #include "event_provider.hpp" #include "event_provider_normal.hpp" -#include "../common/latency_tracker.hpp" - #include "../common.hpp" +#include "../common/latency_tracker.hpp" namespace v2 { static constexpr int EVENTS_BURST = 64; diff --git a/unified-runtime/source/adapters/level_zero/v2/event_provider_normal.hpp b/unified-runtime/source/adapters/level_zero/v2/event_provider_normal.hpp index 811b32f2e23f8..df6946e7ac580 100644 --- a/unified-runtime/source/adapters/level_zero/v2/event_provider_normal.hpp +++ b/unified-runtime/source/adapters/level_zero/v2/event_provider_normal.hpp @@ -21,17 +21,13 @@ #include "common.hpp" #include "event.hpp" +#include "event_provider.hpp" #include "../device.hpp" #include "../ur_interface_loader.hpp" namespace v2 { -enum queue_type { - QUEUE_REGULAR, - QUEUE_IMMEDIATE, -}; - class provider_pool { public: provider_pool(ur_context_handle_t, queue_type, event_flags_t flags); From c1b18b3c79640fd8f04c334c63c1041fc8d8d71e Mon Sep 17 00:00:00 2001 From: "Mateusz P. Nowak" Date: Fri, 26 Sep 2025 12:53:24 +0000 Subject: [PATCH 2/6] fix flags in cb event provider --- sycl/test-e2e/Adapters/level_zero/queue_profiling.cpp | 4 ++-- .../source/adapters/level_zero/v2/event_provider_counter.cpp | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/sycl/test-e2e/Adapters/level_zero/queue_profiling.cpp b/sycl/test-e2e/Adapters/level_zero/queue_profiling.cpp index 0673d55886c57..31eac0ea6a7d9 100644 --- a/sycl/test-e2e/Adapters/level_zero/queue_profiling.cpp +++ b/sycl/test-e2e/Adapters/level_zero/queue_profiling.cpp @@ -10,12 +10,12 @@ // clang-format off // Check the expected output when queue::enable_profiling is not specified // -// WITHOUT: ze_event_pool_desc_t flags set to: 1 +// WITHOUT: {{ze_event_pool_desc_t flags set to: 1|zex_counter_based_event_desc_t flags set to: 5}} // WITHOUT: SYCL exception caught: Profiling information is unavailable as the queue associated with the event does not have the 'enable_profiling' property. // Check the expected output when queue::enable_profiling is specified // -// WITH: ze_event_pool_desc_t flags set to: 5 +// WITH: {{ze_event_pool_desc_t flags set to: 5|zex_counter_based_event_desc_t flags set to: 21}} // WITH: Device kernel time: // clang-format on // diff --git a/unified-runtime/source/adapters/level_zero/v2/event_provider_counter.cpp b/unified-runtime/source/adapters/level_zero/v2/event_provider_counter.cpp index 8a94a3131c12d..8f7b0c8d32f36 100644 --- a/unified-runtime/source/adapters/level_zero/v2/event_provider_counter.cpp +++ b/unified-runtime/source/adapters/level_zero/v2/event_provider_counter.cpp @@ -44,7 +44,7 @@ static zex_counter_based_event_exp_flags_t createZeFlags(queue_type queueType, zex_counter_based_event_exp_flags_t zeFlags = ZEX_COUNTER_BASED_EVENT_FLAG_HOST_VISIBLE; if (flags & EVENT_FLAGS_PROFILING_ENABLED) { - zeFlags |= ZE_EVENT_POOL_FLAG_KERNEL_TIMESTAMP; + zeFlags |= ZEX_COUNTER_BASED_EVENT_FLAG_KERNEL_TIMESTAMP; } if (queueType == QUEUE_IMMEDIATE) { @@ -63,6 +63,8 @@ raii::cache_borrowed_event provider_counter::allocate() { desc.flags = createZeFlags(queueType, flags); desc.signalScope = ZE_EVENT_SCOPE_FLAG_HOST; + // Enhanced debug output to validate control flow integrity + UR_LOG(DEBUG, "zex_counter_based_event_desc_t flags set to: {}", desc.flags); ze_event_handle_t handle; // TODO: allocate host and device buffers to use here From 6e8c857a153ae2d8f5cd3678f37f91e6828d1e34 Mon Sep 17 00:00:00 2001 From: "Mateusz P. Nowak" Date: Tue, 7 Oct 2025 13:55:44 +0000 Subject: [PATCH 3/6] fix zeCommandListAppendMemoryFill bug Signed-off-by: Mateusz P. Nowak --- .../source/adapters/level_zero/v2/command_list_manager.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/unified-runtime/source/adapters/level_zero/v2/command_list_manager.cpp b/unified-runtime/source/adapters/level_zero/v2/command_list_manager.cpp index 142caaecc1a71..c8475dfdef8a4 100644 --- a/unified-runtime/source/adapters/level_zero/v2/command_list_manager.cpp +++ b/unified-runtime/source/adapters/level_zero/v2/command_list_manager.cpp @@ -38,7 +38,9 @@ ur_result_t ur_command_list_manager::appendGenericFillUnlocked( // PatternSize must be a power of two for zeCommandListAppendMemoryFill. // When it's not, the fill is emulated with zeCommandListAppendMemoryCopy. - if (isPowerOf2(patternSize)) { + // WORKAROUND: Level Zero driver rejects zeCommandListAppendMemoryFill when + // patternSize == size, returning ZE_RESULT_ERROR_INVALID_SIZE (0x78000008). + if (isPowerOf2(patternSize) && patternSize != size) { ZE2UR_CALL(zeCommandListAppendMemoryFill, (zeCommandList.get(), pDst, pPattern, patternSize, size, zeSignalEvent, waitListView.num, waitListView.handles)); From c10bbaf06f429b018351f9ce9cb6ba2f601c00d9 Mon Sep 17 00:00:00 2001 From: "Mateusz P. Nowak" Date: Tue, 7 Oct 2025 13:55:44 +0000 Subject: [PATCH 4/6] fix zeCommandListAppendMemoryFill bug Signed-off-by: Mateusz P. Nowak --- unified-runtime/cmake/FetchLevelZero.cmake | 4 +++- .../source/adapters/level_zero/v2/command_list_manager.cpp | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/unified-runtime/cmake/FetchLevelZero.cmake b/unified-runtime/cmake/FetchLevelZero.cmake index 7997e99c6964f..3aa51ed1777eb 100644 --- a/unified-runtime/cmake/FetchLevelZero.cmake +++ b/unified-runtime/cmake/FetchLevelZero.cmake @@ -50,7 +50,9 @@ if(NOT LEVEL_ZERO_LIB_NAME AND NOT LEVEL_ZERO_LIBRARY) set(UR_LEVEL_ZERO_LOADER_REPO "https://github.com/oneapi-src/level-zero.git") # Remember to update the pkg_check_modules minimum version above when updating the # clone tag - set(UR_LEVEL_ZERO_LOADER_TAG v1.24.3) + # set(UR_LEVEL_ZERO_LOADER_TAG v1.24.3) + # commit of updated leak checker (PR#376) + set(UR_LEVEL_ZERO_LOADER_TAG 5187acd1c0f34097658f6ed890f1e5a65bdc35b9) # Disable due to a bug https://github.com/oneapi-src/level-zero/issues/104 set(CMAKE_INCLUDE_CURRENT_DIR OFF) diff --git a/unified-runtime/source/adapters/level_zero/v2/command_list_manager.cpp b/unified-runtime/source/adapters/level_zero/v2/command_list_manager.cpp index 142caaecc1a71..c8475dfdef8a4 100644 --- a/unified-runtime/source/adapters/level_zero/v2/command_list_manager.cpp +++ b/unified-runtime/source/adapters/level_zero/v2/command_list_manager.cpp @@ -38,7 +38,9 @@ ur_result_t ur_command_list_manager::appendGenericFillUnlocked( // PatternSize must be a power of two for zeCommandListAppendMemoryFill. // When it's not, the fill is emulated with zeCommandListAppendMemoryCopy. - if (isPowerOf2(patternSize)) { + // WORKAROUND: Level Zero driver rejects zeCommandListAppendMemoryFill when + // patternSize == size, returning ZE_RESULT_ERROR_INVALID_SIZE (0x78000008). + if (isPowerOf2(patternSize) && patternSize != size) { ZE2UR_CALL(zeCommandListAppendMemoryFill, (zeCommandList.get(), pDst, pPattern, patternSize, size, zeSignalEvent, waitListView.num, waitListView.handles)); From 265ab3f30345aecdab883595bd47576f9d9ae61a Mon Sep 17 00:00:00 2001 From: "Mateusz P. Nowak" Date: Thu, 9 Oct 2025 08:10:10 +0000 Subject: [PATCH 5/6] check if driver supports cb events --- unified-runtime/source/adapters/level_zero/device.cpp | 2 ++ .../source/adapters/level_zero/v2/context.cpp | 10 ++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/unified-runtime/source/adapters/level_zero/device.cpp b/unified-runtime/source/adapters/level_zero/device.cpp index 40ab701312292..7a689a1fd1b61 100644 --- a/unified-runtime/source/adapters/level_zero/device.cpp +++ b/unified-runtime/source/adapters/level_zero/device.cpp @@ -1665,6 +1665,8 @@ ur_result_t urDeviceCreateWithNativeHandle( ur_device_handle_t Dev = nullptr; for (const auto &p : GlobalAdapter->Platforms) { Dev = p->getDeviceFromNativeHandle(ZeDevice); + if (Dev) + break; } if (Dev == nullptr) diff --git a/unified-runtime/source/adapters/level_zero/v2/context.cpp b/unified-runtime/source/adapters/level_zero/v2/context.cpp index acd84bf36015e..3d7c6571a0b75 100644 --- a/unified-runtime/source/adapters/level_zero/v2/context.cpp +++ b/unified-runtime/source/adapters/level_zero/v2/context.cpp @@ -86,8 +86,14 @@ ur_context_handle_t_::ur_context_handle_t_(ze_context_handle_t hContext, auto device = platform->getDeviceById(deviceId); // TODO: just use per-context id? - return std::make_unique( - platform, context, v2::QUEUE_IMMEDIATE, device, flags); + // Use counter-based events only if the extension is available + if (platform->ZeDriverEventPoolCountingEventsExtensionFound) { + return std::make_unique( + platform, context, v2::QUEUE_IMMEDIATE, device, flags); + } else { + return std::make_unique( + context, v2::QUEUE_IMMEDIATE, flags); + } }), eventPoolCacheRegular(this, phDevices[0]->Platform->getNumDevices(), [context = this, platform = phDevices[0]->Platform]( From e3f8aba880ba20a6d60b7a8a26ed224eb558407c Mon Sep 17 00:00:00 2001 From: "Mateusz P. Nowak" Date: Thu, 9 Oct 2025 12:10:01 +0000 Subject: [PATCH 6/6] fix l0 loader version Signed-off-by: Mateusz P. Nowak --- devops/dependencies.json | 6 +- devops/scripts/install_drivers.sh | 250 +++++++++++++++++++-- unified-runtime/cmake/FetchLevelZero.cmake | 38 ++-- 3 files changed, 254 insertions(+), 40 deletions(-) diff --git a/devops/dependencies.json b/devops/dependencies.json index d1e75343fc7e0..d2da2ea1d6353 100644 --- a/devops/dependencies.json +++ b/devops/dependencies.json @@ -19,9 +19,9 @@ "root": "{DEPS_ROOT}/opencl/runtime/linux/oclgpu" }, "level_zero": { - "github_tag": "v1.24.2", + "github_commit": "5187acd1c0f34097658f6ed890f1e5a65bdc35b9", "version": "v1.24.2", - "url": "https://github.com/oneapi-src/level-zero/releases/tag/v1.24.2", + "url": "https://github.com/oneapi-src/level-zero/commit/5187acd1c0f34097658f6ed890f1e5a65bdc35b9", "root": "{DEPS_ROOT}/opencl/runtime/linux/oclgpu" }, "tbb": { @@ -56,4 +56,4 @@ "root": "{DEPS_ROOT}/opencl/runtime/linux/oclcpu" } } -} +} \ No newline at end of file diff --git a/devops/scripts/install_drivers.sh b/devops/scripts/install_drivers.sh index 5aef43582d219..fe33b1e2cdbbc 100755 --- a/devops/scripts/install_drivers.sh +++ b/devops/scripts/install_drivers.sh @@ -1,5 +1,5 @@ #!/bin/bash - +# UPDATED FOR LEVEL-ZERO COMMIT BUILD - $(date) set -e set -x set -o pipefail @@ -10,7 +10,7 @@ if [ -f "$1" ]; then CR_TAG=$(jq -r '.linux.compute_runtime.github_tag' $CONFIG_FILE) IGC_TAG=$(jq -r '.linux.igc.github_tag' $CONFIG_FILE) CM_TAG=$(jq -r '.linux.cm.github_tag' $CONFIG_FILE) - L0_TAG=$(jq -r '.linux.level_zero.github_tag' $CONFIG_FILE) + L0_TAG=$(jq -r '.linux.level_zero.github_tag // .linux.level_zero.github_commit' $CONFIG_FILE) TBB_TAG=$(jq -r '.linux.tbb.github_tag' $CONFIG_FILE) FPGA_TAG=$(jq -r '.linux.fpgaemu.github_tag' $CONFIG_FILE) CPU_TAG=$(jq -r '.linux.oclcpu.github_tag' $CONFIG_FILE) @@ -48,12 +48,162 @@ function get_release() { function get_pre_release_igfx() { URL=$1 HASH=$2 + echo "*** USING UPDATED get_pre_release_igfx FUNCTION - COMMIT: $(date) ***" HEADER="" if [ "$GITHUB_TOKEN" != "" ]; then HEADER="Authorization: Bearer $GITHUB_TOKEN" fi - curl -L -H "$HEADER" -H "Accept: application/vnd.github.v3+json" $URL -o $HASH.zip - unzip $HASH.zip && rm $HASH.zip + + # Ensure we're in a writable directory + WORK_DIR="/tmp/igc-download" + mkdir -p "$WORK_DIR" + cd "$WORK_DIR" + + echo "=== NEW IGC DOWNLOAD FUNCTION - Downloading IGC dev package to $WORK_DIR ===" + if ! curl -L -H "$HEADER" -H "Accept: application/vnd.github.v3+json" "$URL" -o "$HASH.zip"; then + echo "ERROR: Failed to download IGC dev package" + return 1 + fi + + if [ ! -f "$HASH.zip" ]; then + echo "ERROR: Downloaded file $HASH.zip not found" + return 1 + fi + + echo "Extracting IGC dev package" + if ! unzip "$HASH.zip"; then + echo "ERROR: Failed to extract $HASH.zip" + return 1 + fi + + rm "$HASH.zip" + + # Move deb files back to the calling directory if any exist + if ls *.deb 1> /dev/null 2>&1; then + mv *.deb /tmp/ + cd /tmp/ + fi + + # Clean up work directory + rm -rf "$WORK_DIR" +} + +function get_commit_artifacts() { + REPO=$1 + COMMIT=$2 + HEADER="" + if [ "$GITHUB_TOKEN" != "" ]; then + HEADER="Authorization: Bearer $GITHUB_TOKEN" + fi + # Get artifacts from GitHub Actions for the specific commit + curl -s -L -H "$HEADER" -H "Accept: application/vnd.github.v3+json" \ + "https://api.github.com/repos/${REPO}/actions/runs?head_sha=${COMMIT}&status=completed&per_page=1" \ + | jq -r '.workflow_runs[0] | select(.conclusion == "success") | .id' \ + | head -1 \ + | xargs -I {} curl -s -L -H "$HEADER" -H "Accept: application/vnd.github.v3+json" \ + "https://api.github.com/repos/${REPO}/actions/runs/{}/artifacts" \ + | jq -r '.artifacts[] | select(.name | test(".*deb.*")) | .archive_download_url' +} + +function download_commit_artifacts() { + REPO=$1 + COMMIT=$2 + UBUNTU_VER=$3 + HEADER="" + if [ "$GITHUB_TOKEN" != "" ]; then + HEADER="Authorization: Bearer $GITHUB_TOKEN" + fi + + echo "Downloading artifacts for commit $COMMIT from $REPO" + get_commit_artifacts $REPO $COMMIT | while read -r artifact_url; do + if [ -n "$artifact_url" ]; then + echo "Downloading artifact: $artifact_url" + curl -L -H "$HEADER" "$artifact_url" -o "artifact-$(basename $artifact_url).zip" + unzip -j "artifact-$(basename $artifact_url).zip" "*.deb" 2>/dev/null || true + rm "artifact-$(basename $artifact_url).zip" + fi + done +} + +function build_level_zero_from_source() { + COMMIT=$1 + + echo "Building Level Zero from source at commit $COMMIT" + + # Install build dependencies if not already present + echo "Ensuring build dependencies are available..." + apt-get update -qq + apt-get install -y build-essential cmake git libc6-dev linux-libc-dev + + # Check CMake version (Level Zero requires CMake 3.5+) + CMAKE_VERSION=$(cmake --version | head -n1 | sed 's/.*cmake version \([0-9]\+\.[0-9]\+\).*/\1/') + echo "CMake version: $CMAKE_VERSION" + + # Create temporary build directory + BUILD_DIR="/tmp/level-zero-build" + INSTALL_DIR="/tmp/level-zero-install" + rm -rf $BUILD_DIR $INSTALL_DIR + mkdir -p $BUILD_DIR $INSTALL_DIR + cd $BUILD_DIR + + # Clone and checkout specific commit + echo "Cloning Level Zero repository..." + if ! git clone https://github.com/oneapi-src/level-zero.git; then + echo "ERROR: Failed to clone Level Zero repository" + return 1 + fi + + cd level-zero + if ! git checkout $COMMIT; then + echo "ERROR: Failed to checkout commit $COMMIT" + return 1 + fi + + # Create build directory + mkdir build + cd build + + # Configure build + echo "Configuring Level Zero build..." + if ! cmake .. \ + -DCMAKE_BUILD_TYPE=Release \ + -DCMAKE_INSTALL_PREFIX=/usr/local \ + -DLEVEL_ZERO_BUILD_TESTS=OFF \ + -DLEVEL_ZERO_BUILD_SAMPLES=OFF; then + echo "ERROR: CMake configuration failed" + return 1 + fi + + # Build + echo "Building Level Zero..." + if ! make -j$(nproc); then + echo "ERROR: Build failed" + return 1 + fi + + # Staged install (doesn't affect system) + echo "Creating staged installation..." + if ! make install DESTDIR=$INSTALL_DIR; then + echo "ERROR: Staged installation failed" + return 1 + fi + + # Copy files to their final destinations + echo "Installing Level Zero to system..." + if [ -d "$INSTALL_DIR/usr/local" ]; then + cp -r $INSTALL_DIR/usr/local/* /usr/local/ + else + echo "ERROR: Staged installation directory not found" + return 1 + fi + + # Update library cache + ldconfig + + # Clean up build and install directories + rm -rf $BUILD_DIR $INSTALL_DIR + + echo "Level Zero built and installed successfully from commit $COMMIT" } TBB_INSTALLED=false @@ -96,6 +246,16 @@ CheckIGCdevTag() { fi } +CheckIfCommitHash() { + local arg="$1" + # Check if it's a 40-character hex string (SHA-1 commit hash) + if [[ $arg =~ ^[a-f0-9]{40}$ ]]; then + echo "Yes" + else + echo "No" + fi +} + InstallIGFX () { echo "Installing Intel Graphics driver..." echo "Compute Runtime version $CR_TAG" @@ -122,10 +282,29 @@ InstallIGFX () { | grep ".*deb" \ | grep -v "u18" \ | wget -qi - - get_release oneapi-src/level-zero $L0_TAG \ - | grep ".*$UBUNTU_VER.*deb$" \ - | wget -qi - - dpkg -i --force-all *.deb && rm *.deb *.sum + + # Check if L0_TAG is a commit hash or a regular tag + IS_L0_COMMIT=$(CheckIfCommitHash $L0_TAG) + if [ "$IS_L0_COMMIT" == "Yes" ]; then + echo "Level Zero is using commit hash, building from source..." + if ! build_level_zero_from_source $L0_TAG; then + echo "ERROR: Failed to build Level Zero from source" + exit 1 + fi + # Install other packages (Level Zero was already installed from source) + if ls *.deb 1> /dev/null 2>&1; then + dpkg -i --force-all *.deb && rm *.deb + fi + if ls *.sum 1> /dev/null 2>&1; then + rm *.sum + fi + else + get_release oneapi-src/level-zero $L0_TAG \ + | grep ".*$UBUNTU_VER.*deb$" \ + | wget -qi - + # Install all packages including Level Zero + dpkg -i --force-all *.deb && rm *.deb *.sum + fi mkdir -p /usr/local/lib/igc/ echo "$IGC_TAG" > /usr/local/lib/igc/IGCTAG.txt if [ "$IS_IGC_DEV" == "Yes" ]; then @@ -134,22 +313,56 @@ InstallIGFX () { # Backup and install it from release igc as a temporarily workaround # while we working to resolve the issue. echo "Backup libopencl-clang" - cp -d /usr/local/lib/libopencl-clang2.so.15* . + + # Ensure we're in a writable directory for backup operations + BACKUP_DIR="/tmp/igc-backup" + mkdir -p "$BACKUP_DIR" + cd "$BACKUP_DIR" + echo "Working in backup directory: $BACKUP_DIR" + + if ls /usr/local/lib/libopencl-clang2.so.15* 1> /dev/null 2>&1; then + cp -d /usr/local/lib/libopencl-clang2.so.15* . + LIBOPENCL_BACKED_UP=true + echo "Successfully backed up libopencl-clang files" + else + echo "Warning: libopencl-clang2.so.15* not found, skipping backup" + LIBOPENCL_BACKED_UP=false + fi echo "Download IGC dev git hash $IGC_DEV_VER" - get_pre_release_igfx $IGC_DEV_URL $IGC_DEV_VER + if ! get_pre_release_igfx $IGC_DEV_URL $IGC_DEV_VER; then + echo "ERROR: Failed to download IGC dev package" + exit 1 + fi echo "Install IGC dev git hash $IGC_DEV_VER" # New dev IGC packaged iga64 conflicting with iga64 from intel-igc-media # force overwrite to workaround it first. - dpkg -i --force-all *.deb - echo "Install libopencl-clang" - # Workaround only, will download deb and install with dpkg once fixed. - cp -d libopencl-clang2.so.15* /usr/local/lib/ - rm /usr/local/lib/libigc.so /usr/local/lib/libigc.so.1* && \ - ln -s /usr/local/lib/libigc.so.2 /usr/local/lib/libigc.so && \ - ln -s /usr/local/lib/libigc.so.2 /usr/local/lib/libigc.so.1 + if ls *.deb 1> /dev/null 2>&1; then + dpkg -i --force-all *.deb + else + echo "Warning: No IGC dev deb files found after download" + fi + if [ "$LIBOPENCL_BACKED_UP" == "true" ]; then + echo "Install libopencl-clang" + # Workaround only, will download deb and install with dpkg once fixed. + echo "Copying backed up libopencl-clang files from $BACKUP_DIR" + cp -d "$BACKUP_DIR"/libopencl-clang2.so.15* /usr/local/lib/ + fi + if [ -f /usr/local/lib/libigc.so.2 ]; then + rm -f /usr/local/lib/libigc.so /usr/local/lib/libigc.so.1* && \ + ln -s /usr/local/lib/libigc.so.2 /usr/local/lib/libigc.so && \ + ln -s /usr/local/lib/libigc.so.2 /usr/local/lib/libigc.so.1 + fi echo "Clean up" - rm *.deb libopencl-clang2.so.15* + if ls *.deb 1> /dev/null 2>&1; then + rm *.deb + fi echo "$IGC_DEV_TAG" > /usr/local/lib/igc/IGCTAG.txt + + # Clean up backup directory (this also removes the backed up libopencl-clang files) + if [ -d "$BACKUP_DIR" ]; then + echo "Cleaning up backup directory: $BACKUP_DIR" + rm -rf "$BACKUP_DIR" + fi fi } @@ -169,6 +382,7 @@ InstallCPURT () { if [ -e $INSTALL_LOCATION/oclcpu/install.sh ]; then \ bash -x $INSTALL_LOCATION/oclcpu/install.sh else + mkdir -p /etc/OpenCL/vendors echo $INSTALL_LOCATION/oclcpu/x64/libintelocl.so > /etc/OpenCL/vendors/intel_oclcpu.icd fi } diff --git a/unified-runtime/cmake/FetchLevelZero.cmake b/unified-runtime/cmake/FetchLevelZero.cmake index 3aa51ed1777eb..1de2cc0088dbb 100644 --- a/unified-runtime/cmake/FetchLevelZero.cmake +++ b/unified-runtime/cmake/FetchLevelZero.cmake @@ -12,25 +12,25 @@ find_package(PkgConfig QUIET) # LevelZero doesn't install a CMake config target, just PkgConfig, # so try using that to find the install and if it's not available # just try to search for the path. -if(PkgConfig_FOUND) - pkg_check_modules(level-zero level-zero>=1.24.3) - if(level-zero_FOUND) - set(LEVEL_ZERO_INCLUDE_DIR "${level-zero_INCLUDEDIR}/level_zero") - set(LEVEL_ZERO_LIBRARY_SRC "${level-zero_LIBDIR}") - set(LEVEL_ZERO_LIB_NAME "${level-zero_LIBRARIES}") - message(STATUS "Level Zero Adapter: Using preinstalled level zero loader at ${level-zero_LINK_LIBRARIES}") - endif() -else() - set(L0_HEADER_PATH "loader/ze_loader.h") - find_path(L0_HEADER ${L0_HEADER_PATH} ${CMAKE_PREFIX_PATH} PATH_SUFFIXES "level_zero") - find_library(ZE_LOADER NAMES ze_loader HINTS /usr ${CMAKE_PREFIX_PATH}) - if(L0_HEADER AND ZE_LOADER) - set(LEVEL_ZERO_INCLUDE_DIR "${L0_HEADER}") - set(LEVEL_ZERO_LIBRARY "${ZE_LOADER}") - message(STATUS "Level Zero Adapter: Using preinstalled level zero loader at ${LEVEL_ZERO_LIBRARY}") - add_library(ze_loader INTERFACE) - endif() -endif() +# if(PkgConfig_FOUND) +# pkg_check_modules(level-zero level-zero>1.24.3) +# if(level-zero_FOUND) +# set(LEVEL_ZERO_INCLUDE_DIR "${level-zero_INCLUDEDIR}/level_zero") +# set(LEVEL_ZERO_LIBRARY_SRC "${level-zero_LIBDIR}") +# set(LEVEL_ZERO_LIB_NAME "${level-zero_LIBRARIES}") +# message(STATUS "Level Zero Adapter: Using preinstalled level zero loader at ${level-zero_LINK_LIBRARIES}") +# endif() +# else() +# set(L0_HEADER_PATH "loader/ze_loader.h") +# find_path(L0_HEADER ${L0_HEADER_PATH} ${CMAKE_PREFIX_PATH} PATH_SUFFIXES "level_zero") +# find_library(ZE_LOADER NAMES ze_loader HINTS /usr ${CMAKE_PREFIX_PATH}) +# if(L0_HEADER AND ZE_LOADER) +# set(LEVEL_ZERO_INCLUDE_DIR "${L0_HEADER}") +# set(LEVEL_ZERO_LIBRARY "${ZE_LOADER}") +# message(STATUS "Level Zero Adapter: Using preinstalled level zero loader at ${LEVEL_ZERO_LIBRARY}") +# add_library(ze_loader INTERFACE) +# endif() +# endif() if(NOT LEVEL_ZERO_LIB_NAME AND NOT LEVEL_ZERO_LIBRARY) message(STATUS "Level Zero Adapter: Download Level Zero loader and headers from github.com")