From 6a488c33de3725ff1e255c52be7b6eaa2243defd Mon Sep 17 00:00:00 2001 From: "Agarwal, Udit" Date: Wed, 27 Aug 2025 05:21:45 +0200 Subject: [PATCH 1/3] [SYCL] Add _invoke_watson to corecrt STL wrapper --- sycl/include/sycl/stl_wrappers/corecrt.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/sycl/include/sycl/stl_wrappers/corecrt.h b/sycl/include/sycl/stl_wrappers/corecrt.h index c649f7ae02926..833be18e8b452 100644 --- a/sycl/include/sycl/stl_wrappers/corecrt.h +++ b/sycl/include/sycl/stl_wrappers/corecrt.h @@ -36,6 +36,14 @@ extern "C" inline void __cdecl _invalid_parameter(wchar_t const *, // Do nothing when called in device code } +extern "C" __declspec(noreturn) void __cdecl +_invoke_watson(wchar_t const *const expression, + wchar_t const *const function_name, + wchar_t const *const file_name, unsigned int const line_number, + uintptr_t const reserved) { + // Do nothing. +} + #endif #if defined(__has_include_next) From fb445db485819a7e0ed0e46d847d2eed182efe31 Mon Sep 17 00:00:00 2001 From: "Agarwal, Udit" Date: Wed, 27 Aug 2025 19:28:53 +0200 Subject: [PATCH 2/3] Fix comment and formatting. --- sycl/include/sycl/stl_wrappers/corecrt.h | 34 +++++++++--------------- 1 file changed, 13 insertions(+), 21 deletions(-) diff --git a/sycl/include/sycl/stl_wrappers/corecrt.h b/sycl/include/sycl/stl_wrappers/corecrt.h index 833be18e8b452..fac948c1d78ac 100644 --- a/sycl/include/sycl/stl_wrappers/corecrt.h +++ b/sycl/include/sycl/stl_wrappers/corecrt.h @@ -6,22 +6,16 @@ // //===----------------------------------------------------------------------===// -// When std::array is used in device code, MSVC's STL uses a _invalid_parameter -// function. This causes issue when _invalid_parameter is invoked from device -// code: +// MSVC's STL emits functions like _invalid_parameter and _invoke_watson +// to validate parameters passed to STL containers, like std::array, when +// compiled in debug mode. +// STL containers when used in device code fails to compile on Windows +// because these functions are not marked with SYCL_EXTERNAL attribute. -// 1. `_invalid_parameter` is provided via ucrtbased.dll at runtime: DLLs are -// not loaded for device code, thus causing undefined symbol errors. - -// 2. MSVC's STL never defined the function as SYCL_EXTERNAL, errors are thrown -// when device code tries to invoke `_invalid_parameter`. - -// As a workaround, this wrapper wraps around corecrt.h and defines a custom -// _invalid_parameter for device code compilation. - -// This new SYCL_EXTERNAL definition of _invalid_parameter has to be declared -// before corecrt.h is included: Thus, we have this STL wrapper instead of -// declaring _invalid_parameter function in SYCL headers. +// As a workaround, this wrapper defines a custom, empty defination of +// _invalid_parameter and _invoke_watson for device code. +// MSVC picks up these definitions instead of the ones defined in MSVC's +// corecrt header. #pragma once @@ -36,14 +30,12 @@ extern "C" inline void __cdecl _invalid_parameter(wchar_t const *, // Do nothing when called in device code } -extern "C" __declspec(noreturn) void __cdecl -_invoke_watson(wchar_t const *const expression, - wchar_t const *const function_name, - wchar_t const *const file_name, unsigned int const line_number, - uintptr_t const reserved) { +extern "C" __declspec(noreturn) void __cdecl _invoke_watson( + wchar_t const *const expression, wchar_t const *const function_name, + wchar_t const *const file_name, unsigned int const line_number, + uintptr_t const reserved) { // Do nothing. } - #endif #if defined(__has_include_next) From 6f18d5301b4c7c74d30dcbc3bacdedd985faa539 Mon Sep 17 00:00:00 2001 From: Udit Kumar Agarwal Date: Wed, 27 Aug 2025 10:42:58 -0700 Subject: [PATCH 3/3] Address feedback --- sycl/include/sycl/stl_wrappers/corecrt.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sycl/include/sycl/stl_wrappers/corecrt.h b/sycl/include/sycl/stl_wrappers/corecrt.h index fac948c1d78ac..75b49a432131f 100644 --- a/sycl/include/sycl/stl_wrappers/corecrt.h +++ b/sycl/include/sycl/stl_wrappers/corecrt.h @@ -14,8 +14,8 @@ // As a workaround, this wrapper defines a custom, empty defination of // _invalid_parameter and _invoke_watson for device code. -// MSVC picks up these definitions instead of the ones defined in MSVC's -// corecrt header. +// MSVC picks up these definitions instead of the declarations from MSVC's +// header. #pragma once