From fdf535c8a0987777ce6c34197ae7cc8e246f1875 Mon Sep 17 00:00:00 2001 From: Nikita Grigorian Date: Fri, 20 Nov 2026 14:11:48 -0800 Subject: [PATCH 1/5] Instrument only host code for coverage Device-side -fprofile-instr-generate puts every __profc_ counter of a module into each of its kernel images as a device global. The OpenCL CPU runtime then segfaults at random in NDRange::Init, calling clDevCmdStatusChanged on a freed command; dpt.concat in _tensor_impl, whose images carry the counters of choose.cpp and putmask.cpp, crashes in about half the runs. The device counts are lost in dpnp anyway, since libsycl is loaded by dpctl before any instrumented module and never binds __sycl_increment_profile_counters, so instrument the host side only, as the static libtensor sources already are. This makes all dpnp sources of the libtensor modules host only, so the separate list of radix select sources is dropped. --- CMakeLists.txt | 6 ++++-- dpnp/cmake/tensor_build_flags.cmake | 4 +--- dpnp/libtensor/source/CMakeLists.txt | 18 ++++++++---------- 3 files changed, 13 insertions(+), 15 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b100cc1163c7..2e5d8ded1d8c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -375,10 +375,12 @@ mark_as_advanced( ) if(DPNP_GENERATE_COVERAGE) + # Host only: device counters become device globals in every kernel image of + # their module, which crash the OpenCL CPU runtime, and never reach the profile string( CONCAT PROFILE_FLAGS - "-fprofile-instr-generate " - "-fcoverage-mapping " + "-Xarch_host -fprofile-instr-generate " + "-Xarch_host -fcoverage-mapping " "-fno-sycl-use-footer " # "-save-temps=obj " ) diff --git a/dpnp/cmake/tensor_build_flags.cmake b/dpnp/cmake/tensor_build_flags.cmake index 6097cd57e4d1..b3418ee66f42 100644 --- a/dpnp/cmake/tensor_build_flags.cmake +++ b/dpnp/cmake/tensor_build_flags.cmake @@ -45,9 +45,7 @@ endif() # Remove global coverage flags for tensor # use link-time only approach like dpctl if(DPNP_GENERATE_COVERAGE) - string(REPLACE "-fprofile-instr-generate " "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") - string(REPLACE "-fcoverage-mapping " "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") - string(REPLACE "-fno-sycl-use-footer " "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") + string(REPLACE "${PROFILE_FLAGS}" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") endif() # Tensor-specific debug flags diff --git a/dpnp/libtensor/source/CMakeLists.txt b/dpnp/libtensor/source/CMakeLists.txt index 7cb3a19e2bb2..e504fc1d6006 100644 --- a/dpnp/libtensor/source/CMakeLists.txt +++ b/dpnp/libtensor/source/CMakeLists.txt @@ -344,8 +344,6 @@ endforeach() # An inline function with FP math that both instantiate gets the flags of the # copy the linker keeps (the dpnp one, see above), so keep such helpers out of # shared headers or give them the same flags in both groups. -# dpnp sources of the modules with the libtensor radix select kernels -set(_dpnp_radix_select_sources ${_dpnp_sorting_sources} ${_statistics_impl_sources}) foreach(_src_fn ${_dpnp_sources}) get_source_file_property(_cmpl_options_prop ${_src_fn} COMPILE_OPTIONS) set(_combined_options_prop @@ -353,10 +351,13 @@ foreach(_src_fn ${_dpnp_sources}) "${_clang_prefix}-fno-approx-func" "${_clang_prefix}-fno-finite-math-only" ) - if(DPNP_GENERATE_COVERAGE AND NOT _src_fn IN_LIST _dpnp_radix_select_sources) + if(DPNP_GENERATE_COVERAGE) + # host only, as PROFILE_FLAGS in the top-level CMakeLists.txt list( APPEND _combined_options_prop + -Xarch_host -fprofile-instr-generate + -Xarch_host -fcoverage-mapping -fno-sycl-use-footer ) @@ -370,16 +371,11 @@ endforeach() if(DPNP_GENERATE_COVERAGE) # libtensor code the dpnp functions use, measured like the dpnp sources. # Host only: their device coverage records break sycl-link - # (a source property, unlike target options, keeps the repeated -Xarch_host). - # The radix select modules are host only too: every kernel image of a module - # gets all its device counters as device globals, and their init events - # crash the OpenCL CPU runtime at random in the kernel bundle launches. - # The device counts never reach the profile anyway + # (a source property, unlike target options, keeps the repeated -Xarch_host) set_property( SOURCE ${_static_lib_sources} ${CMAKE_CURRENT_SOURCE_DIR}/elementwise_functions/elementwise_functions_type_utils.cpp - ${_dpnp_radix_select_sources} APPEND PROPERTY COMPILE_OPTIONS @@ -426,7 +422,9 @@ foreach(python_module_name ${_py_trgts}) if(DPNP_TENSOR_GENERATE_COVERAGE_FOR_PYBIND11_EXTENSIONS) target_compile_options( ${python_module_name} - PRIVATE -fprofile-instr-generate -fcoverage-mapping + PRIVATE + "SHELL:-Xarch_host -fprofile-instr-generate" + "SHELL:-Xarch_host -fcoverage-mapping" ) endif() target_link_options( From 1748054b2ac3cbf2d5717f20d00f8876f0f1227b Mon Sep 17 00:00:00 2001 From: Nikita Grigorian Date: Fri, 20 Nov 2026 14:14:16 -0800 Subject: [PATCH 2/5] Add gh-3193 to changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f4811a3bc764..7a146b3d9bec 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -62,6 +62,7 @@ This release drops support for Python 3.10, making Python 3.11 the minimum requi * Fixed a `TypeError` in `dpnp.from_dlpack` and `dpnp.tensor.from_dlpack` when importing a DLPack tensor on a oneAPI device with a NULL data pointer, which DLPack asks for in a tensor of size zero [#3197](https://github.com/IntelPython/dpnp/pull/3197) * Fixed `dpnp.from_dlpack` and `dpnp.tensor.from_dlpack` sizing the memory of an empty DLPack tensor on a oneAPI device by its nonzero dimensions, which allocated that size for a NULL data pointer (8 GiB for shape `(0, 2**31)` of `int32`) and otherwise claimed more memory than the producer allocated [#3203](https://github.com/IntelPython/dpnp/pull/3203) * Fixed a segfault in `dpnp.from_dlpack` and `dpnp.tensor.from_dlpack` when importing a DLPack tensor on a oneAPI device with NULL strides, which DLPack before 1.2 allows for a C-contiguous tensor [#3183](https://github.com/IntelPython/dpnp/pull/3183) +* Fixed a random segfault of the OpenCL CPU runtime in coverage builds by instrumenting only host code [#3193](https://github.com/IntelPython/dpnp/pull/3193) ### Security From 8b6a48c53b362f9232e4c6d15cc306fe0198cb74 Mon Sep 17 00:00:00 2001 From: Nikita Grigorian Date: Sun, 29 Nov 2026 10:34:55 -0800 Subject: [PATCH 3/5] Name what drops the device counts in dpnp --- CMakeLists.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2e5d8ded1d8c..31382c6d29aa 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -376,7 +376,8 @@ mark_as_advanced( if(DPNP_GENERATE_COVERAGE) # Host only: device counters become device globals in every kernel image of - # their module, which crash the OpenCL CPU runtime, and never reach the profile + # their module and crash the OpenCL CPU runtime. Their counts are lost anyway: + # libsycl, loaded by dpctl first, never binds __sycl_increment_profile_counters string( CONCAT PROFILE_FLAGS "-Xarch_host -fprofile-instr-generate " From f7365e1ecef7d8258bb89263eec8e8d6b181b585 Mon Sep 17 00:00:00 2001 From: Nikita Grigorian Date: Sun, 29 Nov 2026 10:35:08 -0800 Subject: [PATCH 4/5] Mention the tensor pybind11 coverage build in the changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7a146b3d9bec..b90c233be1c6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -62,7 +62,7 @@ This release drops support for Python 3.10, making Python 3.11 the minimum requi * Fixed a `TypeError` in `dpnp.from_dlpack` and `dpnp.tensor.from_dlpack` when importing a DLPack tensor on a oneAPI device with a NULL data pointer, which DLPack asks for in a tensor of size zero [#3197](https://github.com/IntelPython/dpnp/pull/3197) * Fixed `dpnp.from_dlpack` and `dpnp.tensor.from_dlpack` sizing the memory of an empty DLPack tensor on a oneAPI device by its nonzero dimensions, which allocated that size for a NULL data pointer (8 GiB for shape `(0, 2**31)` of `int32`) and otherwise claimed more memory than the producer allocated [#3203](https://github.com/IntelPython/dpnp/pull/3203) * Fixed a segfault in `dpnp.from_dlpack` and `dpnp.tensor.from_dlpack` when importing a DLPack tensor on a oneAPI device with NULL strides, which DLPack before 1.2 allows for a C-contiguous tensor [#3183](https://github.com/IntelPython/dpnp/pull/3183) -* Fixed a random segfault of the OpenCL CPU runtime in coverage builds by instrumenting only host code [#3193](https://github.com/IntelPython/dpnp/pull/3193) +* Fixed a random segfault of the OpenCL CPU runtime in coverage builds, and their link failure with `DPNP_TENSOR_GENERATE_COVERAGE_FOR_PYBIND11_EXTENSIONS=ON`, by instrumenting only host code [#3193](https://github.com/IntelPython/dpnp/pull/3193) ### Security From b96ba76b05431baee0b4887ff4a7fed2048efb8e Mon Sep 17 00:00:00 2001 From: Anton Volkov Date: Tue, 1 Dec 2026 11:18:59 +0100 Subject: [PATCH 5/5] Name SHELL: in the reason for the source property --- dpnp/libtensor/source/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dpnp/libtensor/source/CMakeLists.txt b/dpnp/libtensor/source/CMakeLists.txt index e504fc1d6006..5de4586a7de8 100644 --- a/dpnp/libtensor/source/CMakeLists.txt +++ b/dpnp/libtensor/source/CMakeLists.txt @@ -371,7 +371,7 @@ endforeach() if(DPNP_GENERATE_COVERAGE) # libtensor code the dpnp functions use, measured like the dpnp sources. # Host only: their device coverage records break sycl-link - # (a source property, unlike target options, keeps the repeated -Xarch_host) + # (a source property keeps the repeated -Xarch_host; target options need SHELL:) set_property( SOURCE ${_static_lib_sources}