diff --git a/CMakeLists.txt b/CMakeLists.txt index c6d06fca2b1..ad08c72d1ae 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -266,6 +266,18 @@ if(EXECUTORCH_BUILD_PTHREADPOOL) executorch_move_interface_include_directories_to_build_time_only( pthreadpool_interface ) + + if(APPLE) + # Use hidden visibility for pthreadpool on Apple platforms to avoid issues + # with pthreadpool symbols from libtorch_cpu taking precedence over the ones + # from the pthreadpool library statically linked in _portable_lib. The + # pthreadpool public APIs are marked as weak by default on some Apple + # platforms, so setting to hidden visibility works around this by not + # putting the symbol in the indirection table. See + # https://github.com/pytorch/executorch/issues/14321 for more details. + target_compile_options(pthreadpool PRIVATE -fvisibility=hidden) + endif() + install( TARGETS pthreadpool pthreadpool_interface fxdiv EXPORT ExecuTorchTargets diff --git a/extension/threadpool/threadpool.cpp b/extension/threadpool/threadpool.cpp index e9f3b0f5f4a..bebb4745581 100644 --- a/extension/threadpool/threadpool.cpp +++ b/extension/threadpool/threadpool.cpp @@ -44,6 +44,8 @@ size_t ThreadPool::get_thread_count() const { } bool ThreadPool::_unsafe_reset_threadpool(uint32_t new_thread_count) { + ET_LOG(Info, "Resetting threadpool to %u threads.", new_thread_count); + // No need to do anything if the count is same or 0 if (new_thread_count == get_thread_count() || new_thread_count == 0) { return true;