Repository navigation
Instrument only host code in the coverage build - #3193
Conversation
|
View rendered docs @ https://intelpython.github.io/dpnp/index.html |
|
Array API standard conformance tests for dpnp=0.22.0dev3=np2py314h8d9cdd5_71 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.
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.
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.
ccef592 to
f7365e1
Compare
…-counters # Conflicts: # CHANGELOG.md
antonwolfy
left a comment
There was a problem hiding this comment.
Approving. Everything from the first round is in: the comment names the loading order that drops the device counts, the radix select list is gone after the rebase, and the description and the changelog say that DPNP_TENSOR_GENERATE_COVERAGE_FOR_PYBIND11_EXTENSIONS=ON builds now. Apart from the comment text, the CMake changes are the ones I built and ran in the first round, so those results still apply. The Coveralls build of the previous head has exactly master's totals at its base: 30813 of 35539 lines and 1906 of 3156 branches.
I pushed two commits. One rewords the comment on the static libtensor sources, since the SHELL: target options for the tensor pybind11 coverage build keep the repeated -Xarch_host too. The other merges master and resolves the CHANGELOG.md conflict with #3207 and #3209 by keeping all three entries.
|
The red |
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 at `libintelocl.so+0x2d5f026`: a TBB worker in `NDRange::Init` calls `clDevCmdStatusChanged` on a freed command. In a coverage build, `-fprofile-instr-generate -fcoverage-mapping` also 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.cpp` and `putmask.cpp` give each `_tensor_impl` image about 800 counters), and for every target that keeps the global flags: the pybind11 extensions, `dpnp_backend_c` and the Cython modules. With them, a few `dpnp.tensor.concat` calls on `opencl:cpu` segfault in about half the runs; `concat` copies with `_copy_usm_ndarray_into_usm_ndarray` of `_tensor_impl`. The device counts are lost in dpnp anyway: libsycl, loaded by dpctl before any instrumented module, never binds `__sycl_increment_profile_counters`, through which the profile runtime would add them. So this PR instruments the host side only (`-Xarch_host`), as the static libtensor sources already are: in the global `PROFILE_FLAGS`, for all dpnp sources of the libtensor modules and under `DPNP_TENSOR_GENERATE_COVERAGE_FOR_PYBIND11_EXTENSIONS`. The radix select sources, which #3138 made host only on their own, are covered by that too, so their separate list is gone. `tensor_build_flags.cmake` now strips `PROFILE_FLAGS` as a whole. Release builds are unchanged. Checked on a local coverage build of master, on `opencl:cpu` (Core Ultra 7 265U): - The reproducer (10 runs of the `concat` calls) crashes 0 times with the change and 5 times without it; `third_party/cupy/math_tests/test_sumprod.py` passes 4 runs out of 4, against 3 crashes out of 3 without it. - No kernel image of any module has a `__profc_` counter left (13261 of 23417 images had them before), and host coverage is still recorded, e.g. 78% of the regions of `choose.cpp` after one `dpnp.choose` call. - With `DPNP_TENSOR_GENERATE_COVERAGE_FOR_PYBIND11_EXTENSIONS=ON`, the libtensor sources get only the `-Xarch_host` forms. This also makes that configuration build: on master the device counters push `_tensor_impl`, `_tensor_elementwise_impl`, `_tensor_reductions_impl` and `_tensor_sorting_impl` past 2 GiB, and their link fails with `relocation R_X86_64_PC32 out of range` (found in review). - After the rebase on master, all 134 instrumented compile commands of a reconfigured coverage tree have only the `-Xarch_host` forms; the modules weren't rebuilt locally after it. The full coverage job wasn't run locally; the CI run of this PR is the check for that.
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.The device counts are lost in dpnp anyway: libsycl, loaded by dpctl before any instrumented module, never binds
__sycl_increment_profile_counters, through which the profile runtime would add them. So this PR instruments the host side only (-Xarch_host), as the static libtensor sources already are: in the globalPROFILE_FLAGS, for all dpnp sources of the libtensor modules and underDPNP_TENSOR_GENERATE_COVERAGE_FOR_PYBIND11_EXTENSIONS. The radix select sources, which #3138 made host only on their own, are covered by that too, so their separate list is gone.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. This also makes that configuration build: on master the device counters push_tensor_impl,_tensor_elementwise_impl,_tensor_reductions_impland_tensor_sorting_implpast 2 GiB, and their link fails withrelocation R_X86_64_PC32 out of range(found in review).-Xarch_hostforms; the modules weren't rebuilt locally after it.The full coverage job wasn't run locally; the CI run of this PR is the check for that.