Skip to content

[SYCL][Driver] Warn when total Device code-size causes relocation errors - #23523

Open
bviyer wants to merge 7 commits into
syclfrom
bviyer-make-better-warning
Open

bviyer wants to merge 7 commits into
syclfrom
bviyer-make-better-warning

Conversation

@bviyer

@bviyer bviyer commented Oct 16, 2026

Copy link
Copy Markdown
Contributor

Large device code can push the 32-bit PC relative relocations past their 2GB reach. this causes host linker to fail with errors such as "relocation truncated to fit." In this PR, such cases are dignosed at linked time via -Wlarge-device-kernel flag and providing user suggestion to use the flink-huge-device-code as a fix.

@bviyer
bviyer requested review from a team as code owners October 16, 2026 20:04
Comment thread clang/include/clang/Basic/DiagnosticDriverKinds.td Outdated
Comment thread clang/include/clang/Basic/DiagnosticDriverKinds.td Outdated
Comment thread clang/lib/Driver/ToolChains/Gnu.cpp Outdated
static constexpr uint64_t SYCLHugeDeviceCodeWarnThreshold = 1ull << 30; // 1GB

// Best-effort: skips non-filename inputs (e.g. linker flags).
static uint64_t getTotalSYCLDeviceCodeSize(ArrayRef<InputInfo> Inputs) {

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 is grabbing size information for the entire object/file. This may not be representative of the actual device code. Consider renaming the function name to better match what is being checked.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Renamed to getTotalLinkInputSize

Comment thread clang/lib/Driver/ToolChains/Gnu.cpp
Comment thread clang/test/Driver/sycl-huge-device-code-warning.cpp Outdated
Comment thread clang/lib/Driver/ToolChains/Gnu.cpp Outdated
Comment thread clang/test/Driver/sycl-huge-device-code-warning.cpp
Comment thread clang/lib/Driver/ToolChains/Gnu.cpp Outdated

@elizabethandrews elizabethandrews 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.

This is primarily a Driver Change with just a warning group declared in FE. I defer to @mdtoguchi for review. I agree that the current proposed warning is too verbose.

@mdtoguchi mdtoguchi changed the title [SYCL] Warn when total Device code-size causes relocation errors [SYCL][Driver] Warn when total Device code-size causes relocation errors Oct 22, 2026
Comment thread clang/test/Driver/sycl-huge-device-code-warning.cpp
@bviyer
bviyer requested a review from mdtoguchi October 22, 2026 17:23
Comment thread clang/lib/Driver/ToolChains/Gnu.cpp Outdated
static constexpr uint64_t HugeLinkInputWarnThreshold = 1ull << 30; // 1GiB

// Best-effort: skips non-filename inputs (e.g. linker flags).
static uint64_t getTotalLinkInputSize(ArrayRef<InputInfo> Inputs) {

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.

My main concern here is this warning may be triggered too much especially when considering any inputs that are not object related and are associated with static archives. The check is basically all user input files, regardless if they impact the device binary size or not. Would it be better to check the final device binary size after the device link and emit the warning then if the device binary is too big?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ok Fixed. I made it such that we only measure the actually wrapped device-code object size.

@bviyer
bviyer requested a review from mdtoguchi October 26, 2026 20:36

for (const InputInfo &II : Inputs)
if (II.isFilename() &&
isa_and_nonnull<OffloadWrapperJobAction>(II.getAction())) {

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 is good for the old offload model. We should also look into a solution for the new model - I would expect that to be more in the clang-linker-wrapper space.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Can we do that in a separate PR?

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.

Yup, this can be done in a separate PR.

static constexpr uint64_t HugeDeviceCodeWarnThreshold = 1ull << 30; // 1GiB

// Sums the size of only those link inputs that carry wrapped device code,
// i.e. skips host objects, static archives, and other linker inputs that

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.

the comment on static archives isn't true - as static archives should be queried as well, as they can be 'fat archives'. But that query happens in a different area so the device objects from any static archives should already be processed along with the other device binaries.

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