Skip to content

Update cpuinfo and apply thread-safe deinitialization patch - #32300

Merged
Vineeth Chelur (crvineeth97) merged 16 commits into
microsoft:mainfrom
crvineeth97:update-cpuinfo-deinit-refcounting
Sep 2, 2026
Merged

Update cpuinfo and apply thread-safe deinitialization patch#32300
Vineeth Chelur (crvineeth97) merged 16 commits into
microsoft:mainfrom
crvineeth97:update-cpuinfo-deinit-refcounting

Conversation

@crvineeth97

@crvineeth97 Vineeth Chelur (crvineeth97) commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

Description

  • Update pytorch/cpuinfo from 4628dc060ce4e82345dc166bbac875609db4ff69 to 66ee79c038d70dad9f08705b2c9b3e58f6d8f512, the latest commit on cpuinfo main as of August 27, 2026.
  • Carry the thread-safe, reference-counted initialization and deinitialization changes from pytorch/cpuinfo#400 as one shared ORT patch used by both FetchContent and vcpkg.
  • Reset Windows ARM64 cache-population state on each initialization so repeated DLL load/unload cycles cannot reuse stale cache indices.
  • Scope XNNPACK's cpuinfo references to hardware discovery so XNNPACK-enabled ORT builds do not retain unmatched references during DLL unload.

The cpuinfo patch can be removed after pytorch/cpuinfo#400, including the ARM64 reinitialization fix, is merged and ORT updates to a revision containing it. The XNNPACK compatibility patch can be removed after the corresponding lifecycle fix is available upstream.

Motivation and Context

microsoft/onnxruntime#28245 integrated cpuinfo_deinitialize() after pytorch/cpuinfo#387 added it upstream. That implementation was later reverted by pytorch/cpuinfo#411 because initialization and deinitialization were not safe for multiple consumers.

Pinning the latest cpuinfo main without an ORT-side patch would therefore make cpuinfo_deinitialize() a no-op again. Carrying the corrected implementation keeps ORT independent of the pending upstream review while preserving safe cleanup during dynamic DLL unload.

Testing

  • onnxruntime_cpuinfo_refcount_test covers sequential consumers, concurrent consumers, and reinitialization after final release.
  • Verified this test fails against ORT main's pinned cpuinfo revision (4628dc060ce4e82345dc166bbac875609db4ff69) and passes against the patched revision (66ee79c038d70dad9f08705b2c9b3e58f6d8f512).
  • In XNNPACK-enabled builds, the refcount test initializes XNNPACK and verifies hardware discovery does not retain a cpuinfo reference.
  • onnxruntime_shared_lib_cpuinfo_dlopen_test loads a small DLL containing ORT's CPUIDInfo and cpuinfo, captures a cpuinfo process-heap allocation, unloads the DLL, and verifies that allocation was released.
  • Verified the FetchContent patch sequences for the default, Linux, and Windows ARM64/ARM64EC paths, plus the vcpkg patch sequence, apply with zero rejected hunks.

@crvineeth97 Vineeth Chelur (crvineeth97) changed the title Update cpuinfo with thread-safe deinitialization Update cpuinfo and apply thread-safe deinitialization patch Aug 27, 2026

Copilot AI 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.

Pull request overview

Updates cpuinfo and adds lifecycle patches to support thread-safe initialization, cleanup, and repeated DLL loading.

Changes:

  • Updates cpuinfo and applies reference-counted deinitialization.
  • Balances XNNPACK cpuinfo usage.
  • Adds concurrency and DLL unload regression tests.

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
onnxruntime/test/shared_lib/cpuinfo_refcount_test.cc Tests cpuinfo lifecycle concurrency.
onnxruntime/test/shared_lib/cpuinfo_dlopen_test.cc Tests repeated DLL unloading and heap growth.
cmake/vcpkg-ports/xnnpack/portfile.cmake Applies the XNNPACK lifecycle patch.
cmake/vcpkg-ports/cpuinfo/portfile.cmake Updates and patches cpuinfo.
cmake/patches/xnnpack/release_cpuinfo_after_hardware_config.patch Releases XNNPACK’s cpuinfo references.
cmake/patches/cpuinfo/enable_deinit_refcounting.patch Implements synchronized, reference-counted cleanup.
cmake/patches/.gitattributes Preserves mixed line endings in the cpuinfo patch.
cmake/onnxruntime_unittests.cmake Registers the new tests.
cmake/external/xnnpack.cmake Applies the XNNPACK patch for fetched sources.
cmake/external/onnxruntime_external_deps.cmake Applies the cpuinfo patch for fetched sources.
cmake/deps.txt Updates the pinned cpuinfo revision.

💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread onnxruntime/test/shared_lib/cpuinfo_dlopen_test.cc Outdated
Comment thread cmake/external/onnxruntime_external_deps.cmake Outdated
Comment thread cmake/external/xnnpack.cmake
Comment thread onnxruntime/test/shared_lib/cpuinfo_refcount_test.cc
@crvineeth97
Vineeth Chelur (crvineeth97) marked this pull request as ready for review August 31, 2026 17:35

Copilot AI 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.

Pull request overview

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

Comment thread cmake/patches/cpuinfo/enable_deinit_refcounting.patch

Copilot AI 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.

Pull request overview

Copilot reviewed 13 out of 13 changed files in this pull request and generated no new comments.

Suppressed comments (1)

onnxruntime/test/shared_lib/cpuinfo_dlopen_test.cc:14

  • The test implementation does not match the PR's stated coverage: it loads this custom test DLL once, rather than repeatedly loading/unloading onnxruntime.dll, exercising XNNPACK, or measuring sustained process-heap growth. Either implement the described end-to-end loop or update the PR's Testing section so it does not claim coverage that this test does not provide.
  HMODULE library = LoadLibraryW(ORT_CPUINFO_DLOPEN_TEST_LIBRARY);

Copilot AI 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.

🔵 Needs a closer look

It carries a large unmerged, cross-platform memory-lifecycle patch requiring final human validation.

Review details
  • Files reviewed: 13/13 changed files
  • Comments generated: 1
  • Review effort level: Balanced

Comment thread onnxruntime/test/shared_lib/cpuinfo_dlopen_test.cc
@crvineeth97
Vineeth Chelur (crvineeth97) merged commit d87c7ad into microsoft:main Sep 2, 2026
90 checks passed
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