Skip to content

[DevTSAN] Sync thread clock to global state before kernel exit #18529

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: sycl
Choose a base branch
from

Conversation

zhaomaosu
Copy link
Contributor

We need to sync each thread's clock back to global state before the thread exit to avoid false alarms in some reduction cases.

We need to sync each thread's clock back to global state before the
thread exit to avoid false alarms in some reduction cases.
@zhaomaosu zhaomaosu requested a review from a team as a code owner May 19, 2025 08:40
@zhaomaosu zhaomaosu requested a review from Copilot May 19, 2025 08:40
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR ensures that each thread synchronizes its clock back to the global state before kernel exit to avoid false alarms, with changes applied to instrumentation logic and sanitizer driver arguments.

  • Updated the SPIR-V instrumentation routine to properly handle function entry/exit instrumentation.
  • Introduced a new __tsan_func_exit() in the device sanitizer runtime to sync clocks.
  • Adjusted sanitizer argument handling for device offloading by removing tsan function entry/exit flags.

Reviewed Changes

Copilot reviewed 3 out of 8 changed files in this pull request and generated 1 comment.

File Description
llvm/lib/Transforms/Instrumentation/ThreadSanitizer.cpp Updated API call and instrumentation logic to force exit instrumentation based on SPIR-V conditions.
libdevice/sanitizer/tsan_rtl.cpp Added __tsan_func_exit() to sync thread clocks to global state.
clang/lib/Driver/SanitizerArgs.cpp Removed tsan function entry/exit flag for device offloading.
Files not reviewed (5)
  • llvm/test/Instrumentation/ThreadSanitizer/SPIRV/basic.ll: Language not supported
  • llvm/test/Instrumentation/ThreadSanitizer/SPIRV/cleanup_private_shadow.ll: Language not supported
  • llvm/test/Instrumentation/ThreadSanitizer/SPIRV/instrument_barrier.ll: Language not supported
  • llvm/test/Instrumentation/ThreadSanitizer/SPIRV/instrument_device_global.ll: Language not supported
  • llvm/test/Instrumentation/ThreadSanitizer/SPIRV/kernel_metadata.ll: Language not supported
Comments suppressed due to low confidence (2)

clang/lib/Driver/SanitizerArgs.cpp:1282

  • Removal of tsan function entry/exit instrumentation flags for device offloading should be double-checked to ensure it aligns with the intended behavior of synchronizing thread clocks before exit.
CmdArgs.push_back("-tsan-instrument-func-entry-exit=0");

libdevice/sanitizer/tsan_rtl.cpp:470

  • Ensure that using kThreadSlotCount as an index for the global clock array is valid and within expected bounds, as this update affects thread synchronization logic.
TsanLaunchInfo->Clock[kThreadSlotCount].clk_[sid] =

// The tsan function entry/exit builtins are used to record stack
// position, we don't need them in device offloading.
CmdArgs.push_back("-mllvm");
CmdArgs.push_back("-tsan-instrument-func-entry-exit=0");
Copy link
Contributor

Choose a reason for hiding this comment

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

Kindly remind @jinge90 for this change. Please remember to update the fortran driver.

Copy link
Contributor

Choose a reason for hiding this comment

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

OK, thanks for the reminder.

@zhaomaosu zhaomaosu requested a review from a team as a code owner May 19, 2025 08:58
Copy link
Contributor

@mdtoguchi mdtoguchi left a comment

Choose a reason for hiding this comment

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

OK for driver

@zhaomaosu zhaomaosu deployed to WindowsCILock May 20, 2025 03:49 — with GitHub Actions Active
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.

4 participants