diff --git a/devops/dependencies.json b/devops/dependencies.json index d1e75343fc7e0..3a2e17d5abdd0 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_tag": "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..3ba466a0fcd7e 100755 --- a/devops/scripts/install_drivers.sh +++ b/devops/scripts/install_drivers.sh @@ -1,5 +1,4 @@ #!/bin/bash - set -e set -x set -o pipefail @@ -52,8 +51,62 @@ function get_pre_release_igfx() { 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 + + WORK_DIR="/tmp/igc-download" + mkdir -p "$WORK_DIR" + cd "$WORK_DIR" + + curl -L -H "$HEADER" -H "Accept: application/vnd.github.v3+json" "$URL" -o "$HASH.zip" + + unzip "$HASH.zip" + 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 build_level_zero_from_source() { + COMMIT=$1 + + apt-get update -qq + apt-get install -y build-essential cmake git libc6-dev linux-libc-dev + + 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 + + git clone https://github.com/oneapi-src/level-zero.git + + cd level-zero + git checkout $COMMIT + + mkdir build + cd build + + cmake .. \ + -DCMAKE_BUILD_TYPE=Release \ + -DCMAKE_INSTALL_PREFIX=/usr/local \ + -DLEVEL_ZERO_BUILD_TESTS=OFF \ + -DLEVEL_ZERO_BUILD_SAMPLES=OFF + + make -j$(nproc) + make install DESTDIR=$INSTALL_DIR + + cp -r $INSTALL_DIR/usr/local/* /usr/local/ + + ldconfig + + rm -rf $BUILD_DIR $INSTALL_DIR + + echo "Level Zero built and installed successfully from commit $COMMIT" } TBB_INSTALLED=false @@ -96,6 +149,15 @@ CheckIGCdevTag() { fi } +CheckIfCommitHash() { + local arg="$1" + 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 +184,28 @@ 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 + 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 +214,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 +283,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/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/cmake/FetchLevelZero.cmake b/unified-runtime/cmake/FetchLevelZero.cmake index 7997e99c6964f..518c34730836f 100644 --- a/unified-runtime/cmake/FetchLevelZero.cmake +++ b/unified-runtime/cmake/FetchLevelZero.cmake @@ -12,8 +12,11 @@ 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) +string(LENGTH "${UR_LEVEL_ZERO_LOADER_TAG}" TAG_LENGTH) +string(REGEX MATCH "^[0-9a-fA-F]+$" IS_HEX "${UR_LEVEL_ZERO_LOADER_TAG}") + +if(PkgConfig_FOUND AND NOT (TAG_LENGTH EQUAL 40 AND IS_HEX)) + 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}") @@ -50,7 +53,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/device.cpp b/unified-runtime/source/adapters/level_zero/device.cpp index 5b117e62a42b0..9e9e6e3c7fc3a 100644 --- a/unified-runtime/source/adapters/level_zero/device.cpp +++ b/unified-runtime/source/adapters/level_zero/device.cpp @@ -1667,6 +1667,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/command_list_manager.cpp b/unified-runtime/source/adapters/level_zero/v2/command_list_manager.cpp index 142caaecc1a71..cb8413ac4b3fd 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 @@ -36,16 +36,26 @@ ur_result_t ur_command_list_manager::appendGenericFillUnlocked( hDevice.get(), ur_mem_buffer_t::device_access_mode_t::read_only, offset, size, zeCommandList.get(), waitListView)); + // Store pattern in event if this is an async operation + // This prevents use-after-return bug when pPattern points to stack memory + const void *patternPtr = pPattern; + if (phEvent && zeSignalEvent) { + phEvent->retainFillPattern(pPattern, patternSize); + patternPtr = phEvent->getFillPattern(); + } + // 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, + (zeCommandList.get(), pDst, patternPtr, patternSize, size, zeSignalEvent, waitListView.num, waitListView.handles)); } else { // Copy pattern into every entry in memory array pointed by Ptr. uint32_t numOfCopySteps = size / patternSize; - const void *src = pPattern; + const void *src = patternPtr; for (uint32_t step = 0; step < numOfCopySteps; ++step) { void *dst = reinterpret_cast(reinterpret_cast(pDst) + diff --git a/unified-runtime/source/adapters/level_zero/v2/context.cpp b/unified-runtime/source/adapters/level_zero/v2/context.cpp index 3d2a7758d6be4..3d7c6571a0b75 100644 --- a/unified-runtime/source/adapters/level_zero/v2/context.cpp +++ b/unified-runtime/source/adapters/level_zero/v2/context.cpp @@ -80,11 +80,20 @@ 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); + // 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]( diff --git a/unified-runtime/source/adapters/level_zero/v2/event.cpp b/unified-runtime/source/adapters/level_zero/v2/event.cpp index 7151e10a4be8a..baeebd536e274 100644 --- a/unified-runtime/source/adapters/level_zero/v2/event.cpp +++ b/unified-runtime/source/adapters/level_zero/v2/event.cpp @@ -141,12 +141,41 @@ uint64_t ur_event_handle_t_::getEventEndTimestamp() { return profilingData.getEventEndTimestamp(); } +void ur_event_handle_t_::retainFillPattern(const void *pPattern, size_t patternSize) { + if (!fillPattern) { + fillPattern.emplace(); + } + + auto &storage = fillPattern.value(); + storage.size = patternSize; + + // Small buffer optimization: use inline buffer for patterns <= 16 bytes + if (patternSize <= FillPatternStorage::INLINE_SIZE) { + std::memcpy(storage.inlineBuffer.data(), pPattern, patternSize); + storage.useHeap = false; + } else { + // Use heap buffer for larger patterns + storage.heapBuffer.resize(patternSize); + std::memcpy(storage.heapBuffer.data(), pPattern, patternSize); + storage.useHeap = true; + } +} + +const void *ur_event_handle_t_::getFillPattern() const { + if (!fillPattern) { + return nullptr; + } + return fillPattern->data(); +} + void ur_event_handle_t_::reset() { // consider make an abstraction for regular/counter based // events if there's more of this type of conditions if (!(flags & v2::EVENT_FLAGS_COUNTER)) { zeEventHostReset(getZeEvent()); } + // Clear the fill pattern to avoid memory leak when event is reused from pool + fillPattern.reset(); } ze_event_handle_t ur_event_handle_t_::getZeEvent() const { diff --git a/unified-runtime/source/adapters/level_zero/v2/event.hpp b/unified-runtime/source/adapters/level_zero/v2/event.hpp index 98b3b98c3ce1f..6122b9f54902a 100644 --- a/unified-runtime/source/adapters/level_zero/v2/event.hpp +++ b/unified-runtime/source/adapters/level_zero/v2/event.hpp @@ -9,7 +9,10 @@ //===----------------------------------------------------------------------===// #pragma once +#include +#include #include +#include #include #include @@ -83,6 +86,12 @@ struct ur_event_handle_t_ : ur_object { // deffered events list in the queue ur_result_t releaseDeferred(); + // Store pattern data for USM fill commands to keep it alive + void retainFillPattern(const void *pPattern, size_t patternSize); + + // Get pointer to the retained fill pattern data + const void *getFillPattern() const; + // Tells if this event was created as a timestamp event, allowing profiling // info even if profiling is not enabled. bool isTimestamped() const; @@ -135,4 +144,20 @@ struct ur_event_handle_t_ : ur_object { v2::event_flags_t flags; event_profiling_data_t profilingData; + + // Storage for fill pattern to keep it alive during async execution + // Uses std::optional to avoid overhead for non-fill events + // Small buffer optimization: patterns ≤16 bytes use inline storage + struct FillPatternStorage { + static constexpr size_t INLINE_SIZE = 16; + std::array inlineBuffer; + std::vector heapBuffer; + size_t size = 0; + bool useHeap = false; + + const void* data() const { + return useHeap ? heapBuffer.data() : inlineBuffer.data(); + } + }; + std::optional fillPattern; }; 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..663c5923057c3 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,38 @@ 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 |= ZEX_COUNTER_BASED_EVENT_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; + + // 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 - 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 +83,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); diff --git a/unified-runtime/source/loader/layers/sanitizer/sanitizer_common/sanitizer_utils.hpp b/unified-runtime/source/loader/layers/sanitizer/sanitizer_common/sanitizer_utils.hpp index 1f0f250a9453d..4bf3ab2273f2f 100644 --- a/unified-runtime/source/loader/layers/sanitizer/sanitizer_common/sanitizer_utils.hpp +++ b/unified-runtime/source/loader/layers/sanitizer/sanitizer_common/sanitizer_utils.hpp @@ -75,8 +75,28 @@ ur_result_t EnqueueUSMSet(ur_queue_handle_t Queue, void *Ptr, T Value, const ur_event_handle_t *EventWaitList = nullptr, ur_event_handle_t *OutEvent = nullptr) { assert(Size % sizeof(T) == 0); - return getContext()->urDdiTable.Enqueue.pfnUSMFill( - Queue, Ptr, sizeof(T), &Value, Size, NumEvents, EventWaitList, OutEvent); + ur_event_handle_t LocalEvent = nullptr; + ur_event_handle_t *EventStorage = OutEvent ? OutEvent : &LocalEvent; + + auto Result = getContext()->urDdiTable.Enqueue.pfnUSMFill( + Queue, Ptr, sizeof(T), &Value, Size, NumEvents, EventWaitList, + EventStorage); + if (Result != UR_RESULT_SUCCESS) { + return Result; + } + + if (!OutEvent && LocalEvent) { + auto WaitResult = getContext()->urDdiTable.Event.pfnWait(1, &LocalEvent); + auto ReleaseResult = getContext()->urDdiTable.Event.pfnRelease(LocalEvent); + if (WaitResult != UR_RESULT_SUCCESS) { + return WaitResult; + } + if (ReleaseResult != UR_RESULT_SUCCESS) { + return ReleaseResult; + } + } + + return Result; } void PrintUrBuildLogIfError(ur_result_t Result, ur_program_handle_t Program, diff --git a/unified-runtime/test/adapters/level_zero/v2/event_pool_test.cpp b/unified-runtime/test/adapters/level_zero/v2/event_pool_test.cpp index 2de31b830895a..94dc41111a2c0 100644 --- a/unified-runtime/test/adapters/level_zero/v2/event_pool_test.cpp +++ b/unified-runtime/test/adapters/level_zero/v2/event_pool_test.cpp @@ -136,8 +136,8 @@ struct EventPoolTest : public uur::urQueueTestWithParam { // the provider switch (params.provider) { case TEST_PROVIDER_COUNTER: - return std::make_unique(platform, context, - device); + return std::make_unique( + platform, context, params.queue, device, flags); case TEST_PROVIDER_NORMAL: return std::make_unique(context, params.queue, flags);