Enable CoreML in the macos package (#10675)

* packaging pipeline change

* Enable CoreML on macos

Co-authored-by: Guoyu Wang <wanggy@outlook.com>
This commit is contained in:
Scott McKay 2022-02-28 09:12:37 +10:00 committed by GitHub
parent b30e0e2283
commit f2ca43fe0d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 23 additions and 13 deletions

View file

@ -814,17 +814,14 @@ namespace Microsoft.ML.OnnxRuntime
[DllImport(NativeLib.DllName, CharSet = CharSet.Ansi)]
public static extern IntPtr /*(OrtStatus*)*/ OrtSessionOptionsAppendExecutionProvider_CPU(IntPtr /*(OrtSessionOptions*) */ options, int use_arena);
#if __MOBILE__
#if __ANDROID__
[DllImport(NativeLib.DllName, CharSet = CharSet.Ansi)]
public static extern IntPtr /*(OrtStatus*)*/ OrtSessionOptionsAppendExecutionProvider_Nnapi(IntPtr /*(OrtSessionOptions*)*/ options, uint nnapi_flags);
#endif
#if __IOS__
#else
// CoreML is available on iOS and macOS so we can't exclude based on __MOBILE__ && __IOS__
[DllImport(NativeLib.DllName, CharSet = CharSet.Ansi)]
public static extern IntPtr /*(OrtStatus*)*/ OrtSessionOptionsAppendExecutionProvider_CoreML(IntPtr /*(OrtSessionOptions*)*/ options, uint coreml_flags);
#endif
#else
// on non-mobile platforms any of these EPs are possible
[DllImport(NativeLib.DllName, CharSet = CharSet.Ansi)]
public static extern IntPtr /*(OrtStatus*)*/ OrtSessionOptionsAppendExecutionProvider_Dnnl(IntPtr /*(OrtSessionOptions*) */ options, int use_arena);

View file

@ -336,7 +336,18 @@ namespace Microsoft.ML.OnnxRuntime
NativeApiStatus.VerifySuccess(
NativeMethods.OrtSessionOptionsAppendExecutionProvider_CoreML(handle, (uint)coremlFlags));
#else
throw new NotSupportedException("The CoreML Execution Provider is not supported in this build");
#if !__ANDROID__
// the CoreML EP entry point is registered unless this is Android but is only valid if this is OSX
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
NativeApiStatus.VerifySuccess(
NativeMethods.OrtSessionOptionsAppendExecutionProvider_CoreML(handle, (uint)coremlFlags));
}
else
#endif
{
throw new NotSupportedException("The CoreML Execution Provider is not supported in this build");
}
#endif
}
@ -739,11 +750,11 @@ namespace Microsoft.ML.OnnxRuntime
}
private ExecutionMode _executionMode = ExecutionMode.ORT_SEQUENTIAL;
#endregion
#endregion
#region Private Methods
#region Private Methods
#if! __MOBILE__
#if !__MOBILE__
// Declared, but called only if OS = Windows.
[DllImport("kernel32.dll")]
private static extern IntPtr LoadLibrary(string dllToLoad);

View file

@ -148,21 +148,21 @@ jobs:
- template: mac-packaging.yml
parameters :
AdditionalBuildFlags : ${{ parameters.AdditionalBuildFlags }} --build_java --build_nodejs --cmake_extra_defines CMAKE_OSX_ARCHITECTURES=arm64
AdditionalBuildFlags : ${{ parameters.AdditionalBuildFlags }} --build_java --build_nodejs --use_coreml --cmake_extra_defines CMAKE_OSX_ARCHITECTURES=arm64
MacosArch: arm64
BuildJava: true
BuildNodejs: true
- template: mac-packaging.yml
parameters :
AdditionalBuildFlags : ${{ parameters.AdditionalBuildFlags }} --cmake_extra_defines CMAKE_OSX_ARCHITECTURES="arm64;x86_64"
AdditionalBuildFlags : ${{ parameters.AdditionalBuildFlags }} --use_coreml --cmake_extra_defines CMAKE_OSX_ARCHITECTURES="arm64;x86_64"
MacosArch: universal2
BuildJava: false
BuildNodejs: false
- template: mac-packaging.yml
parameters :
AdditionalBuildFlags : ${{ parameters.AdditionalBuildFlags }} --build_java --build_nodejs
AdditionalBuildFlags : ${{ parameters.AdditionalBuildFlags }} --build_java --build_nodejs --use_coreml
MacosArch: x86_64
BuildJava: true
BuildNodejs: true

View file

@ -35,6 +35,8 @@ then
dsymutil $BINARY_DIR/$ARTIFACT_NAME/lib/$LIB_NAME -o $BINARY_DIR/$ARTIFACT_NAME/lib/$LIB_NAME.dSYM
strip -S $BINARY_DIR/$ARTIFACT_NAME/lib/$LIB_NAME
ln -s $LIB_NAME $BINARY_DIR/$ARTIFACT_NAME/lib/libonnxruntime.dylib
# copy the CoreML EP header for macOS build (libs with .dylib ext)
cp $SOURCE_DIR/onnxruntime/core/providers/coreml/coreml_execution_provider.h $BINARY_DIR/$ARTIFACT_NAME/include
elif [[ $LIB_NAME == *.so.* ]]
then
ln -s $LIB_NAME $BINARY_DIR/$ARTIFACT_NAME/lib/libonnxruntime.so