llvm
94a600cd - [SYCL] Remove iostream from the SYCL header path (#22047)

Commit
86 days ago
[SYCL] Remove iostream from the SYCL header path (#22047) ## Motivation Downstream kernel-compilation flows are moving to a model where the device pass compiles against a reduced C++ standard library (LLVM libc++ plus a small vendor libc subset). In that model `<iostream>`/`<ostream>`/`<istream>` are unsupportable: they declare host-only globals and emit per-TU static initializers (`std::ios_base::Init`) that have no meaning in device JIT/AOT pipelines. Today SYCL public headers pull them transitively into every device compilation, even with `-fsycl-device-only`. This PR removes the dependency structurally, superseding the macro-gating approach of #22236. ## The contract Every header under `<sycl/khr/...>` is now guaranteed free of iostream headers and the `iostream_proxy` shim in both compilation passes. New lit test `device_only_no_iostream.cpp` locks this: it compiles an umbrella of all KHR headers and asserts no iostream pull via the `-MD` dependency listing. ## Approach Three orthogonal fixes, one per leak mechanism: 1. **Stream operators → runtime.** The five inline stream operators in public headers (`backend`, `half` ×2, `bfloat16` ×2) now live in `sycl/source/printers.cpp` as `__SYCL_EXPORT` symbols; headers keep forward declarations plus `<iosfwd>`. Four ESIMD type-traits headers had identical operators with zero test coverage — removed. 2. **Inline diagnostic code → runtime functions.** `__SYCL_REPORT_EXCEPTION_TO_STREAM`, `defaultAsyncHandler`, and the `Adjust` lambda in `range_rounding.hpp` no longer write to streams from header code; each now calls an exported runtime function. 3. **`iostream_proxy.hpp` → runtime-private.** Moved from the public include path to `sycl/source/detail/`. While there, the 7 runtime TUs including `<iostream>` directly were switched to the proxy: zero `<iostream>` includes left in the runtime, single `__ioinit` static, smaller `.so`. **ABI:** 8 new exported symbols (the 5 operators + 3 diagnostic functions), additions only — previously inline, never exported. Added to `sycl_symbols_linux.dump`. **Compile time** (via `measure_split_headers_compile_time.py`): aggregate **−4.9%** across all 39 KHR split headers; standouts `half.hpp` −60.3%, `exception.hpp` −21.9%. Regressions are <2% and within noise. ## Reviewing this PR The diff stat (~725 files) overstates the review surface. The real change is **~10-15 files** (header restructuring, `printers.cpp`, the proxy move, the new test). The other ~660 are mechanical one-line `+#include <iostream>` adds in e2e tests that were free-riding on the transitive pull — include-what-you-use, the expected cost of the fix. ## Out of scope `<sycl/sycl.hpp>` is not yet verified device-clean (`syclbin_kernel_bundle.hpp` pulls `<filesystem>` → `<sstream>`; fixable separately). `<sycl/ext/...>` cleanliness is partial: `bfloat16.hpp` and the ESIMD type-traits headers are done, others untouched.
Author
Parents
Loading