Skip to content

Add Xamarin support#9436

Merged
skottmckay merged 7 commits intomasterfrom
skottmckay/AddXamarinSupport_PR
Oct 27, 2021
Merged

Add Xamarin support#9436
skottmckay merged 7 commits intomasterfrom
skottmckay/AddXamarinSupport_PR

Conversation

@skottmckay
Copy link
Copy Markdown
Contributor

Description:
Add Xamarin support to the ORT nuget packages.

  • Update C# code to support Xamarin builds for iOS and Android
    • refactor some things to split out common code
  • include iOS and Android ORT native shared library in native nuget package

Motivation and Context
Enable usage of ORT in Xamarin apps

#We can't fix it because cmake only supports the "TargetFrameworkVersion" property, not "TargetFramework".
set_target_properties(Microsoft.ML.OnnxRuntime Microsoft.ML.OnnxRuntime.InferenceSample Microsoft.ML.OnnxRuntime.Tests
Microsoft.ML.OnnxRuntime.PerfTool PROPERTIES EXCLUDE_FROM_ALL 1)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No point adding these entries just to exclude them.

@@ -0,0 +1,15 @@
---
# clang-format settings for the C# code
BasedOnStyle: Microsoft
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is only used for the C# projects. The .clang-format in the root directory is used for everything else.

</None>
<None Include="$(NativeBuildOutputDir)\onnxruntime.pdb" Condition="'$(IsWindowsBuild)'=='true'And Exists('$(NativeBuildOutputDir)\onnxruntime.pdb')">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<Visible>false</Visible>
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using PreserveNewest as these files are large and the copy was taking minutes on my dev machine every time you wanted to run a test.

EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FasterRcnnSample.Forms", "FasterRcnnSample.Forms\FasterRcnnSample.Forms.csproj", "{51D1A8FB-ADFF-43DE-8215-DB5E86DA4870}"
EndProject
Global
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will most likely move to the inference samples repo once the nuget package is released.

return new DisposableNamedOnnxValue(name, dt, OnnxValueType.ONNX_TYPE_TENSOR, nativeTensorWrapper.ElementType, nativeTensorWrapper);
} catch(Exception e)
} catch(Exception)
{
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixing some warnings.

#region Runtime/Environment API

[UnmanagedFunctionPointer(CallingConvention.Winapi)]
public delegate IntPtr /* OrtStatus* */DOrtCreateEnv(LogLevel default_warning_level, string logId, out IntPtr /*(OrtEnv*)*/ env);
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'WinApi' actually means the appropriate platform specific default.

#if USE_TENSORRT
[Fact]
private void CanRunInferenceOnAModelWithTensorRT()
{
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved to Tests.NetCoreApp

ALLOW_UNICODE_NAMES = NO
OUTPUT_LANGUAGE = English
OUTPUT_TEXT_DIRECTION = None
BRIEF_MEMBER_DESC = YES
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing deprecated options

EXCLUDE_SYMBOLS =
EXAMPLE_PATH = $(ORT_DOXY_SRC)\csharp\sample\Microsoft.ML.OnnxRuntime.InferenceSample\Program.cs
EXAMPLE_PATH =
EXAMPLE_PATTERNS = *
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't have any 'example' code in doxygen comments so this is unnecessary.

displayName: 'Restore nuget packages'
- task: NuGetCommand@2
displayName: Restore NuGet Packages
inputs:
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dotnet.exe doesn't support all the new target frameworks, so use nuget and msbuild.

<PackageId>Microsoft.ML.OnnxRuntime.Managed</PackageId>
<Authors>Microsoft</Authors>
<PackageVersion Condition=" '$(PackageVersion)' == '' ">0.0</PackageVersion>
<PackageVersion Condition=" '$(PackageVersion)' == '' And '$(Configuration)' == 'Debug' ">1.0.0</PackageVersion>
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.

just curious as to why Debug has version 1.0.0?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mikeparker104 do you remember? May have been so the version was valid when testing locally.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was during local testing where the package was being built via the csproj not the normal way via the .proj in the \csharp dir.

{
var opt = new SessionOptions();
opt.AppendExecutionProvider_CoreML(CoreMLFlags.COREML_FLAG_ONLY_ENABLE_DEVICE_WITH_ANE);
Assert.NotNull(opt);
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.

similar to the android test, remove opt != null assertion after opt is used

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will do as separate PR

@skottmckay skottmckay merged commit b5a652c into master Oct 27, 2021
@skottmckay skottmckay deleted the skottmckay/AddXamarinSupport_PR branch October 27, 2021 10:07
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