Skip to content

[Mobile] [MarshalAs] attribute required to marshal arrays to managed code #26587

@jdluzen

Description

@jdluzen

Describe the issue

I am attempting to run a heavily quantized 4bit Llama 3.2-1b model on Android. Things work fast and great on Win11 x64, but does not run on the Android x64 emulator with either the CPU or NNAPI provider. Both instantly crash without a stacktrace: F/mono-rt (17716): [ERROR] FATAL UNHANDLED EXCEPTION: System.Runtime.InteropServices.MarshalDirectiveException: [MarshalAs] attribute required to marshal arrays to managed code.
Log messages:

11-16 17:10:34.634 I/ExecutionPlan(17917): ExecutionPlan::SimpleBody::finish: compilation finished successfully on nnapi-reference
11-16 17:10:34.683 W/onnxruntime(17917):  [W:onnxruntime:, session_state.cc:1316 VerifyEachNodeIsAssignedToAnEp] Some nodes were not assigned to the preferred execution providers which may or may not have an negative impact on performance. e.g. ORT explicitly assigns shape related ops to CPU to improve perf.
11-16 17:10:34.683 W/onnxruntime(17917):  [W:onnxruntime:, session_state.cc:1318 VerifyEachNodeIsAssignedToAnEp] Rerunning with verbose output on a non-minimal build will show node assignments.
11-16 17:10:37.533 F/mono-rt (17917): [ERROR] FATAL UNHANDLED EXCEPTION: System.Runtime.InteropServices.MarshalDirectiveException: [MarshalAs] attribute required to marshal arrays to managed code.
11-16 17:10:37.533 F/mono-rt (17917): 
11-16 17:10:37.538 F/libc    (17917): FORTIFY: pthread_mutex_lock called on a destroyed mutex (0x7a9834202c38)
11-16 17:10:37.538 F/libc    (17917): FORTIFY: pthread_mutex_lock called on a destroyed mutex (0x7a9834202c38)
11-16 17:10:37.538 F/libc    (17917): Fatal signal 6 (SIGABRT), code -1 (SI_QUEUE) in tid 17955 (hwuiTask1), pid 17917 (<my app>)

Thoughts on how I can start to isolate things to aid in debugging this? I'm hoping it's really as easy as needing a [MarshalAs] attribute somewhere in managed code.

To reproduce

In progress.

Urgency

Fully blocked. No workarounds.

Platform

Android

OS Version

16

ONNX Runtime Installation

Released Package

Compiler Version (if 'Built from Source')

No response

Package Name (if 'Released Package')

onnxruntime-android

ONNX Runtime Version or Commit ID

1.23.2

ONNX Runtime API

C#

Architecture

X64

Execution Provider

NNAPI

Execution Provider Library Version

1.23.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    api:CSharpissues related to the C# APIplatform:mobileissues related to ONNX Runtime mobile; typically submitted using template

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions