From da7667f8bea5ab6ef7a1a3545c6db571f1750ab2 Mon Sep 17 00:00:00 2001 From: "Neil R. Spruit" Date: Mon, 8 Jul 2024 13:33:20 -0700 Subject: [PATCH 1/2] Merge pull request #1806 from againull/review/againull/fix_overflow [UR][L0] Fix undefined behavior caused by shifting more than bits count --- source/adapters/level_zero/device.cpp | 3 +-- source/adapters/level_zero/device.hpp | 6 ++++++ source/adapters/level_zero/event.cpp | 3 +-- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/source/adapters/level_zero/device.cpp b/source/adapters/level_zero/device.cpp index b0a5f3fefa..6817c6f2ab 100644 --- a/source/adapters/level_zero/device.cpp +++ b/source/adapters/level_zero/device.cpp @@ -1514,8 +1514,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetGlobalTimestamps( ) { const uint64_t &ZeTimerResolution = Device->ZeDeviceProperties->timerResolution; - const uint64_t TimestampMaxCount = - ((1ULL << Device->ZeDeviceProperties->kernelTimestampValidBits) - 1ULL); + const uint64_t TimestampMaxCount = Device->getTimestampMask(); uint64_t DeviceClockCount, Dummy; ZE2UR_CALL(zeDeviceGetGlobalTimestamps, diff --git a/source/adapters/level_zero/device.hpp b/source/adapters/level_zero/device.hpp index 3cdfcbce7e..08589d74a4 100644 --- a/source/adapters/level_zero/device.hpp +++ b/source/adapters/level_zero/device.hpp @@ -186,6 +186,12 @@ struct ur_device_handle_t_ : _ur_object { .ZeIndex >= 0; } + uint64_t getTimestampMask() { + auto ValidBits = ZeDeviceProperties->kernelTimestampValidBits; + assert(ValidBits <= 64); + return ValidBits == 64 ? ~0ULL : (1ULL << ValidBits) - 1ULL; + } + // Cache of the immutable device properties. ZeCache> ZeDeviceProperties; ZeCache> ZeDeviceComputeProperties; diff --git a/source/adapters/level_zero/event.cpp b/source/adapters/level_zero/event.cpp index 8ce798aa2d..0619b5b9fc 100644 --- a/source/adapters/level_zero/event.cpp +++ b/source/adapters/level_zero/event.cpp @@ -486,8 +486,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urEventGetProfilingInfo( Event->UrQueue ? Event->UrQueue->Device : Event->Context->Devices[0]; uint64_t ZeTimerResolution = Device->ZeDeviceProperties->timerResolution; - const uint64_t TimestampMaxValue = - ((1ULL << Device->ZeDeviceProperties->kernelTimestampValidBits) - 1ULL); + const uint64_t TimestampMaxValue = Device->getTimestampMask(); UrReturnHelper ReturnValue(PropValueSize, PropValue, PropValueSizeRet); From 394bdaa4f13c18ee137401189a7eeaed8bf34126 Mon Sep 17 00:00:00 2001 From: "Neil R. Spruit" Date: Mon, 8 Jul 2024 13:50:16 -0700 Subject: [PATCH 2/2] Bump version to v0.9.8 Signed-off-by: Neil R. Spruit --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 03768fc7e8..b82a58a4ff 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,7 +4,7 @@ # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception cmake_minimum_required(VERSION 3.14.0 FATAL_ERROR) -project(unified-runtime VERSION 0.9.7) +project(unified-runtime VERSION 0.9.8) include(GNUInstallDirs) include(CheckCXXSourceCompiles)