diff --git a/CMakeLists.txt b/CMakeLists.txt index 3cd58f5c59..c1aebe3b10 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.20.0 FATAL_ERROR) -project(unified-runtime VERSION 0.10.3) +project(unified-runtime VERSION 0.10.4) # Check if unified runtime is built as a standalone project. if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR OR UR_STANDALONE_BUILD) diff --git a/source/adapters/opencl/usm.cpp b/source/adapters/opencl/usm.cpp index 77a2941e0f..58ce4c0fc6 100644 --- a/source/adapters/opencl/usm.cpp +++ b/source/adapters/opencl/usm.cpp @@ -87,6 +87,11 @@ urUSMHostAlloc(ur_context_handle_t hContext, const ur_usm_desc_t *pUSMDesc, void *Ptr = nullptr; uint32_t Alignment = pUSMDesc ? pUSMDesc->align : 0; + if (pUSMDesc && pUSMDesc->align != 0 && + ((pUSMDesc->align & (pUSMDesc->align - 1)) != 0)) { + return UR_RESULT_ERROR_INVALID_VALUE; + } + std::vector AllocProperties; if (pUSMDesc && pUSMDesc->pNext) { UR_RETURN_ON_FAILURE(usmDescToCLMemProperties( @@ -130,6 +135,11 @@ urUSMDeviceAlloc(ur_context_handle_t hContext, ur_device_handle_t hDevice, void *Ptr = nullptr; uint32_t Alignment = pUSMDesc ? pUSMDesc->align : 0; + if (pUSMDesc && pUSMDesc->align != 0 && + ((pUSMDesc->align & (pUSMDesc->align - 1)) != 0)) { + return UR_RESULT_ERROR_INVALID_VALUE; + } + std::vector AllocProperties; if (pUSMDesc && pUSMDesc->pNext) { UR_RETURN_ON_FAILURE(usmDescToCLMemProperties( @@ -173,6 +183,11 @@ urUSMSharedAlloc(ur_context_handle_t hContext, ur_device_handle_t hDevice, void *Ptr = nullptr; uint32_t Alignment = pUSMDesc ? pUSMDesc->align : 0; + if (pUSMDesc && pUSMDesc->align != 0 && + ((pUSMDesc->align & (pUSMDesc->align - 1)) != 0)) { + return UR_RESULT_ERROR_INVALID_VALUE; + } + std::vector AllocProperties; if (pUSMDesc && pUSMDesc->pNext) { UR_RETURN_ON_FAILURE(usmDescToCLMemProperties( diff --git a/source/common/CMakeLists.txt b/source/common/CMakeLists.txt index e327d7672b..025c3a3808 100644 --- a/source/common/CMakeLists.txt +++ b/source/common/CMakeLists.txt @@ -23,8 +23,8 @@ if (NOT DEFINED UMF_REPO) endif() if (NOT DEFINED UMF_TAG) - # v0.9.x 19.08.2024: Merge pull request #688 ... - set(UMF_TAG 59c4150b7120a7af5b3c8eb2d9b8bbb5d2e96aa3) + # v0.9.x 12.09.2024: 0.9.0 release + set(UMF_TAG v0.9.0) endif() message(STATUS "Will fetch Unified Memory Framework from ${UMF_REPO}") diff --git a/source/loader/layers/tracing/ur_tracing_layer.cpp b/source/loader/layers/tracing/ur_tracing_layer.cpp index 722ee77faa..c6fd4ca40d 100644 --- a/source/loader/layers/tracing/ur_tracing_layer.cpp +++ b/source/loader/layers/tracing/ur_tracing_layer.cpp @@ -34,14 +34,15 @@ struct XptiContextManager { ~XptiContextManager() { xptiFrameworkFinalize(); } }; -static std::shared_ptr xptiContextManagerGlobal = [] { - return std::make_shared(); -}(); +static std::shared_ptr xptiContextManagerGet() { + static auto contextManager = std::make_shared(); + return contextManager; +}; static thread_local xpti_td *activeEvent; /////////////////////////////////////////////////////////////////////////////// context_t::context_t() : logger(logger::create_logger("tracing", true, true)) { - this->xptiContextManager = xptiContextManagerGlobal; + this->xptiContextManager = xptiContextManagerGet(); call_stream_id = xptiRegisterStream(CALL_STREAM_NAME); std::ostringstream streamv; diff --git a/source/loader/ur_loader.cpp b/source/loader/ur_loader.cpp index bfc9da3e50..7609747622 100644 --- a/source/loader/ur_loader.cpp +++ b/source/loader/ur_loader.cpp @@ -15,6 +15,27 @@ context_t *getContext() { return context_t::get_direct(); } /////////////////////////////////////////////////////////////////////////////// ur_result_t context_t::init() { +#ifdef _WIN32 + // Suppress system errors. + // Tells the system to not display the critical-error-handler message box. + // Instead, the system sends the error to the calling process. + // This is crucial for graceful handling of adapters that couldn't be + // loaded, e.g. due to missing native run-times. + // TODO: add reporting in case of an error. + // NOTE: we restore the old mode to not affect user app behavior. + // See https://github.com/intel/llvm/blob/sycl/sycl/ur_win_proxy_loader/ur_win_proxy_loader.cpp (preloadLibraries()) + UINT SavedMode = SetErrorMode(SEM_FAILCRITICALERRORS); +#endif + +#ifdef UR_STATIC_ADAPTER_LEVEL_ZERO + // If the adapters were force loaded, it means the user wants to use + // a specific adapter library. Don't load any static adapters. + if (!adapter_registry.adaptersForceLoaded()) { + auto &level_zero = platforms.emplace_back(nullptr); + ur::level_zero::urAdapterGetDdiTables(&level_zero.dditable.ur); + } +#endif + for (const auto &adapterPaths : adapter_registry) { for (const auto &path : adapterPaths) { auto handle = LibLoader::loadAdapterLibrary(path.string().c_str()); @@ -24,6 +45,10 @@ ur_result_t context_t::init() { } } } +#ifdef _WIN32 + // Restore system error handling. + (void)SetErrorMode(SavedMode); +#endif forceIntercept = getenv_tobool("UR_ENABLE_LOADER_INTERCEPT");