Repository navigation
Instrument only host code in the coverage build - #3193
ndgrigorian wants to merge 3 commits into
Conversation
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.
|
View rendered docs @ https://intelpython.github.io/dpnp/pull/3193/index.html |
|
Array API standard conformance tests for dpnp=0.22.0dev2=np2py314h8d9cdd5_39 ran successfully. |
antonwolfy
left a comment
There was a problem hiding this comment.
I tested this PR rebased on current master (I resolved the conflict myself, see the inline comment) against master itself. Both were Coverage builds with the CMake options of gen_coverage.py and DPC++ 2026.2.0, run on the CPU device of a Xeon Platinum 8480+ (OpenCL CPU runtime 2026.22.10) and on a Data Center GPU Max 1100 (Level Zero).
The fix works.
- No kernel image keeps a
__profc_counter. On master, 83 of the 90 images oflibdpnp_backend_c,_blas_impland_rng_implhave them, and stripped copies of_tensor_impland_tensor_elementwise_implstill hold 4.1 and 5.0 million__profc_strings (1186 and 2246 counters). With this PR no module has any. - The coverage build gets much smaller: all its
.sofiles take 262 MB instead of 1980 MB, and_tensor_implis 46 MB instead of 749 MB. - On
opencl:cpu,third_party/cupy/math_tests/test_sumprod.pycrashed master in 2 of 3 runs, in an elementwise call underdpnp.gradient, and passed in 3 of 3 with this PR. In the full dpnp anddpnp.tensorsuites under xdist, master lost 130 and 141 workers to crashes, this PR none. Theconcatreproducer didn't crash master on this Xeon in 20 runs. - Coverage stays the same. The Coveralls build of this PR has master's totals at its base: 30569 of 35301 lines and 1876 of 3144 branches. On the GPU, the per-line C++ report of the dpnp and
dpnp.tensorsuites is identical on master and with this PR: 12394 of 16273 lines and 1909 of 3156 branches, with no line different.
DPNP_TENSOR_GENERATE_COVERAGE_FOR_PYBIND11_EXTENSIONS=ON works with this PR and is broken on master. On master the build fails to link _tensor_impl, _tensor_elementwise_impl, _tensor_reductions_impl and _tensor_sorting_impl, with 84 relocation R_X86_64_PC32 out of range errors: the device counters push these modules past 2 GiB. With this PR it builds, the SHELL: forms keep both -Xarch_host in every compile command, and no image has a counter. gen_coverage.py --tensor-cpp-coverage then adds 126 libtensor files with real counts: 24225 of their 29638 lines are covered after the dpnp and dpnp.tensor suites. The description says this configuration wasn't built; it could say that the PR makes it build, and the changelog entry could mention it too.
Device counts can reach a profile, just not dpnp's. The new comment and the description say that the device counts never reach the profile. With DPC++ 2026.2 they do in a standalone program: when the SYCL runtime frees the counters' device globals, it adds them to the host counters through __sycl_increment_profile_counters of the profile runtime. A small kernel built with -fprofile-instr-generate -fcoverage-mapping gets exact device counts on both devices that way. In dpnp they can't arrive:
- libsycl refers to
__sycl_increment_profile_countersas a weak undefined symbol and binds it when it's loaded. dpctl loads libsycl before any instrumented module, so the reference stays null. The same instrumented library, loaded withctypesafterimport dpctl, gets no device counts. - Even when the reference binds, only the module it bound to gets counts. With two instrumented libraries in one process, the kernel lines of the second one stay at 0.
- The counts are added only when the device globals are freed, and a queue that lives until exit (as dpctl's cached ones do) gets none.
So the PR loses nothing, and an option to keep device instrumentation wouldn't bring any data back. It's the loading order that drops the counts, not the toolchain, and the inline comment suggests a wording.
No other CMake file needs a change. The link options without -Xarch_host add no device counters (no image has any), the dpnp.tensor Cython modules get no C++ instrumentation with or without this PR, and simplify_iteration_space.cpp, which isn't compiled as SYCL, is still measured.
| # 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 |
There was a problem hiding this comment.
The counts can reach a profile with this toolchain (see the review), so the reason could name what drops them in dpnp:
| # 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 | |
| # Host only: device counters become device globals in every kernel image of | |
| # their module and crash the OpenCL CPU runtime. Their counts are lost anyway: | |
| # libsycl, loaded by dpctl first, never binds __sycl_increment_profile_counters |
| "${_clang_prefix}-fno-finite-math-only" | ||
| ) | ||
| if(DPNP_GENERATE_COVERAGE) | ||
| # host only, as PROFILE_FLAGS in the top-level CMakeLists.txt |
There was a problem hiding this comment.
This conflicts with master now, here and in CHANGELOG.md. #3138 made the dpnp sources of the radix select modules host only with _dpnp_radix_select_sources: the AND NOT _src_fn IN_LIST _dpnp_radix_select_sources condition on this line, the list's entry in the set_property below, and the comment there that ends with "The device counts never reach the profile anyway". With this change every source in _dpnp_sources is host only, so the rebase can drop the list, the condition, the entry and that part of the comment. I resolved it that way for my runs, and the rebased build then has no device counter in any module, _statistics_impl and _tensor_sorting_impl included.
vlad-perevezentsev
left a comment
There was a problem hiding this comment.
I checked the coverage configuration with icpx 2026.1.1: no compile command instruments device code any more, the host counters stay the same, and the device code of the compiled objects has no counters. Agreed with @antonwolfy on the comment wording, on the rebase on master, which now conflicts, and on mentioning the tensor pybind11 coverage build in the changelog.
This PR fixes a random segfault of the OpenCL CPU runtime in the coverage build, which fails the coverage job of PRs, such as #3157 in
test_sumprod.py, and makes it rely on the retry elsewhere. The crash is always atlibintelocl.so+0x2d5f026: a TBB worker inNDRange::InitcallsclDevCmdStatusChangedon a freed command.In a coverage build,
-fprofile-instr-generate -fcoverage-mappingalso instrument device code, and the device compiler puts every__profc_counter of a module into each of its kernel images, where SYCL treats them as device globals. This happens for the dpnp sources compiled into the libtensor modules (choose.cppandputmask.cppgive each_tensor_implimage about 800 counters), and for every target that keeps the global flags: the pybind11 extensions,dpnp_backend_cand the Cython modules. With them, a fewdpnp.tensor.concatcalls onopencl:cpusegfault in about half the runs;concatcopies with_copy_usm_ndarray_into_usm_ndarrayof_tensor_impl.Device counts never reach the profile, so this PR instruments the host side only (
-Xarch_host), as the static libtensor sources already are: in the globalPROFILE_FLAGS, for the dpnp sources of the libtensor modules and underDPNP_TENSOR_GENERATE_COVERAGE_FOR_PYBIND11_EXTENSIONS.tensor_build_flags.cmakenow stripsPROFILE_FLAGSas a whole. Release builds are unchanged.Checked on a local coverage build of master, on
opencl:cpu(Core Ultra 7 265U):concatcalls) crashes 0 times with the change and 5 times without it;third_party/cupy/math_tests/test_sumprod.pypasses 4 runs out of 4, against 3 crashes out of 3 without it.__profc_counter left (13261 of 23417 images had them before), and host coverage is still recorded, e.g. 78% of the regions ofchoose.cppafter onedpnp.choosecall.DPNP_TENSOR_GENERATE_COVERAGE_FOR_PYBIND11_EXTENSIONS=ON, the libtensor sources get only the-Xarch_hostforms; that configuration was not built.The full coverage job wasn't run locally; the CI run of this PR is the check for that.