microsoft / onnxruntime

ONNX Runtime: cross-platform, high performance ML inferencing and training accelerator
https://onnxruntime.ai
MIT License
13.92k stars 2.81k forks source link

Cannot create arena allocator with Environment::CreateAndRegisterAllocator on MAC M2 with clang #21191

Open gsigms opened 1 month ago

gsigms commented 1 month ago

Describe the issue

it does not seem possible to create a CPU arena allocator on mac M2 with clang. When trying to do so, the allocator is set to device because of this Environment::CreateAndRegisterAllocatorhttps://github.com/microsoft/onnxruntime/blob/main/onnxruntime/core/session/environment.cc#L125

it is unclear if this is intended to also apply to arm64 (then the comment is outdated) or if this is unintended.

To reproduce

1- create a cpu arena allocator 2- register it to ort env 3- create session 4- set session option kOrtSessionOptionsConfigUseEnvAllocators to "1" 5- create run with option kOrtRunOptionsConfigEnableMemoryArenaShrinkage "cpu" 6- start run

runs as expected on 64b arch. fails with "The registered allocator for device-id combination is not an arena based allocator: cpu" error on Mac m2

Urgency

No response

Platform

Mac

OS Version

14.5

ONNX Runtime Installation

Built from Source

ONNX Runtime Version or Commit ID

2ac381c55397dffff327cc6efecf6f95a70f90a1

ONNX Runtime API

C++

Architecture

ARM64

Execution Provider

Default CPU

Execution Provider Library Version

No response

hariharans29 commented 1 month ago

It seems like this is a gap in the shared allocator creation code. This is how the CPU EP seems to be dealing with creation of an arena allocator by default- https://github.com/microsoft/onnxruntime/blob/d1ab94c2b0697c0268abca1f096f641675dc3b07/onnxruntime/core/providers/cpu/cpu_execution_provider.cc#L39.

Can you please try replicating that and build from source ? As you rightly guessed, the exact reason why you are hitting that error is because the created shared allocator isn't an arena allocator.

github-actions[bot] commented 3 weeks ago

This issue has been automatically marked as stale due to inactivity and will be closed in 30 days if no further activity occurs. If further support is needed, please provide an update and/or more details.