mirror of
https://github.com/saymrwulf/onnxruntime.git
synced 2026-05-21 21:52:11 +00:00
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
53 lines
1.7 KiB
C#
53 lines
1.7 KiB
C#
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
// Licensed under the MIT License.
|
|
|
|
using System;
|
|
using System.Runtime.InteropServices;
|
|
|
|
namespace Microsoft.ML.OnnxRuntime
|
|
{
|
|
|
|
/// <summary>
|
|
/// This class holds pre-packed weights of shared initializers to be shared across sessions using these initializers
|
|
/// and thereby provide memory savings by sharing the same pre-packed versions of these shared initializers
|
|
/// </summary>
|
|
public class PrePackedWeightsContainer : SafeHandle
|
|
{
|
|
|
|
/// <summary>
|
|
/// Constructs an empty PrePackedWeightsContainer
|
|
/// </summary>
|
|
public PrePackedWeightsContainer()
|
|
: base(IntPtr.Zero, true)
|
|
{
|
|
NativeApiStatus.VerifySuccess(NativeMethods.OrtCreatePrepackedWeightsContainer(out handle));
|
|
}
|
|
|
|
/// <summary>
|
|
/// Internal accessor to call native methods
|
|
/// </summary>
|
|
internal IntPtr Pointer { get { return handle; } }
|
|
|
|
/// <summary>
|
|
/// Overrides SafeHandle.IsInvalid
|
|
/// </summary>
|
|
/// <value>returns true if handle is equal to Zero</value>
|
|
public override bool IsInvalid { get { return handle == IntPtr.Zero; } }
|
|
|
|
#region SafeHandle
|
|
/// <summary>
|
|
/// Overrides SafeHandle.ReleaseHandle() to deallocate
|
|
/// a chunk of memory using the specified allocator.
|
|
/// </summary>
|
|
/// <returns>always returns true</returns>
|
|
protected override bool ReleaseHandle()
|
|
{
|
|
NativeMethods.OrtReleasePrepackedWeightsContainer(handle);
|
|
handle = IntPtr.Zero;
|
|
return true;
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
|
|
}
|