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

[CoreML] Adapt to MLMultiArray.dataPointer being deprecated #17652

Closed
NickLucche opened this issue Sep 21, 2023 · 6 comments · Fixed by #17726
Closed

[CoreML] Adapt to MLMultiArray.dataPointer being deprecated #17652

NickLucche opened this issue Sep 21, 2023 · 6 comments · Fixed by #17726
Labels
platform:mobile issues related to ONNX Runtime mobile; typically submitted using template

Comments

@NickLucche
Copy link
Contributor

Describe the issue

Hey,

I've seen we're using this MLMultiArray.dataPointer method here https://github.com/microsoft/onnxruntime/blob/main/onnxruntime/core/providers/coreml/model/model.mm#L327 to access the underlying memory before moving that to a C lifetime-managed location.

I noticed this method appears to be deprecated on Apple docs. I am merely speculating, but maybe is it because they support non-contiguously stored MLMultiArrays..?
My question is should we do something about this, like using some of the other non-deprecated element access methods (although it may decrease performance compared to memcpy), or are we sure this won't ever cause issues going forward?

To reproduce

Urgency

No response

Platform

iOS

OS Version

/

ONNX Runtime Installation

Released Package

Compiler Version (if 'Built from Source')

No response

Package Name (if 'Released Package')

None

ONNX Runtime Version or Commit ID

1.16.0

ONNX Runtime API

C++/C

Architecture

ARM64

Execution Provider

CoreML

Execution Provider Library Version

No response

@NickLucche NickLucche added the platform:mobile issues related to ONNX Runtime mobile; typically submitted using template label Sep 21, 2023
@edgchen1
Copy link
Contributor

Good point. It's probably a good idea to move away from the deprecated API in case it gets removed later.

I think maybe we can use getBytesWithHandler: and verify that we have a contiguous layout by checking strides.

@NickLucche
Copy link
Contributor Author

Sounds like a plan, if it's not contiguous we just copy each block into output_buffer right? Or should we like panic as unsupported? I am not sure what was the original intent in moving to non-contiguous by Apple to be honest..
Anyways, will you accept PR on the issue or do you have it covered?

@edgchen1
Copy link
Contributor

Sorry for the delayed response. I think either approach is fine. It may be simpler to just treat a non-contiguous buffer as unsupported initially and we can see if we actually do run into such a case.

PRs are welcome. :)

Otherwise, we can get to it eventually.

@NickLucche
Copy link
Contributor Author

Sure I am on it :)

@github-actions
Copy link
Contributor

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

@github-actions github-actions bot added the stale issues that have not been addressed in a while; categorized by a bot label Oct 28, 2023
@edgchen1
Copy link
Contributor

Update: PR #17726 is open, waiting for input about minimum MacOS version to support.

@edgchen1 edgchen1 removed the stale issues that have not been addressed in a while; categorized by a bot label Oct 30, 2023
fs-eire pushed a commit that referenced this issue Nov 18, 2023
### Description
This PR addresses #17652.
The deprecated `MLMultiArray.dataPointer` is replaced with
`.getBytesWithHandler`, as suggested by the docs.
For now, I am only checking that the output `MLMultiArray` is
contiguous, returning unsupported operation when that is not the case.
I think this is already better than what we have right now, so we can
block unsafe calls to `.dataPointer` (if any..).

I would be happy to implement the handling of the non-contiguous case
(replacing `memcpy` for such cases) as suggested by @edgchen1, but I am
not sure how to reproduce that case to add a corresponding unit-test.
Would we have to define a custom `MLCustomLayer` to get a non-contiguous
output from a model..?

### Motivation and Context
Fix #17652.

---------

Co-authored-by: nicolo-lucchesi <[email protected]>
Co-authored-by: Edward Chen <[email protected]>
kleiti pushed a commit to kleiti/onnxruntime that referenced this issue Mar 22, 2024
…7726)

### Description
This PR addresses microsoft#17652.
The deprecated `MLMultiArray.dataPointer` is replaced with
`.getBytesWithHandler`, as suggested by the docs.
For now, I am only checking that the output `MLMultiArray` is
contiguous, returning unsupported operation when that is not the case.
I think this is already better than what we have right now, so we can
block unsafe calls to `.dataPointer` (if any..).

I would be happy to implement the handling of the non-contiguous case
(replacing `memcpy` for such cases) as suggested by @edgchen1, but I am
not sure how to reproduce that case to add a corresponding unit-test.
Would we have to define a custom `MLCustomLayer` to get a non-contiguous
output from a model..?

### Motivation and Context
Fix microsoft#17652.

---------

Co-authored-by: nicolo-lucchesi <[email protected]>
Co-authored-by: Edward Chen <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
platform:mobile issues related to ONNX Runtime mobile; typically submitted using template
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants