Skip to content

Align the build flags of all SYCL modules with dpnp.tensor - #3198

Open
ndgrigorian wants to merge 3 commits into
feature/remove-legacy-rngfrom
align-libtensor-flags
Open

ndgrigorian wants to merge 3 commits into
feature/remove-legacy-rngfrom
align-libtensor-flags

Conversation

@ndgrigorian

@ndgrigorian ndgrigorian commented Nov 24, 2026 •

Copy link
Copy Markdown
Collaborator

This PR aligns the compiler and linker flags of all dpnp SYCL modules with those dpnp.tensor inherited from dpctl. It is stacked on #3163: with dpnp_backend_c removed, every SYCL target is a pybind11 module in dpnp/libtensor.

Until now, only dpnp/tensor and dpnp/libtensor/source included tensor_build_flags.cmake, and the oneMKL extensions used a separate set of options:

  • The directory flags (no global -fsycl, lld, -Wno-unused-parameter, Debug -g with device -g0) move to the top-level CMakeLists.txt, so every target gets them. tensor_build_flags.cmake keeps only the coverage strip of the tensor directories; coverage is otherwise unchanged and doesn't overlap Instrument only host code in the coverage build #3193.
  • Every pybind11 module, the eight of libtensor/source included, is now built by build_dpnp_pybind11_ext. It compiles the whole module with -fno-fast-math instead of -fno-approx-func -fno-finite-math-only, and adds the hardening DPNP_LDFLAGS and DPNP_TENSOR_OFFLOAD_COMPRESS, which the extensions lacked.
  • -fno-fast-math on the whole module, not on a list of sources as in dpctl: the sources left out of that list have no floating-point math worth relaxing. Both groups of sources of a libtensor module now share the floating-point flags, so an inline function both instantiate no longer depends on which copy the linker keeps. The dpnp kernels (sinc, i0, interpolate, the statistics functions, ...) and the extensions now keep signed zeros and don't reassociate.

The flags also caused compiler warnings in Debug and Coverage builds, which are fixed:

  • -Xsycl-target-frontend=spir64 -g0 was unused for the Cython modules and the simplify_iteration_space static library, which no longer get -fsycl; it now goes only to the SYCL modules.
  • -g1 was ignored for spir64 in every SYCL source of a coverage build (also on master); CMAKE_CXX_FLAGS_COVERAGE passes it to the host only.
  • -fno-sycl-use-footer was unused for the static library, which now takes the plain coverage flags.

Checked locally:

  • The Release build (234 compiles) has no compiler warnings.

  • 18 test modules (elementwise, statistics, histogram, linalg, fft, random, sort, window, ...) pass on a Level Zero GPU: 53577 passed, 230 skipped. They were not run on a CPU device, and performance was not measured.

  • Have you provided a meaningful PR description?

  • Have you added a test, reproducer or referred to an issue with a reproducer?

  • Have you tested your changes locally for CPU and GPU devices?

  • Have you made sure that new changes do not introduce compiler warnings?

  • Have you checked performance impact of proposed changes?

  • Have you added documentation for your changes, if necessary?

  • Have you added your changes to the changelog?

The directory flags of dpnp/tensor and libtensor/source (no global -fsycl,
lld, -Wno-unused-parameter, Debug -g with device -g0) move to the top-level
CMakeLists.txt, and every pybind11 module, including those of
libtensor/source, is built by build_dpnp_pybind11_ext. It compiles the whole
module with -fno-fast-math and adds the hardening linker flags and
DPNP_TENSOR_OFFLOAD_COMPRESS, which the extensions lacked.

Device-only flags go only to SYCL targets, and coverage builds pass -g1 to
the host only, so neither warns.
@github-actions

Copy link
Copy Markdown
Contributor

View rendered docs @ https://intelpython.github.io/dpnp/pull/3198/index.html

@coveralls

coveralls commented Nov 24, 2026 •

Copy link
Copy Markdown
Collaborator

Coverage Status

Coverage is 86.422% — align-libtensor-flags into feature/remove-legacy-rng. No base build found for feature/remove-legacy-rng.

libmkl_sycl_* don't record their dependency on the oneMKL interface,
threading and core libraries. With lld, the --as-needed of the conda LDFLAGS
dropped them from the oneMKL modules, so importing dpnp failed with an
undefined fftw3_mkl. Link the MKL::MKL_SYCL domain targets with
--no-as-needed.
@github-actions

Copy link
Copy Markdown
Contributor

Array API standard conformance tests for dpnp=0.22.0dev3=np2py314h8d9cdd5_134 ran successfully.
Passed: 1491
Failed: 0
Skipped: 6

@vlad-perevezentsev vlad-perevezentsev left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Everything passes, results match the base apart from a sinc fix, and the benchmarks show no slowdown on any device.
Two small comments below:

Comment thread CHANGELOG.md
* Improved performance of `dpnp.top_k` and `dpnp.tensor.top_k` on a GPU for batches of rows of 65536 to about 10^6 elements that occupy it with a work-group per row [#3138](https://github.com/IntelPython/dpnp/pull/3138)
* Reimplemented `dpnp.random.RandomState` and the `dpnp.random` functions on device kernels, drawing on the queue of the generator. `device`, `usm_type` and `sycl_queue` are now keyword-only, `usm_type` defaults to the USM type of the array parameters, `randint(dtype=int)` returns `int64` and `shuffle` requires a `dpnp.ndarray` or `usm_ndarray` [#3162](https://github.com/IntelPython/dpnp/pull/3162)
* Moved the vendored CMake modules of `IntelSYCL`, `MKL`, `TBB` and `oneDPL` from `dpnp/backend/cmake/Modules` to `cmake/Modules` [#3163](https://github.com/IntelPython/dpnp/pull/3163)
* Aligned the build flags of all dpnp SYCL modules with those of `dpnp.tensor`, so the dpnp kernels and the oneMKL extensions are compiled with `-fno-fast-math` and the extensions get the hardening linker flags and `DPNP_TENSOR_OFFLOAD_COMPRESS` [#3198](https://github.com/IntelPython/dpnp/pull/3198)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change also fixes dpnp.sinc for subnormal float32 on a GPU: with the old fast-math flags it returned inf.

import numpy, dpnp

x = numpy.array([1e-40], dtype=numpy.float32)
print(dpnp.sinc(dpnp.asarray(x)))  # GPU: [inf] before this PR, [1.] now; numpy: [1.]

Could the entry mention it, and a test in TestSinc keep it fixed?

Comment on lines +278 to 288
foreach(
python_module_name
_tensor_impl
_tensor_accumulation_impl
_tensor_elementwise_impl
_tensor_reductions_impl
_tensor_sorting_impl
_tensor_linalg_impl
)
target_link_libraries(${python_module_name} PRIVATE ${_static_lib_trgt})
endforeach()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: This loop repeats six of the eight module names only to link simplify_iteration_space. A module missing here still links and fails only at import (undefined symbol). Linking it in the loop above for every module keeps one list: _statistics_impl and _window_impl relinked with it come out byte-identical.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants