From 688227322ac9995096891e47ea061b4f0b61a2a5 Mon Sep 17 00:00:00 2001 From: Nikita Grigorian Date: Fri, 20 Nov 2026 14:11:48 -0800 Subject: [PATCH 1/2] 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. Device counts never reach the profile, so instrument the host side only, as the static libtensor sources already are. --- CMakeLists.txt | 6 ++++-- dpnp/cmake/tensor_build_flags.cmake | 4 +--- dpnp/libtensor/source/CMakeLists.txt | 7 ++++++- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4e45698b116..a07f6a38c03 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 6097cd57e4d..b3418ee66f4 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 d79115eddf5..ad06120e267 100644 --- a/dpnp/libtensor/source/CMakeLists.txt +++ b/dpnp/libtensor/source/CMakeLists.txt @@ -346,9 +346,12 @@ foreach(_src_fn ${_dpnp_sources}) "${_clang_prefix}-fno-finite-math-only" ) 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 ) @@ -413,7 +416,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 c863ff7e3e7d1759151d87a249bb7e01fa72e2a2 Mon Sep 17 00:00:00 2001 From: Nikita Grigorian Date: Fri, 20 Nov 2026 14:14:16 -0800 Subject: [PATCH 2/2] Add gh-3193 to changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7f24e4b179f..0ff01da4f32 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -48,6 +48,7 @@ This release drops support for Python 3.10, making Python 3.11 the minimum requi * Fixed the example of handling duplicate indices in the `dpnp.tensor.put` docstring, which imported `dpctl.tensor`, did not parse and lost writes when `x` is longer than `indices` [#3165](https://github.com/IntelPython/dpnp/pull/3165) * Fixed a segfault when setting `writable` on a `Flags` object created without an array [#3168](https://github.com/IntelPython/dpnp/pull/3168) * Fixed a crash of the OpenCL CPU compiler in `dpnp.sort`, `dpnp.argsort`, `dpnp.tensor.sort` and `dpnp.tensor.argsort` by radix sort of rows of 2049 to 16384 elements [#3191](https://github.com/IntelPython/dpnp/pull/3191) +* 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