Skip to content

[Runtime][CoreML] Fix FFI casts in CoreML runtime#19762

Merged
tqchen merged 1 commit into
apache:mainfrom
tlopex:fix-coreml-runtime-ffi-casts
Jun 14, 2026
Merged

[Runtime][CoreML] Fix FFI casts in CoreML runtime#19762
tqchen merged 1 commit into
apache:mainfrom
tlopex:fix-coreml-runtime-ffi-casts

Conversation

@tlopex

@tlopex tlopex commented Jun 14, 2026

Copy link
Copy Markdown
Member

The CoreML runtime still used legacy packed argument conversions, including direct AnyView-to-string conversion, type_code checks, and old tensor handle constants. After the FFI update, enabling USE_COREML failed to compile and the runtime create function was not registered.

This pr updates the runtime to use current PackedArgs cast helpers for strings, indices, and DLTensor arguments, and use the Objective-C NSArray type for CoreML metadata inputs. This restores the CoreML runtime registration when USE_COREML is enabled.

The CoreML runtime still used legacy packed argument conversions, including direct AnyView-to-string conversion, type_code checks, and old tensor handle constants. After the FFI update, enabling USE_COREML failed to compile and the runtime create function was not registered.

Update the runtime to use current PackedArgs cast helpers for strings, indices, and DLTensor arguments, and use the Objective-C NSArray type for CoreML metadata inputs. This restores the CoreML runtime registration when USE_COREML is enabled.

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request refactors the CoreML runtime implementation to utilize the new TVM FFI casting mechanism (args[i].cast<T>()) and simplifies the input/output tensor copying logic. The review feedback highlights several critical safety improvements, specifically recommending that you validate the argument count (args.size()) and the parsed JSON metadata to prevent potential unsigned underflow, out-of-bounds access, or null-pointer crashes.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread src/runtime/extra/contrib/coreml/coreml_runtime.mm
Comment thread src/runtime/extra/contrib/coreml/coreml_runtime.mm
Comment thread src/runtime/extra/contrib/coreml/coreml_runtime.mm
Comment thread src/runtime/extra/contrib/coreml/coreml_runtime.mm
@tqchen tqchen merged commit 07fe3fe into apache:main Jun 14, 2026
10 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