Skip to content

Update cpuinfo dependency and add cpuinfo_deinitialize() integration#28245

Merged
crvineeth97 merged 5 commits into
microsoft:mainfrom
crvineeth97:vchelur/cpuinfo-memory-leak-patch
Jun 25, 2026
Merged

Update cpuinfo dependency and add cpuinfo_deinitialize() integration#28245
crvineeth97 merged 5 commits into
microsoft:mainfrom
crvineeth97:vchelur/cpuinfo-memory-leak-patch

Conversation

@crvineeth97

@crvineeth97 crvineeth97 commented Apr 27, 2026

Copy link
Copy Markdown
Contributor

Description

Updates the cpuinfo dependency to include the new cpuinfo_deinitialize() API (pytorch/cpuinfo#387) and integrates it into ORT to free heap-allocated globals during DLL unload, fixing memory leaks reported by App Verifier, Valgrind, AddressSanitizer, and LeakSanitizer.

cpuinfo dependency update:

  • Bumped cpuinfo to commit 4628dc06 on pytorch/cpuinfo main which includes the merged cpuinfo_deinitialize() function
  • Updated cmake/deps.txt (SHA1) and cmake/vcpkg-ports/cpuinfo/portfile.cmake (SHA512, HEAD_REF master→main)
  • Removed win_arm_fp16_detection_fallback.patch (merged upstream via Add fallback for ARM Windows fp16 detection. pytorch/cpuinfo#348)
  • Updated patch_vcpkg_arm64ec_support.patch — regenerated for new cpuinfo; still needed (Support ARM64EC vcpkg build pytorch/cpuinfo#324 not yet merged)
  • Updated patch_cpuinfo_h_for_arm64ec.patch — retained, not yet upstream
  • Regenerated fix_missing_sysfs_fallback.patch — updated context lines for new cpuinfo code

ORT integration for cpuinfo_deinitialize():

  • Added Shutdown() method to CPUIDInfo that calls cpuinfo_deinitialize()
  • Added ShutdownCpuInfo() static method with guard against singleton creation during DLL unload
  • Wired ShutdownCpuInfo() into DllMain DLL_PROCESS_DETACH handler
  • InstanceCreated atomic guard prevents singleton creation during DLL unload

Other fixes:

  • Fixed QNN ETW log level from ERROR to WARNING for backend initialization events (reduces excessive telemetry noise)
  • Fixed ep_weight_sharing_ctx_gen build by gating on onnxruntime_USE_CUDA

Motivation and Context

Applications that dynamically load and unload the onnxruntime DLL leave orphaned heap allocations from cpuinfo when the library is unloaded mid-process. These are flagged as memory leaks by App Verifier, Valgrind, AddressSanitizer, and LeakSanitizer.

@devang-ml devang-ml requested a review from edgchen1 April 27, 2026 20:31
Comment thread cmake/patches/cpuinfo/0001-Add-implementation-for-cpuinfo_deinitialize.patch Outdated
@crvineeth97

Copy link
Copy Markdown
Contributor Author

@crvineeth97 please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.

@microsoft-github-policy-service agree [company="{your company}"]

Options:

  • (default - no company specified) I have sole ownership of intellectual property rights to my Submissions and I am not making Submissions in the course of work for my employer.
@microsoft-github-policy-service agree
  • (when company given) I am making Submissions in the course of work for my employer (or my employer has intellectual property rights in my Submissions by contract or applicable law). I have permission from my employer to make Submissions and enter into this Agreement on behalf of my employer. By signing below, the defined term “You” includes me and my employer.
@microsoft-github-policy-service agree company="Microsoft"

Contributor License Agreement

@microsoft-github-policy-service agree company="Microsoft"

@crvineeth97 crvineeth97 force-pushed the vchelur/cpuinfo-memory-leak-patch branch from b478e1c to c53f5d5 Compare May 5, 2026 16:48
@crvineeth97 crvineeth97 force-pushed the vchelur/cpuinfo-memory-leak-patch branch 6 times, most recently from 1f827a7 to 091118f Compare June 12, 2026 19:46
crvineeth97 and others added 3 commits June 12, 2026 14:50
…tx_gen build

- Downgrade QNN ETW profiling mismatch logs from ERROR to VERBOSE to prevent
  excessive telemetry events (~1 billion/week across Windows devices)
- Add bounds checking in GQA attention to prevent size_t underflow when
  seqlens_k contains invalid data (fixes github.com/microsoft/issues/27170)
- Build ep_weight_sharing_ctx_gen for TensorRT, OpenVINO, and VitisAI in
  addition to QNN

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Bump pytorch/cpuinfo to crvineeth97/cpuinfo@df8c6a8 which implements
cpuinfo_deinitialize() to properly free heap-allocated globals. This
prevents memory leak reports from App Verifier, Valgrind, and sanitizers
when ORT is dynamically loaded/unloaded.

ORT integration:
- Add CPUIDInfo::ShutDown() which calls cpuinfo_deinitialize()
- Call ShutdownCpuInfo() from DllMain on DLL_PROCESS_DETACH
- In memleak-check builds, also call shutdown during process termination

The cpuinfo bump also includes upstream fixes that make three ORT patches
redundant (removed):
- patch_vcpkg_arm64ec_support.patch (pytorch/cpuinfo#324)
- win_arm_fp16_detection_fallback.patch (pytorch/cpuinfo#348)
- 0001-Add-implementation-for-cpuinfo_deinitialize.patch

The patch_cpuinfo_h_for_arm64ec.patch is retained as it is not yet
upstream in cpuinfo.

Related: pytorch/cpuinfo#150, pytorch/cpuinfo#387

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@crvineeth97 crvineeth97 force-pushed the vchelur/cpuinfo-memory-leak-patch branch from 091118f to 6300958 Compare June 12, 2026 21:51
@crvineeth97 crvineeth97 changed the title Add support for dealloc of heap memory from CPUInfo library to prevent memory leaks during dynamic unload of ORT Update cpuinfo to include cpuinfo_deinitialize(), fix QNN ETW logging, GQA underflow, and ep_weight_sharing_ctx_gen build Jun 13, 2026
@crvineeth97 crvineeth97 enabled auto-merge (squash) June 13, 2026 01:28
@crvineeth97 crvineeth97 requested a review from edgchen1 June 15, 2026 21:16
Comment thread onnxruntime/core/dll/dllmain.cc
Comment thread onnxruntime/core/providers/qnn/builder/qnn_backend_manager.cc Outdated
Comment thread onnxruntime/core/common/cpuid_info.cc Outdated
Comment thread onnxruntime/contrib_ops/cpu/bert/group_query_attention.cc Outdated
Comment thread cmake/onnxruntime_unittests.cmake
Comment thread onnxruntime/core/common/cpuid_info.h Outdated
@crvineeth97 crvineeth97 changed the title Update cpuinfo to include cpuinfo_deinitialize(), fix QNN ETW logging, GQA underflow, and ep_weight_sharing_ctx_gen build Update cpuinfo dependency and add cpuinfo_deinitialize() integration Jun 18, 2026
@crvineeth97 crvineeth97 requested a review from edgchen1 June 18, 2026 23:22
Comment thread onnxruntime/core/common/cpuid_info.cc Outdated
@crvineeth97 crvineeth97 requested a review from edgchen1 June 24, 2026 21:21
@crvineeth97 crvineeth97 force-pushed the vchelur/cpuinfo-memory-leak-patch branch from 038f00a to cae9388 Compare June 24, 2026 21:24
Comment thread onnxruntime/core/platform/posix/env.cc
@crvineeth97 crvineeth97 merged commit 4ed5a4a into microsoft:main Jun 25, 2026
91 of 92 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.

2 participants