Skip to content
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

Fix a data race and add a CMake TSan option. #848

Merged
merged 1 commit into from
Jan 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions shortfin/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,16 @@ option(SHORTFIN_ENABLE_ASAN "Enable ASAN" OFF)
if(SHORTFIN_ENABLE_ASAN)
add_compile_options(-fsanitize=address)
add_link_options(-fsanitize=address)

# Enable more ASAN checks.
add_compile_definitions(IREE_SANITIZER_ADDRESS)
endif()

option(SHORTFIN_ENABLE_TSAN "Enable TSAN" OFF)
Copy link
Member

Choose a reason for hiding this comment

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

Can you add a note here advertising the TSAN option too?

shark-ai/shortfin/README.md

Lines 146 to 148 in 26bb250

* `SHORTFIN_ENABLE_ASAN=ON` : Enables an ASAN build. Requires a Python runtime
setup that is ASAN clean (either by env vars to preload libraries or set
suppressions or a dev build of Python with ASAN enabled).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I haven't tried to run anything else than ctest so I have no experience with Python so I wouldn't know what to write here.... can I just defer to you in a follow-up?

Copy link
Member

Choose a reason for hiding this comment

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

Ah, fair. That is Python-specific and does also rely on this plumbing:

add_env_cmake_setting(cmake_args, "SHORTFIN_ENABLE_ASAN")

I was mainly looking for any developer docs we have that mention ASan, since they could also mention TSan and other sanitizers too.

Fine to just add the option to CMake for now.

if(SHORTFIN_ENABLE_TSAN)
add_compile_options(-fsanitize=thread)
add_link_options(-fsanitize=thread)
add_compile_definitions(IREE_SANITIZER_THREAD)
endif()

# Thread safety annotations: Enabled if the compiler supports it.
check_cxx_compiler_flag("-Wthread-safety" SHORTFIN_HAS_THREAD_SAFETY_ANNOTATIONS)
if(SHORTFIN_HAS_THREAD_SAFETY)
Expand Down
6 changes: 5 additions & 1 deletion shortfin/src/shortfin/support/blocking_executor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,11 @@ int BlockingExecutor::ThreadInstance::RunOnThread() noexcept {
auto status = iree_wait_source_wait_one(signal_transact.await(),
iree_infinite_timeout());
IREE_CHECK_OK(status);
Task exec_task = std::move(current_task);
Task exec_task;
{
iree::slim_mutex_lock_guard g(executor->control_mu_);
exec_task = std::move(current_task);
}
if (exec_task) {
exec_task();
}
Expand Down
Loading