/
PrepackedWeightsContainer.shared.cs
53 lines (44 loc) · 1.66 KB
/
PrepackedWeightsContainer.shared.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// 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
}
}