Skip to content

[SYCL] Make PFWG variables have automatic destructor semantics. - #23702

Open
inteltdelisle wants to merge 6 commits into
intel:syclfrom
inteltdelisle:work/pfwg/automatic_dtor
Open

inteltdelisle wants to merge 6 commits into
intel:syclfrom
inteltdelisle:work/pfwg/automatic_dtor

Conversation

@inteltdelisle

@inteltdelisle inteltdelisle commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Variables declared inside parallel_for_work_group need to have global storage since local storage cannot be accessed across work items. Previously, these variables would also get global destructor semantics, i.e., using __cxa_atexit, which is incorrect for device code. This behaviour is now replaced with automatic variable semantics, i.e., destructors are executed once per work group at scope exit.

Other changes:

  • Fixed work_group_static variables not being zero initialized when inside PFWG.
  • -ftrivial-auto-var-init now applies to work-group-scope locals.
  • Added defensive tests for work_group_static, to confirm previous behaviour is unchanged.

Known limitation: Issue #23700 causes certain destructos to be run too many times, notably destructors for captured variables. There is still an existing diagnosis covering these destructors, so the problem is not silent. Once issue 23700 is fixed, the diagnostic warn_sycl_work_group_scope_dtor can be removed and tests should be added for captured variables.

Variables declared inside parallel_for_work_group need to have global
storage since local storage cannot be accessed across work items.
Previously, these variables would also get global destructor semantics,
i.e., using __cxa_atexit, which is incorrect for device code.
This behaviour is now replaced with automatic variable semantics, i.e.,
destructors are executed once per work group at scope exit.

Other changes:
 - Fixed work_group_static variables not being zero initialized when
   inside PFWG.
 - -ftrivial-auto-var-init now applies to work-group-scope locals.
 - Added defensive tests for work_group_static, to confirm previous
   behaviour is unchanged.

Known limitation: Issue 23700 causes certain destructos to be run
too many times, notably destructors for captured variables. There is
still an existing diagnosis covering these destructors, so the problem
is not silent. Once issue 23700 is fixed, the diagnostic
warn_sycl_work_group_scope_dtor can be removed and tests should be added
for captured variables.

Signed-off-by: Delisle, Thierry <thierry.delisle@intel.com>
@elizabethandrews

Copy link
Copy Markdown
Contributor

@inteltdelisle is this PR ready for review? In our offline discussion, I believe you said another PR will need to go first before this. Will there be changes to this PR as a result? If this is not ready for review, please mark it as draft and ping when ready for review. Thank you!

@inteltdelisle

inteltdelisle commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor Author

@elizabethandrews It depends if this is worth merging with the known limitation in the description. Arguably this PR still improves the current state of things. But it's also not consistently fixing all cases, where as previously non-trivial destructors were just generally better avoided. Honestly, either works for me.

@inteltdelisle

inteltdelisle commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor Author

Worth noting that #23765 should fix #23700.

Signed-off-by: Delisle, Thierry <thierry.delisle@intel.com>

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.

2 participants